Project

General

Profile

1
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
2
import {ActivatedRoute, Router} from '@angular/router';
3
import {Meta, Title} from '@angular/platform-browser';
4
import {OrganizationService} from '../../services/organization.service';
5
import {OrganizationInfo} from '../../utils/entities/organizationInfo';
6
import {ReportsService} from '../../services/reports.service';
7
import {FetchProjects} from '../../utils/fetchEntitiesClasses/fetchProjects.class';
8
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
9
import {SearchDataprovidersService} from '../../services/searchDataproviders.service';
10
import {SearchProjectsService} from '../../services/searchProjects.service';
11
import {ErrorCodes} from '../../utils/properties/errorCodes';
12
import {RouterHelper} from '../../utils/routerHelper.class';
13

    
14
import {ModalLoading} from '../../utils/modal/loading.component';
15
import {PiwikService} from '../../utils/piwik/piwik.service';
16
import {StringUtils} from '../../utils/string-utils.class';
17
import {EnvProperties} from '../../utils/properties/env-properties';
18
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
19
import {HelperFunctions} from "../../utils/HelperFunctions.class";
20
import {HelperService} from "../../utils/helper/helper.service";
21
import {Location} from "@angular/common";
22
import {FetchResearchResults} from "../../utils/fetchEntitiesClasses/fetchResearchResults.class";
23
import {FetchDataproviders} from "../../utils/fetchEntitiesClasses/fetchDataproviders.class";
24
import {IndexInfoService} from "../../utils/indexInfo.service";
25
import {Subscriber} from "rxjs";
26
import {properties} from "../../../../environments/environment";
27

    
28
@Component({
29
  selector: 'organization',
30
  templateUrl: 'organization.component.html',
31
})
32
export class OrganizationComponent {
33
  @Input() piwikSiteId = null;
34
  @Input() communityId = null;
35
  
36
  public organizationInfo: OrganizationInfo;
37
  public organizationId: string;
38
  
39
  // Message variables
40
  public warningMessage = "";
41
  public errorMessage = "";
42
  public showLoading: boolean = true;
43
  
44
  // CSV variables
45
  public downloadURLAPI: string;
46
  public csvProjectParamsHead: string;
47
  public csvParamsTail: string;
48
  
49
  // Variables for publications, research data, projects, dataproviders tabs
50
  public fetchProjects: FetchProjects;
51
  public fetchPublications: FetchResearchResults;
52
  public fetchDatasets: FetchResearchResults;
53
  public fetchSoftware: FetchResearchResults;
54
  public fetchOrps: FetchResearchResults;
55
  public fetchDataproviders: FetchDataproviders
56
  public searchNumber: number = 5;
57

    
58
  // Request results of each tab only the one time (first time tab is clicked)
59
  private reloadPublications: boolean = true;
60
  private reloadDatasets: boolean = true;
61
  private reloadSoftware: boolean = true;
62
  private reloadOrps: boolean = true;
63
  private reloadDataproviders: boolean = true;
64

    
65
  // Active tab variable for responsiveness
66
  public activeTab: string = "";
67

    
68
  @ViewChild('downloadReportModal') downloadReportModal;
69
  @ViewChild('downloadFunderReportModal') downloadFunderReportModal;
70
  
71
  @ViewChild(ModalLoading) loading: ModalLoading;
72
  // Alert box when CSV: Project Publications for a funder is requested
73
  @ViewChild('AlertModalApplyAll') alertApplyAll;
74
  // Alert box when something is wrong with CSV requests
75
  @ViewChild('AlertModalCsvError') alertCsvError;
76
  
77
  public routerHelper: RouterHelper = new RouterHelper();
78
  public errorCodes: ErrorCodes = new ErrorCodes();
79
  public pageContents = null;
80
  public divContents = null;
81
  
82
  // Helper variables to specify funder in downloadPublicationsFile function
83
  public contentTypes: [string, string][] = [
84
    ['results', 'all research outcomes'],
85
    ['publications', 'publications'],
86
    ['datasets', 'research data'],
87
    ['software', 'software'],
88
    ['other', 'other research products'],
89
  ];
90
  public funderContentType: string = '';
91
  public funder: any = "";
92
  private funderId: string;
93
  private funderCount: number;
94
  subscriptions = [];
95
  properties: EnvProperties;
96
  public indexUpdateDate: Date;
97
  public showFeedback: boolean = false;
98
  public feedbackFields: string [] = ['Name', 'Country', 'Other'];
99
  
100
  @ViewChild('AlertModalDeletedByInference') alertModalDeletedByInference;
101
  @ViewChild('projectsModal') projectsModal;
102
  public deleteByInferenceOpened: boolean = false;
103
  
104

    
105
  constructor(private element: ElementRef,
106
              private _organizationService: OrganizationService,
107
              private _piwikService: PiwikService,
108
              private  route: ActivatedRoute,
109
              private _searchDataprovidersService: SearchDataprovidersService,
110
              private _reportsService: ReportsService,
111
              private _searchResearchResultsService: SearchResearchResultsService,
112
              private _searchProjectsService: SearchProjectsService,
113
              private _meta: Meta,
114
              private _title: Title,
115
              private _router: Router,
116
              private helper: HelperService,
117
              private seoService: SEOService,
118
              private _location: Location,
119
              private indexInfoService: IndexInfoService) {
120
    this.fetchProjects = new FetchProjects(this._searchProjectsService);
121
    this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
122
    this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
123
    this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
124
    this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
125
    this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
126
  }
127
  
128
  ngOnInit() {
129

    
130
        this.properties = properties;
131
        if (typeof document !== 'undefined') {
132
          this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
133
            if (lastIndexUpdate) {
134
              this.indexUpdateDate = new Date(lastIndexUpdate);
135
            }
136
          }));
