Project

General

Profile

1
import {merge as observableMerge} from 'rxjs';
2
import {Component, Input} from '@angular/core';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {Meta, Title} from '@angular/platform-browser';
5

    
6

    
7
import {EnvProperties} from '../../utils/properties/env-properties';
8

    
9
import {DataProviderInfo} from '../../utils/entities/dataProviderInfo';
10
import {DataProviderService} from './dataProvider.service';
11
import {FetchPublications} from '../../utils/fetchEntitiesClasses/fetchPublications.class';
12
import {SearchPublicationsService} from '../../services/searchPublications.service';
13
import {FetchDatasets} from '../../utils/fetchEntitiesClasses/fetchDatasets.class';
14
import {SearchDatasetsService} from '../../services/searchDatasets.service';
15
import {FetchSoftware} from '../../utils/fetchEntitiesClasses/fetchSoftware.class';
16
import {SearchSoftwareService} from '../../services/searchSoftware.service';
17
import {FetchOrps} from '../../utils/fetchEntitiesClasses/fetchOrps.class';
18
import {SearchOrpsService} from '../../services/searchOrps.service';
19
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
20
import {SearchProjectsService} from '../../services/searchProjects.service';
21
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
22
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
23
import {ErrorCodes} from '../../utils/properties/errorCodes';
24
import {RouterHelper} from '../../utils/routerHelper.class';
25
import {PiwikService} from '../../utils/piwik/piwik.service';
26
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
27
import {HelperFunctions} from "../../utils/HelperFunctions.class";
28
import {HelperService} from "../../utils/helper/helper.service";
29

    
30

    
31
@Component({
32
  selector: 'dataprovider',
33
  templateUrl: 'dataProvider.component.html',
34
})
35

    
36
export class DataProviderComponent {
37
  @Input() piwikSiteId = null;
38
  @Input() communityId = null;
39
  public dataProviderInfo: DataProviderInfo;
40
  public datasourceId: string;
41

    
42
  // Message variables
43
  public warningMessage = "";
44
  public errorMessage = "";
45
  public showLoading: boolean = true;
46

    
47
  // Variable to specify requests with either collectedFrom or hostedBy
48
  public paramsForSearchLink = {};
49

    
50
  // Metrics tab variables
51
  public metricsClicked: boolean;
52
  public viewsFrameUrl: string;
53
  public downloadsFrameUrl: string;
54
  public totalViews: number;
55
  public totalDownloads: number;
56
  public pageViews: number;
57

    
58
  // Statistics tab variables
59
  public statsClicked: boolean = false;
60
  public docsTimelineUrl: string;
61
  public docsTypesUrl: string;
62
  public docsFunderUrl: string;
63
  public dataProjectsUrl: string;
64
  public pubsProjectsUrl: string;
65

    
66
  // Variables for publications, research data, projects, content providers, related content providers tabs
67
  public fetchPublications: FetchPublications;
68
  public fetchDatasets: FetchDatasets;
69
  public fetchSoftware: FetchSoftware;
70
  public fetchOrps: FetchOrps;
71
  public fetchProjects: FetchProjects;
72
  public fetchDataproviders: FetchDataproviders;
73
  public fetchAggregatorsPublications: FetchPublications;
74
  public fetchAggregatorsDatasets: FetchDatasets;
75
  public fetchAggregatorsSoftware: FetchSoftware;
76
  public fetchAggregatorsOrps: FetchOrps;
77

    
78
  public loadingRelatedDatasources: boolean = true;
79

    
80
  // Active tab variable for responsiveness - show tabs only if main request is completed
81
  public activeTab: string = "";
82
  public showTabs: boolean = false;
83

    
84
  public routerHelper: RouterHelper = new RouterHelper();
85
  public errorCodes: ErrorCodes = new ErrorCodes();
86
  public pageContents = null;
87
  public divContents = null;
88

    
89
  // Request results of each tab only the one time (first time tab is clicked)
90
  private reloadPublications: boolean = true;
91
  private reloadDatasets: boolean = true;
92
  private reloadSoftware: boolean = true;
93
  private reloadOrps: boolean = true;
94
  private reloadProjects: boolean = true;
95
  private reloadDataproviders: boolean = true;
96
  private reloadRelatedDatasources: boolean = true;
97

    
98
  sub: any;
99
  piwiksub: any;
100
  subInfo: any;
101
  relatedDatasourcesSub: any;
102
  properties: EnvProperties;
103

    
104
  constructor(private _dataproviderService: DataProviderService,
105
              private _piwikService: PiwikService,
106
              private route: ActivatedRoute,
107
              private _meta: Meta,
108
              private _title: Title,
109
              private _router: Router,
110
              private _searchPublicationsService: SearchPublicationsService,
111
              private _searchDatasetsService: SearchDatasetsService,
112
              private _searchSoftwareService: SearchSoftwareService,
113
              private _searchOrpsService: SearchOrpsService,
114
              private _searchProjectsService: SearchProjectsService,
115
              private _searchDataprovidersService: SearchDataprovidersService,
116
              private seoService: SEOService,
117
              private helper: HelperService) {
118
    this.fetchPublications = new FetchPublications(this._searchPublicationsService);
119
    this.fetchDatasets = new FetchDatasets(this._searchDatasetsService);
120
    this.fetchSoftware = new FetchSoftware(this._searchSoftwareService);
121
    this.fetchOrps = new FetchOrps(this._searchOrpsService);
122
    this.fetchProjects = new FetchProjects(this._searchProjectsService);
123
    this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
124

    
125
  }
126

    
127
  ngOnInit() {
128
    this.route.data
129
      .subscribe((data: { envSpecific: EnvProperties }) => {
130
        this.properties = data.envSpecific;
131
        //this.getDivContents();
132
        this.getPageContents();
133
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
134

    
135
      });
136
    this.sub = this.route.queryParams.subscribe(data => {
137
      this.updateTitle("Content provider");
138
      this.updateDescription("");
139
      this.datasourceId = data['datasourceId'];
140
      if (this.datasourceId) {
141
        this.getDataProviderInfo(this.datasourceId);
142
      }
143

    
144
      HelperFunctions.scroll();
145
    });
146
  }
147

    
148
  private getPageContents() {
149
    this.helper.getPageHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
150
      this.pageContents = contents;
151
    })
