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, "DownloadCSV" + filename, 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
                  if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
427
                    this.subscriptions.push(this._piwikService.trackDownload(this.properties, "DownloadCSV" + filename, this.piwikSiteId).subscribe());
428
                  }
429
                }
430
              } else {
431
                let url: string;
432
                if (!title) {
433
                  title_index = index;
434
                  //console.info(title_index);
435
                  url = this.downloadURLAPI + '?format=csv-special&' + this.getTypeParam(this.funderContentType) + '&fq=((relprojectid exact "' + projects[index].id + '"))';
436
                } else {
437
                  url = this.downloadURLAPI + '?format=csv-special-notitle&' + this.getTypeParam(this.funderContentType) + '&fq=((relprojectid exact "' + projects[index].id + '"))';
438
                }
439
                title = true;
440

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

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