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
        }
140
      );
141
    }
142

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

    
148
        this.publicationInfo = null;
149

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

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

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

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

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

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

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

    
195
                this.showLoading = false;
196

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

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

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

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

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

    
235
        return tooltipContent+= "</div>";
236
    }
237

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

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

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

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

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

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

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

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

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

    
299
      if(bioentitiesPage == 1) {
300
        return 0;
301
      }
302

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

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

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

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

    
354
}
(3-3/5)