Project

General

Profile

1
import {Component, ViewChild}         from '@angular/core';
2
import {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';
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
import {HelperFunctions} from "../../utils/HelperFunctions.class";
16

    
17

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

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

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

    
33
    public thresholdDescription: number = 270;
34
    public showNumDescription: number = 270;
35
    
36
    // Metrics tab variables
37
    public metricsClicked: boolean;
38
    public viewsFrameUrl: string;
39
    public downloadsFrameUrl: string;
40
    public totalViews: number;
41
    public totalDownloads: number;
42
    public pageViews: number;
43

    
44
    // Custom tab paging variables
45
    public referencesPage: number = 1;
46
    public pageSize: number = 10;
47

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

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

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

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

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

    
65
    constructor (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

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

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

    
94
            this.metricsClicked = false;
95

    
96
            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';
97

    
98
            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';
99

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

    
103
    }
104

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

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

    
122
        this.orpInfo = null;
123

    
124
        this.infoSub = this._orpService.getOrpInfo(id, this. properties).subscribe(
125
            data => {
126
                this.orpInfo = data;
127
              this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToOrp + this.orpInfo.record["result"]["header"]["dri:objIdentifier"]);
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
              this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToOrps);
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
      HelperFunctions.scroll();
193
    }
194

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

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

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