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 {FetchResearchResults} from '../../utils/fetchEntitiesClasses/fetchResearchResults.class';
12
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
13
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
14
import {SearchProjectsService} from '../../services/searchProjects.service';
15
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
16
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
17
import {ErrorCodes} from '../../utils/properties/errorCodes';
18
import {RouterHelper} from '../../utils/routerHelper.class';
19
import {PiwikService} from '../../utils/piwik/piwik.service';
20
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
21
import {HelperFunctions} from "../../utils/HelperFunctions.class";
22
import {HelperService} from "../../utils/helper/helper.service";
23

    
24

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

    
30
export class DataProviderComponent {
31
  @Input() piwikSiteId = null;
32
  @Input() communityId = null;
33
  public dataProviderInfo: DataProviderInfo;
34
  public datasourceId: string;
35

    
36
  // Message variables
37
  public warningMessage = "";
38
  public errorMessage = "";
39
  public showLoading: boolean = true;
40

    
41
  // Variable to specify requests with either collectedFrom or hostedBy
42
  public paramsForSearchLink = {};
43

    
44
  // Metrics tab variables
45
  public metricsClicked: boolean;
46
  public viewsFrameUrl: string;
47
  public downloadsFrameUrl: string;
48
  public totalViews: number;
49
  public totalDownloads: number;
50
  public pageViews: number;
51

    
52
  // Statistics tab variables
53
  public statsClicked: boolean = false;
54
  public docsTimelineUrl: string;
55
  public docsTypesUrl: string;
56
  public docsFunderUrl: string;
57
  public dataProjectsUrl: string;
58
  public pubsProjectsUrl: string;
59

    
60
  // Variables for publications, research data, projects, content providers, related content providers tabs
61
  public fetchPublications: FetchResearchResults;
62
  public fetchDatasets: FetchResearchResults;
63
  public fetchSoftware: FetchResearchResults;
64
  public fetchOrps: FetchResearchResults;
65
  public fetchProjects: FetchProjects;
66
  public fetchDataproviders: FetchDataproviders;
67
  public fetchAggregatorsPublications: FetchResearchResults;
68
  public fetchAggregatorsDatasets: FetchResearchResults;
69
  public fetchAggregatorsSoftware: FetchResearchResults;
70
  public fetchAggregatorsOrps: FetchResearchResults;
71

    
72
  public loadingRelatedDatasources: boolean = true;
73

    
74
  // Active tab variable for responsiveness - show tabs only if main request is completed
75
  public activeTab: string = "";
76
  public showTabs: boolean = false;
77

    
78
  public routerHelper: RouterHelper = new RouterHelper();
79
  public errorCodes: ErrorCodes = new ErrorCodes();
80
  public pageContents = null;
81
  public divContents = null;
82

    
83
  // Request results of each tab only the one time (first time tab is clicked)
84
  private reloadPublications: boolean = true;
85
  private reloadDatasets: boolean = true;
86
  private reloadSoftware: boolean = true;
87
  private reloadOrps: boolean = true;
88
  private reloadProjects: boolean = true;
89
  private reloadDataproviders: boolean = true;
90
  private reloadRelatedDatasources: boolean = true;
91

    
92
  sub: any;
93
  piwiksub: any;
94
  subInfo: any;
95
  relatedDatasourcesSub: any;
96
  properties: EnvProperties;
97

    
98
  constructor(private _dataproviderService: DataProviderService,
99
              private _piwikService: PiwikService,
100
              private route: ActivatedRoute,
101
              private _meta: Meta,
102
              private _title: Title,
103
              private _router: Router,
104
              private _searchResearchResultsService: SearchResearchResultsService,
105
              private _searchProjectsService: SearchProjectsService,
106
              private _searchDataprovidersService: SearchDataprovidersService,
107
              private seoService: SEOService,
108
              private helper: HelperService) {
109
    this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
110
    this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
111
    this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
112
    this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
113
    this.fetchProjects = new FetchProjects(this._searchProjectsService);
114
    this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
115

    
116
  }
117

    
118
  ngOnInit() {
119
    this.route.data
120
      .subscribe((data: { envSpecific: EnvProperties }) => {
121
        this.properties = data.envSpecific;
122
        //this.getDivContents();
123
        this.getPageContents();
124
        this.updateUrl(data.envSpecific.baseLink + this._router.url);
125

    
126
      });
127
    this.sub = this.route.queryParams.subscribe(data => {
128
      this.updateTitle("Content provider");
129
      this.updateDescription("");
130
      this.datasourceId = data['datasourceId'];
131
      if (this.datasourceId) {
132
        this.getDataProviderInfo(this.datasourceId);
133
      } else {
134
        this.showLoading = false;
135
        this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToDataProvider + this.datasourceId, "page_type": "dataprovider"}});
136
      }
137

    
138
      HelperFunctions.scroll();
139
    });
