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 '../../sharedComponents/metaService';
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 {ErrorCodes} from '../../utils/properties/errorCodes';
17
import {RouterHelper} from '../../utils/routerHelper.class';
18
import {PiwikService} from '../../utils/piwik/piwik.service';
19
import{EnvProperties} from '../../utils/properties/env-properties';
20

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

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

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

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

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

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

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

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

    
65
  public loadingRelatedDatasources: boolean = true;
66

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

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

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

    
81
  private nativeElement : Node;
82

    
83
  sub: any;
84
  piwiksub: any;
85
  subInfo: any;
86
  relatedDatasourcesSub: any;
87
  properties:EnvProperties;
88

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

    
104
 }
105

    
106
 ngOnInit() {
107
   this.route.data
108
     .subscribe((data: { envSpecific: EnvProperties }) => {
109
        this.properties = data.envSpecific;
110
        this.updateUrl(data.envSpecific.baseLink+this._router.url);
111

    
112
     });
113
   this.sub =  this.route.queryParams.subscribe(data => {
114
      this.updateTitle("Content provider");
115
      this.updateDescription("Content provider, search, repositories, open access");
116
      this.datasourceId = data['datasourceId'];
117
      if(this.datasourceId){
118
       this.getDataProviderInfo(this.datasourceId);
119
      }else{
120
       // console.info("Content Provider id not found");
121
      }
122

    
123
      if (typeof document !== 'undefined') {
124
        this.element.nativeElement.scrollIntoView();
125
      }
126
   });
127
 }
128

    
129
   ngOnDestroy() {
130
     this.sub.unsubscribe();
131
     if(this.piwiksub){
132
       this.piwiksub.unsubscribe();
133
     }
134
     if(this.subInfo) {
135
      this.subInfo.unsubscribe();
136
     }
137

    
138
     if(this.relatedDatasourcesSub) {
139
       this.relatedDatasourcesSub.unsubscribe();
140
     }
141
   }
142
  private getDataProviderInfo(id:string) {
143
    this.warningMessage = '';
144
    this.errorMessage=""
145
    this.showLoading = true;
146

    
147
    this.showTabs = false ;
148
    if(this.datasourceId==null || this.datasourceId==''){
149
      this.showLoading = false;
150
      this.warningMessage="No valid datasource id";
151
    }else{
152
      this.subInfo = this._dataproviderService.getDataproviderInfo(this.datasourceId, this.properties).subscribe(
153
        data => {
154
            this.dataProviderInfo = data;
155
            this.initTabs();
156
            this.showTabs = true ;
157
            this.updateTitle(this.dataProviderInfo.title.name);
158
            this.updateDescription("Content provider, search, repositories, open access,"+this.dataProviderInfo.title.name);
159
            if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
160
              this.piwiksub = this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name).subscribe();
161
            }
162

    
163
            this.showLoading = false;
164

    
165
            if(this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
166
              this.activeTab = this.dataProviderInfo.tabs[0].name;
167
            }
168
        },
169
        err => {
170
          console.log(err);
171
          // console.info("error");
172
          this.errorMessage = 'No dataProvider found';
173
          this.showLoading = false;
174
        }
175
      );
176
    }
177
   }
178

    
179
   private updateDescription(description:string){
180
     this._meta.updateMeta("description", description);
181
     this._meta.updateProperty("og:description", description);
182
   }
183
   private updateTitle(title:string){
184
     var _prefix ="OpenAIRE | ";
185
     var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
186
     this._meta.setTitle(_title );
187
     this._meta.updateProperty("og:title",_title);
188
   }
189
   private updateUrl(url:string){
190
     this._meta.updateProperty("og:url", url);
191
   }