152
  }
153

    
154
  private getDivContents() {
155
    this.helper.getDivHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
156
      this.divContents = contents;
157
    })
158
  }
159

    
160
  ngOnDestroy() {
161
    if (this.sub) {
162
      this.sub.unsubscribe();
163
    }
164
    if (this.piwiksub) {
165
      this.piwiksub.unsubscribe();
166
    }
167
    if (this.subInfo) {
168
      this.subInfo.unsubscribe();
169
    }
170

    
171
    if (this.relatedDatasourcesSub) {
172
      this.relatedDatasourcesSub.unsubscribe();
173
    }
174
  }
175

    
176
  private getDataProviderInfo(id: string) {
177
    this.warningMessage = '';
178
    this.errorMessage = ""
179
    this.showLoading = true;
180

    
181
    this.dataProviderInfo = null;
182

    
183
    this.showTabs = false;
184
    if (this.datasourceId == null || this.datasourceId == '') {
185
      this.showLoading = false;
186
      this.warningMessage = "No valid datasource id";
187
    } else {
188
      this.subInfo = this._dataproviderService.getDataproviderInfo(this.datasourceId, this.properties).subscribe(
189
        data => {
190
          this.dataProviderInfo = data;
191
          this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this._router.url);
192
          if (typeof document !== 'undefined') {
193
            this.getDataProviderAggregationStatus(this.dataProviderInfo.originalId);
194
          }
195
          this.initTabs();
196
          this.showTabs = true;
197
          this.updateTitle(this.dataProviderInfo.title.name);
198
          this.updateDescription("Content provider, " + this.dataProviderInfo.title.name);
199
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
200
            this.piwiksub = this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name, this.piwikSiteId).subscribe();
201
          }
202

    
203
          this.showLoading = false;
204

    
205
          if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
206
            this.activeTab = this.dataProviderInfo.tabs[0].name;
207
          }
208
        },
209
        err => {
210
          //console.log(err);
211
          this.handleError("Error getting content provider for id: " + this.datasourceId, err);
212
          this.errorMessage = 'No dataProvider found';
213
          this.showLoading = false;
214
          this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToDataProviders);
