Project

General

Profile

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

    
5

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

    
8
import {DataProviderInfo} from '../../utils/entities/dataProviderInfo';
9
import {DataProviderService} from './dataProvider.service';
10
import {FetchResearchResults} from '../../utils/fetchEntitiesClasses/fetchResearchResults.class';
11
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
12
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
13
import {SearchProjectsService} from '../../services/searchProjects.service';
14
import {FetchDataproviders} from '../../utils/fetchEntitiesClasses/fetchDataproviders.class';
15
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
16
import {ErrorCodes} from '../../utils/properties/errorCodes';
17
import {RouterHelper} from '../../utils/routerHelper.class';
18
import {PiwikService} from '../../utils/piwik/piwik.service';
19
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
20
import {HelperFunctions} from "../../utils/HelperFunctions.class";
21
import {HelperService} from "../../utils/helper/helper.service";
22
import {Location} from "@angular/common";
23
import {StringUtils} from "../../utils/string-utils.class";
24
import {SearchResult} from "../../utils/entities/searchResult";
25
import {ResultPreview} from "../../utils/result-preview/result-preview";
26
import {IndexInfoService} from "../../utils/indexInfo.service";
27
import {properties} from "../../../../environments/environment";
28
import {Subscriber} from "rxjs";
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
  // Metrics tab variables
48
  public metricsClicked: boolean;
49
  public viewsFrameUrl: string;
50
  public downloadsFrameUrl: string;
51
  public totalViews: number;
52
  public totalDownloads: number;
53
  public pageViews: number;
54
  
55
  // Statistics tab variables
56
  public statsClicked: boolean = false;
57
  
58
  @ViewChild('statisticsModal') statisticsModal;
59
  @ViewChild('relatedDatasourcesModal') relatedDatasourcesModal;
60
  
61
  // Variables for publications, research data, projects, content providers, related content providers tabs
62
  public fetchPublications: FetchResearchResults;
63
  public fetchDatasets: FetchResearchResults;
64
  public fetchSoftware: FetchResearchResults;
65
  public fetchOrps: FetchResearchResults;
66
  public fetchProjects: FetchProjects;
67
  public fetchDataproviders: FetchDataproviders;
68
  public fetchAggregatorsResults: FetchResearchResults;
69
  public searchNumber: number = 5;
70
  
71
  public aggregationStatusIsInitialized: boolean = false;
72
  
73
  public loadingRelatedDatasources: boolean = true;
74
  
75
  // Active tab variable for responsiveness - show tabs only if main request is completed
76
  public activeTab: string = "";
77
  public showTabs: boolean = false;
78
  
79
  public _numberOfTabs: number = 0;
80
  public tabsAreInitialized: boolean = false;
81
  
82
  public routerHelper: RouterHelper = new RouterHelper();
83
  public errorCodes: ErrorCodes = new ErrorCodes();
84
  public pageContents = null;
85
  public divContents = null;
86
  
87
  // Request results of each tab only the one time (first time tab is clicked)
88
  private reloadPublications: boolean = true;
89
  private reloadDatasets: boolean = true;
90
  private reloadSoftware: boolean = true;
91
  private reloadOrps: boolean = true;
92
  private reloadProjects: boolean = true;
93
  private reloadDataproviders: boolean = true;
94
  private reloadRelatedDatasources: boolean = true;
95
  
96
  // Organizations variables for view more/less functionality
97
  public thresholdOrganizations: number = 20;
98
  public showNumOrganizations: number = 20;
99
  
100
  // Subjects variables for view more/less functionality
101
  public thresholdSubjects: number = 20;
102
  public showNumSubjects: number = 20;
103
  
104
  // Description variables for view more/less functionality
105
  public thresholdDescription: number = 670;
106
  public showNumDescription: number = 670;
107
  
108
  public indexUpdateDate: Date;
109
  public showFeedback: boolean = false;
110
  public feedbackFields: string [] = ['Name', 'Organizations', 'Country', 'Other'];
111
  
112
  subscriptions = [];
113
  properties: EnvProperties = properties;
114
  
