Project

General

Profile

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
import {ResultLandingInfo} from '../utils/entities/resultLandingInfo';
7
import {RouterHelper} from '../utils/routerHelper.class';
8

    
9
import {PiwikService} from '../utils/piwik/piwik.service';
10
import {ResultLandingService} from './resultLanding.service';
11
import {SEOService} from '../sharedComponents/SEO/SEO.service';
12
import {HelperFunctions} from '../utils/HelperFunctions.class';
13
import {HelperService} from '../utils/helper/helper.service';
14

    
15

    
16
@Component({
17
  selector: 'result-landing',
18
  templateUrl: 'resultLanding.component.html',
19

    
20
})
21

    
22
export class ResultLandingComponent {
23
  @Input() type: string = "publication";
24
  @Input() piwikSiteId = null;
25
  @Input() communityId = null;
26

    
27
  // Active tab variable for responsiveness
28
  @Input() activeTab: string = "References";
29

    
30
  public resultLandingInfo: ResultLandingInfo;
31
  public id: string;
32
  public title: string;
33

    
34
  // Links for SEO
35
  public linkToLandingPage: string = null;
36
  public linkToSearchPage: string = null;
37

    
38
  // APP BOX variables
39
  public showAllCollectedFrom: boolean = false;
40
  public showAllDownloadFrom: boolean = false;
41

    
42
  public thresholdDescription: number = 270;
43
  public showNumDescription: number = 270;
44

    
45
  // Metrics tab variables
46
  public metricsClicked: boolean;
47
  public viewsFrameUrl: string;
48
  public downloadsFrameUrl: string;
49
  public totalViews: number;
50
  public totalDownloads: number;
51
  public pageViews: number;
52

    
53
  // Custom tab paging variables
54
  public referencesPage: number = 1;
55
  public organizationsPage: number = 1;
56
  public softwarePage: number = 1;
57
  public bioentitiesPage: number = 1;
58
  public openCitationsPage: number = 1;
59
  public pageSize: number = 10;
60

    
61
  // Map counting variables
62
  public bioentitiesNum: number = 0;
63
  public relatedResearchResultsNum: number = 0;
64

    
65
  // Message variables
66
  public warningMessage = "";
67
  public errorMessage = "";
68
  public showLoading: boolean = true;
69

    
70
  public routerHelper: RouterHelper = new RouterHelper();
71

    
72
  private doi: string;
73
  public doiURL: string;
74
  private result;
75
  sub: any;
76
  piwiksub: any;
77
  infoSub: any;
78
  properties: EnvProperties;
79
  public pageContents = null;
80
  public divContents = null;
81

    
82
  constructor(private _resultLaningService: ResultLandingService,
83
              private _piwikService: PiwikService,
84
              private route: ActivatedRoute,
85
              private router: Router,
86
              private _meta: Meta,
87
              private _title: Title,
88
              private _router: Router,
89
              private helper: HelperService,
90
              private seoService: SEOService) {
91
  }
92

    
93
  ngOnInit() {
94
    this.route.data
95
      .subscribe((data: { envSpecific: EnvProperties }) => {
96
        this.properties = data.envSpecific;
97
        //this.getDivContents();
98
        this.getPageContents();
99
        this.doiURL = this.properties.doiURL;
100
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
101

    
102
        this.sub = this.route.queryParams.subscribe(data => {
103
          this.resultLandingInfo = null;
104
          if(this.type == "publication") {
105
            this.updateTitle("Publication");
106
            this.linkToLandingPage = this.properties.searchLinkToPublication;
107
            this.linkToSearchPage = this.properties.searchLinkToPublications;
108
            this.id = data['articleId'];
109
            this.title = "Publication";
110
          } else if(this.type == "dataset") {
111
            this.updateTitle("Dataset");
112
            this.linkToLandingPage = this.properties.searchLinkToDataset;
113
            this.linkToSearchPage = this.properties.searchLinkToDatasets;
114
            this.id = data['datasetId'];
115
            this.title = "Research Data";
116
          } else if(this.type == "software") {
117
            this.updateTitle("Software");
118
            this.linkToLandingPage = this.properties.searchLinkToSoftware;
119
            this.linkToSearchPage = this.properties.searchLinkToSoftwareLanding;
120
            this.id = data['softwareId'];
121
            this.title = "Software";
122
          } else if(this.type == "orp") {
123
            this.updateTitle("Other Research Product");
124
            this.linkToLandingPage = this.properties.searchLinkToOrp;
125
            this.linkToSearchPage = this.properties.searchLinkToOrps;
126
            this.id = data['orpId'];
127
            this.title = "Other Research Product";
128
          }
129
          this.updateDescription("");
130

    
131
          this.metricsClicked = false;
132

    
133
          if (this.id) {
134
            this.getResultLandingInfo(this.id);
135
          } else {
136
            this.showLoading = false;
137

    
138
            this.warningMessage = "No valid ";
139
            if(this.type == "publication" || this.type == "software") {
140
              this.warningMessage += this.type + " ";
141
            } else if(this.type == "dataset") {
142
              this.warningMessage += "research data ";
143
            } else if(this.type == "orp") {
144
              this.warningMessage += "other research product ";
145
            }
146
            this.warningMessage += "id";
147
          }
148

    
149
          this.viewsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"' + this.id + '", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
150
          this.downloadsFrameUrl = this.properties.framesAPIURL + 'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"' + this.id + '", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
151

    
152
          this.scroll();
153
        });
154
      });
155
  }
156

    
157
  private getPageContents() {
158
    this.helper.getPageHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
159
      this.pageContents = contents;
160
    });
