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