215
        }
216
      );
217
    }
218
  }
219

    
220
  private getDataProviderAggregationStatus(originalId: string) {
221
    this.subInfo = this._dataproviderService.getDataproviderAggregationStatus(originalId, this.properties).subscribe(
222
      data => {
223
        this.dataProviderInfo.aggregationStatus = data;
224
      },
225
      err => {
226
        //console.log(err);
227
        this.handleError("Error getting content provider aggregation status for id: " + this.datasourceId, err);
228
      }
229
    );
230
  }
231

    
232
  private updateDescription(description: string) {
233
    this._meta.updateTag({content: description}, "name='description'");
234
    this._meta.updateTag({content: description}, "property='og:description'");
235
  }
236

    
237
  private updateTitle(title: string) {
238
    var _prefix = "OpenAIRE | ";
239
    var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
240
    this._title.setTitle(_title);
241
    this._meta.updateTag({content: _title}, "property='og:title'");
242
  }
243

    
244
  private updateUrl(url: string) {
245
    this._meta.updateTag({content: url}, "property='og:url'");
246
  }
247

    
248
  private initTabs() {
249

    
250
    if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
251
      this.reloadPublications = true;
252
      this.reloadDatasets = true;
253
      this.reloadSoftware = true;
254
      this.reloadOrps = true;
255
      this.reloadProjects = true;
256
      this.reloadDataproviders = true;
257
      this.reloadRelatedDatasources = true;
258
      this.statsClicked = false;
259

    
260
      //this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
261
      this.count(1, 0);
262

    
263
      this.metricsClicked = false;
264

    
265
      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';
266
      /*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';
267
      */
268

    
269
      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';
270
      /*
271
      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';
272
      */
273

    
274
      this.docsTimelineUrl = this.properties.statisticsFrameAPIURL + '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=100%&h=250';
275
      this.docsTypesUrl = this.properties.statisticsFrameAPIURL + '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=100%&h=250';
276
      this.docsFunderUrl = this.properties.statisticsFrameAPIURL + '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=100%&h=250';
277
      this.dataProjectsUrl = this.properties.statisticsFrameAPIURL + '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=100%&h=250';
278
      this.pubsProjectsUrl = this.properties.statisticsFrameAPIURL + '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=100%&h=250';
279

    
280
      //if({"name": "Publications", "content": "publicationsTab"} in this.dataProviderInfo.tabs) {
281
      //if(this.dataProviderInfo.tabs.some(function (tab) {
282
      //    return tab.name === 'Publications';
283
      //})) {
284
      //    this.relatedDataprovidersResultsType = 'publications';
285
      this.fetchAggregatorsPublications = new FetchPublications(this._searchPublicationsService);
286
      //} else {
287
      //   this.relatedDataprovidersResultsType = 'datasets';
288
      this.fetchAggregatorsDatasets = new FetchDatasets(this._searchDatasetsService);
289
      //}
290
      this.fetchAggregatorsSoftware = new FetchSoftware(this._searchSoftwareService);
291
      this.fetchAggregatorsOrps = new FetchOrps(this._searchOrpsService);
292
    }
293
    if (this.dataProviderInfo.resultsBy == "collectedFrom") {
294
      //this.paramsForSearchLink = "?collectedFrom="+this.datasourceId+"&co=and";
295
      this.paramsForSearchLink = this.routerHelper.createQueryParams(['collectedFrom', 'cl'], [this.datasourceId, 'and']);
296
    } else if (this.dataProviderInfo.resultsBy == "hostedBy") {
297
      //this.paramsForSearchLink = "?hostedBy="+this.datasourceId+"&ho=and";
298
      this.paramsForSearchLink = this.routerHelper.createQueryParams(['hostedBy', 'hs'], [this.datasourceId, 'and']);
299
    }
300

    
301
  }