137
        }
138
        //this.getDivContents();
139
        this.getPageContents();
140
        this.updateUrl(this.properties.domain + this.properties.baseLink + this._router.url);
141

    
142
    this.subscriptions.push(this.route.queryParams.subscribe(params => {
143
      this.organizationInfo = null;
144
      this.updateTitle("Organization");
145
      this.updateDescription("");
146
      
147
      this.organizationId = params['organizationId'];
148
      
149
      if (this.organizationId  && StringUtils.isOpenAIREID(this.organizationId)) {
150
        this.getOrganizationInfo();
151
      } else {
152
        this.showLoading = false;
153
        this._router.navigate(['/error'], {
154
          queryParams: {
155
            "page": this._location.path(true),
156
            "page_type": "organization"
157
          }
158
        });
159
        //this.warningMessage = "No valid organization id";
160
      }
161
      
162
      HelperFunctions.scroll();
163
      
164
      this.csvParamsTail = '" and relorganizationid exact "' + this.organizationId + '" ))';
165
      
166
    }));
167
    
168
    this.downloadURLAPI = this.properties.csvAPIURL;
169
    //this.csvAffiliatedPublications = this.downloadURLAPI + "?format=csv&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relorganizationid exact \"" + this.organizationId + "\"))";
170
    this.csvProjectParamsHead = 'format=csv&type=projects&fq=((funder exact "';
171
    //this.csvPublicationParamsHead = 'format=csv-special&type=publications&page=0&query=((((oaftype exact result) and (resulttypeid exact publication)) and (funderid exact ';
172
  }
173
  
174
  private getPageContents() {
175
    if(this.communityId) {
176
      this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
177
        this.pageContents = contents;
178
      }));
179
    }
180
  }
181
  
182
  private getDivContents() {
183
    if(this.communityId) {
184
      this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
185
        this.divContents = contents;
186
      }));
187
    }
188
  }
189

    
190
  ngOnDestroy() {
191
    this.subscriptions.forEach(subscription => {
192
      if (subscription instanceof Subscriber) {
193
        subscription.unsubscribe();
194
      }
195
    });
196
    this.fetchDatasets.clearSubscriptions();
197
    this.fetchPublications.clearSubscriptions();
198
    this.fetchSoftware.clearSubscriptions();
199
    this.fetchPublications.clearSubscriptions();
200
    this.fetchDataproviders.clearSubscriptions();
201
    this.fetchProjects.clearSubscriptions();
202
  }
