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 pageSize: number = 10;
46
  /*
47
    public startt: number = 0;
48
    public stopp: number = 0;
49
  */
50

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

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

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

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

    
65
  private doi: string;
66
  private result;
67
  sub: any; piwiksub: any; infoSub: any;
68
  properties:EnvProperties;
69

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

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

    
86
      });
87
       this.sub =  this.route.queryParams.subscribe(data => {
88
           this.publicationInfo = null;
89
           this.updateTitle("Publication");
90
           this.updateDescription("Publication, open access, collected from");
91
           this.seoService.createLinkForCanonicalURL();
92

    
93
          this.articleId = data['articleId'];
94
          console.info("Article id is :"+this.articleId);
95

    
96
          this.metricsClicked = false;
97

    
98
          if(this.articleId){
99

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

    
109
          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';
110

    
111
          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';
112

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

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

    
131
    private getPublicationInfo(id:string) {
132
        this.warningMessage = '';
133
        this.errorMessage=""
134
        this.showLoading = true;
135

    
136
        this.publicationInfo = null;
137

    
138
        this.infoSub = this._publicationService.getPublicationInfo(this.articleId, this.properties).subscribe(
139
            data => {
140
                this.publicationInfo = data;
141

    
142
                // this.result = []
143
                // this.result = {id: id, type :"dataset", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: this.publicationInfo.bestaccessright, embargoEndDate: ''};
144
                /*if(this.publicationInfo.title.name != undefined && this.publicationInfo.title.name!= ''){
145
                  this.updateTitle(this.publicationInfo.title.name);
146
                  this.updateDescription("Dataset, search, repositories, open access,"+this.publicationInfo.title.name);
147
                }*/
148
                if(this.publicationInfo.title){
149
                  this.updateTitle(this.publicationInfo.title);
150
                  this.updateDescription("Dataset, search, repositories, open access,"+this.publicationInfo.title);
151
                }
152
                if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
153
                  this.piwiksub =  this._piwikService.trackView(this.properties, this.publicationInfo.title/*.name*/, this.piwikSiteId).subscribe();
154
                }
155

    
156
                let bioentitiesNum = 0;
157
                if(this.publicationInfo.bioentities != undefined) {
158
                    this.publicationInfo.bioentities.forEach(function (value, key, map) {
159
                        bioentitiesNum += value.size;
160
                    });
161
                }
162
                this.bioentitiesNum = bioentitiesNum;
163

    
164
                let relatedResearchResultsNum = 0;
165
                if(this.publicationInfo.relatedResearchResults != undefined) {
166
                    this.publicationInfo.relatedResearchResults.forEach(function (value, key, map) {
167
                        relatedResearchResultsNum += value.length;
168
                    });
169
                }
170
                this.relatedResearchResultsNum = relatedResearchResultsNum;
171

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

    
175
                if(this.publicationInfo.identifiers != undefined && this.publicationInfo.identifiers.has('doi')) {
176
                    this.doi = this.publicationInfo.identifiers.get('doi')[0];
177
                }
178

    
179
                this.showLoading = false;
180

    
181
                if(this.publicationInfo.references) {
182
                  this.activeTab = "References";
183
                } else if(this.publicationInfo.relatedResearchResults) {
184
                  this.activeTab = "Related Research Results";
185
                } else if(this.publicationInfo.similarResearchResults) {
186
                  this.activeTab = "Similar Research Results";
187
                } else if(this.publicationInfo.organizations) {
188
                  this.activeTab = "Related Organizations";
189
                } else if(this.publicationInfo.bioentities) {
190
                  this.activeTab = "bioentities";
191
                } else if(this.publicationInfo.software) {
192
                  this.activeTab = "Software";
193
                } else {
194
                  this.activeTab = "Metrics";
195
                  this.metricsClicked = true;
196
                }
197
                console.info("activeTab is "+this.activeTab);
198
            },
199
            err => {
200
              console.log(err);
201
              console.info("error");
202

    
203
              this.errorMessage = 'No publication found';
204
              this.showLoading = false;
205
            }
206
      );
207
    }
208

    
209
    public metricsResults($event) {
210
      this.totalViews = $event.totalViews;
211
      this.totalDownloads = $event.totalDownloads;
212
      this.pageViews = $event.pageViews;
213
    }
214

    
215
    public buildCurationTooltip() {
216
        let tooltipContent: string = "<div class='uk-margin uk-padding-small'>";
217

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

    
221
        return tooltipContent+= "</div>";
222
    }
223

    
224
    private updateDescription(description:string){
225
      this._meta.updateTag({content:description},"name='description'");
226
      this._meta.updateTag({content:description},"property='og:description'");
227
    }
228
    private updateTitle(title:string){
229
      var _prefix ="OpenAIRE | ";
230
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
231
      this._title.setTitle(title);
232
      this._meta.updateTag({content:title},"property='og:title'");
233
    }
234

    
235
    private updateUrl(url:string){
236
      this._meta.updateTag({content:url},"property='og:url'");
237
    }
238

    
239
    public totalPages(totalResults: number): number {
240
      let totalPages:any = totalResults/this.pageSize;
241
      if(!(Number.isInteger(totalPages))) {
242
          totalPages = (parseInt(totalPages, this.pageSize) + 1);
243
      }
244
      return totalPages;
245
    }
246

    
247
    public updateReferencesPage($event) {
248
      this.referencesPage = $event.value;
249
    }
250

    
251
    public updateOrganizationsPage($event) {
252
      this.organizationsPage = $event.value;
253
    }
254

    
255
    public updateSoftwarePage($event) {
256
      this.softwarePage = $event.value;
257
    }
258

    
259
    public updateBioentitiesPage($event) {
260
      this.bioentitiesPage = $event.value;
261
    }
262

    
263
    public keysToArray(bioentities: Map<string, string>) : string[] {
264
      let keys: string[] = [];
265
      bioentities.forEach(function (value, key, map) {
266
        keys.push(key);
267
      });
268
      return keys;
269
    }
270
    public getKeys( map) {
271
      return Array.from(map.keys());
272
    }
273
/*
274
    start(i: number, bioentitiesPage: number) {
275
      let sum = 0;
276
      let index=0;
277
      let retValue = 0;
278
      let valuesToPage = this.pageSize*bioentitiesPage;
279
      let valuesToPreviousPage = valuesToPage - this.pageSize;
280

    
281
      if(bioentitiesPage == 1) {
282
        return 0;
283
      }
284

    
285
      this.publicationInfo.bioentities.forEach(function (value, key, map) {
286
        sum += map.get(key).size;
287

    
288
        if(index == i) {
289
          if(sum <= valuesToPreviousPage) {
290
            retValue =  0;
291
          } else if((sum-map.get(key).size) >= valuesToPage){
292
            retValue = 0;
293
          } else {
294
            if(map.get(key).size < (sum - valuesToPreviousPage)) {
295
              retValue = 0;
296
            } else {
297
              retValue = map.get(key).size - (sum - valuesToPreviousPage);
298
            }
299
          }
300
        }
301
        index++;
302
      });
303
      this.startt = retValue;
304
      return retValue;
305
    }
306

    
307
    stop(i: number, bioentitiesPage: number) {
308
      let sum = 0;
309
      let index=0;
310
      let retValue = 0;
311
      let valuesToPage = this.pageSize*bioentitiesPage;
312
      let valuesToPreviousPage = valuesToPage - this.pageSize;
313

    
314
      this.publicationInfo.bioentities.forEach(function (value, key, map) {
315
        sum += map.get(key).size;
316
        if(index == i) {
317
          if(sum <= valuesToPreviousPage) {
318
            retValue =  0;
319
          } else if((sum - map.get(key).size) >= valuesToPage){
320
            retValue = 0;
321
          } else {
322
            if(sum < valuesToPage) {
323
              retValue = map.get(key).size;
324
            } else {
325
              retValue = map.get(key).size - (sum - valuesToPage);
326
            }
327
          }
328
        }
329
        index++;
330
      });
331
      this.stopp = retValue;
332
      return retValue;
333
    }
334
*/
335

    
336
}
(3-3/5)