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
            this.countResultsWithFundingInfo();
233
          } else {
234
            this.aggregationStatusIsInitialized = true;
235
          }
236
          if (typeof document !== 'undefined') {
237
            this.initTabs();
238
          }
239
          this.showTabs = true;
240
          this.updateTitle(this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName);
241
          this.updateDescription(this.dataProviderInfo.description?this.dataProviderInfo.description: "Content provider, " + (this.dataProviderInfo.title.name?this.dataProviderInfo.title.name:this.dataProviderInfo.officialName));
242
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
243
            this.subscriptions.push(this._piwikService.trackView(this.properties, this.dataProviderInfo.title.name, this.piwikSiteId).subscribe());
244
          }
245
          
246
          this.showLoading = false;
247
          
248
          // if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
249
          //   this.activeTab = this.dataProviderInfo.tabs[0].name;
250
          // }
251
        },
252
        err => {
253
          //console.log(err);
254
          this.handleError("Error getting content provider for id: " + this.datasourceId, err);
255
          if (err.status == 404) {
256
            this._router.navigate(['/error'], {
257
              queryParams: {
258
                "page": this._location.path(true),
259
                "page_type": "dataprovider"
260
              }
261
            });
262
          }
263
          this.errorMessage = 'No dataProvider found';
264
          this.showLoading = false;
265
          this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink + this.properties.searchLinkToDataProviders);
266
        }
267
      ));
268
    }
269
  }
270
  
271
  private getDataProviderAggregationStatus(originalId: string) {
272
    this.subscriptions.push(this._dataproviderService.getDataproviderAggregationStatus(originalId, this.properties).subscribe(
273
      data => {
274
        this.dataProviderInfo.aggregationStatus = data;
275
        this.aggregationStatusIsInitialized = true;
276
      },
277
      err => {
278
        //console.log(err);
279
        this.aggregationStatusIsInitialized = true;
280
        this.handleError("Error getting content provider aggregation status for id: " + this.datasourceId, err);
281
      }
282
    ));
283
  }
284

    
285
  private countResultsWithFundingInfo() {
286
    this.subscriptions.push(this._searchResearchResultsService.countCollectedResultsWithFundingInfo(this.datasourceId).subscribe(
287
      fundedContent => {
288
        this.dataProviderInfo.fundedContent = fundedContent;
289
        console.log(this.dataProviderInfo.fundedContent);
290
      },
291
      err => {
292
        this.handleError("Error getting results with funding information for datasource id: " + this.datasourceId, err);
293
      }
294
    ))
295
  }
296
  
297
  private updateDescription(description: string) {
298
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
299
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
300
  }
301
  
302
  private updateTitle(title: string) {
303
    var _prefix = "";
304
    // if(this.communityId) {
305
    //   _prefix = "OpenAIRE | ";
306
    // }
307
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
308
    this._title.setTitle(title);
309
    this._meta.updateTag({content: title}, "property='og:title'");
310
  }
311
  
312
  private updateUrl(url: string) {
313
    this._meta.updateTag({content: url}, "property='og:url'");
314
  }
315
  
316
  private initTabs() {
317
    
318
    //if (this.dataProviderInfo.tabs != undefined && this.dataProviderInfo.tabs.length > 0) {
319
    this.reloadPublications = true;
320
    this.reloadDatasets = true;
321
    this.reloadSoftware = true;
322
    this.reloadOrps = true;
323
    this.reloadProjects = true;
324
    this.reloadDataproviders = true;
325
    this.reloadRelatedDatasources = true;
326
    this.statsClicked = false;
327
    
328
    //this.search(this.dataProviderInfo.tabs[0].content, 1, 10);
329
    this.count(1, 0);
330
    
331
    this.metricsClicked = false;
332
    
333
    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';
334
    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';
335
    this.fetchAggregatorsResults = new FetchResearchResults(this._searchResearchResultsService);
336

    
337
  }
338
  
339
  public getParamsForSearchLink(type: string = "") {
340

    
341
    if (type) {
342
      return this.routerHelper.createQueryParams(['f0', 'fv0', 'f1', 'fv1', 'type', 'qf', 'sortBy'], ["collectedfromdatasourceid", this.datasourceId, "resulthostingdatasourceid,or", this.datasourceId, type, "false", 'resultdateofacceptance,descending']);
343
    } else {
344
      return this.routerHelper.createQueryParams(['f0', 'fv0', 'f1', 'fv1'], ["collectedfromdatasourceid", this.datasourceId, "resulthostingdatasourceid,or", this.datasourceId]);
345
    }
346
  }
347
  
348
  private count(page: number, size: number) {
349

    
350
    this.countPublications(page, size);
351
    this.countDatasets(page, size);
352
    this.countSoftware(page, size);
353
    this.countOrps(page, size);
354
    this.countProjects(page, size);
355
    this.countDatasources(page, size);
356

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

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

    
628
    return (!!this.dataProviderInfo.aggregationStatus &&
629
      ((!!this.dataProviderInfo.aggregationStatus.fulltexts && parseInt(this.dataProviderInfo.aggregationStatus.fulltexts) != -1)));
630
  }
631

    
632
  public get hasJournalInfo(): boolean {
633
    return (!!this.dataProviderInfo.journal && (
634
      !!this.dataProviderInfo.journal['journal'] || !!this.dataProviderInfo.journal['issn'] ||
635
      !!this.dataProviderInfo.journal['lissn'] || !!this.dataProviderInfo.journal['eissn'] ||
636
      !!this.dataProviderInfo.journal['volume'] || !!this.dataProviderInfo.journal['issue'] ||
637
      !!this.dataProviderInfo.journal['start_page'] || !!this.dataProviderInfo.journal['end_page']));
638
    //return true;
639
  }
640
  
641
  public get hasPrimaryInfo(): boolean {
642
    return !!this.dataProviderInfo && (
643
      !!this.dataProviderInfo.description ||
644
      this.hasJournalInfo ||
645
      //this.hasAggregationStatusInfo ||
646
      !!this.dataProviderInfo.countries ||
647
      (!!this.dataProviderInfo.subjects && this.dataProviderInfo.subjects.length > 0));
648
  }
649
  
650
  public get hasSecondaryInfo(): boolean {
651
    return !!this.dataProviderInfo && (
652
      (!!this.dataProviderInfo.organizations && this.dataProviderInfo.organizations.length > 0)
653
      || !!this.dataProviderInfo.oaiPmhURL || !!this.dataProviderInfo.openDoarId || !!this.dataProviderInfo.r3DataId
654
    );
655
  }
656

    
657
}
(2-2/13)