203

    
204
  private getTotalResearchResults() {
205
    this.fetchPublications.getNumForEntity('publication', 'organization', this.organizationId, this.properties);
206
    this.fetchDatasets.getNumForEntity('dataset', 'organization', this.organizationId, this.properties);
207
    this.fetchSoftware.getNumForEntity('software', 'organization', this.organizationId, this.properties);
208
    this.fetchOrps.getNumForEntity('other', 'organization', this.organizationId, this.properties);
209
  }
210
  
211
  private getTotalDataproviders() {
212
    this.fetchDataproviders.getNumForEntity('organization', this.organizationId, this.properties);
213
  }
214
  
215
  // private searchContentProviders() {
216
  //   this.fetchDataproviders.getResultsForEntity("organization", this.organizationId, 1, this.searchNumber, this.properties);
217
  // }
218
  private searchContentProviders(page: number, size: number) {
219
    if (this.reloadDataproviders &&
220
      (this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
221
        (this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE && this.fetchDataproviders.searchUtils.totalResults > 0)
222
      )
223
    ) {
224
      this.fetchDataproviders.getResultsForEntity("organization", this.organizationId, page, size, this.properties);
225
    }
226
    this.reloadDataproviders = false;
227
  }
228
  
229
  // private searchPublications() {
230
  //   this.fetchPublications.getResultsForEntity("publication", "organization", this.organizationId, 1, size, this.properties);
231
  // }
232
  private searchPublications(page: number, size: number) {
233
    if (this.reloadPublications &&
234
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
235
        (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
236
      )
237
    ) {
238
      this.fetchPublications.getResultsForEntity("publication", "organization", this.organizationId, page, size, this.properties);
239
    }
240
    this.reloadPublications = false;
241
  }
242
  
243
  // private searchDatasets() {
244
  //   this.fetchDatasets.getResultsForEntity("dataset", "organization", this.organizationId, 1, this.searchNumber, this.properties);
245
  // }
246
  private searchDatasets(page: number, size: number) {
247
    if (this.reloadDatasets &&
248
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
249
        (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
250
      )
251
    ) {
252
      this.fetchDatasets.getResultsForEntity("dataset", "organization", this.organizationId, page, size, this.properties);
253
    }
254
    this.reloadDatasets = false;
255
  }
256

    
257
  // private searchSoftware() {
258
  //   this.fetchSoftware.getResultsForEntity("software", "organization", this.organizationId, 1, this.searchNumber, this.properties);
259
  // }
260
  private searchSoftware(page: number, size: number) {
261
    if (this.reloadSoftware &&
262
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
263
        (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
264
      )
265
    ) {
266
      this.fetchSoftware.getResultsForEntity("software", "organization", this.organizationId, page, size, this.properties);
267
    }
268
    this.reloadSoftware = false;
269
  }
270

    
271
  // private searchOrps() {
272
  //   this.fetchOrps.getResultsForEntity("other", "organization", this.organizationId, 1, this.searchNumber, this.properties);
273
  // }
274
  private searchOrps(page: number, size: number) {
275
    if (this.reloadOrps &&
276
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
277
        (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
278
      )
279
    ) {
280
      this.fetchOrps.getResultsForEntity("other", "organization", this.organizationId, page, size, this.properties);
281
    }
282
    this.reloadOrps = false;
283
  }
284
  