161
  }
162

    
163
  private getDivContents() {
164
    this.helper.getDivHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
165
      this.divContents = contents;
166
    });
167
  }
168

    
169
  ngOnDestroy() {
170
    if (this.sub) {
171
      this.sub.unsubscribe();
172
    }
173
    if (this.piwiksub) {
174
      this.piwiksub.unsubscribe();
175
    }
176
    if (this.infoSub) {
177
      this.infoSub.unsubscribe();
178
    }
179
  }
180

    
181
  private getOpenCitations(id: string) {
182
    this._resultLaningService.getOpenCitations(this.id, this.properties).subscribe(
183
      data => {
184
        this.resultLandingInfo.openCitations = data[1];
185
      },
186
      err => {
187
        this.handleError("Error getting open citation for "+this.type+" with id: " + this.id, err);
188
      }
189
    );
190
  }
191

    
192
  private getResultLandingInfo(id: string) {
193
    this.warningMessage = '';
194
    this.errorMessage = '';
195
    this.showLoading = true;
196

    
197
    this.resultLandingInfo = null;
198

    
199
    this.infoSub = this._resultLaningService.getResultLandingInfo(this.id, this.type, this.properties).subscribe(
200
      data => {
201
        this.resultLandingInfo = data;
202
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.linkToLandingPage + this.resultLandingInfo.record["result"]["header"]["dri:objIdentifier"]);
203
        if ((this.type == "publication") && (this.properties.environment == "beta" || this.properties.environment == "development") && (typeof document !== 'undefined')) {
204
          this.getOpenCitations(this.id);
205
        }
206

    
207
        if (this.resultLandingInfo.title) {
208
          this.updateTitle(this.resultLandingInfo.title);
209
          this.updateDescription((this.resultLandingInfo.description ? (this.resultLandingInfo.description) : ("," + this.resultLandingInfo.title)));
210
        }
211
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
212
          this.piwiksub = this._piwikService.trackView(this.properties, this.resultLandingInfo.title/*.name*/, this.piwikSiteId).subscribe();
213
        }
214

    
215
        if(this.type == "publication") {
216
          let bioentitiesNum = 0;
217
          if (this.resultLandingInfo.bioentities != undefined) {
218
            this.resultLandingInfo.bioentities.forEach(function (value, key, map) {
219
              bioentitiesNum += value.size;
220
            });
221
          }
222
          this.bioentitiesNum = bioentitiesNum;
223
        }
224

    
225
        let relatedResearchResultsNum = 0;
226
        if (this.resultLandingInfo.relatedResearchResults != undefined) {
227
          this.resultLandingInfo.relatedResearchResults.forEach(function (value, key, map) {
228
            relatedResearchResultsNum += value.length;
229
          });
230
        }
231
        this.relatedResearchResultsNum = relatedResearchResultsNum;
232

    
233
        this.result = {
234
          id: this.id,
235
          type: this.type,
236
          source: "openaire",
237
          title: this.resultLandingInfo.title,
238
          url: '',
239
          result: '',
240
          accessRights: this.resultLandingInfo.accessMode,
241
          embargoEndDate: ''
242
        };
243

    
244
        if (this.resultLandingInfo.identifiers != undefined && this.resultLandingInfo.identifiers.has('doi')) {
245
          this.doi = this.resultLandingInfo.identifiers.get('doi')[0];
246
        }
247

    
248
        this.showLoading = false;
249

    
250
        if (this.resultLandingInfo.references) {
251
          this.activeTab = "References";
252
        } else if (this.resultLandingInfo.relatedResearchResults) {
253
          this.activeTab = "Related Research Results";
254
        } else if (this.resultLandingInfo.similarResearchResults) {
255
          this.activeTab = "Similar Research Results";
256
        } else if (this.resultLandingInfo.organizations) {
257
          this.activeTab = "Related Organizations";
258
        } else if (this.resultLandingInfo.bioentities) {
259
          this.activeTab = "Bioentities";
260
        } else if (this.resultLandingInfo.software) {
261
          this.activeTab = "Software";
262
        } else {
263
          this.activeTab = "Metrics";
264
          this.metricsClicked = true;
265
        }
266
      },