115
  constructor(private _dataproviderService: DataProviderService,
116
              private _piwikService: PiwikService,
117
              private route: ActivatedRoute,
118
              private _meta: Meta,
119
              private _title: Title,
120
              private _router: Router,
121
              private _searchResearchResultsService: SearchResearchResultsService,
122
              private _searchProjectsService: SearchProjectsService,
123
              private _searchDataprovidersService: SearchDataprovidersService,
124
              private seoService: SEOService,
125
              private helper: HelperService,
126
              private _location: Location,
127
              private indexInfoService: IndexInfoService) {
128
    this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
129
    this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
130
    this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
131
    this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
132
    this.fetchProjects = new FetchProjects(this._searchProjectsService);
133
    this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
134
    
135
  }
136
  
137
  ngOnInit() {
138
    if (typeof document !== 'undefined') {
139
      this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
140
        if (lastIndexUpdate) {
141
          this.indexUpdateDate = new Date(lastIndexUpdate);
142
        }
143
      }));
144
    }
145
    //this.getDivContents();
146
    this.getPageContents();
147
    this.updateUrl(this.properties.domain + this.properties.baseLink +  this._router.url);
148
    this.subscriptions.push(this.route.queryParams.subscribe(data => {
149
      this.updateTitle("Content provider");
150
      this.updateDescription("");
151
      this.datasourceId = data['datasourceId'];
152
      if (this.datasourceId && StringUtils.isOpenAIREID(this.datasourceId)) {
153
        this.initializeValues();
154
        this.getDataProviderInfo(this.datasourceId);
155
      } else {
156
        this.showLoading = false;
157
        this._router.navigate(['/error'], {
158
          queryParams: {
159
            "page": this._location.path(true),
160
            "page_type": "dataprovider"
161
          }
162
        });
163
      }
164
    }));
165
  }
166
  
167
  public initializeValues() {
168
    this._numberOfTabs = 0;
169
    this.tabsAreInitialized = false;
170
    this.dataProviderInfo = null;
171
    this.aggregationStatusIsInitialized = false;
172
    this.fetchProjects.searchUtils.status = this.errorCodes.LOADING;
173
    this.fetchProjects.searchUtils.totalResults = 0;
174
    this.fetchDataproviders.searchUtils.status = this.errorCodes.LOADING;
175
    this.fetchDataproviders.searchUtils.totalResults = 0;
176
    this.fetchPublications.searchUtils.status = this.errorCodes.LOADING;
177
    this.fetchPublications.searchUtils.totalResults = 0;
178
    this.fetchDatasets.searchUtils.status = this.errorCodes.LOADING;
179
    this.fetchDatasets.searchUtils.totalResults = 0;
180
    this.fetchSoftware.searchUtils.status = this.errorCodes.LOADING;
181
    this.fetchSoftware.searchUtils.totalResults = 0;
182
    this.fetchOrps.searchUtils.status = this.errorCodes.LOADING;
183
    this.fetchOrps.searchUtils.totalResults = 0;
184
    this.statsClicked = false;
185
    this.metricsClicked = false;
186
  }
187
  
188
  private getPageContents() {
189
    this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
190
      this.pageContents = contents;
191
    }));
192
  }
193
  
194
  private getDivContents() {
195
    this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
196
      this.divContents = contents;
197
    }));
198
  }
199
  
200
  ngOnDestroy() {
201
    this.subscriptions.forEach(subscription => {
202
      if (subscription instanceof Subscriber) {
203
        subscription.unsubscribe();
204
      }
205
    });
206
    this.fetchDatasets.clearSubscriptions();
207
    this.fetchPublications.clearSubscriptions();
208
    this.fetchSoftware.clearSubscriptions();
209
    this.fetchPublications.clearSubscriptions();
210
    this.fetchDataproviders.clearSubscriptions();
211
    this.fetchProjects.clearSubscriptions();
212
  }
213
  