285
  private getOrganizationInfo() {
286
    
287
    this.warningMessage = '';
288
    this.errorMessage = ""
289
    this.showLoading = true;
290
    
291
    this.organizationInfo = null;
292

    
293
    this.subscriptions.push(this._organizationService.getOrganizationInfo(this.organizationId, this.properties).subscribe(
294
      data => {
295
        if (data == null) {
296
          this.showLoading = false;
297
          this._router.navigate(['/error'], {
298
            queryParams: {
299
              "page": this._location.path(true),
300
              "page_type": "organization"
301
            }
302
          });
303
          this.errorMessage = 'No organization found';
304
        } else {
305
          this.organizationInfo = data;
306
          this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink  + this.properties.searchLinkToOrganization + this.organizationInfo.relcanId);
307
          this.updateTitle((this.organizationInfo.title.name?this.organizationInfo.title.name:(this.organizationInfo.name?this.organizationInfo.name:'No title available')));
308
          this.updateDescription("Organization, country, " +
309
            (this.organizationInfo.title.name?this.organizationInfo.title.name:'No title available') +
310
            ((this.organizationInfo.title.name && this.organizationInfo.title.name != this.organizationInfo.name) ? (', ') : '') +
311
            (this.organizationInfo.name?this.organizationInfo.name:''));
312
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
313
            this.subscriptions.push(this._piwikService.trackView(this.properties, this.organizationInfo.title.name, this.piwikSiteId).subscribe());
314
          }
315
          var refineFields: string [] = ["funder"];
316

    
317
          if (typeof document !== 'undefined') {
318
            this.getTotalResearchResults();
319
            this.getTotalDataproviders();
320
          }
321

    
322
          this.fetchProjects.getResultsForOrganizations(this.organizationId, "", 1, this.searchNumber, refineFields, this.properties);
323
          this.showLoading = false;
324
        }
325
      },
326
      err => {
327
        //console.log(err)
328
        this.handleError("Error getting organization for id: " + this.organizationId, err);
329
        if (err.status == 404) {
330
          this._router.navigate(['/error'], {
331
            queryParams: {
332
              "page": this._location.path(true),
333
              "page_type": "organization"
334
            }
335
          });
336
        }
337
        this.seoService.createLinkForCanonicalURL(this.properties.domain+ this.properties.baseLink  + this.properties.searchLinkToOrganizations);
338
        this.errorMessage = 'No organization found';
339
        this.showLoading = false;
340
      }
341
    ));
342
  }
343
  
344
  public downloadFile(url: string, filename: string) {
345
    this.openLoading();
346
    this.setMessageLoading("Downloading CSV file");
347

    
348
    this.subscriptions.push(this._reportsService.downloadCSVFile(url).subscribe(
349
      data => {
350
        this.closeLoading();
351
        
352
        var url = window.URL.createObjectURL(data);
353
        var a = window.document.createElement('a');
354
        window.document.body.appendChild(a);
355
        a.setAttribute('style', 'display: none');
356
        a.href = url;
357
        a.download = filename + ".csv";
358
        a.click();
359
        window.URL.revokeObjectURL(url);
360
        a.remove(); // remove the element
361
        
362
        //window.open(window.URL.createObjectURL(data));
363
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
364
          this.subscriptions.push(this._piwikService.trackDownload(this.properties, this.piwikSiteId).subscribe());
365
        }
366
      },
367
      err => {
368
        //console.log("Error downloading the file.");
369
        this.handleError("Error downloading file: " + filename + ".csv", err);
370
        
371
        this.closeLoading();
372
        this.confirmOpenCsvError();
373
      }/*,
374
           () => console.log('Completed file download.')*/
375
    ));
376
  }
377
  
