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 { RelatedDatasourcesTabComponent } from './relatedDatasourcesTab.component';
16
import {OpenaireProperties, ErrorCodes} from '../../utils/properties/openaireProperties';
17
import {RouterHelper} from '../../utils/routerHelper.class';
18
import {PiwikService} from '../../utils/piwik/piwik.service';
19

    
20
import 'rxjs/add/operator/switch';
21
import 'rxjs/add/operator/switchMap';
22

    
23
@Component({
24
    selector: 'dataprovider',
25
     templateUrl: 'dataProvider.component.html',
26
 })
27

    
28
export class DataProviderComponent {
29
  public dataProviderInfo: DataProviderInfo;
30
  public datasourceId: string;
31

    
32
  // Message variables
33
  public warningMessage = "";
34
  public errorMessage = "";
35
  public showLoading: boolean = true;
36

    
37
  // Variable to specify requests with either collectedFrom or hostedBy
38
  public paramsForSearchLink = {};
39

    
40
  // Metrics tab variables
41
  public metricsClicked: boolean;
42
  public viewsFrameUrl: string;
43
  public downloadsFrameUrl: string;
44
  public totalViews: number;
45
  public totalDownloads: number;
46
  public pageViews: number;
47

    
48
  // Statistics tab variables
49
  public statsClicked: boolean = false;
50
  public docsTimelineUrl: string;
51
  public docsTypesUrl:string;
52
  public docsFunderUrl:string;
53
  public dataProjectsUrl:string ;
54
  public pubsProjectsUrl:string;
55

    
56
  // Variables for publications, research data, projects, content providers, related content providers tabs
57
  public fetchPublications : FetchPublications;
58
  public fetchDatasets: FetchDatasets;
59
  public fetchProjects: FetchProjects;
60
  public fetchDataproviders: FetchDataproviders;
61
  public fetchAggregatorsPublications: FetchPublications;
62
  public fetchAggregatorsDatasets: FetchDatasets;
63

    
64
  public loadingRelatedDatasources: boolean = true;
65

    
66
  // Active tab variable for responsiveness - show tabs only if main request is completed
67
  public activeTab: string = "";
68
  public showTabs:boolean = false;
69

    
70
  public routerHelper:RouterHelper = new RouterHelper();
71
  public errorCodes:ErrorCodes = new ErrorCodes();
72

    
73
  // Request results of each tab only the one time (first time tab is clicked)
74
  private reloadPublications: boolean = true;
75
  private reloadDatasets: boolean = true;
76
  private reloadProjects: boolean = true;
77
  private reloadDataproviders: boolean = true;
78
  private reloadRelatedDatasources: boolean = true;
79

    
80
  private nativeElement : Node;
81

    
82
  sub: any;
83
  piwiksub: any;
84
  subInfo: any;
85
  relatedDatasourcesSub: any;
86

    
87
  constructor (private element: ElementRef,
88
               private _dataproviderService: DataProviderService,
89
               private _piwikService:PiwikService,
90
               private route: ActivatedRoute,
91
               private _meta: Meta,
92
               private _router: Router,
93
               private _searchPublicationsService: SearchPublicationsService,
94
               private _searchDatasetsService: SearchDatasetsService,
95
               private _searchProjectsService: SearchProjectsService,
96
               private _searchDataprovidersService: SearchDataprovidersService) {
97
                 this.fetchPublications = new FetchPublications(this._searchPublicationsService);
98
                 this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
99
                 this.fetchProjects = new FetchProjects(this._searchProjectsService);
100
                 this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
101

    
102
                 this.updateUrl(OpenaireProperties.getBaseLink()+this._router.url);
103
 }
104

    
105
 ngOnInit() {
106
   this.sub =  this.route.queryParams.subscribe(data => {
107
      this.updateTitle("Content provider");
108
      this.updateDescription("Content provider, search, repositories, open access");
109
      this.datasourceId = data['datasourceId'];
110
      if(this.datasourceId){
111
       this.getDataProviderInfo(this.datasourceId);
112
      }else{
113
       // console.info("Content Provider id not found");
114
      }
115

    
116
      if (typeof document !== 'undefined') {
117
        this.element.nativeElement.scrollIntoView();
118
      }
119
   });
120
 }
121

    
122
   ngOnDestroy() {
123
     this.sub.unsubscribe();
124
     if(this.piwiksub){
125
       this.piwiksub.unsubscribe();
126
     }
127
     if(this.subInfo) {
128
      this.subInfo.unsubscribe();
129
     }
130

    
131
     if(this.relatedDatasourcesSub) {
132
       this.relatedDatasourcesSub.unsubscribe();
133
     }
134
   }
135
  private getDataProviderInfo(id:string) {
136
    this.warningMessage = '';
137
    this.errorMessage=""
138
    this.showLoading = true;
139

    
140
    this.showTabs = false ;
141
    if(this.datasourceId==null || this.datasourceId==''){
142
      this.showLoading = false;
143
      this.warningMessage="No valid datasource id";
144
    }else{
145
      this.subInfo = this._dataproviderService.getDataproviderInfo(this.datasourceId).subscribe(
146
        data => {
147
            this.dataProviderInfo = data;
148
            this.initTabs();
149
            this.showTabs = true ;
150
            this.updateTitle(this.dataProviderInfo.title.name);
151
            this.updateDescription("Content provider, search, repositories, open access,"+this.dataProviderInfo.title.name);
152
            if(OpenaireProperties.isPiwikTrackEnabled() && (typeof document !== 'undefined')){
153
              this.piwiksub = this._piwikService.trackView(this.dataProviderInfo.title.name).subscribe();
154
            }
155

    
156
            this.showLoading = false;
157

    
158
            if(this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
159
              this.activeTab = this.dataProviderInfo.tabs[0].name;
160
            }
161
        },
162
        err => {
163
          console.log(err)
164
          // console.info("error");
165
          this.errorMessage = 'No dataProvider found';
166
          this.showLoading = false;
167
        }
168
      );
169
    }
170
   }
171

    
172
   private updateDescription(description:string){
173
     this._meta.updateMeta("description", description);
174
     this._meta.updateProperty("og:description", description);
175
   }
176
   private updateTitle(title:string){
177
     var _prefix ="OpenAIRE | ";
178
     var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
179
     this._meta.setTitle(_title );
180
     this._meta.updateProperty("og:title",_title);
181
   }
182
   private updateUrl(url:string){
183
     this._meta.updateProperty("og:url", url);
184
   }
185

    
186
   private initTabs(){
187

    
188
           if(this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
189
               this.reloadPublications = true;
190
               this.reloadDatasets = true;
191
               this.reloadProjects = true;
192
               this.reloadDataproviders = true;
193
               this.reloadRelatedDatasources = true;
194
               this.statsClicked = false;
195

    
196
               this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
197
               this.count(1, 0);
198

    
199
               this.metricsClicked = false;
200

    
201
               this.viewsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"dtsrcRepoViews","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":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["column"]&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';
202
               /*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';
203
               */
204

    
205
               this.downloadsFrameUrl = OpenaireProperties.getFramesAPIURL()+'merge.php?com=query&data=[{"query":"dtsrcRepoDownloads","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":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]&info_types=["column"]&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';
206
               /*
207
               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';
208
               */
209

    
210
               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": -30, "s": "-", "l": "-", "ft": "-", "wt": "-"}, "yaxisheaders": [""], "fieldsheaders": ["Research Results"], "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';
211
               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": ["Research Results"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
212
               this.docsFunderUrl =' 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": ["Research Results"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
213
               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": ["Research Data"], "in": [], "filters": [{"name": "result_datasources-datasource-name", "values": [""], "to": "-1"}], "having": [], "incfilters": [], "inchaving": [], "title": "", "subtitle": "", "xaxistitle": ""}&w=600&h=250';
214
               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';
215

    
216
               //if({"name": "Publications", "content": "publicationsTab"} in this.dataProviderInfo.tabs) {
217
               //if(this.dataProviderInfo.tabs.some(function (tab) {
218
               //    return tab.name === 'Publications';
219
               //})) {
220
               //    this.relatedDataprovidersResultsType = 'publications';
221
                   this.fetchAggregatorsPublications = new FetchPublications(this._searchPublicationsService);
222
               //} else {
223
               //   this.relatedDataprovidersResultsType = 'datasets';
224
                   this.fetchAggregatorsDatasets = new FetchDatasets(this._searchDatasetsService);
225
               //}
226
           }
227
           if(this.dataProviderInfo.resultsBy == "collectedFrom") {
228
               //this.paramsForSearchLink = "?collectedFrom="+this.datasourceId+"&co=and";
229
               this.paramsForSearchLink = this.routerHelper.createQueryParams(['collectedFrom', 'co'], [this.datasourceId, 'and']);
230
           } else if (this.dataProviderInfo.resultsBy == "hostedBy") {
231
               //this.paramsForSearchLink = "?hostedBy="+this.datasourceId+"&ho=and";
232
               this.paramsForSearchLink = this.routerHelper.createQueryParams(['hostedBy', 'ho'], [this.datasourceId, 'and']);
233
           }
234

    
235
   }
236

    
237
   private count(page: number, size: number) {
238
       for(let i=1; i<this.dataProviderInfo.tabs.length; i++) {
239
           let content: string = this.dataProviderInfo.tabs[i].content;
240

    
241
           if(content=='publicationsTab') {
242
               this.countPublications(page, size);
243
           } else if(content=='datasetsTab') {
244
               this.countDatasets(page, size);
245
           } else if(content=='projectsTab') {
246
               this.countProjects(page, size);
247
           } else if(content=='datasourcesTab') {
248
               this.countDatasources(page, size);
249
           }// else if(content=='relatedDatasourcesTab') {
250
           //    this.countRelatedDatasources(page, size);
251
           //}
252
       }
253
   }
254

    
255
   public search(content: string, page: number, size: number) {
256
       if(content=='publicationsTab') {
257
           this.searchPublications(page, size);
258
       } else if(content=='datasetsTab') {
259
           this.searchDatasets(page, size);
260
       } else if(content=='projectsTab') {
261
           this.searchProjects(page, size);
262
       } else if(content=='datasourcesTab') {
263
           this.searchDatasources(page, size);
264
       } else if(content=='relatedDatasourcesTab') {
265
           this.searchRelatedDatasources(1, 0);
266
       } else if(content=='metricsTab') {
267
           this.metricsClicked = true;
268
       } else if(content=='statisticsTab') {
269
           this.statsClicked = true;
270
       }
271
   }
272

    
273
   private searchPublications(page: number, size: number) {
274
     if(this.fetchPublications.searchUtils.status == this.errorCodes.NONE) {
275
       this.reloadPublications = false;
276
     }
277

    
278
     if(this.reloadPublications) {
279
       this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
280
     }
281
     this.reloadPublications = false;
282
    }
283

    
284
    private countPublications(page: number, size: number) {
285
      this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
286
    }
287

    
288
    private searchDatasets(page: number, size: number) {
289
      if(this.fetchDatasets.searchUtils.status == this.errorCodes.NONE) {
290
        this.reloadDatasets = false;
291
      }
292

    
293
      if(this.reloadDatasets) {
294
        this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
295
      }
296
      this.reloadDatasets = false;
297
    }
298

    
299
    private countDatasets(page: number, size: number) {
300
      this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size);
301
    }
