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