Project

General

Profile

1
import {Component, ViewChild, ElementRef} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {DatasetService} from './dataset.service';
4
import {DatasetInfo} from '../../utils/entities/datasetInfo';
5
import {ActivatedRoute, Router} from '@angular/router';
6
import {RouterHelper} from '../../utils/routerHelper.class';
7
import { Meta} from '../../sharedComponents/metaService';
8
import {PiwikService} from '../../utils/piwik/piwik.service';
9
import{EnvProperties} from '../../utils/properties/env-properties';
10

    
11
@Component({
12
    selector: 'dataset',
13
    templateUrl: 'dataset.component.html',
14
})
15

    
16
export class DatasetComponent {
17
    public datasetInfo: DatasetInfo;
18
    public datasetId : string ;
19

    
20
    // APP BOX variables
21
    public showAllCollectedFrom: boolean = false;
22
    public showAllDownloadFrom: boolean = false;
23
    public showAllPublishedIn: boolean = false;
24

    
25
    // Metrics tab variables
26
    public metricsClicked: boolean;
27
    public viewsFrameUrl: string;
28
    public downloadsFrameUrl: string;
29
    public totalViews: number;
30
    public totalDownloads: number;
31
    public pageViews: number;
32

    
33
    // Active tab variable for responsiveness
34
    public activeTab: string = "Related Research Results";
35

    
36
    // Map counting variable
37
    public relatedResearchResultsNum: number = 0;
38

    
39
    // Message variables
40
    public warningMessage = "";
41
    public errorMessage = "";
42
    public showLoading: boolean = true;
43

    
44
    public routerHelper:RouterHelper = new RouterHelper();
45

    
46
    private result ;
47
    sub: any; piwiksub: any; infoSub: any;
48
    properties:EnvProperties;
49

    
50
    constructor (private element: ElementRef,
51
                 private _datasetService: DatasetService,
52
                 private _piwikService:PiwikService,
53
                 private  route: ActivatedRoute,
54
                 private _meta: Meta,
55
                 private _router: Router) {
56
    }
57

    
58
    ngOnInit() {
59
      this.route.data
60
        .subscribe((data: { envSpecific: EnvProperties }) => {
61
           this.properties = data.envSpecific;
62
           this.updateUrl(data.envSpecific.baseLink+this._router.url);
63

    
64
        });
65
      this.sub =  this.route.queryParams.subscribe(params => {
66
          this.datasetInfo = null;
67
          this.updateTitle("Dataset");
68
          this.updateDescription("Dataset, search, open access");
69

    
70
            this.datasetId = params['datasetId'];
71
             console.info("Id is :"+this.datasetId);
72

    
73
             if(this.datasetId){
74
                this.getDatasetInfo(this.datasetId);
75
            }else{
76
              this.showLoading = false;
77
                this.warningMessage="No valid research data id";
78
            }
79

    
80
            this.metricsClicked = false;
81

    
82
            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';
83
            /*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';
84
            */
85

    
86
            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';
87
            /*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';
88
            */
89
            if (typeof document !== 'undefined') {
90
               this.element.nativeElement.scrollIntoView();
91
            }
92
        });
93

    
94
    }
95

    
96
    ngOnDestroy() {
97
      this.sub.unsubscribe();
98
      if(this.piwiksub){
99
        this.piwiksub.unsubscribe();
100
      }
101
      if(this.infoSub) {
102
        this.infoSub.unsubscribe();
103
      }
104
    }
105

    
106
    private getDatasetInfo(id:string) {
107
        this.warningMessage = '';
108
        this.errorMessage=""
109
        this.showLoading = true;
110

    
111
        this.infoSub = this._datasetService.getDatasetInfo(id, this. properties).subscribe(
112
            data => {
113
                this.datasetInfo = data;
114
                this.updateTitle(this.datasetInfo.title.name);
115
                this.updateDescription("Dataset, search, repositories, open access,"+this.datasetInfo.title.name);
116
                if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
117
                  this.piwiksub = this._piwikService.trackView(this.datasetInfo.title.name).subscribe();
118
                }
119

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

    
123
                let relatedResearchResultsNum = 0;
124
                if(this.datasetInfo.relatedResearchResults != undefined) {
125
                    this.datasetInfo.relatedResearchResults.forEach(function (value, key, map) {
126
                        relatedResearchResultsNum += value.length;
127
                    });
128
                }
129
                this.relatedResearchResultsNum = relatedResearchResultsNum;
130

    
131
                this.showLoading = false;
132
            },
133
            err => {
134
                console.log(err)
135
                console.info("error");
136

    
137
                this.errorMessage = 'No research data found';
138
                this.showLoading = false;
139
            }
140
        );
141
    }
142

    
143
    // showChange($event) {
144
    //     this.showAllReferences=$event.value;
145
    // }
146

    
147
    public metricsResults($event) {
148
      this.totalViews = $event.totalViews;
149
      this.totalDownloads = $event.totalDownloads;
150
      this.pageViews = $event.pageViews;
151
    }
152

    
153
    private updateDescription(description:string){
154
      this._meta.updateMeta("description", description);
155
      this._meta.updateProperty("og:description", description);
156
    }
157
    private updateTitle(title:string){
158
      var _prefix ="OpenAIRE | ";
159
      var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
160
      this._meta.setTitle(_title );
161
      this._meta.updateProperty("og:title",_title);
162
    }
163
    private updateUrl(url:string){
164
      this._meta.updateProperty("og:url", url);
165
    }
166

    
167
    public buildCurationTooltip() {
168
        let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
169

    
170
        tooltipContent += "<h4>Record in preview</h4>";
171
        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>";
172

    
173
        return tooltipContent;
174
    }
175
    public getKeys( map) {
176
      return Array.from(map.keys());
177
    }
178
}
(3-3/5)