Project

General

Profile

1
import {Component, ViewChild, ElementRef} from '@angular/core';
2
import {Observable} from 'rxjs/Observable';
3
import {DataProviderService} from './dataProvider.service';
4
import {DataProviderInfo} from '../../utils/entities/dataProviderInfo';
5
import {ActivatedRoute, Router} from '@angular/router';
6
import { Meta} from '../../../angular2-meta';
7
import { FetchPublications } from '../../utils/fetchEntitiesClasses/fetchPublications.class';
8
import { SearchPublicationsService } from '../../services/searchPublications.service';
9
import { FetchDatasets } from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
10
import { SearchDatasetsService } from '../../services/searchDatasets.service';
11
import { FetchProjects } from '../../utils/fetchEntitiesClasses/fetchProjects.class';
12
import { SearchProjectsService } from '../../services/searchProjects.service';
13
import { FetchDataproviders } from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
14
import { SearchDataprovidersService } from '../../services/searchDataproviders.service';
15
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
16
import {RouterHelper} from '../../utils/routerHelper.class';
17
@Component({
18
    selector: 'dataprovider',
19
     templateUrl: 'dataProvider.component.html',
20
 })
21

    
22
export class DataProviderComponent {
23

    
24
  sub: any;
25
  datasourceId: string;
26
  public dataProviderInfo: DataProviderInfo;
27

    
28
  private showAllReferences: boolean = false;
29
  private showAllRelResData: boolean = false;
30
  private showAllSimilPubl: boolean = false;
31
  private showAllBioentities: boolean = false;
32
  private showFundingDetails: boolean = false;
33

    
34
  private bioentitiesNum: number = 0;
35

    
36
  private result ;
37

    
38
  public warningMessage = "";
39
  public errorMessage = "";
40
  public relatedDataprovidersResultsType: string;
41
  public paramsForSearchLink = {};//: string = "";
42

    
43
  public reloadPublications: boolean = true;
44
  public reloadDatasets: boolean = true;
45
  public reloadProjects: boolean = true;
46
  public reloadDataproviders: boolean = true;
47
  public reloadRelatedDatasources: boolean = true;
48
  public metricsClicked: boolean;
49
  private viewsFrameUrl: string;
50
  private downloadsFrameUrl: string;
51
  private totalViews: number;
52
  private totalDownloads: number;
53
  private pageViews: number;
54

    
55
  public statsClicked: boolean = false;
56
  private  docsTimelineUrl: string;
57
  private  docsTypesUrl:string;
58
  private  pubsFunderUrl:string;
59
  private  dataProjectsUrl:string ;
60
  private  pubsProjectsUrl:string;
61

    
62
  public fetchPublications : FetchPublications;
63
  public fetchDatasets: FetchDatasets;
64
  public fetchProjects: FetchProjects;
65
  public fetchDataproviders: FetchDataproviders;
66
  public fetchResultsAggregators: any;
67

    
68
  private nativeElement : Node;
69

    
70
  public routerHelper:RouterHelper = new RouterHelper();
71
  showTabs:boolean = false;
72

    
73
  public errorCodes:ErrorCodes = new ErrorCodes();
74

    
75
  constructor (private element: ElementRef,
76
               private _dataproviderService: DataProviderService,
77
               private route: ActivatedRoute,
78
               private _meta: Meta,
79
               private _router: Router,
80
               private _searchPublicationsService: SearchPublicationsService,
81
               private _searchDatasetsService: SearchDatasetsService,
82
               private _searchProjectsService: SearchProjectsService,
83
               private _searchDataprovidersService: SearchDataprovidersService) {
84
                 this.fetchPublications = new FetchPublications(this._searchPublicationsService);
85
                 this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
86
                 this.fetchProjects = new FetchProjects(this._searchProjectsService);
87
                 this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
88

    
89
                 this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
90
 }
91

    
92
 ngOnInit() {
93
   this.sub =  this.route.queryParams.subscribe(data => {
94
       this.updateTitle("Data provider");
95
       this.updateDescription("Data provider, search, repositories, open access");
96
       this.datasourceId = data['datasourceId'];
97
        if(this.datasourceId){
98
         this.getDataProviderInfo(this.datasourceId);
99
       }else{
100
         // console.info("Datasource id not found");
101
       }
102

    
103
       if (typeof document !== 'undefined') {
104
          this.element.nativeElement.scrollIntoView();
105
       }
106
   });
107

    
108
   }
109

    
110
   ngOnDestroy() {
111
     this.sub.unsubscribe();
112
   }
113
  getDataProviderInfo(id:string) {
114
    this.warningMessage = '';
115
    this.errorMessage=""
116
    this.showTabs = false ;
117
    if(this.datasourceId==null || this.datasourceId==''){
118
      this.warningMessage="No valid datasource id";
119
    }else{
120
      this._dataproviderService.getDataproviderInfo(this.datasourceId).subscribe(
121
        data => {
122
            this.dataProviderInfo = data;
123
            this.initTabs();
124
            this.showTabs = true ;
125
            this.updateTitle(this.dataProviderInfo.title.name);
126
            this.updateDescription("Data provider, search, repositories, open access,"+this.dataProviderInfo.title.name);
127
        },
128
        err => {
129
          console.log(err)
130
          // console.info("error");
131
          this.errorMessage = 'No dataProvider found';
132
        }
133
      );
134
    }
135
   }
136
   updateDescription(description:string){
137
     this._meta.updateMeta("description", description);
138
     this._meta.updateProperty("og:description", description);
139
   }
140
   updateTitle(title:string){
141
     var _suffix ="| OpenAIRE";
142
     var _title = ((title.length> 50 ) ?title.substring(0,50):title) + _suffix;
143
     this._meta.setTitle(_title );
144
     this._meta.updateProperty("og:title",_title);
145
   }
146
   updateUrl(url:string){
147
     this._meta.updateProperty("og:url", url);
148
   }
149

    
150
   public initTabs(){
151

    
152
           if(this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
153
               this.reloadPublications = true;
154
               this.reloadDatasets = true;
155
               this.reloadProjects = true;
156
               this.reloadDataproviders = true;
157
               this.reloadRelatedDatasources = true;
158
               this.statsClicked = false;
159

    
160
               this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
161
               this.count(1, 0);
162

    
163
               this.metricsClicked = false;
164

    
165
               this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"dtsrcRepoViews","dtsrcName":"'+this.datasourceId+'","table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","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":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["spline"]&stacking=&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';
166
               /*this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"dtsrcOpenAIRETimeline", "dtsrcName":"'+this.datasourceId+'", "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":"OpenAIRE","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]},{"query":"dtsrcRepoTimeline", "dtsrcName":"'+this.datasourceId+'", "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":[""],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column","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';
167
               */
168

    
169
               this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"dtsrcRepoDownloads","dtsrcName":"'+this.datasourceId+'","table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","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":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["spline"]&stacking=&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';
170
               /*
171
               this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"dtsrcDownloadsTimeline","dtsrcName":"'+this.datasourceId+'","table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","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":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["spline"]&stacking=&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';
172
               */
173

    
174
               this.docsTimelineUrl ='https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"dtsrcYear","dtsrcName":"'+this.datasourceId+'","table": "result", "fields": [{"fld": "number", "agg": "count", "type": "line", "yaxis":1, "c":true}], "xaxis":{"name": "year", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Documents"], "in": [{"f":0, "text": "Yearly"}], "filters": [{"name":"year","max":"2016","min":"1997"},{"name": "result_datasources-datasource-name", "values":[""], "to": "-1"}],"having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": "Year"}&w=600&h=250';
175
               this.docsTypesUrl = 'https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"dtsrcPubs","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "pie", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Documents"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
176
               this.pubsFunderUrl =' https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"dtsrcPubsFund","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "pie", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Documents"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
177
               this.dataProjectsUrl ='https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"dtsrcProjData","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "bar", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Datasets"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
178
               this.pubsProjectsUrl ='https://beta.openaire.eu/stats/chart.php?com=query&persistent=false&data={"query":"dtsrcProjPubs","dtsrcName":"'+this.datasourceId+'", "table": "result", "fields": [{"fld": "number", "agg": "count", "type": "bar", "yaxis":1, "c":false}], "xaxis":{"name": "result_classifications-type", "agg": "avg"}, "group": "", "color": "", "type": "chart", "size":30, "sort": "xaxis", "xStyle":{"r": "-", "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Publications"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
179

    
180
               //if({"name": "Publications", "content": "publicationsTab"} in this.dataProviderInfo.tabs) {
181
               if(this.dataProviderInfo.tabs.some(function (tab) {
182
                   return tab.name === 'Publications';
183
               })) {
184
                   this.relatedDataprovidersResultsType = 'publications';
185
                   this.fetchResultsAggregators = new FetchPublications(this._searchPublicationsService);
186
               } else {
187
                   this.relatedDataprovidersResultsType = 'datasets';
188
                   this.fetchResultsAggregators = new FetchDatasets(this._searchDatasetsService);
189
               }
190
           }
191
           if(this.dataProviderInfo.resultsBy == "collectedFrom") {
192
               //this.paramsForSearchLink = "?collectedFrom="+this.datasourceId+"&co=and";
193
               this.paramsForSearchLink = this.routerHelper.createQueryParams(['collectedFrom', 'co'], [this.datasourceId, 'and']);
194
           } else if (this.dataProviderInfo.resultsBy == "hostedBy") {
195
               //this.paramsForSearchLink = "?hostedBy="+this.datasourceId+"&ho=and";
196
               this.paramsForSearchLink = this.routerHelper.createQueryParams(['hostedBy', 'ho'], [this.datasourceId, 'and']);
197
           }
198

    
199
   }
200

    
201
   private count(page: number, size: number) {
202
       for(let i=1; i<this.dataProviderInfo.tabs.length; i++) {
203
           let content: string = this.dataProviderInfo.tabs[i].content;
204

    
205
           if(content=='publicationsTab') {
206
               this.countPublications(page, size);
207
           } else if(content=='datasetsTab') {
208
               this.countDatasets(page, size);
209
           } else if(content=='projectsTab') {
210
               this.countProjects(page, size);
211
           } else if(content=='datasourcesTab') {
212
               this.countDatasources(page, size);
213
           }// else if(content=='relatedDatasourcesTab') {
214
           //    this.countRelatedDatasources(page, size);
215
           //}
216
       }
217
   }
218

    
219
   private search(content: string, page: number, size: number) {
220
       if(content=='publicationsTab') {
221
           this.searchPublications(page, size);
222
       } else if(content=='datasetsTab') {
223
           this.searchDatasets(page, size);
224
       } else if(content=='projectsTab') {
225
           this.searchProjects(page, size);
226
       } else if(content=='datasourcesTab') {
227
           this.searchDatasources(page, size);
228
       } else if(content=='relatedDatasourcesTab') {
229
           this.searchRelatedDatasources(1, 0);
230
       } else if(content=='metricsTab') {
231
           this.metricsClicked = true;
232
       } else if(content=='statisticsTab') {
233
           this.statsClicked = true;
234
       }
235
   }
236

    
237
   private searchPublications(page: number, size: number) {
238
       if(this.reloadPublications) {
239
           this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
240
       }
241
       this.reloadPublications = false;
242
    }
243

    
244
    private countPublications(page: number, size: number) {
245
        this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
246
    }
247

    
248
    private searchDatasets(page: number, size: number) {
249
        if(this.reloadDatasets) {
250
            this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
251
        }
252
        this.reloadDatasets = false;
253
    }
254

    
255
    private countDatasets(page: number, size: number) {
256
        this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
257
    }
258

    
259
    private searchProjects(page: number, size: number) {
260
        if(this.reloadProjects) {
261
            this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
262
        }
263
        this.reloadProjects = false;
264
    }
265

    
266
    private countProjects(page: number, size: number) {
267
        this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
268
    }
269

    
270
    private searchDatasources(page: number, size: number) {
271
        if(this.reloadDataproviders) {
272

    
273
            this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
274

    
275
        }
276
        this.reloadDataproviders = false;
277
    }
278

    
279
    private countDatasources(page: number, size: number) {
280
        this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
281
    }
282

    
283
    private searchRelatedDatasources(page: number, size: number) {
284
        if(this.reloadRelatedDatasources) {
285
            this.fetchResultsAggregators.getAggregatorResults(this.datasourceId, page, size);
286
        }
287
        this.reloadRelatedDatasources = false;
288
    }
289

    
290
    private countRelatedDatasources(page: number, size: number) {
291
        this.fetchResultsAggregators.getAggregatorResults(this.datasourceId, page, size);
292
    }
293

    
294
    public metricsResults($event) {
295
      this.totalViews = $event.totalViews;
296
      this.totalDownloads = $event.totalDownloads;
297
      this.pageViews = $event.pageViews;
298
    }
299
}
(3-3/13)