302

    
303
    private searchProjects(page: number, size: number) {
304
      if(this.fetchProjects.searchUtils.status == this.errorCodes.NONE) {
305
        this.reloadProjects = false;
306
      }
307

    
308
      if(this.reloadProjects) {
309
        this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
310
      }
311
      this.reloadProjects = false;
312
    }
313

    
314
    private countProjects(page: number, size: number) {
315
      this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size);
316
    }
317

    
318
    private searchDatasources(page: number, size: number) {
319
      if(this.fetchDataproviders.searchUtils.status == this.errorCodes.NONE) {
320
        this.reloadDataproviders = false;
321
      }
322

    
323
      if(this.reloadDataproviders) {
324
        this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
325
      }
326
      this.reloadDataproviders = false;
327
    }
328

    
329
    private countDatasources(page: number, size: number) {
330
      this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size);
331
    }
332

    
333
    private searchRelatedDatasources(page: number, size: number) {
334
      // Currently no counting is done for this tab. Following condition is always false
335
      if(this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.NONE
336
          && this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.NONE) {
337
        this.reloadRelatedDatasources = false;
338
        this.loadingRelatedDatasources = false;
339
      }
340

    
341
      if(this.reloadRelatedDatasources) {
342
        this.relatedDatasourcesSub = Observable.merge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete)
343
                               .subscribe(
344
                                 data => {},
345
                                 err => {},
346
                                 () => { this.preprocessRelatedDatasources(); }
347
                               )
348

    
349
         this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size);
