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 {OrpInfo}                  from '../../utils/entities/orpInfo';
9
import {EnvProperties}                from '../../utils/properties/env-properties';
10
import {RouterHelper}                 from '../../utils/routerHelper.class';
11

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

    
16

    
17
@Component({
18
    selector: 'orp',
19
    templateUrl: 'orp.component.html',
20
})
21

    
22
export class OrpComponent {
23
    @Input() piwikSiteId = null;
24
    public orpInfo: OrpInfo;
25
    public orpId : string ;
26

    
27
    // APP BOX variables
28
    public showAllCollectedFrom: boolean = false;
29
    public showAllDownloadFrom: boolean = false;
30
    public showAllPublishedIn: 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 pageSize: number = 10;
46

    
47
    // Active tab variable for responsiveness
48
    public activeTab: string = "References";
49

    
50
    // Map counting variable
51
    public relatedResearchResultsNum: number = 0;
52

    
53
    // Message variables
54
    public warningMessage = "";
55
    public errorMessage = "";
56
    public showLoading: boolean = true;
57

    
58
    public routerHelper:RouterHelper = new RouterHelper();
59

    
60
    private result ;
61
    sub: any; piwiksub: any; infoSub: any;
62
    properties:EnvProperties;
63

    
64
    constructor (private element: ElementRef,
65
                 private _orpService: OrpService,
66
                 private _piwikService:PiwikService,
67
                 private  route: ActivatedRoute,
68
                 private _meta: Meta,
69
                 private _title: Title,
70
                 private _router: Router,
71
               private seoService: SEOService) {
72
    }
73

    
74
    ngOnInit() {
75
      this.route.data
76
        .subscribe((data: { envSpecific: EnvProperties }) => {
77
           this.properties = data.envSpecific;
78
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
79
           this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
80

    
81
        });
82
      this.sub =  this.route.queryParams.subscribe(params => {
83
          this.orpInfo = null;
84
          this.updateTitle("Other Research Product");
85
          this.updateDescription("");
86
            this.orpId = params['orpId'];
87

    
88
             if(this.orpId){
89
                this.getOrpInfo(this.orpId);
90
            }else{
91
              this.showLoading = false;
92
                this.warningMessage="No valid research product id";
93
            }
94

    
95
            this.metricsClicked = false;
96

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

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

    
101
            this.scroll();
102
        });
103

    
104
    }
105

    
106
    ngOnDestroy() {
107
      if(this.sub){
108
        this.sub.unsubscribe();
109
      }
110
      if(this.piwiksub){
111
        this.piwiksub.unsubscribe();
112
      }
113
      if(this.infoSub) {
114
        this.infoSub.unsubscribe();
115
      }
116
    }
117

    
118
    private getOrpInfo(id:string) {
119
        this.warningMessage = '';
120
        this.errorMessage=""
121
        this.showLoading = true;
122

    
123
        this.orpInfo = null;
124

    
125
        this.infoSub = this._orpService.getOrpInfo(id, this. properties).subscribe(
126
            data => {
127
                this.orpInfo = data;
128
                if(this.orpInfo.title){
129
                  this.updateTitle(this.orpInfo.title);
130
                  this.updateDescription((this.orpInfo.description?(this.orpInfo.description):(","+this.orpInfo.title)));
131
                }
132
                if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
133
                  this.piwiksub = this._piwikService.trackView(this.properties, this.orpInfo.title, this.piwikSiteId).subscribe();
134
                }
135

    
136
                this.result = []
137
                this.result = {id: id, type :"orp", source : "openaire", title: this.orpInfo.title,url: '', result: '', accessRights: this.orpInfo.accessMode, embargoEndDate: ''};
138

    
139
                let relatedResearchResultsNum = 0;
140
                if(this.orpInfo.relatedResearchResults != undefined) {
141
                    this.orpInfo.relatedResearchResults.forEach(function (value, key, map) {
142
                        relatedResearchResultsNum += value.length;
143
                    });
144
                }
145
                this.relatedResearchResultsNum = relatedResearchResultsNum;
146

    
147
                this.showLoading = false;
148
            },
149
            err => {
150
                //console.log(err)
151
                this.handleError("Error getting other research product for id: "+this.orpId, err);
152

    
153
                this.errorMessage = 'No research product found';
154
                this.showLoading = false;
155
            }
156
        );
157
    }
158

    
159
    public metricsResults($event) {
160
      this.totalViews = $event.totalViews;
161
      this.totalDownloads = $event.totalDownloads;
162
      this.pageViews = $event.pageViews;
163
    }
164

    
165
    private updateDescription(description:string){
166
      this._meta.updateTag({content:description},"name='description'");
167
      this._meta.updateTag({content:description},"property='og:description'");
168
    }
169
    private updateTitle(title:string){
170
      var _prefix ="OpenAIRE | ";
171
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
172
      this._title.setTitle(_title);
173
      this._meta.updateTag({content:_title},"property='og:title'");
174
    }
175
    private updateUrl(url:string){
176
      this._meta.updateTag({content:url},"property='og:url'");
177
    }
178

    
179
    public buildCurationTooltip() {
180
        let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
181

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

    
185
        return tooltipContent;
186
    }
187
    public getKeys( map) {
188
      return Array.from(map.keys());
189
    }
190

    
191
    public scroll() {
192
      if (typeof document !== 'undefined') {
193
         this.element.nativeElement.scrollIntoView();
194
      }
195
    }
196

    
197
    private handleError(message: string, error) {
198
        console.error("Other Research Product Landing Page: "+message, error);
199
    }
200

    
201
    public updateReferencesPage($event) {
202
      this.referencesPage = $event.value;
203
    }
204

    
205
    public totalPages(totalResults: number): number {
206
      let totalPages:any = totalResults/this.pageSize;
207
      if(!(Number.isInteger(totalPages))) {
208
          totalPages = (parseInt(totalPages, this.pageSize) + 1);
209
      }
210
      return totalPages;
211
    }
212
}
(2-2/4)