1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {Meta, Title} from '@angular/platform-browser';
|
4
|
|
5
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
6
|
|
7
|
import {HtmlProjectReportService} from './htmlProjectReport.service';
|
8
|
import {ProjectService} from '../project/project.service';
|
9
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
10
|
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
|
11
|
import {HelperService} from "../../utils/helper/helper.service";
|
12
|
import {Subscriber} from "rxjs";
|
13
|
import {properties} from "../../../../environments/environment";
|
14
|
|
15
|
declare var UIkit: any;
|
16
|
|
17
|
@Component({
|
18
|
selector: 'htmlProjectReport',
|
19
|
template: `
|
20
|
<div id="tm-main" class=" uk-section uk-padding-remove-top tm-middle">
|
21
|
<div uk-grid>
|
22
|
<div class="tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first ">
|
23
|
<helper *ngIf="pageContents && pageContents['top'] && pageContents['top'].length > 0"
|
24
|
[texts]="pageContents['top']" styleName="uk-width-1-1"></helper>
|
25
|
<div class="uk-container uk-margin-top uk-width-1-1">
|
26
|
<div *ngIf="warningMessage" class="uk-alert uk-alert-warning" role="alert">{{warningMessage}}</div>
|
27
|
<div [style.display]="showLoading ? 'inline' : 'none'"
|
28
|
class="uk-animation-fade uk-margin-large-top uk-width-1-1" role="alert"><span
|
29
|
class="loading-gif uk-align-center"></span></div>
|
30
|
|
31
|
<div *ngIf="!showLoading && !warningMessage">
|
32
|
<div *ngIf="header1" class="uk-h4 uk-text-bold ">{{header1}}</div>
|
33
|
<div *ngIf="header1 || htmlResult" class=" ">{{header2}}</div>
|
34
|
|
35
|
<div class="uk-clearfix uk-margin-bottom">
|
36
|
<button *ngIf="htmlResult" class="uk-icon-clipboard uk-button uk-button-primary clipBtn uk-float-right"
|
37
|
(click)="copied()">
|
38
|
Copy to clipboard
|
39
|
</button>
|
40
|
</div>
|
41
|
<!--div class="uk-panel-scrollable custom-html-table-height" *ngIf="htmlResult" id="clipboard" [innerHTML]="htmlResult"></div-->
|
42
|
<div class="uk-overflow-auto custom-html-table-height" *ngIf="htmlResult" id="clipboard"
|
43
|
[innerHTML]="htmlResult"></div>
|
44
|
|
45
|
<div *ngIf="errorMessage" class="uk-alert uk-alert-danger" role="alert">{{errorMessage}}</div>
|
46
|
</div>
|
47
|
</div>
|
48
|
<helper *ngIf="pageContents && pageContents['bottom'] && pageContents['bottom'].length > 0"
|
49
|
[texts]="pageContents['bottom']" styleName="uk-width-1-1"></helper>
|
50
|
</div>
|
51
|
</div>
|
52
|
</div>
|
53
|
|
54
|
`
|
55
|
})
|
56
|
export class HtmlProjectReportComponent {
|
57
|
@Input() piwikSiteId = null;
|
58
|
@Input() communityId = null;
|
59
|
private projectId: string;
|
60
|
private totalResults: number = 10;
|
61
|
private resultsType: string = "publication";
|
62
|
|
63
|
public header1: string = "";
|
64
|
public header2: string = "";
|
65
|
public htmlResult: string = "";
|
66
|
|
67
|
subscriptions = [];
|
68
|
|
69
|
public warningMessage: string = "";
|
70
|
public errorMessage: string = "";
|
71
|
public showLoading: boolean = true;
|
72
|
properties: EnvProperties;
|
73
|
public pageContents = null;
|
74
|
public divContents = null;
|
75
|
|
76
|
constructor(private route: ActivatedRoute,
|
77
|
private htmlService: HtmlProjectReportService,
|
78
|
private _piwikService: PiwikService,
|
79
|
private _projectService: ProjectService,
|
80
|
private _meta: Meta,
|
81
|
private _title: Title,
|
82
|
private _router: Router,
|
83
|
private helper: HelperService,
|
84
|
private seoService: SEOService) {
|
85
|
}
|
86
|
|
87
|
ngOnInit() {
|
88
|
|
89
|
this.properties = properties;
|
90
|
//this.getDivContents();
|
91
|
this.getPageContents();
|
92
|
this.updateUrl(this.properties.domain + this.properties.baseLink + this._router.url);
|
93
|
this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this._router.url);
|
94
|
|
95
|
|
96
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
97
|
this.projectId = params['projectId'];
|
98
|
|
99
|
if (params['size'] == parseInt(params['size'], 10)) {
|
100
|
this.totalResults = params['size'];
|
101
|
} else {
|
102
|
this.showLoading = false;
|
103
|
this.warningMessage = "Requested size is not an integer";
|
104
|
}
|
105
|
|
106
|
if (params['type'] && (params['type'] == "publication" || params['type'] == "dataset" || params['type'] == "software" || params['type'] == "other")) {
|
107
|
if (params['type'] == "publication") {
|
108
|
this.resultsType = 'publication';
|
109
|
} else if (params['type'] == "dataset") {
|
110
|
this.resultsType = 'research data';
|
111
|
} else if (params['type'] == "software") {
|
112
|
this.resultsType = 'software';
|
113
|
} else if (params['type'] == "other") {
|
114
|
this.resultsType = "other research product";
|
115
|
}
|
116
|
|
117
|
var title = "Project's " + this.resultsType + " report";
|
118
|
var description = "project, project " + this.resultsType + " report, funding, open access, publications, research data, software, other research products";
|
119
|
this.updateTitle(title);
|
120
|
this.updateDescription(description);
|
121
|
|
122
|
|
123
|
} else {
|
124
|
this.showLoading = false;
|
125
|
this.warningMessage = "Requested type should be publication or research data or software or other research product";
|
126
|
}
|
127
|
|
128
|
//showLoading is true if no warnings
|
129
|
if (this.showLoading) {
|
130
|
if (this.projectId) {
|
131
|
this.createHeaders();
|
132
|
} else {
|
133
|
this.showLoading = false;
|
134
|
this.warningMessage = "No valid project id";
|
135
|
}
|
136
|
}
|
137
|
}));
|
138
|
}
|
139
|
|
140
|
private getPageContents() {
|
141
|
if(this.communityId) {
|
142
|
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
143
|
this.pageContents = contents;
|
144
|
}));
|
145
|
}
|
146
|
}
|
147
|
|
148
|
private getDivContents() {
|
149
|
if(this.communityId) {
|
150
|
this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
|
151
|
this.divContents = contents;
|
152
|
}));
|
153
|
}
|
154
|
}
|
155
|
|
156
|
ngOnDestroy() {
|
157
|
this.subscriptions.forEach(subscription => {
|
158
|
if (subscription instanceof Subscriber) {
|
159
|
subscription.unsubscribe();
|
160
|
}
|
161
|
});
|
162
|
}
|
163
|
|
164
|
private createHeaders() {
|
165
|
this.subscriptions.push(this._projectService.getHTMLInfo(this.projectId, this.properties).subscribe(
|
166
|
data => {
|
167
|
this.createHeader1(data);
|
168
|
if (data.acronym) {
|
169
|
this.updateTitle(data.acronym + " " + this.resultsType + " report");
|
170
|
} else if (data.title) {
|
171
|
this.updateTitle(data.title + " " + this.resultsType + " report");
|
172
|
}
|
173
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
174
|
this.subscriptions.push(this._piwikService.trackView(this.properties, ((data.acronym) ? data.acronym : data.title) + " " + this.resultsType + " report", this.piwikSiteId).subscribe());
|
175
|
}
|
176
|
},
|
177
|
err => {
|
178
|
this.handleError("Error getting html information for project id: " + this.projectId, err);
|
179
|
//console.log(err);
|
180
|
this.createClipboard();
|
181
|
}
|
182
|
));
|
183
|
|
184
|
if (this.resultsType == "publication") {
|
185
|
this.header2 += this.totalResults.toLocaleString('en-US') + " publications";
|
186
|
} else if (this.resultsType == "research data") {
|
187
|
this.header2 += this.totalResults.toLocaleString('en-US') + " research data";
|
188
|
} else if (this.resultsType == "software") {
|
189
|
this.header2 += this.totalResults.toLocaleString('en-US') + " software";
|
190
|
} else if (this.resultsType == "other research product") {
|
191
|
this.header2 += this.totalResults.toLocaleString('en-US') + " other";
|
192
|
}
|
193
|
}
|
194
|
|
195
|
private createClipboard() {
|
196
|
let intro: string = '<!doctype html>';
|
197
|
intro += '<html lang="en-gb" dir="ltr" vocab="http://schema.org/">';
|
198
|
intro += '<head>';
|
199
|
intro += '<title>' + this.header1 + '</title>'
|
200
|
intro += '</head>';
|
201
|
|
202
|
if (typeof window !== 'undefined') {
|
203
|
this.subscriptions.push(this.htmlService.getHTML(this.projectId, this.resultsType, this.properties.csvAPIURL).subscribe(
|
204
|
data => {
|
205
|
//let body: string = intro+'<body><h1>'+this.header1+'</h1><h2>'+this.header2+'</h2>'+data+'</body></html>';
|
206
|
let body: string = intro + '<body><h1>' + this.header1 + '</h1><h2>' + this.header2 + '</h2>';
|
207
|
body += "<table><thead><tr> <th>Title</th><th>Authors</th><th>Publication Year</th><th>DOI</th><th>Permanent Identifier</th><th>Publication type</th><th>Journal</th><th>Project Name (GA Number)</th><th>Access Mode</th></tr></thead><tbody>" + data + "</tbody></table>";
|
208
|
body += '</body></html>';
|
209
|
|
210
|
//this.htmlResult = data;
|
211
|
this.htmlResult = "<table><thead><tr> <th>Title</th><th>Authors</th><th>Publication Year</th><th>DOI</th><th>Permanent Identifier</th><th>Publication type</th><th>Journal</th><th>Project Name (GA Number)</th><th>Access Mode</th></tr></thead><tbody>" + data + "</tbody></table>";
|
212
|
|
213
|
let clipboard;
|
214
|
let Clipboard;
|
215
|
Clipboard = require('clipboard');
|
216
|
clipboard = new Clipboard('.clipBtn', {
|
217
|
/*target: function(trigger) {
|
218
|
return document.getElementById("clipboard");
|
219
|
}*/
|
220
|
text: function (trigger) {
|
221
|
return body;//document.getElementById("clipboard").getAttribute('innerHTML');//"aaaa"+tmp+"oo";
|
222
|
}
|
223
|
});
|
224
|
|
225
|
this.showLoading = false;
|
226
|
},
|
227
|
err => {
|
228
|
//console.log(err);
|
229
|
this.handleError("Error getting html for id: " + this.projectId, err);
|
230
|
|
231
|
this.errorMessage = 'Service not available';
|
232
|
this.showLoading = false;
|
233
|
}
|
234
|
));
|
235
|
}
|
236
|
}
|
237
|
|
238
|
createHeader1(data: { "title": string, "acronym": string, "callIdentifier": string }) {
|
239
|
if (this.resultsType == "publication") {
|
240
|
this.header1 += "Publications";
|
241
|
} else if (this.resultsType == "research data") {
|
242
|
this.header1 += "Research Data";
|
243
|
} else if (this.resultsType == "software") {
|
244
|
this.header1 += "Software";
|
245
|
} else if (this.resultsType == "other research product") {
|
246
|
this.header1 += "Other Research Products";
|
247
|
}
|
248
|
|
249
|
if (data != undefined) {
|
250
|
if (data.title != undefined && data.title != "") {
|
251
|
this.header1 += data.title;
|
252
|
}
|
253
|
if ((data.title != undefined && data.title != "") &&
|
254
|
((data.acronym != undefined && data.acronym != "") ||
|
255
|
(data.callIdentifier != undefined && data.callIdentifier != ""))) {
|
256
|
this.header1 += "(";
|
257
|
}
|
258
|
if (data.acronym != undefined && data.acronym != "") {
|
259
|
this.header1 += data.acronym + " - ";
|
260
|
}
|
261
|
if (data.callIdentifier != undefined && data.callIdentifier != "") {
|
262
|
this.header1 += data.callIdentifier;
|
263
|
}
|
264
|
if ((data.title != undefined && data.title != "") &&
|
265
|
((data.acronym != undefined && data.acronym != "") ||
|
266
|
(data.callIdentifier != undefined && data.callIdentifier != ""))) {
|
267
|
this.header1 += ")";
|
268
|
}
|
269
|
}
|
270
|
|
271
|
this.createClipboard();
|
272
|
}
|
273
|
|
274
|
public copied() {
|
275
|
UIkit.notification({
|
276
|
message: '<strong>Raw html is copied. Please paste it on an html file.<strong>',
|
277
|
status: 'success',
|
278
|
timeout: 3000,
|
279
|
pos: 'top-center'
|
280
|
});
|
281
|
}
|
282
|
|
283
|
private updateDescription(description: string) {
|
284
|
this._meta.updateTag({content: description}, "name='description'");
|
285
|
this._meta.updateTag({content: description}, "property='og:description'");
|
286
|
}
|
287
|
|
288
|
private updateTitle(title: string) {
|
289
|
var _prefix = "";
|
290
|
if(!this.communityId) {
|
291
|
_prefix = "OpenAIRE | ";
|
292
|
}
|
293
|
var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
|
294
|
this._title.setTitle(_title);
|
295
|
this._meta.updateTag({content: _title}, "property='og:title'");
|
296
|
}
|
297
|
|
298
|
private updateUrl(url: string) {
|
299
|
this._meta.updateTag({content: url}, "property='og:url'");
|
300
|
}
|
301
|
|
302
|
private handleError(message: string, error) {
|
303
|
console.error("Html Project Report Page: " + message, error);
|
304
|
}
|
305
|
}
|