267
      err => {
268
        this.handleError("Error getting "+this.type+" for id: " + this.id, err);
269

    
270
        if(this.type == "publication" || this.type == "software") {
271
          this.errorMessage = 'No "+this.type+" found';
272
        } else if(this.type == "dataset") {
273
          this.errorMessage += "No research data found";
274
        } else if(this.type == "orp") {
275
          this.errorMessage += "No research product found";
276
        }
277
        this.showLoading = false;
278
        this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.linkToSearchPage);
279
      }
280
    );
281
  }
282

    
283
  public metricsResults($event) {
284
    this.totalViews = $event.totalViews;
285
    this.totalDownloads = $event.totalDownloads;
286
    this.pageViews = $event.pageViews;
287
  }
288

    
289
  public buildCurationTooltip(): string {
290
    let tooltipContent: string = "<div class='uk-margin uk-padding-small'>";
291

    
292
    tooltipContent += "<h4>Record in preview</h4>";
293
    tooltipContent += "<p>Bibliographic record accepted by the system, but not yet processed by <br> OpenAIRE tools for information quality improvement and de-duplication</p>";
294

    
295
    tooltipContent += "</div>";
296
    return tooltipContent;
297
  }
298

    
299
  private updateDescription(description: string) {
300
    this._meta.updateTag({content: description}, "name='description'");
301
    this._meta.updateTag({content: description}, "property='og:description'");
302
  }
303

    
304
  private updateTitle(title: string) {
305
    var _prefix = "";
306
    if(!this.communityId) {
307
      _prefix = "OpenAIRE | ";
308
    }
309
    var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
310
    this._title.setTitle(_title);
311
    this._meta.updateTag({content: _title}, "property='og:title'");
312
  }
313

    
314
  private updateUrl(url: string) {
315
    this._meta.updateTag({content: url}, "property='og:url'");
316
  }
317

    
318
  public totalPages(totalResults: number): number {
319
    let totalPages: any = totalResults / this.pageSize;
320
    if (!(Number.isInteger(totalPages))) {
321
      totalPages = (parseInt(totalPages, this.pageSize) + 1);
322
    }
323
    return totalPages;
324
  }
325

    
326
  public updateReferencesPage($event) {
327
    this.referencesPage = $event.value;
328
  }
329

    
330
  public updateOrganizationsPage($event) {
331
    this.organizationsPage = $event.value;
332
  }
333

    
334
  public updateSoftwarePage($event) {
335
    this.softwarePage = $event.value;
336
  }
337

    
338
  public updateBioentitiesPage($event) {
339
    this.bioentitiesPage = $event.value;
340
  }
341

    
342
  public updateOpenCitationsPage($event) {
343
    this.openCitationsPage = $event.value;
344
  }
345

    
346
  public keysToArray(bioentities: Map<string, string>): string[] {
347
    let keys: string[] = [];
348
    bioentities.forEach(function (value, key, map) {
349
      keys.push(key);
350
    });
351
    return keys;
352
  }
353

    
354
  public getKeys(map) {
355
    return Array.from(map.keys());
356
  }
357

    
358
  public scroll() {
359
    HelperFunctions.scroll();
360
  }
361

    
362
  private handleError(message: string, error) {
363
    if(this.type == "publication") {
364
      console.error("Publication Landing Page: " + message, error);
365
    } else if(this.type == "dataset") {
366
      console.error("Research Data Landing Page: " + message, error);
367
    } else if(this.type == "software") {
368
      console.error("Software Landing Page: " + message, error);
369
    } else if(this.type == "orp") {
370
      console.error("Other Research Product Landing Page: " + message, error);
371
    } else {
372
      console.error("Landing Page: " + message, error);
373
    }
374
  }
375

    
376
  isRouteAvailable(routeToCheck: string) {
377
    for (let i = 0; i < this.router.config.length; i++) {
378
      let routePath: string = this.router.config[i].path;
379
      if (routePath == routeToCheck) {
380
        return true;
381
      }
382
    }
383
    return false;
384
  }
385
}
(2-2/4)