378
  private downloadFileByFunder() {
379
    
380
    this.openLoading();
381
    this.setMessageLoading("Downloading CSV file");
382
    
383
    let response: string[] = [];
384
    let totalResponse: string = "";
385
    let projects = [];
386
    let counter: number = this.funderCount;
387
    let title: boolean = false;
388
    let title_index: number = 0;
389
    
390
    let filename: string = 'funder-project-' + this.funderContentType + '-report';
391

    
392
    this.subscriptions.push(this._searchProjectsService.getProjectsForOrganizations(this.organizationId, ' and (funder exact "' + this.encodeURI(this.funderId) + '" ) ', 1, this.funderCount, [], this.properties).subscribe(
393
      data => {
394
        projects = data[1];
395
        for (let index = 0; index < projects.length; index++) {
396
          this.subscriptions.push(this._searchResearchResultsService.numOfEntityResults(this.funderContentType, projects[index].id, "project", this.properties).subscribe(
397
            data => {
398
              //if(data == 0 && title) {   // if no publications for this project
399
              if (data == 0 && (counter > 1 || title)) {   // if no publications for this project
400
                counter--;
401
                response[index] = "";
402
                //console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
403
                
404
                if (counter == 0) {
405
                  //for(let i=count-1; i>=0; i--) {
406
                  for (let i = 0; i < projects.length; i++) {
407
                    if (response[i] != "") {
408
                      if (i == title_index) {
409
                        totalResponse = response[i] + totalResponse;
410
                      } else {
411
                        totalResponse += response[i];
412
                      }
413
                    }
414
                  }
415
                  this.closeLoading();
416
                  
417
                  var csvurl = window.URL.createObjectURL(new Blob([totalResponse], {type: 'text/csv'}));
418
                  var a = window.document.createElement('a');
419
                  window.document.body.appendChild(a);
420
                  a.setAttribute('style', 'display: none');
421
                  a.href = csvurl;
422
                  a.download = filename + ".csv";
423
                  a.click();
424
                  window.URL.revokeObjectURL(csvurl);
425
                  a.remove(); // remove the element
426
                }
427
              } else {
428
                let url: string;
429
                if (!title) {
430
                  title_index = index;
431
                  //console.info(title_index);
432
                  url = this.downloadURLAPI + '?format=csv-special&' + this.getTypeParam(this.funderContentType) + '&fq=((relprojectid exact "' + projects[index].id + '"))';
433
                } else {
434
                  url = this.downloadURLAPI + '?format=csv-special-notitle&' + this.getTypeParam(this.funderContentType) + '&fq=((relprojectid exact "' + projects[index].id + '"))';
435
                }
436
                title = true;
437

    
438
                this.subscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
439
                  data => {
440
                    counter--;
441
                    response[index] = data;
442
                    //console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
443
                    
444
                    if (counter == 0) {
445
                      //for(let i=count-1; i>=0; i--) {
446
                      for (let i = 0; i < projects.length; i++) {
447
                        if (response[i] != "") {
448
                          if (i == title_index) {
449
                            totalResponse = response[i] + totalResponse;
450
                          } else {
451
                            totalResponse += response[i];
452
                          }
453
                        }
454
                      }
455
                      this.closeLoading();
456
                      
457
                      var csvurl = window.URL.createObjectURL(new Blob([totalResponse], {type: 'text/csv'}));
458
                      var a = window.document.createElement('a');
459
                      window.document.body.appendChild(a);
460
                      a.setAttribute('style', 'display: none');
461
                      a.href = csvurl;
462
                      a.download = filename + ".csv";
463
                      a.click();
464
                      window.URL.revokeObjectURL(csvurl);
465
                      a.remove(); // remove the element
466
                    }
467
                  },
468
                  err => {
469
                    this.handleError("Error downloading file: " + filename, err);
470
                    
471
                    this.closeLoading();
472
                    this.confirmOpenCsvError();
473
                  }/*,
474
                            () => console.log('Completed file download.')*/
475
                ) );
476
              }
477
            },
478
            err => {
479
              this.handleError("Error getting number of publications for project with id: " + projects[index].id, err);
480
            }));
481
        }
482
      },
483
      err => {
484
        this.handleError("Error getting projects for organization with id: " + this.organizationId, err);
485
        
486
        this.closeLoading();
487
        this.confirmOpenCsvError();
488
      }
489
    ));
490
  }
491
  
492
  private updateDescription(description: string) {
493
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
494
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
495
  }
496
  
497
  private updateTitle(title: string) {
498
    var _prefix = "";
499
    // if(!this.communityId) {
500
    //   _prefix = "OpenAIRE | ";
501
    // }
502
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
503
    this._title.setTitle(title);
504
    this._meta.updateTag({content: title}, "property='og:title'");
505
  }
506
  
507
  private updateUrl(url: string) {
508
    this._meta.updateTag({content: url}, "property='og:url'");
509
  }
510
  
511
  private openLoading() {
512
    if (this.loading) {
513
      this.loading.open();
514
    }
515
  }
516
  
517
  private closeLoading() {
518
    if (this.loading) {
519
      this.loading.close();
520
    }
521
  }
522
  
523
  private setMessageLoading(message: string) {
524
    if (this.loading) {
525
      this.loading.message = message;
526
    }
527
  }
528
  