350
         this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size);
351
        }
352

    
353

    
354
      this.reloadRelatedDatasources = false;
355
    }
356

    
357
    private countRelatedDatasources(page: number, size: number) {
358
      this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size);
359
      this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size);
360
    }
361

    
362

    
363
    private preprocessRelatedDatasources() {
364
      if(this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE || this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE) {
365
        this.dataProviderInfo.relatedDatasources = new Map<string, {"name": string, "countPublications": string, "countDatasets": string}>();
366
      }
367
      for(let result of this.fetchAggregatorsPublications.results) {
368
        if(!this.dataProviderInfo.relatedDatasources.has(result.id)) {
369
          this.dataProviderInfo.relatedDatasources.set(result.id, {"name": result.name, "countPublications": result.count, "countDatasets": "0"});
370
        } else {
371
          this.dataProviderInfo.relatedDatasources.get(result.id).countPublications = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countPublications + result.count)+"";
372
        }
373
      }
374

    
375
      for(let result of this.fetchAggregatorsDatasets.results) {
376
        if(!this.dataProviderInfo.relatedDatasources.has(result.id)) {
377
          this.dataProviderInfo.relatedDatasources.set(result.id, {"name": result.name, "countPublications": "0", "countDatasets": result.count});
378
        } else {
379
          this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets + result.count)+"";
380
        }
381
      }
382

    
383
      this.loadingRelatedDatasources = false;
384
    }
385

    
386
    public metricsResults($event) {
387
      this.totalViews = $event.totalViews;
388
      this.totalDownloads = $event.totalDownloads;
389
      this.pageViews = $event.pageViews;
390
    }
391
}
(3-3/13)