Project

General

Profile

1
import {Component, ViewChild}         from '@angular/core';
2
import {ElementRef, Input}            from '@angular/core';
3
import {ActivatedRoute, Router}       from '@angular/router';
4
import {Title, Meta}                  from '@angular/platform-browser';
5

    
6
import {Observable}                   from 'rxjs/Observable';
7

    
8
import {EnvProperties}                from '../../utils/properties/env-properties';
9
import {PublicationInfo}              from '../../utils/entities/publicationInfo';
10
import {RouterHelper}                 from '../../utils/routerHelper.class';
11

    
12
import {PiwikService}                 from '../../utils/piwik/piwik.service';
13
import {PublicationService}           from './publication.service';
14
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
15

    
16

    
17
@Component({
18
    selector: 'publication',
19
    templateUrl: 'publication.component.html',
20

    
21
})
22

    
23
export class PublicationComponent {
24
  @Input() piwikSiteId = null;
25
  public publicationInfo: PublicationInfo;
26
  public articleId: string;
27

    
28
  // APP BOX variables
29
  public showAllCollectedFrom: boolean = false;
30
  public showAllDownloadFrom: boolean = false;
31

    
32
  // Metrics tab variables
33
  public metricsClicked: boolean;
34
  public viewsFrameUrl: string;
35
  public downloadsFrameUrl: string;
36
  public totalViews: number;
37
  public totalDownloads: number;
38
  public pageViews: number;
39

    
40
  // Custom tab paging variables
41
  public referencesPage: number = 1;
42
  public organizationsPage: number = 1;
43
  public softwarePage: number = 1;
44
  public bioentitiesPage: number = 1;
45
  public openCitationsPage: number = 1;
46
  public pageSize: number = 10;
47
  /*
48
    public startt: number = 0;
49
    public stopp: number = 0;
50
  */
51

    
52
  // Active tab variable for responsiveness
53
  public activeTab: string = "References";
54

    
55
  // Map counting variables
56
  public bioentitiesNum: number = 0;
57
  public relatedResearchResultsNum: number = 0;
58

    
59
  // Message variables
60
  public warningMessage = "";
61
  public errorMessage = "";
62
  public showLoading: boolean = true;
63

    
64
  public routerHelper:RouterHelper = new RouterHelper();
65

    
66
  private doi: string;
67
  public doiURL: string;
68
  private result;
69
  sub: any; piwiksub: any; infoSub: any;
70
  properties:EnvProperties;
71

    
72
  constructor ( private element: ElementRef,
73
                private _publicationService: PublicationService,
74
                private _piwikService:PiwikService,
75
                private route: ActivatedRoute,
76
                private _meta: Meta,
77
                private _title: Title,
78
                private _router: Router,
79
              private seoService: SEOService) {
80
  }
81

    
82
  ngOnInit() {
83
    this.route.data
84
      .subscribe((data: { envSpecific: EnvProperties }) => {
85
         this.properties = data.envSpecific;
86
         this.doiURL = this.properties.doiURL;
87
         this.updateUrl(data.envSpecific.baseLink+this._router.url);
88

    
89
      });
90
       this.sub =  this.route.queryParams.subscribe(data => {
91
           this.publicationInfo = null;
92
           this.updateTitle("Publication");
93
           this.updateDescription("");
94
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
95
          this.articleId = data['articleId'];
96

    
97
          this.metricsClicked = false;
98

    
99
          if(this.articleId){
100

    
101
              this.getPublicationInfo(this.articleId);
102
              // if (typeof document !== 'undefined') {
103
              //   switcher(UIkit);
104
              // }
105
          }else{
106
              this.showLoading = false;
107
              this.warningMessage="No valid publication id";
108
          }
109

    
110
          this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"'+this.articleId+'", "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';
111

    
112
          this.downloadsFrameUrl =this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"'+this.articleId+'", "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';
113

    
114
          if (typeof document !== 'undefined') {
115
             this.element.nativeElement.scrollIntoView();
116
          }
117
    });
118
  }
119

    
120
    ngOnDestroy() {
121
        if(this.sub){
122
          this.sub.unsubscribe();
123
        }
124
        if(this.piwiksub){
125
          this.piwiksub.unsubscribe();
126
        }
127
        if(this.infoSub) {
128
          this.infoSub.unsubscribe();
129
        }
130
    }
131

    
132
    private getOpenCitations(id: string) {
133
      this._publicationService.getOpenCitations(this.articleId, this.properties).subscribe(
134
        data => {
135
          this.publicationInfo.openCitations = data[1];
136
        },
137
        err => {
138
          //console.log(err);
139
          this.handleError("Error getting open citation for publication with id: "+this.articleId, err);
140
        }
141
      );
142
    }
143

    
144
    private getPublicationInfo(id:string) {
145
        this.warningMessage = '';
146
        this.errorMessage=""
147
        this.showLoading = true;
148

    
149
        this.publicationInfo = null;
150

    
151
        this.infoSub = this._publicationService.getPublicationInfo(this.articleId, this.properties).subscribe(
152
            data => {
153
                this.publicationInfo = data;
154

    
155
                if((this.properties.environment == "beta") && (typeof document !== 'undefined')) {
156
                  this.getOpenCitations(this.articleId);
157
                }
158

    
159
                // this.result = []
160
                // this.result = {id: id, type :"dataset", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: this.publicationInfo.bestaccessright, embargoEndDate: ''};
161
                /*if(this.publicationInfo.title.name != undefined && this.publicationInfo.title.name!= ''){
162
                  this.updateTitle(this.publicationInfo.title.name);
163
                  this.updateDescription("Dataset, search, repositories, open access,"+this.publicationInfo.title.name);
164
                }*/
165
                if(this.publicationInfo.title){
166
                  this.updateTitle(this.publicationInfo.title);
167
                  this.updateDescription((this.publicationInfo.description?(this.publicationInfo.description):(","+this.publicationInfo.title)));
168
                }
169
                if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
170
                  this.piwiksub =  this._piwikService.trackView(this.properties, this.publicationInfo.title/*.name*/, this.piwikSiteId).subscribe();
171
                }
172

    
173
                let bioentitiesNum = 0;
174
                if(this.publicationInfo.bioentities != undefined) {
175
                    this.publicationInfo.bioentities.forEach(function (value, key, map) {
176
                        bioentitiesNum += value.size;
177
                    });
178
                }
179
                this.bioentitiesNum = bioentitiesNum;
180

    
181
                let relatedResearchResultsNum = 0;
182
                if(this.publicationInfo.relatedResearchResults != undefined) {
183
                    this.publicationInfo.relatedResearchResults.forEach(function (value, key, map) {
184
                        relatedResearchResultsNum += value.length;
185
                    });
186
                }
187
                this.relatedResearchResultsNum = relatedResearchResultsNum;
188

    
189
                this.result = {id: this.articleId, type :"publication", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: /*this.publicationInfo.title.accessMode*/this.publicationInfo.accessMode, embargoEndDate: ''};
190
                // this.result.push(result_);
191

    
192
                if(this.publicationInfo.identifiers != undefined && this.publicationInfo.identifiers.has('doi')) {
193
                    this.doi = this.publicationInfo.identifiers.get('doi')[0];
194
                }
195

    
196
                this.showLoading = false;
197

    
198
                if(this.publicationInfo.references) {
199
                  this.activeTab = "References";
200
                } else if(this.publicationInfo.relatedResearchResults) {
201
                  this.activeTab = "Related Research Results";
202
                } else if(this.publicationInfo.similarResearchResults) {
203
                  this.activeTab = "Similar Research Results";
204
                } else if(this.publicationInfo.organizations) {
205
                  this.activeTab = "Related Organizations";
206
                } else if(this.publicationInfo.bioentities) {
207
                  this.activeTab = "bioentities";
208
                } else if(this.publicationInfo.software) {
209
                  this.activeTab = "Software";
210
                } else {
211
                  this.activeTab = "Metrics";
212
                  this.metricsClicked = true;
213
                }
214
            },
215
            err => {
216
              //console.log(err);
217
              this.handleError("Error getting publication for id: "+this.articleId, err);
218

    
219
              this.errorMessage = 'No publication found';
220
              this.showLoading = false;
221
            }
222
      );
223
    }
