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

    
12
import {DatasetService}               from './dataset.service';
13
import {PiwikService}                 from '../../utils/piwik/piwik.service';
14

    
15

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

    
21
export class DatasetComponent {
22
    @Input() piwikSiteId = null;
23
    public datasetInfo: DatasetInfo;
24
    public datasetId : string ;
25

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

    
31
    // Metrics tab variables
32
    public metricsClicked: boolean;
33
    public viewsFrameUrl: string;
34
    public downloadsFrameUrl: string;
35
    public totalViews: number;
36
    public totalDownloads: number;
37
    public pageViews: number;
38

    
39
    // Active tab variable for responsiveness
40
    public activeTab: string = "Related Research Results";
41

    
42
    // Map counting variable
43
    public relatedResearchResultsNum: number = 0;
44

    
45
    // Message variables
46
    public warningMessage = "";
47
    public errorMessage = "";
48
    public showLoading: boolean = true;
49

    
50
    public routerHelper:RouterHelper = new RouterHelper();
51

    
52
    private result ;
53
    sub: any; piwiksub: any; infoSub: any;
54
    properties:EnvProperties;
55

    
56
    constructor (private element: ElementRef,
57
                 private _datasetService: DatasetService,
58
                 private _piwikService:PiwikService,
59
                 private  route: ActivatedRoute,
60
                 private _meta: Meta,
61
                 private _title: Title,
62
                 private _router: Router) {
63
    }
64

    
65
    ngOnInit() {
66
      this.route.data
67
        .subscribe((data: { envSpecific: EnvProperties }) => {
68
           this.properties = data.envSpecific;
69
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
70

    
71
        });
72
      this.sub =  this.route.queryParams.subscribe(params => {
73
          this.datasetInfo = null;
74
          this.updateTitle("Dataset");
75
          this.updateDescription("Dataset, search, open access");
76

    
77
            this.datasetId = params['datasetId'];
78
             console.info("Id is :"+this.datasetId);
79

    
80
             if(this.datasetId){
81
                this.getDatasetInfo(this.datasetId);
82
            }else{
83
              this.showLoading = false;
84
                this.warningMessage="No valid research data id";
85
            }
86

    
87
            this.metricsClicked = false;
88

    
89
            this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"'+this.datasetId+'", "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';
90
            /*this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resViewsTimeline", "resTitle":"'+this.datasetId+'", "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(124, 181, 236, 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';
91
            */
92

    
93
            this.downloadsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"'+this.datasetId+'", "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';
94
            /*this.downloadsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloadTimeline", "resTitle":"'+this.datasetId+'", "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';
95
            */
96
            if (typeof document !== 'undefined') {
97
               this.element.nativeElement.scrollIntoView();
98
            }
99
        });
100

    
101
    }
102

    
103
    ngOnDestroy() {
104
      this.sub.unsubscribe();
105
      if(this.piwiksub){
106
        this.piwiksub.unsubscribe();
107
      }
108
      if(this.infoSub) {
109
        this.infoSub.unsubscribe();
110
      }
111
    }
112

    
113
    private getDatasetInfo(id:string) {
114
        this.warningMessage = '';
115
        this.errorMessage=""
116
        this.showLoading = true;
117

    
118
        this.infoSub = this._datasetService.getDatasetInfo(id, this. properties).subscribe(
119
            data => {
120
                this.datasetInfo = data;
121
                this.updateTitle(this.datasetInfo.title.name);
122
                this.updateDescription("Dataset, search, repositories, open access,"+this.datasetInfo.title.name);
123
                if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
124
                  this.piwiksub = this._piwikService.trackView(this.properties, this.datasetInfo.title.name, this.piwikSiteId).subscribe();
125
                }
126

    
127
                this.result = []
128
                this.result = {id: id, type :"dataset", source : "openaire", title: this.datasetInfo.title,url: '', result: '', accessRights: this.datasetInfo.title.accessMode, embargoEndDate: ''};
129

    
130
                let relatedResearchResultsNum = 0;
131
                if(this.datasetInfo.relatedResearchResults != undefined) {
132
                    this.datasetInfo.relatedResearchResults.forEach(function (value, key, map) {
133
                        relatedResearchResultsNum += value.length;
134
                    });
135
                }
136
                this.relatedResearchResultsNum = relatedResearchResultsNum;
137

    
138
                this.showLoading = false;
139
            },
140
            err => {
141
                console.log(err)
142
                console.info("error");
143

    
144
                this.errorMessage = 'No research data found';
145
                this.showLoading = false;
146
            }
147
        );
148
    }
149

    
150
    // showChange($event) {
151
    //     this.showAllReferences=$event.value;
152
    // }
153

    
154
    public metricsResults($event) {
155
      this.totalViews = $event.totalViews;
156
      this.totalDownloads = $event.totalDownloads;
157
      this.pageViews = $event.pageViews;
158
    }
159

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

    
174
    public buildCurationTooltip() {
175
        let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
176

    
177
        tooltipContent += "<h4>Record in preview</h4>";
178
        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>";
179

    
180
        return tooltipContent;
181
    }
182
    public getKeys( map) {
183
      return Array.from(map.keys());
184
    }
185
}
(3-3/5)