214
  private getDataProviderInfo(id: string) {
215
    this.warningMessage = '';
216
    this.errorMessage = "";
217
    this.showLoading = true;
218
    
219
    this.dataProviderInfo = null;
220
    
221
    this.showTabs = false;
222
    if (this.datasourceId == null || this.datasourceId == '') {
223
      this.showLoading = false;
224
      this.warningMessage = "No valid datasource id";
225
    } else {
226
      this.subscriptions.push(this._dataproviderService.getDataproviderInfo(this.datasourceId, this.properties).subscribe(
227
        data => {
228
          this.dataProviderInfo = data;
229
          this.seoService.createLinkForCanonicalURL(this.properties.domain +this.properties.baseLink +  this._router.url);
230
          if (typeof document !== 'undefined') {
231
            this.getDataProviderAggregationStatus(this.dataProviderInfo.originalId);
232
          } else {
233
            this.aggregationStatusIsInitialized = true;
234
          }
235
          if (typeof document !== 'undefined') {
236
            this.initTabs();
237
          }
238
          this.showTabs = true;
239
          this.updateTitle(this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName);
240
          this.updateDescription(this.dataProviderInfo.description?this.dataProviderInfo.description: "Content provider, " + (this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName));
241
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
242
            this.subscriptions.push(this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name, this.piwikSiteId).subscribe());
243
          }
244
          
245
          this.showLoading = false;
246
          
247
          // if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
248
          //   this.activeTab = this.dataProviderInfo.tabs[0].name;
249
          // }
250
        },
251
        err => {
252
          //console.log(err);
253
          this.handleError("Error getting content provider for id: " + this.datasourceId, err);
254
          if (err.status == 404) {
255
            this._router.navigate(['/error'], {
256
              queryParams: {
257
                "page": this._location.path(true),
258
                "page_type": "dataprovider"
259
              }
260
            });
261
          }
262
          this.errorMessage = 'No dataProvider found';
263
          this.showLoading = false;
264
          this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToDataProviders);
265
        }
266
      ));
267
    }
268
  }
269
  
270
  private getDataProviderAggregationStatus(originalId: string) {
271
    this.subscriptions.push(this._dataproviderService.getDataproviderAggregationStatus(originalId, this.properties).subscribe(
272
      data => {
273
        this.dataProviderInfo.aggregationStatus = data;
274
      },
275
      err => {
276
        //console.log(err);
277
        this.handleError("Error getting content provider aggregation status for id: " + this.datasourceId, err);
278
      },
279
      () => {
280
        this.aggregationStatusIsInitialized = true;
281
      }
282
    ));
283
  }
284
  
285
  private updateDescription(description: string) {
286
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
287
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
288
  }
289
  
290
  private updateTitle(title: string) {
291
    var _prefix = "";
292
    // if(this.communityId) {
293
    //   _prefix = "OpenAIRE | ";
294
    // }
295
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
296
    this._title.setTitle(title);
297
    this._meta.updateTag({content: title}, "property='og:title'");
298
  }
299
  
300
  private updateUrl(url: string) {
301
    this._meta.updateTag({content: url}, "property='og:url'");
302
  }
303
  
304
  private initTabs() {
305
    
306
    //if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
307
    this.reloadPublications = true;
308
    this.reloadDatasets = true;
309
    this.reloadSoftware = true;
310
    this.reloadOrps = true;
311
    this.reloadProjects = true;
312
    this.reloadDataproviders = true;
313
    this.reloadRelatedDatasources = true;
314
    this.statsClicked = false;
315
    
316
    //this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
317
    this.count(1, 0);
318
    
319
    this.metricsClicked = false;
320
    
321
    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":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","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';
322
    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":200,"sort":"xaxis","xStyle":{"r":-30,"s":"6","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';
323
    this.fetchAggregatorsResults = new FetchResearchResults(this._searchResearchResultsService);
324

    
325
  }
326
  
327
  public getParamsForSearchLink(type: string = "") {
328

    
329
    if (type) {
330
      return this.routerHelper.createQueryParams(['f0', 'fv0', 'f1', 'fv1', 'type', 'qf', 'sortBy'], ["collectedfromdatasourceid", this.datasourceId, "resulthostingdatasourceid,or", this.datasourceId, type, "false", 'resultdateofacceptance,descending']);
331
    } else {
332
      return this.routerHelper.createQueryParams(['f0', 'fv0', 'f1', 'fv1'], ["collectedfromdatasourceid", this.datasourceId, "resulthostingdatasourceid,or", this.datasourceId]);
333
    }
334
  }
335
  
336
  private count(page: number, size: number) {
337

    
338
    this.countPublications(page, size);
339
    this.countDatasets(page, size);
340
    this.countSoftware(page, size);
341
    this.countOrps(page, size);
342
    this.countProjects(page, size);
343
    this.countDatasources(page, size);
344

    
345
  }