302

    
303
  private count(page: number, size: number) {
304
    for (let i = 0; i < this.dataProviderInfo.tabs.length; i++) {
305
      let content: string = this.dataProviderInfo.tabs[i].content;
306

    
307
      if (content == 'publicationsTab') {
308
        this.countPublications(page, size);
309
      } else if (content == 'datasetsTab') {
310
        this.countDatasets(page, size);
311
      } else if (content == 'softwareTab') {
312
        this.countSoftware(page, size);
313
      } else if (content == 'orpsTab') {
314
        this.countOrps(page, size);
315
      } else if (content == 'projectsTab') {
316
        this.countProjects(page, size);
317
      } else if (content == 'datasourcesTab') {
318
        this.countDatasources(page, size);
319
      }// else if(content=='relatedDatasourcesTab') {
320
      //    this.countRelatedDatasources(page, size);
321
      //}
322
    }
323
  }
324

    
325
  public search(content: string, page: number, size: number) {
326
    if (content == 'publicationsTab') {
327
      this.searchPublications(page, size);
328
    } else if (content == 'datasetsTab') {
329
      this.searchDatasets(page, size);
330
    } else if (content == 'softwareTab') {
331
      this.searchSoftware(page, size);
332
    } else if (content == 'orpsTab') {
333
      this.searchOrps(page, size);
334
    } else if (content == 'projectsTab') {
335
      this.searchProjects(page, size);
336
    } else if (content == 'datasourcesTab') {
337
      this.searchDatasources(page, size);
338
    } else if (content == 'relatedDatasourcesTab') {
339
      this.searchRelatedDatasources(1, 0);
340
    } else if (content == 'metricsTab') {
341
      this.metricsClicked = true;
342
    } else if (content == 'statisticsTab') {
343
      this.statsClicked = !this.statsClicked;
344
    }
345
  }
346

    
347
  private searchPublications(page: number, size: number) {
348
    if (this.reloadPublications &&
349
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
350
        this.fetchPublications.searchUtils.status == this.errorCodes.DONE)) {
351
      this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
352
    }
353
    this.reloadPublications = false;
354
  }
355

    
356
  private countPublications(page: number, size: number) {
357
    this.fetchPublications.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
358
  }
359

    
360
  private searchDatasets(page: number, size: number) {
361
    if (this.reloadDatasets &&
362
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
363
        this.fetchDatasets.searchUtils.status == this.errorCodes.DONE)) {
364
      this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
365
    }
366
    this.reloadDatasets = false;
367
  }
368

    
369
  private countDatasets(page: number, size: number) {
370
    this.fetchDatasets.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
371
  }
372

    
373
  private searchSoftware(page: number, size: number) {
374
    if (this.reloadSoftware &&
375
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
376
        this.fetchSoftware.searchUtils.status == this.errorCodes.DONE)) {
377
      this.fetchSoftware.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
378
    }
379
    this.reloadSoftware = false;
380
  }
381

    
382
  private countSoftware(page: number, size: number) {
383
    this.fetchSoftware.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
384
  }
385

    
386
  private searchOrps(page: number, size: number) {
387
    if (this.reloadOrps &&
388
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
389
        this.fetchOrps.searchUtils.status == this.errorCodes.DONE)) {
390
      this.fetchOrps.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
391
    }
392
    this.reloadOrps = false;
393
  }
394

    
395
  private countOrps(page: number, size: number) {
396
    this.fetchOrps.getResultsForDataproviders(this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
397
  }
398

    
399
  private searchProjects(page: number, size: number) {
400
    if (this.reloadProjects &&
401
      (this.fetchProjects.searchUtils.status == this.errorCodes.LOADING ||
402
        this.fetchProjects.searchUtils.status == this.errorCodes.DONE)) {
403
      this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
404
    }
405
    this.reloadProjects = false;
406
  }
407

    
408
  private countProjects(page: number, size: number) {
409
    this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
410
  }
411

    
412
  private searchDatasources(page: number, size: number) {
413
    if (this.reloadDataproviders &&
414
      (this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
415
        this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE)) {
416
      this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
417
    }
418
    this.reloadDataproviders = false;
419
  }
420

    
421
  private countDatasources(page: number, size: number) {
422
    this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
423
  }
424

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

    
428
    if (this.reloadRelatedDatasources &&
429
      (this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.LOADING ||
430
        this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE)
431
      &&
432
      (this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.LOADING ||
433
        this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE)
434
      &&
435
      (this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.LOADING ||
436
        this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.DONE)
437
      &&
438
      (this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.LOADING ||
439
        this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE)) {
440
      this.relatedDatasourcesSub = observableMerge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete, this.fetchAggregatorsSoftware.requestComplete, this.fetchAggregatorsOrps.requestComplete)
441
        .subscribe(
442
          data => {
443
          },
444
          err => {
445
          },
446
          () => {
447
            this.preprocessRelatedDatasources();
448
          }
449
        )
450

    
451
      this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size, this.properties);
