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
  public thresholdDescription: number = 270;
33
  public showNumDescription: number = 270;
34

    
35
  // Metrics tab variables
36
  public metricsClicked: boolean;
37
  public viewsFrameUrl: string;
38
  public downloadsFrameUrl: string;
39
  public totalViews: number;
40
  public totalDownloads: number;
41
  public pageViews: number;
42

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

    
55
  // Active tab variable for responsiveness
56
  public activeTab: string = "References";
57

    
58
  // Map counting variables
59
  public bioentitiesNum: number = 0;
60
  public relatedResearchResultsNum: number = 0;
61

    
62
  // Message variables
63
  public warningMessage = "";
64
  public errorMessage = "";
65
  public showLoading: boolean = true;
66

    
67
  public routerHelper:RouterHelper = new RouterHelper();
68

    
69
  private doi: string;
70
  public doiURL: string;
71
  private result;
72
  sub: any; piwiksub: any; infoSub: any;
73
  properties:EnvProperties;
74

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

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

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

    
100
          this.metricsClicked = false;
101

    
102
          if(this.articleId){
103

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

    
113
          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';
114

    
115
          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';
116

    
117
          this.scroll();
118
    });
119
  }
120

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

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

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

    
150
        this.publicationInfo = null;
151

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

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

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

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

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

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

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

    
197
                this.showLoading = false;
198

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
284
    public keysToArray(bioentities: Map<string, string>) : string[] {
285
      let keys: string[] = [];
286
      bioentities.forEach(function (value, key, map) {
287
        keys.push(key);
288
      });
289
      return keys;
290
    }
291
    public getKeys( map) {
292
      return Array.from(map.keys());
293
    }
294

    
295
    public scroll() {
296
      if (typeof document !== 'undefined') {
297
         this.element.nativeElement.scrollIntoView();
298
      }
299
    }
300
/*
301
    start(i: number, bioentitiesPage: number) {
302
      let sum = 0;
303
      let index=0;
304
      let retValue = 0;
305
      let valuesToPage = this.pageSize*bioentitiesPage;
306
      let valuesToPreviousPage = valuesToPage - this.pageSize;
307

    
308
      if(bioentitiesPage == 1) {
309
        return 0;
310
      }
311

    
312
      this.publicationInfo.bioentities.forEach(function (value, key, map) {
313
        sum += map.get(key).size;
314

    
315
        if(index == i) {
316
          if(sum <= valuesToPreviousPage) {
317
            retValue =  0;
318
          } else if((sum-map.get(key).size) >= valuesToPage){
319
            retValue = 0;
320
          } else {
321
            if(map.get(key).size < (sum - valuesToPreviousPage)) {
322
              retValue = 0;
323
            } else {
324
              retValue = map.get(key).size - (sum - valuesToPreviousPage);
325
            }
326
          }
327
        }
328
        index++;
329
      });
330
      this.startt = retValue;
331
      return retValue;
332
    }
333

    
334
    stop(i: number, bioentitiesPage: number) {
335
      let sum = 0;
336
      let index=0;
337
      let retValue = 0;
338
      let valuesToPage = this.pageSize*bioentitiesPage;
339
      let valuesToPreviousPage = valuesToPage - this.pageSize;
340

    
341
      this.publicationInfo.bioentities.forEach(function (value, key, map) {
342
        sum += map.get(key).size;
343
        if(index == i) {
344
          if(sum <= valuesToPreviousPage) {
345
            retValue =  0;
346
          } else if((sum - map.get(key).size) >= valuesToPage){
347
            retValue = 0;
348
          } else {
349
            if(sum < valuesToPage) {
350
              retValue = map.get(key).size;
351
            } else {
352
              retValue = map.get(key).size - (sum - valuesToPage);
353
            }
354
          }
355
        }
356
        index++;
357
      });
358
      this.stopp = retValue;
359
      return retValue;
360
    }
361
*/
362

    
363
  private handleError(message: string, error) {
364
    console.error("Publication Landing Page: "+message, error);
365
  }
366
}
(3-3/5)