192

    
193
   private initTabs(){
194

    
195
           if(this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
196
               this.reloadPublications = true;
197
               this.reloadDatasets = true;
198
               this.reloadProjects = true;
199
               this.reloadDataproviders = true;
200
               this.reloadRelatedDatasources = true;
201
               this.statsClicked = false;
202

    
203
               this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
204
               this.count(1, 0);
205

    
206
               this.metricsClicked = false;
207

    
208
               this.viewsFrameUrl = this.properties.framesAPIURL +'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';
209
               /*this.viewsFrameUrl = this.properties.framesAPIURL+'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';
210
               */
211

    
212
               this.downloadsFrameUrl = this.properties.framesAPIURL +'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';
213
               /*
214
               this.downloadsFrameUrl = this.properties.framesAPIURL +'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';
215
               */
216

    
217
               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';
218
               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';
219
               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';
220
               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';
221
               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';
222

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

    
242
   }
243

    
244
   private count(page: number, size: number) {
245
       for(let i=1; i<this.dataProviderInfo.tabs.length; i++) {
246
           let content: string = this.dataProviderInfo.tabs[i].content;
247

    
248
           if(content=='publicationsTab') {
249
               this.countPublications(page, size);
250
           } else if(content=='datasetsTab') {
251
               this.countDatasets(page, size);
252
           } else if(content=='projectsTab') {
253
               this.countProjects(page, size);
254
           } else if(content=='datasourcesTab') {
255
               this.countDatasources(page, size);
256
           }// else if(content=='relatedDatasourcesTab') {
257
           //    this.countRelatedDatasources(page, size);
258
           //}
259
       }
260
   }
261

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

    
280
   private searchPublications(page: number, size: number) {
281
     if(  this.reloadPublications &&
282
          ( this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
283
            this.fetchPublications.searchUtils.status == this.errorCodes.DONE ) ) {
284
       this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
285
     }
286
     this.reloadPublications = false;
287
    }
288

    
289
    private countPublications(page: number, size: number) {
290
      this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
291
    }
292

    
293
    private searchDatasets(page: number, size: number) {
294
      if( this.reloadDatasets &&
295
          ( this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
296
            this.fetchDatasets.searchUtils.status == this.errorCodes.DONE ) ) {
297
        this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
298
      }
299
      this.reloadDatasets = false;
300
    }
301

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

    
306
    private searchProjects(page: number, size: number) {
307
      if( this.reloadProjects &&
308
          ( this.fetchProjects.searchUtils.status == this.errorCodes.LOADING ||
309
            this.fetchProjects.searchUtils.status == this.errorCodes.DONE ) ) {
310
        this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
311
      }
312
      this.reloadProjects = false;
313
    }
314

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

    
319
    private searchDatasources(page: number, size: number) {
320
      if( this.reloadDataproviders &&
321
          ( this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
322
            this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE ) ) {
323
        this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
324
      }
325
      this.reloadDataproviders = false;
326
    }
327

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

    
332
    private searchRelatedDatasources(page: number, size: number) {
333
      // Currently no counting is done for this tab. Following condition is always false
334

    
335
      if( this.reloadRelatedDatasources &&
336
          ( this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.LOADING ||
337
            this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE )
338
          &&
339
          ( this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.LOADING ||
340
            this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE ) ) {
341
        this.relatedDatasourcesSub = Observable.merge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete)
342
                               .subscribe(
343
                                 data => {},
344
                                 err => {},
345
                                 () => { this.preprocessRelatedDatasources(); }
346
                               )
347

    
348
         this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size, this.properties);
349
         this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size, this.properties);
350
       } else {
351
         this.loadingRelatedDatasources = false;
352
       }
353

    
354

    
355
      this.reloadRelatedDatasources = false;
356
    }
357

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

    
363

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

    
377
      for(let result of this.fetchAggregatorsDatasets.results) {
378
        if(!this.dataProviderInfo.relatedDatasources.has(result.id)) {
379
          this.dataProviderInfo.relatedDatasources.set(result.id, {"name": result.name, "countPublications": "0", "countDatasets": result.count});
380
        } else {
381
          this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets + result.count)+"";
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/12)