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

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

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

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

    
157
            this.showLoading = false;
158

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

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

    
187
   private initTabs(){
188

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

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

    
200
               this.metricsClicked = false;
201

    
202
               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';
203
               /*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';
204
               */
205

    
206
               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';
207
               /*
208
               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';
209
               */
210

    
211
               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';
212
               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';
213
               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';
214
               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';
215
               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';
216

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

    
236
   }
237

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
354

    
355
      this.reloadRelatedDatasources = false;
356
    }
357

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

    
363

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

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

    
384
      this.loadingRelatedDatasources = false;
385
    }
386

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