529
  public confirmOpenApplyAll(contentType: string) {
530
    this.alertApplyAll.cancelButton = true;
531
    this.alertApplyAll.okButton = true;
532
    this.alertApplyAll.alertTitle = "CSV FILE";
533
    this.alertApplyAll.message = "Do you wish to download a CSV file? Note that this process may take a while.";
534
    this.alertApplyAll.okButtonText = "Yes";
535
    this.alertApplyAll.cancelButtonText = "No";
536
    this.alertApplyAll.open();
537
    this.funderId = this.funder.id;
538
    this.funderCount = this.funder.number;
539
    this.funderContentType = contentType;
540
  }
541
  
542
  public confirmCloseApplyAll() {
543
    this.downloadFileByFunder();
544
  }
545
  
546
  public confirmOpenCsvError() {
547
    this.alertCsvError.cancelButton = false;
548
    this.alertCsvError.okButton = true;
549
    this.alertCsvError.alertTitle = "ERROR DOWNLOADING CSV FILE";
550
    this.alertCsvError.message = "There was an error in csv downloading. Please try again later.";
551
    this.alertCsvError.okButtonText = "OK";
552
    this.alertCsvError.open();
553
  }
554
  
555
  encodeURI(input: string): string {
556
    return StringUtils.URIEncode(input);
557
  }
558
  
559
  private handleError(message: string, error) {
560
    console.error("Organizaton Landing Page: " + message, error);
561
  }
562
  
563
  openDeletedByInference() {
564
    this.deleteByInferenceOpened = true;
565
    this.alertModalDeletedByInference.cancelButton = false;
566
    this.alertModalDeletedByInference.okButton = false;
567
    this.alertModalDeletedByInference.alertTitle = "Other versions of";
568
    this.alertModalDeletedByInference.open();
569
  }
570
  
571
  public getTypeParam(type: string): string {
572
    if (type == 'results') {
573
      type = 'publications&type=datasets&type=software&type=other';
574
    }
575
    return 'type=' + type;
576
  }
577
  
578
  getCSVAffiliated(contentType: string): string {
579
    return this.downloadURLAPI + '?format=csv&' + this.getTypeParam(contentType) + '&fq=(relorganizationid exact "' + this.organizationId + '")';
580
  }
581
  
582
  getFunderProjects(): string {
583
    return this.downloadURLAPI + '?' + this.csvProjectParamsHead + encodeURI(this.funder.id) + this.csvParamsTail;
584
  }
585
  
586
  open(value: any) {
587
    console.log(value);
588
  }
589
  
590
  openDownloadReportModal() {
591
    this.downloadReportModal.cancelButton = false;
592
    this.downloadReportModal.okButton = false;
593
    this.downloadReportModal.alertTitle = "Download content report";
594
    this.downloadReportModal.open();
595
  }
596
  
597
  openDownloadFunderReportModal() {
598
    this.funder = this.fetchProjects.funders[0];
599
    this.downloadFunderReportModal.cancelButton = false;
600
    this.downloadFunderReportModal.okButton = false;
601
    this.downloadFunderReportModal.alertTitle = "Download funder report";
602
    this.downloadFunderReportModal.open();
603
  }
604

    
605
  public getParamsForSearchLink(type: string = "") {
606
    if(type) {
607
      return this.routerHelper.createQueryParams(['f0', 'fv0', 'type', 'qf', 'sortBy'], ['relorganizationid', this.organizationId, type, 'false', 'resultdateofacceptance,descending']);
608
    } else {
609
      return this.routerHelper.createQueryParams(['f0', 'fv0'], ['relorganizationid', this.organizationId]);
610
    }
611
  }
612
  
613
  public onSelectActiveTab(activeTabId) {
614
    if (this.activeTab != activeTabId) {   // tab really changed
615
      if (activeTabId == 'projects') {
616
        this.activeTab = 'projects';
617
      } else if (activeTabId == 'dataProviders') {
618
        this.activeTab = 'dataProviders';
619
        this.searchContentProviders(1, this.searchNumber);
620
      } else if (activeTabId == 'publications') {
621
        this.activeTab = 'publications';
622
        this.searchPublications(1, this.searchNumber);
623
      } else if (activeTabId == 'datasets') {
624
        this.activeTab = 'datasets';
625
        this.searchDatasets(1, this.searchNumber);
626
      } else if (activeTabId == 'software') {
627
        this.activeTab = 'software';
628
        this.searchSoftware(1, this.searchNumber);
629
      } else if (activeTabId == 'other') {
630
        this.activeTab = "other";
631
        this.searchOrps(1, this.searchNumber);
632
      }
633
    }
634
  }