346
  
347
  public search(content: string, page: number, size: number) {
348
    if (content == 'publicationsTab') {
349
      this.searchPublications(page, size);
350
    } else if (content == 'datasetsTab') {
351
      this.searchDatasets(page, size);
352
    } else if (content == 'softwareTab') {
353
      this.searchSoftware(page, size);
354
    } else if (content == 'orpsTab') {
355
      this.searchOrps(page, size);
356
    } else if (content == 'projectsTab') {
357
      this.searchProjects(page, size);
358
    } else if (content == 'datasourcesTab') {
359
      this.searchDatasources(page, size);
360
    } else if (content == 'relatedDatasourcesTab') {
361
      this.searchRelatedDatasources(1, 0);
362
    } else if (content == 'metricsTab') {
363
      this.metricsClicked = true;
364
    } else if (content == 'statisticsTab') {
365
      this.statsClicked = !this.statsClicked;
366
    }
367
  }
368
  
369
  private searchPublications(page: number, size: number) {
370
    if (this.reloadPublications &&
371
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
372
        (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
373
      )
374
    ) {
375
      this.fetchPublications.getResultsForDataproviders("publication", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
376
    }
377
    this.reloadPublications = false;
378
  }
379
  
380
  private countPublications(page: number, size: number) {
381
    this.fetchPublications.getResultsForDataproviders("publication", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
382
  }
383
  
384
  private searchDatasets(page: number, size: number) {
385
    if (this.reloadDatasets &&
386
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
387
        (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
388
      )
389
    ) {
390
      this.fetchDatasets.getResultsForDataproviders("dataset", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
391
    }
392
    this.reloadDatasets = false;
393
  }
394
  
395
  private countDatasets(page: number, size: number) {
396
    this.fetchDatasets.getResultsForDataproviders("dataset", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
397
  }
398
  
399
  private searchSoftware(page: number, size: number) {
400
    if (this.reloadSoftware &&
401
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
402
        (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
403
      )
404
    ) {
405
      this.fetchSoftware.getResultsForDataproviders("software", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
406
    }
407
    this.reloadSoftware = false;
408
  }
409
  
410
  private countSoftware(page: number, size: number) {
411
    this.fetchSoftware.getResultsForDataproviders("software", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
412
  }
413
  
414
  private searchOrps(page: number, size: number) {
415
    if (this.reloadOrps &&
416
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
417
        (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
418
      )
419
    ) {
420
      this.fetchOrps.getResultsForDataproviders("other", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
421
    }
422
    this.reloadOrps = false;
423
  }
424
  
425
  private countOrps(page: number, size: number) {
426
    this.fetchOrps.getResultsForDataproviders("other", this.datasourceId, this.dataProviderInfo.resultsBy, page, size, this.properties);
427
  }
428
  
429
  private searchProjects(page: number, size: number) {
430
    if (this.reloadProjects &&
431
      (this.fetchProjects.searchUtils.status == this.errorCodes.LOADING ||
432
        (this.fetchProjects.searchUtils.status == this.errorCodes.DONE && this.fetchProjects.searchUtils.totalResults > 0)
433
      )
434
    ) {
435
      this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
436
    }
437
    this.reloadProjects = false;
438
  }
439
  
440
  private countProjects(page: number, size: number) {
441
    this.fetchProjects.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
442
  }
443
  
444
  private searchDatasources(page: number, size: number) {
445
    if (this.reloadDataproviders &&
446
      (this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
447
        (this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE && this.fetchDataproviders.searchUtils.totalResults > 0)
448
      )
449
    ) {
450
      this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
451
    }
452
    this.reloadDataproviders = false;
453
  }
454
  
455
  private countDatasources(page: number, size: number) {
456
    this.fetchDataproviders.getResultsForDataproviders(this.datasourceId, page, size, this.properties);
457
  }
458
  
459
  private searchRelatedDatasources(page: number, size: number) {
460
    // Currently no counting is done for this tab. Following condition is always false
461
    
462
    // if (this.reloadRelatedDatasources &&
463
    //   (this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.LOADING ||
464
    //     this.fetchAggregatorsPublications.searchUtils.status == this.errorCodes.DONE)
465
    //   &&
466
    //   (this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.LOADING ||
467
    //     this.fetchAggregatorsDatasets.searchUtils.status == this.errorCodes.DONE)
468
    //   &&
469
    //   (this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.LOADING ||
470
    //     this.fetchAggregatorsSoftware.searchUtils.status == this.errorCodes.DONE)
471
    //   &&
472
    //   (this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.LOADING ||
473
    //     this.fetchAggregatorsOrps.searchUtils.status == this.errorCodes.DONE)
474
    // ) {
475
    //   this.relatedDatasourcesSub = observableMerge(this.fetchAggregatorsPublications.requestComplete, this.fetchAggregatorsDatasets.requestComplete, this.fetchAggregatorsSoftware.requestComplete, this.fetchAggregatorsOrps.requestComplete)
476
    //     .subscribe(
477
    //       data => {
478
    //       },
479
    //       err => {
480
    //       },
481
    //       () => {
482
    //         this.preprocessRelatedDatasources();
483
    //       }
484
    //     );
485
    //
486
    //   this.fetchAggregatorsPublications.getAggregatorResults("publication", this.datasourceId, page, size, this.properties);
487
    //   this.fetchAggregatorsDatasets.getAggregatorResults("dataset", this.datasourceId, page, size, this.properties);
488
    //   this.fetchAggregatorsSoftware.getAggregatorResults("software", this.datasourceId, page, size, this.properties);
489
    //   this.fetchAggregatorsOrps.getAggregatorResults("other", this.datasourceId, page, size, this.properties);
490
    if (this.reloadRelatedDatasources &&
491
      (this.fetchAggregatorsResults.searchUtils.status == this.errorCodes.LOADING ||
492
        (this.fetchAggregatorsResults.searchUtils.status == this.errorCodes.DONE && this.fetchAggregatorsResults.searchUtils.totalResults > 0)
493
      )
494
    ) {
495
      this.subscriptions.push(this.fetchAggregatorsResults.requestComplete.subscribe(
496
        data => {
497
        },
498
        err => {
499
        },
500
        () => {
501
          //this.preprocessRelatedDatasources();
502
          this.dataProviderInfo.relatedDatasources = this.fetchAggregatorsResults.results;
503
          this.loadingRelatedDatasources = false;
504
        }
505
      ));
506
      
507
      this.fetchAggregatorsResults.getAggregatorResults("results", this.datasourceId, page, size, this.properties);
508
    } else {
509
      this.loadingRelatedDatasources = false;
510
    }
511
    
512
    
513
    this.reloadRelatedDatasources = false;
514
  }
515
  
516
  private countRelatedDatasources(page: number, size: number) {
517
    this.fetchAggregatorsResults.getAggregatorResults("results", this.datasourceId, page, size, this.properties);
518
  }
519

    
520
  public metricsResults($event) {
521
    this.totalViews = $event.totalViews;
522
    this.totalDownloads = $event.totalDownloads;
523
    this.pageViews = $event.pageViews;
524
  }
525
  
526
  public get hasMetrics(): boolean {
527
    return !(this.totalViews && this.totalDownloads && this.pageViews) || this.totalViews > 0 || this.totalDownloads > 0 || this.pageViews > 0;
528
  }
529
  
530
  public openStatistics() {
531
    this.statsClicked = true;
532
    this.statisticsModal.cancelButton = false;
533
    this.statisticsModal.okButton = false;
534
    this.statisticsModal.alertTitle = "Statistics of";
535
    this.statisticsModal.open();
536
  }
537
  
538
  public openRelatedDatasources() {
539
    this.searchRelatedDatasources(1, 0);
540
    this.relatedDatasourcesModal.cancelButton = false;
541
    this.relatedDatasourcesModal.okButton = false;
542
    this.relatedDatasourcesModal.alertTitle = "Related content providers of";
543
    this.relatedDatasourcesModal.open();
544
  }
545
  
546
  public scroll() {
547
    HelperFunctions.scroll();
548
  }
549
  
550
  public removeUnknown(array: string[]): string[] {
551
    return array.filter(value => value.toLowerCase() !== 'unknown');
552
  }
553
  
554
  private handleError(message: string, error) {
555
    console.error("Content Provider Landing Page: " + message, error);
556
  }
557
  
558
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
559
    if (entityType == "publication") {
560
      return "publication" + (plural ? "s" : "");
561
    } else if (entityType == "dataset") {
562
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
563
    } else if (entityType == "software") {
564
      return "software";
565
    } else if (entityType == "other") {
566
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
567
    } else if (entityType == "dataprovider") {
568
      return (full ? ("content provider" + (plural ? "s" : "")) : "dataprovider" + (plural ? "s" : ""));
569
    } else {
570
      return entityType + (plural ? "s" : "");
571
    }
572
  }
573
  
574
  public getResultPreview(result: SearchResult, type: string): ResultPreview {
575
    return ResultPreview.searchResultConvert(result, type);
576
  }
577
  
578
  public onSelectActiveTab(activeTabId) {
579
    if (this.activeTab != "activaTabId") {   // tab really changed
580
      if (activeTabId == 'summary') {
581
        this.activeTab = 'summary';
582
      } else if (activeTabId == 'publications') {
583
        this.activeTab = 'publications';
584
        this.searchPublications(1, this.searchNumber);
585
      } else if (activeTabId == 'datasets') {
586
        this.activeTab = 'datasets';
587
        this.searchDatasets(1, this.searchNumber);
588
      } else if (activeTabId == 'software') {
589
        this.activeTab = 'software';
590
        this.searchSoftware(1, this.searchNumber);
591
      } else if (activeTabId == 'other') {
592
        this.activeTab = "other";
593
        this.searchOrps(1, this.searchNumber);
594
      } else if (activeTabId == 'projects') {
595
        this.activeTab = "projects";
596
        this.searchProjects(1, this.searchNumber);
597
      } else if (activeTabId == 'datasources') {
598
        this.activeTab = "datasources";
599
        this.searchDatasources(1, this.searchNumber);
600
      } else if (activeTabId == 'relatedDatasources') {
601
        this.activeTab = "relatedDatasources";
602
        this.searchRelatedDatasources(1, this.searchNumber);
603
      } else if (activeTabId == 'statistics') {
604
        this.activeTab = 'statistics';
605
        this.statsClicked = true;
606
      }
607
    }
608
  }
609
  
610
  public get hasAggregationStatusInfo(): boolean {
611
    return (!!this.dataProviderInfo.aggregationStatus &&
612
      ((!!this.dataProviderInfo.aggregationStatus.fulltexts && parseInt(this.dataProviderInfo.aggregationStatus.fulltexts) != -1)
613
        || (!!this.dataProviderInfo.aggregationStatus.fundedContent && parseInt(this.dataProviderInfo.aggregationStatus.fundedContent) != -1)
614
        || !!this.dataProviderInfo.aggregationStatus.lastUpdateDate));
615
  }
616
  
617
  public get hasJournalInfo(): boolean {
618
    return (!!this.dataProviderInfo.journal && (
619
      !!this.dataProviderInfo.journal['journal'] || !!this.dataProviderInfo.journal['issn'] ||
620
      !!this.dataProviderInfo.journal['lissn'] || !!this.dataProviderInfo.journal['eissn'] ||
621
      !!this.dataProviderInfo.journal['volume'] || !!this.dataProviderInfo.journal['issue'] ||
622
      !!this.dataProviderInfo.journal['start_page'] || !!this.dataProviderInfo.journal['end_page']));
623
    //return true;
624
  }
625
  
626
  public get hasPrimaryInfo(): boolean {
627
    return !!this.dataProviderInfo && (
628
      !!this.dataProviderInfo.description ||
629
      this.hasJournalInfo ||
630
      //this.hasAggregationStatusInfo ||
631
      !!this.dataProviderInfo.countries ||
632
      (!!this.dataProviderInfo.subjects && this.dataProviderInfo.subjects.length > 0));
633
  }
634
  
635
  public get hasSecondaryInfo(): boolean {
636
    return !!this.dataProviderInfo && (
637
      (!!this.dataProviderInfo.organizations && this.dataProviderInfo.organizations.length > 0)
638
      || !!this.dataProviderInfo.oaiPmhURL || !!this.dataProviderInfo.openDoarId || !!this.dataProviderInfo.r3DataId
639
    );
640
  }
641

    
642
}
(2-2/13)