140
  }
141

    
142
  private getPageContents() {
143
    this.helper.getPageHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
144
      this.pageContents = contents;
145
    })
146
  }
147

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

    
154
  ngOnDestroy() {
155
    if (this.sub) {
156
      this.sub.unsubscribe();
157
    }
158
    if (this.piwiksub) {
159
      this.piwiksub.unsubscribe();
160
    }
161
    if (this.subInfo) {
162
      this.subInfo.unsubscribe();
163
    }
164

    
165
    if (this.relatedDatasourcesSub) {
166
      this.relatedDatasourcesSub.unsubscribe();
167
    }
168
  }
169

    
170
  private getDataProviderInfo(id: string) {
171
    this.warningMessage = '';
172
    this.errorMessage = ""
173
    this.showLoading = true;
174

    
175
    this.dataProviderInfo = null;
176

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

    
197
          this.showLoading = false;
198

    
199
          if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
200
            this.activeTab = this.dataProviderInfo.tabs[0].name;
201
          }
202
        },
203
        err => {
204
          //console.log(err);
205
          this.handleError("Error getting content provider for id: " + this.datasourceId, err);
206
          if(err.status == 404) {
207
            this._router.navigate(['/error'], {queryParams: {"page": this.properties.searchLinkToDataProvider + this.datasourceId, "page_type": "dataprovider"}});
208
          }
209
          //this.errorMessage = 'No dataProvider found';
210
          this.showLoading = false;
211
          this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToDataProviders);
212
        }
213
      );
214
    }
215
  }
216

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

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

    
234
  private updateTitle(title: string) {
235
    var _prefix = "";
236
    if(this.communityId) {
237
      _prefix = "OpenAIRE | ";
238
    }
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=90%&h=90%';
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=90%&h=90%';
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=90%&h=90%';
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=90%&h=90%';
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=90%&h=90%';
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 FetchResearchResults(this._searchResearchResultsService);
286
      //} else {
287
      //   this.relatedDataprovidersResultsType = 'datasets';
288
      this.fetchAggregatorsDatasets = new FetchResearchResults(this._searchResearchResultsService);
289
      //}
290
      this.fetchAggregatorsSoftware = new FetchResearchResults(this._searchResearchResultsService);
291
      this.fetchAggregatorsOrps = new FetchResearchResults(this._searchResearchResultsService);
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("publication", 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("publication", 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("dataset", 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("dataset", 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("software", 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("software", 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("other", 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("other", 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("publication", this.datasourceId, page, size, this.properties);
452
      this.fetchAggregatorsDatasets.getAggregatorResults("dataset", this.datasourceId, page, size, this.properties);
453
      this.fetchAggregatorsSoftware.getAggregatorResults("software", this.datasourceId, page, size, this.properties);
454
      this.fetchAggregatorsOrps.getAggregatorResults("other", 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("publication", this.datasourceId, page, size, this.properties);
465
    this.fetchAggregatorsDatasets.getAggregatorResults("dataset", this.datasourceId, page, size, this.properties);
466
    this.fetchAggregatorsSoftware.getAggregatorResults("software", this.datasourceId, page, size, this.properties);
467
    this.fetchAggregatorsOrps.getAggregatorResults("other", 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)