224

    
225
    public metricsResults($event) {
226
      this.totalViews = $event.totalViews;
227
      this.totalDownloads = $event.totalDownloads;
228
      this.pageViews = $event.pageViews;
229
    }
230

    
231
    public buildCurationTooltip() {
232
        let tooltipContent: string = "<div class='uk-margin uk-padding-small'>";
233

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

    
237
        return tooltipContent+= "</div>";
238
    }
239

    
240
    private updateDescription(description:string){
241
      this._meta.updateTag({content:description},"name='description'");
242
      this._meta.updateTag({content:description},"property='og:description'");
243
    }
244
    private updateTitle(title:string){
245
      var _prefix ="OpenAIRE | ";
246
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
247
      this._title.setTitle(title);
248
      this._meta.updateTag({content:title},"property='og:title'");
249
    }
250

    
251
    private updateUrl(url:string){
252
      this._meta.updateTag({content:url},"property='og:url'");
253
    }
254

    
255
    public totalPages(totalResults: number): number {
256
      let totalPages:any = totalResults/this.pageSize;
257
      if(!(Number.isInteger(totalPages))) {
258
          totalPages = (parseInt(totalPages, this.pageSize) + 1);
259
      }
260
      return totalPages;
261
    }
262

    
263
    public updateReferencesPage($event) {
264
      this.referencesPage = $event.value;
265
    }