635
  
636
  public get total(): number {
637
    let total = this.fetchPublications.searchUtils.totalResults;
638
    total += this.fetchDatasets.searchUtils.totalResults;
639
    total += this.fetchSoftware.searchUtils.totalResults;
640
    total += this.fetchOrps.searchUtils.totalResults;
641
    return total;
642
  }
643
  
644
  // public get numberOfTabs(): number {
645
  //   if (this.tabsAreInitialized) {
646
  //     return this._numberOfTabs;
647
  //   }
648
  //   if (!this.organizationInfo
649
  //     || this.fetchProjects.searchUtils.status === this.errorCodes.LOADING
650
  //     || this.fetchDataproviders.searchUtils.status === this.errorCodes.LOADING
651
  //     || this.fetchPublications.searchUtils.status == this.errorCodes.LOADING
652
  //     || this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING
653
  //     || this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING
654
  //     || this.fetchOrps.searchUtils.status == this.errorCodes.LOADING) {
655
  //     return 0;
656
  //   }
657
  //   if (this.fetchProjects.searchUtils.totalResults > 0) {
658
  //     if (this._numberOfTabs == 0) {
659
  //       this.firstTab = 'projects';
660
  //     }
661
  //     this._numberOfTabs++;
662
  //   }
663
  //   if (this.fetchDataproviders.searchUtils.totalResults > 0) {
664
  //     if (this._numberOfTabs == 0) {
665
  //       this.firstTab = 'dataProviders';
666
  //       this.searchContentProviders(1, this.searchNumber);
667
  //     }
668
  //     this._numberOfTabs++;
669
  //   }
670
  //   if (this.fetchPublications.searchUtils.totalResults > 0) {
671
  //     if (this._numberOfTabs == 0) {
672
  //       this.firstTab = 'publications';
673
  //       this.searchPublications(1, this.searchNumber);
674
  //     }
675
  //     this._numberOfTabs++;
676
  //   }
677
  //   if (this.fetchDatasets.searchUtils.totalResults > 0) {
678
  //     if (this._numberOfTabs == 0) {
679
  //       this.firstTab = 'datasets';
680
  //       this.searchDatasets(1, this.searchNumber);
681
  //     }
682
  //     this._numberOfTabs++;
683
  //   }
684
  //   if (this.fetchSoftware.searchUtils.totalResults > 0) {
685
  //     if (this._numberOfTabs == 0) {
686
  //       this.firstTab = 'software';
687
  //       this.searchSoftware(1, this.searchNumber);
688
  //     }
689
  //     this._numberOfTabs++;
690
  //   }
691
  //   if (this.fetchOrps.searchUtils.totalResults > 0) {
692
  //     if (this._numberOfTabs == 0) {
693
  //       this.firstTab = 'other';
694
  //       this.searchOrps(1, this.searchNumber);
695
  //     }
696
  //     this._numberOfTabs++;
697
  //   }
698
  //   this.activeTab = this.firstTab;
699
  //   this.tabsAreInitialized = true;
700
  //   return this._numberOfTabs;
701
  // }
702
  
703
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
704
    if (entityType == "publication") {
705
      return "publication" + (plural ? "s" : "");
706
    } else if (entityType == "dataset") {
707
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
708
    } else if (entityType == "software") {
709
      return "software";
710
    } else if (entityType == "other") {
711
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
712
    } else if (entityType == "dataprovider") {
713
      return (full ? ("content provider" + (plural ? "s" : "")) : "dataprovider" + (plural ? "s" : ""));
714
    } else {
715
      return entityType + (plural ? "s" : "");
716
    }
717
  }
718
  
719
  public scroll() {
720
    HelperFunctions.scroll();
721
  }
722
}
(2-2/3)