452
      this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size, this.properties);
453
      this.fetchAggregatorsSoftware.getAggregatorResults(this.datasourceId, page, size, this.properties);
454
      this.fetchAggregatorsOrps.getAggregatorResults(this.datasourceId, page, size, this.properties);
455
    } else {
456
      this.loadingRelatedDatasources = false;
457
    }
458

    
459

    
460
    this.reloadRelatedDatasources = false;
461
  }
462

    
463
  private countRelatedDatasources(page: number, size: number) {
464
    this.fetchAggregatorsPublications.getAggregatorResults(this.datasourceId, page, size, this.properties);
465
    this.fetchAggregatorsDatasets.getAggregatorResults(this.datasourceId, page, size, this.properties);
466
    this.fetchAggregatorsSoftware.getAggregatorResults(this.datasourceId, page, size, this.properties);
467
    this.fetchAggregatorsOrps.getAggregatorResults(this.datasourceId, page, size, this.properties);
468
  }
469

    
470

    
471
  private preprocessRelatedDatasources() {
472
    if (this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE ||
473
      this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE ||
474
      this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.DONE ||
475
      this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE) {
476
      this.dataProviderInfo.relatedDatasources = new Map<string, { "name": string, "countPublications": string, "countDatasets": string, "countSoftware": string, "countOrps": string }>();
477
    }
478
    for (let result of this.fetchAggregatorsPublications.results) {
479
      if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
480
        this.dataProviderInfo.relatedDatasources.set(result.id, {
481
          "name": result.name,
482
          "countPublications": result.count,
483
          "countDatasets": "0",
484
          "countSoftware": "0",
485
          "countOrps": "0"
486
        });
487
      } else {
488
        this.dataProviderInfo.relatedDatasources.get(result.id).countPublications = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countPublications + result.count) + "";
489
      }
490
    }
491

    
492
    for (let result of this.fetchAggregatorsDatasets.results) {
493
      if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
494
        this.dataProviderInfo.relatedDatasources.set(result.id, {
495
          "name": result.name,
496
          "countPublications": "0",
497
          "countDatasets": result.count,
498
          "countSoftware": "0",
499
          "countOrps": "0"
500
        });
501
      } else {
502
        this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countDatasets + result.count) + "";
503
      }
504
    }
505

    
506
    for (let result of this.fetchAggregatorsSoftware.results) {
507
      if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
508
        this.dataProviderInfo.relatedDatasources.set(result.id, {
509
          "name": result.name,
510
          "countPublications": "0",
511
          "countDatasets": "0",
512
          "countSoftware": result.count,
513
          "countOrps": "0"
514
        });
515
      } else {
516
        this.dataProviderInfo.relatedDatasources.get(result.id).countSoftware = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countSoftware + result.count) + "";
517
      }
518
    }
519

    
520
    for (let result of this.fetchAggregatorsOrps.results) {
521
      if (!this.dataProviderInfo.relatedDatasources.has(result.id)) {
522
        this.dataProviderInfo.relatedDatasources.set(result.id, {
523
          "name": result.name,
524
          "countPublications": "0",
525
          "countDatasets": "0",
526
          "countSoftware": "0",
527
          "countOrps": result.count
528
        });
529
      } else {
530
        this.dataProviderInfo.relatedDatasources.get(result.id).countOrps = parseInt(this.dataProviderInfo.relatedDatasources.get(result.id).countOrps + result.count) + "";
531
      }
532
    }
533
    this.loadingRelatedDatasources = false;
534
  }
535

    
536
  public metricsResults($event) {
537
    this.totalViews = $event.totalViews;
538
    this.totalDownloads = $event.totalDownloads;
539
    this.pageViews = $event.pageViews;
540
  }
541

    
542
  private handleError(message: string, error) {
543
    console.error("Content Provider Landing Page: " + message, error);
544
  }
545
}
(2-2/13)