266

    
267
    public updateOrganizationsPage($event) {
268
      this.organizationsPage = $event.value;
269
    }
270

    
271
    public updateSoftwarePage($event) {
272
      this.softwarePage = $event.value;
273
    }
274

    
275
    public updateBioentitiesPage($event) {
276
      this.bioentitiesPage = $event.value;
277
    }
278

    
279
    public updateOpenCitationsPage($event) {
280
      this.openCitationsPage = $event.value;
281
    }
282

    
283
    public keysToArray(bioentities: Map<string, string>) : string[] {
284
      let keys: string[] = [];
285
      bioentities.forEach(function (value, key, map) {
286
        keys.push(key);
287
      });
288
      return keys;
289
    }
290
    public getKeys( map) {
291
      return Array.from(map.keys());
292
    }
293
/*
294
    start(i: number, bioentitiesPage: number) {
295
      let sum = 0;
296
      let index=0;
297
      let retValue = 0;
298
      let valuesToPage = this.pageSize*bioentitiesPage;
299
      let valuesToPreviousPage = valuesToPage - this.pageSize;
300

    
301
      if(bioentitiesPage == 1) {
302
        return 0;
303
      }
304

    
305
      this.publicationInfo.bioentities.forEach(function (value, key, map) {
306
        sum += map.get(key).size;
307

    
308
        if(index == i) {
309
          if(sum <= valuesToPreviousPage) {
310
            retValue =  0;
311
          } else if((sum-map.get(key).size) >= valuesToPage){
312
            retValue = 0;
313
          } else {
314
            if(map.get(key).size < (sum - valuesToPreviousPage)) {
315
              retValue = 0;
316
            } else {
317
              retValue = map.get(key).size - (sum - valuesToPreviousPage);
318
            }
319
          }
320
        }
321
        index++;
322
      });
323
      this.startt = retValue;
324
      return retValue;
325
    }
326

    
327
    stop(i: number, bioentitiesPage: number) {
328
      let sum = 0;
329
      let index=0;
330
      let retValue = 0;
331
      let valuesToPage = this.pageSize*bioentitiesPage;
332
      let valuesToPreviousPage = valuesToPage - this.pageSize;
333

    
334
      this.publicationInfo.bioentities.forEach(function (value, key, map) {
335
        sum += map.get(key).size;
336
        if(index == i) {
337
          if(sum <= valuesToPreviousPage) {
338
            retValue =  0;
339
          } else if((sum - map.get(key).size) >= valuesToPage){
340
            retValue = 0;
341
          } else {
342
            if(sum < valuesToPage) {
343
              retValue = map.get(key).size;
344
            } else {
345
              retValue = map.get(key).size - (sum - valuesToPage);
346
            }
347
          }
348
        }
349
        index++;
350
      });
351
      this.stopp = retValue;
352
      return retValue;
353
    }
354
*/
355

    
356
  private handleError(message: string, error) {
357
    console.error("Publication Landing Page: "+message, error);
358
  }
359
}
(3-3/5)