Project

General

Profile

1 56644 k.triantaf
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 57027 konstantin
import {SearchResearchResultsService} from '../../services/searchResearchResults.service';
9 56644 k.triantaf
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 50169 argiro.kok
14 56644 k.triantaf
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 55418 konstantin
import {HelperFunctions} from "../../utils/HelperFunctions.class";
20 56644 k.triantaf
import {HelperService} from "../../utils/helper/helper.service";
21 57536 konstantin
import {Location} from "@angular/common";
22 58784 k.triantaf
import {FetchResearchResults} from "../../utils/fetchEntitiesClasses/fetchResearchResults.class";
23
import {FetchDataproviders} from "../../utils/fetchEntitiesClasses/fetchDataproviders.class";
24 58874 konstantin
import {IndexInfoService} from "../../utils/indexInfo.service";
25 59816 argiro.kok
import {Subscriber} from "rxjs";
26 59899 argiro.kok
import {properties} from "../../../../environments/environment";
27 51835 sofia.balt
28 50169 argiro.kok
@Component({
29 56644 k.triantaf
  selector: 'organization',
30
  templateUrl: 'organization.component.html',
31 50169 argiro.kok
})
32
export class OrganizationComponent {
33 51746 argiro.kok
  @Input() piwikSiteId = null;
34 56644 k.triantaf
  @Input() communityId = null;
35 58275 k.triantaf
36 56644 k.triantaf
  public organizationInfo: OrganizationInfo;
37
  public organizationId: string;
38 58275 k.triantaf
39 56644 k.triantaf
  // Message variables
40
  public warningMessage = "";
41
  public errorMessage = "";
42
  public showLoading: boolean = true;
43 58275 k.triantaf
44 56644 k.triantaf
  // CSV variables
45
  public downloadURLAPI: string;
46
  public csvProjectParamsHead: string;
47
  public csvParamsTail: string;
48 58275 k.triantaf
49 56644 k.triantaf
  // Variables for publications, research data, projects, dataproviders tabs
50
  public fetchProjects: FetchProjects;
51 58784 k.triantaf
  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 58807 konstantin
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 58790 k.triantaf
  // Active tab variable for responsiveness
66
  public activeTab: string = "";
67 59816 argiro.kok
68 58778 k.triantaf
  @ViewChild('downloadReportModal') downloadReportModal;
69
  @ViewChild('downloadFunderReportModal') downloadFunderReportModal;
70 58275 k.triantaf
71 56644 k.triantaf
  @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 58275 k.triantaf
77 56644 k.triantaf
  public routerHelper: RouterHelper = new RouterHelper();
78
  public errorCodes: ErrorCodes = new ErrorCodes();
79
  public pageContents = null;
80
  public divContents = null;
81 58275 k.triantaf
82 56644 k.triantaf
  // Helper variables to specify funder in downloadPublicationsFile function
83 58790 k.triantaf
  public contentTypes: [string, string][] = [
84 58275 k.triantaf
    ['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 56644 k.triantaf
  private funderId: string;
93 58275 k.triantaf
  private funderCount: number;
94 59816 argiro.kok
  subscriptions = [];
95 61262 konstantin
  innerReportSubscriptions = [];
96 56644 k.triantaf
  properties: EnvProperties;
97 58275 k.triantaf
  public indexUpdateDate: Date;
98
  public showFeedback: boolean = false;
99
  public feedbackFields: string [] = ['Name', 'Country', 'Other'];
100
101 57238 konstantin
  @ViewChild('AlertModalDeletedByInference') alertModalDeletedByInference;
102 58275 k.triantaf
  @ViewChild('projectsModal') projectsModal;
103 57238 konstantin
  public deleteByInferenceOpened: boolean = false;
104 58275 k.triantaf
105 59816 argiro.kok
106 56644 k.triantaf
  constructor(private element: ElementRef,
107
              private _organizationService: OrganizationService,
108
              private _piwikService: PiwikService,
109
              private  route: ActivatedRoute,
110
              private _searchDataprovidersService: SearchDataprovidersService,
111
              private _reportsService: ReportsService,
112 57027 konstantin
              private _searchResearchResultsService: SearchResearchResultsService,
113 56644 k.triantaf
              private _searchProjectsService: SearchProjectsService,
114
              private _meta: Meta,
115
              private _title: Title,
116
              private _router: Router,
117
              private helper: HelperService,
118 57536 konstantin
              private seoService: SEOService,
119 58874 konstantin
              private _location: Location,
120
              private indexInfoService: IndexInfoService) {
121 56644 k.triantaf
    this.fetchProjects = new FetchProjects(this._searchProjectsService);
122 58790 k.triantaf
    this.fetchDataproviders = new FetchDataproviders(this._searchDataprovidersService);
123
    this.fetchPublications = new FetchResearchResults(this._searchResearchResultsService);
124
    this.fetchDatasets = new FetchResearchResults(this._searchResearchResultsService);
125
    this.fetchSoftware = new FetchResearchResults(this._searchResearchResultsService);
126
    this.fetchOrps = new FetchResearchResults(this._searchResearchResultsService);
127 56644 k.triantaf
  }
128 58275 k.triantaf
129 56644 k.triantaf
  ngOnInit() {
130 59899 argiro.kok
131
        this.properties = properties;
132 58874 konstantin
        if (typeof document !== 'undefined') {
133 59816 argiro.kok
          this.subscriptions.push(this.indexInfoService.getLastIndexDate(this.properties).subscribe(lastIndexUpdate => {
134 58874 konstantin
            if (lastIndexUpdate) {
135
              this.indexUpdateDate = new Date(lastIndexUpdate);
136
            }
137 59816 argiro.kok
          }));
138 58275 k.triantaf
        }
139 56644 k.triantaf
        //this.getDivContents();
140
        this.getPageContents();
141 59413 argiro.kok
        this.updateUrl(this.properties.domain + this.properties.baseLink + this._router.url);
142 59899 argiro.kok
143 59816 argiro.kok
    this.subscriptions.push(this.route.queryParams.subscribe(params => {
144 56644 k.triantaf
      this.organizationInfo = null;
145
      this.updateTitle("Organization");
146
      this.updateDescription("");
147 58275 k.triantaf
148 56644 k.triantaf
      this.organizationId = params['organizationId'];
149 58790 k.triantaf
150 58940 argiro.kok
      if (this.organizationId  && StringUtils.isOpenAIREID(this.organizationId)) {
151 56644 k.triantaf
        this.getOrganizationInfo();
152
      } else {
153
        this.showLoading = false;
154 58275 k.triantaf
        this._router.navigate(['/error'], {
155
          queryParams: {
156
            "page": this._location.path(true),
157
            "page_type": "organization"
158
          }
159
        });
160 56644 k.triantaf
      }
161
      this.csvParamsTail = '" and relorganizationid exact "' + this.organizationId + '" ))';
162 59816 argiro.kok
    }));
163 58275 k.triantaf
164 56644 k.triantaf
    this.downloadURLAPI = this.properties.csvAPIURL;
165 58275 k.triantaf
    //this.csvAffiliatedPublications = this.downloadURLAPI + "?format=csv&type=publications&fq=(((oaftype exact result) and (resulttypeid exact publication)) and (relorganizationid exact \"" + this.organizationId + "\"))";
166
    this.csvProjectParamsHead = 'format=csv&type=projects&fq=((funder exact "';
167 56644 k.triantaf
    //this.csvPublicationParamsHead = 'format=csv-special&type=publications&page=0&query=((((oaftype exact result) and (resulttypeid exact publication)) and (funderid exact ';
168
  }
169 58275 k.triantaf
170 56644 k.triantaf
  private getPageContents() {
171 59007 k.triantaf
    if(this.communityId) {
172 59816 argiro.kok
      this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
173 59007 k.triantaf
        this.pageContents = contents;
174 59816 argiro.kok
      }));
175 59007 k.triantaf
    }
176 56644 k.triantaf
  }
177 58275 k.triantaf
178 56644 k.triantaf
  private getDivContents() {
179 59007 k.triantaf
    if(this.communityId) {
180 59816 argiro.kok
      this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.communityId, this._router.url).subscribe(contents => {
181 59007 k.triantaf
        this.divContents = contents;
182 59816 argiro.kok
      }));
183 59007 k.triantaf
    }
184 56644 k.triantaf
  }
185 59816 argiro.kok
186 56644 k.triantaf
  ngOnDestroy() {
187 59816 argiro.kok
    this.subscriptions.forEach(subscription => {
188
      if (subscription instanceof Subscriber) {
189
        subscription.unsubscribe();
190
      }
191
    });
192 61262 konstantin
    this.innerReportSubscriptions.forEach(subscription => {
193
      if(subscription instanceof Subscriber) {
194
        subscription.unsubscribe();
195
      }
196
    });
197
198 59816 argiro.kok
    this.fetchDatasets.clearSubscriptions();
199
    this.fetchPublications.clearSubscriptions();
200
    this.fetchSoftware.clearSubscriptions();
201
    this.fetchPublications.clearSubscriptions();
202
    this.fetchDataproviders.clearSubscriptions();
203
    this.fetchProjects.clearSubscriptions();
204 56644 k.triantaf
  }
205 59816 argiro.kok
206 58275 k.triantaf
  private getTotalResearchResults() {
207 58790 k.triantaf
    this.fetchPublications.getNumForEntity('publication', 'organization', this.organizationId, this.properties);
208
    this.fetchDatasets.getNumForEntity('dataset', 'organization', this.organizationId, this.properties);
209
    this.fetchSoftware.getNumForEntity('software', 'organization', this.organizationId, this.properties);
210
    this.fetchOrps.getNumForEntity('other', 'organization', this.organizationId, this.properties);
211 58275 k.triantaf
  }
212
213
  private getTotalDataproviders() {
214 58790 k.triantaf
    this.fetchDataproviders.getNumForEntity('organization', this.organizationId, this.properties);
215 58275 k.triantaf
  }
216
217 58807 konstantin
  // private searchContentProviders() {
218
  //   this.fetchDataproviders.getResultsForEntity("organization", this.organizationId, 1, this.searchNumber, this.properties);
219
  // }
220
  private searchContentProviders(page: number, size: number) {
221
    if (this.reloadDataproviders &&
222
      (this.fetchDataproviders.searchUtils.status == this.errorCodes.LOADING ||
223 58812 konstantin
        (this.fetchDataproviders.searchUtils.status == this.errorCodes.DONE && this.fetchDataproviders.searchUtils.totalResults > 0)
224
      )
225
    ) {
226 58807 konstantin
      this.fetchDataproviders.getResultsForEntity("organization", this.organizationId, page, size, this.properties);
227
    }
228
    this.reloadDataproviders = false;
229 58790 k.triantaf
  }
230
231 58807 konstantin
  // private searchPublications() {
232
  //   this.fetchPublications.getResultsForEntity("publication", "organization", this.organizationId, 1, size, this.properties);
233
  // }
234
  private searchPublications(page: number, size: number) {
235
    if (this.reloadPublications &&
236
      (this.fetchPublications.searchUtils.status == this.errorCodes.LOADING ||
237 58812 konstantin
        (this.fetchPublications.searchUtils.status == this.errorCodes.DONE && this.fetchPublications.searchUtils.totalResults > 0)
238
      )
239
    ) {
240 58807 konstantin
      this.fetchPublications.getResultsForEntity("publication", "organization", this.organizationId, page, size, this.properties);
241
    }
242
    this.reloadPublications = false;
243 58790 k.triantaf
  }
244
245 58807 konstantin
  // private searchDatasets() {
246
  //   this.fetchDatasets.getResultsForEntity("dataset", "organization", this.organizationId, 1, this.searchNumber, this.properties);
247
  // }
248
  private searchDatasets(page: number, size: number) {
249
    if (this.reloadDatasets &&
250
      (this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING ||
251 58812 konstantin
        (this.fetchDatasets.searchUtils.status == this.errorCodes.DONE && this.fetchDatasets.searchUtils.totalResults > 0)
252
      )
253
    ) {
254 58807 konstantin
      this.fetchDatasets.getResultsForEntity("dataset", "organization", this.organizationId, page, size, this.properties);
255
    }
256
    this.reloadDatasets = false;
257 58790 k.triantaf
  }
258 58807 konstantin
259
  // private searchSoftware() {
260
  //   this.fetchSoftware.getResultsForEntity("software", "organization", this.organizationId, 1, this.searchNumber, this.properties);
261
  // }
262
  private searchSoftware(page: number, size: number) {
263
    if (this.reloadSoftware &&
264
      (this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING ||
265 58812 konstantin
        (this.fetchSoftware.searchUtils.status == this.errorCodes.DONE && this.fetchSoftware.searchUtils.totalResults > 0)
266
      )
267
    ) {
268 58807 konstantin
      this.fetchSoftware.getResultsForEntity("software", "organization", this.organizationId, page, size, this.properties);
269
    }
270
    this.reloadSoftware = false;
271 58790 k.triantaf
  }
272 58807 konstantin
273
  // private searchOrps() {
274
  //   this.fetchOrps.getResultsForEntity("other", "organization", this.organizationId, 1, this.searchNumber, this.properties);
275
  // }
276
  private searchOrps(page: number, size: number) {
277
    if (this.reloadOrps &&
278
      (this.fetchOrps.searchUtils.status == this.errorCodes.LOADING ||
279 58812 konstantin
        (this.fetchOrps.searchUtils.status == this.errorCodes.DONE && this.fetchOrps.searchUtils.totalResults > 0)
280
      )
281
    ) {
282 58807 konstantin
      this.fetchOrps.getResultsForEntity("other", "organization", this.organizationId, page, size, this.properties);
283
    }
284
    this.reloadOrps = false;
285 58790 k.triantaf
  }
286
287 56644 k.triantaf
  private getOrganizationInfo() {
288 58275 k.triantaf
289 56644 k.triantaf
    this.warningMessage = '';
290
    this.errorMessage = ""
291
    this.showLoading = true;
292 58275 k.triantaf
293 56644 k.triantaf
    this.organizationInfo = null;
294 59816 argiro.kok
295
    this.subscriptions.push(this._organizationService.getOrganizationInfo(this.organizationId, this.properties).subscribe(
296 56644 k.triantaf
      data => {
297
        if (data == null) {
298
          this.showLoading = false;
299 58275 k.triantaf
          this._router.navigate(['/error'], {
300
            queryParams: {
301
              "page": this._location.path(true),
302
              "page_type": "organization"
303
            }
304
          });
305 56644 k.triantaf
          this.errorMessage = 'No organization found';
306
        } else {
307
          this.organizationInfo = data;
308 60604 argiro.kok
          this.organizationId = this.organizationInfo.objIdentifier; // reset in case the parameter was a canonical url. The related queries  and reports should have the dedup id
309
          this.csvParamsTail = '" and relorganizationid exact "' + this.organizationId + '" ))';
310 59411 argiro.kok
          this.seoService.createLinkForCanonicalURL(this.properties.domain + this.properties.baseLink  + this.properties.searchLinkToOrganization + this.organizationInfo.relcanId);
311 59108 k.triantaf
          this.updateTitle((this.organizationInfo.title.name?this.organizationInfo.title.name:(this.organizationInfo.name?this.organizationInfo.name:'No title available')));
312
          this.updateDescription("Organization, country, " +
313
            (this.organizationInfo.title.name?this.organizationInfo.title.name:'No title available') +
314
            ((this.organizationInfo.title.name && this.organizationInfo.title.name != this.organizationInfo.name) ? (', ') : '') +
315
            (this.organizationInfo.name?this.organizationInfo.name:''));
316 56644 k.triantaf
          if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
317 59816 argiro.kok
            this.subscriptions.push(this._piwikService.trackView(this.properties, this.organizationInfo.title.name, this.piwikSiteId).subscribe());
318 56644 k.triantaf
          }
319
          var refineFields: string [] = ["funder"];
320 58874 konstantin
321
          if (typeof document !== 'undefined') {
322
            this.getTotalResearchResults();
323
            this.getTotalDataproviders();
324
          }
325
326 58807 konstantin
          this.fetchProjects.getResultsForOrganizations(this.organizationId, "", 1, this.searchNumber, refineFields, this.properties);
327 56644 k.triantaf
          this.showLoading = false;
328
        }
329
      },
330
      err => {
331
        //console.log(err)
332
        this.handleError("Error getting organization for id: " + this.organizationId, err);
333 58275 k.triantaf
        if (err.status == 404) {
334
          this._router.navigate(['/error'], {
335
            queryParams: {
336
              "page": this._location.path(true),
337
              "page_type": "organization"
338
            }
339
          });
340 57494 konstantin
        }
341 59411 argiro.kok
        this.seoService.createLinkForCanonicalURL(this.properties.domain+ this.properties.baseLink  + this.properties.searchLinkToOrganizations);
342 58286 konstantin
        this.errorMessage = 'No organization found';
343 56644 k.triantaf
        this.showLoading = false;
344
      }
345 59816 argiro.kok
    ));
346 56644 k.triantaf
  }
347 58275 k.triantaf
348 56644 k.triantaf
  public downloadFile(url: string, filename: string) {
349
    this.openLoading();
350
    this.setMessageLoading("Downloading CSV file");
351 59816 argiro.kok
352
    this.subscriptions.push(this._reportsService.downloadCSVFile(url).subscribe(
353 56644 k.triantaf
      data => {
354
        this.closeLoading();
355 58275 k.triantaf
356 56644 k.triantaf
        var url = window.URL.createObjectURL(data);
357
        var a = window.document.createElement('a');
358
        window.document.body.appendChild(a);
359
        a.setAttribute('style', 'display: none');
360
        a.href = url;
361
        a.download = filename + ".csv";
362
        a.click();
363
        window.URL.revokeObjectURL(url);
364
        a.remove(); // remove the element
365 58275 k.triantaf
366 56644 k.triantaf
        //window.open(window.URL.createObjectURL(data));
367
        if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
368 60406 argiro.kok
          this.subscriptions.push(this._piwikService.trackDownload(this.properties, "DownloadCSV" + filename, this.piwikSiteId).subscribe());
369 56644 k.triantaf
        }
370
      },
371
      err => {
372
        //console.log("Error downloading the file.");
373
        this.handleError("Error downloading file: " + filename + ".csv", err);
374 58275 k.triantaf
375 56644 k.triantaf
        this.closeLoading();
376
        this.confirmOpenCsvError();
377
      }/*,
378 54825 konstantin
           () => console.log('Completed file download.')*/
379 59816 argiro.kok
    ));
380 56644 k.triantaf
  }
381 58275 k.triantaf
382
  private downloadFileByFunder() {
383
384 56644 k.triantaf
    this.openLoading();
385
    this.setMessageLoading("Downloading CSV file");
386 58275 k.triantaf
387 56644 k.triantaf
    let response: string[] = [];
388
    let totalResponse: string = "";
389
    let projects = [];
390 58275 k.triantaf
    let counter: number = this.funderCount;
391 56644 k.triantaf
    let title: boolean = false;
392
    let title_index: number = 0;
393 58275 k.triantaf
394
    let filename: string = 'funder-project-' + this.funderContentType + '-report';
395 59816 argiro.kok
396
    this.subscriptions.push(this._searchProjectsService.getProjectsForOrganizations(this.organizationId, ' and (funder exact "' + this.encodeURI(this.funderId) + '" ) ', 1, this.funderCount, [], this.properties).subscribe(
397 56644 k.triantaf
      data => {
398
        projects = data[1];
399
        for (let index = 0; index < projects.length; index++) {
400 61262 konstantin
          this.innerReportSubscriptions.push(this._searchResearchResultsService.numOfEntityResults(this.funderContentType, projects[index].id, "project", this.properties).subscribe(
401 56644 k.triantaf
            data => {
402
              //if(data == 0 && title) {   // if no publications for this project
403
              if (data == 0 && (counter > 1 || title)) {   // if no publications for this project
404
                counter--;
405
                response[index] = "";
406
                //console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
407 58275 k.triantaf
408 56644 k.triantaf
                if (counter == 0) {
409
                  //for(let i=count-1; i>=0; i--) {
410
                  for (let i = 0; i < projects.length; i++) {
411
                    if (response[i] != "") {
412
                      if (i == title_index) {
413
                        totalResponse = response[i] + totalResponse;
414
                      } else {
415
                        totalResponse += response[i];
416
                      }
417
                    }
418
                  }
419
                  this.closeLoading();
420 58275 k.triantaf
421 56644 k.triantaf
                  var csvurl = window.URL.createObjectURL(new Blob([totalResponse], {type: 'text/csv'}));
422
                  var a = window.document.createElement('a');
423
                  window.document.body.appendChild(a);
424
                  a.setAttribute('style', 'display: none');
425
                  a.href = csvurl;
426
                  a.download = filename + ".csv";
427
                  a.click();
428
                  window.URL.revokeObjectURL(csvurl);
429
                  a.remove(); // remove the element
430 60406 argiro.kok
                  if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
431
                    this.subscriptions.push(this._piwikService.trackDownload(this.properties, "DownloadCSV" + filename, this.piwikSiteId).subscribe());
432
                  }
433 56644 k.triantaf
                }
434
              } else {
435
                let url: string;
436
                if (!title) {
437
                  title_index = index;
438
                  //console.info(title_index);
439 58790 k.triantaf
                  url = this.downloadURLAPI + '?format=csv-special&' + this.getTypeParam(this.funderContentType) + '&fq=((relprojectid exact "' + projects[index].id + '"))';
440 56644 k.triantaf
                } else {
441 58790 k.triantaf
                  url = this.downloadURLAPI + '?format=csv-special-notitle&' + this.getTypeParam(this.funderContentType) + '&fq=((relprojectid exact "' + projects[index].id + '"))';
442 56644 k.triantaf
                }
443
                title = true;
444 59816 argiro.kok
445 61262 konstantin
                this.innerReportSubscriptions.push(this._reportsService.getCSVResponse(url).subscribe(
446 56644 k.triantaf
                  data => {
447
                    counter--;
448
                    response[index] = data;
449
                    //console.info("index: "+index, "counter: "+counter, "id:"+projects[index].id, response[index]);
450 58275 k.triantaf
451 56644 k.triantaf
                    if (counter == 0) {
452
                      //for(let i=count-1; i>=0; i--) {
453
                      for (let i = 0; i < projects.length; i++) {
454
                        if (response[i] != "") {
455
                          if (i == title_index) {
456
                            totalResponse = response[i] + totalResponse;
457 56268 konstantin
                          } else {
458 56644 k.triantaf
                            totalResponse += response[i];
459 56268 konstantin
                          }
460 56644 k.triantaf
                        }
461
                      }
462
                      this.closeLoading();
463 58275 k.triantaf
464 56644 k.triantaf
                      var csvurl = window.URL.createObjectURL(new Blob([totalResponse], {type: 'text/csv'}));
465
                      var a = window.document.createElement('a');
466
                      window.document.body.appendChild(a);
467
                      a.setAttribute('style', 'display: none');
468
                      a.href = csvurl;
469
                      a.download = filename + ".csv";
470
                      a.click();
471
                      window.URL.revokeObjectURL(csvurl);
472
                      a.remove(); // remove the element
473 60406 argiro.kok
                      if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
474
                        this.subscriptions.push(this._piwikService.trackDownload(this.properties, "DownloadCSV" + filename, this.piwikSiteId).subscribe());
475
                      }
476 56644 k.triantaf
                    }
477
                  },
478
                  err => {
479
                    this.handleError("Error downloading file: " + filename, err);
480 58275 k.triantaf
481 56644 k.triantaf
                    this.closeLoading();
482
                    this.confirmOpenCsvError();
483 61262 konstantin
                    this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe());
484 56644 k.triantaf
                  }/*,
485
                            () => console.log('Completed file download.')*/
486 59816 argiro.kok
                ) );
487 56644 k.triantaf
              }
488
            },
489
            err => {
490
              this.handleError("Error getting number of publications for project with id: " + projects[index].id, err);
491 61249 konstantin
              this.closeLoading();
492 61262 konstantin
              this.confirmOpenCsvError();
493
              this.innerReportSubscriptions.forEach(subscription => subscription.unsubscribe());
494 59816 argiro.kok
            }));
495 56644 k.triantaf
        }
496
      },
497
      err => {
498
        this.handleError("Error getting projects for organization with id: " + this.organizationId, err);
499 58275 k.triantaf
500 56644 k.triantaf
        this.closeLoading();
501
        this.confirmOpenCsvError();
502
      }
503 59816 argiro.kok
    ));
504 56644 k.triantaf
  }
505 58275 k.triantaf
506 56644 k.triantaf
  private updateDescription(description: string) {
507 57820 argiro.kok
    this._meta.updateTag({content: description.substring(0, 160)}, "name='description'");
508
    this._meta.updateTag({content: description.substring(0, 160)}, "property='og:description'");
509 56644 k.triantaf
  }
510 58275 k.triantaf
511 56644 k.triantaf
  private updateTitle(title: string) {
512 56840 konstantin
    var _prefix = "";
513 57820 argiro.kok
    // if(!this.communityId) {
514
    //   _prefix = "OpenAIRE | ";
515
    // }
516
    // var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
517
    this._title.setTitle(title);
518
    this._meta.updateTag({content: title}, "property='og:title'");
519 56644 k.triantaf
  }
520 58275 k.triantaf
521 56644 k.triantaf
  private updateUrl(url: string) {
522
    this._meta.updateTag({content: url}, "property='og:url'");
523
  }
524 58275 k.triantaf
525 56644 k.triantaf
  private openLoading() {
526 61249 konstantin
    this.closeDownloadReportModal();
527
    this.closeDownloadFunderReportModal();
528
529 56644 k.triantaf
    if (this.loading) {
530
      this.loading.open();
531 50169 argiro.kok
    }
532 56644 k.triantaf
  }
533 58275 k.triantaf
534 56644 k.triantaf
  private closeLoading() {
535
    if (this.loading) {
536
      this.loading.close();
537 50169 argiro.kok
    }
538 56644 k.triantaf
  }
539 58275 k.triantaf
540 56644 k.triantaf
  private setMessageLoading(message: string) {
541
    if (this.loading) {
542
      this.loading.message = message;
543 50169 argiro.kok
    }
544 56644 k.triantaf
  }
545 58275 k.triantaf
546
  public confirmOpenApplyAll(contentType: string) {
547 56644 k.triantaf
    this.alertApplyAll.cancelButton = true;
548
    this.alertApplyAll.okButton = true;
549
    this.alertApplyAll.alertTitle = "CSV FILE";
550
    this.alertApplyAll.message = "Do you wish to download a CSV file? Note that this process may take a while.";
551
    this.alertApplyAll.okButtonText = "Yes";
552
    this.alertApplyAll.cancelButtonText = "No";
553
    this.alertApplyAll.open();
554 58275 k.triantaf
    this.funderId = this.funder.id;
555
    this.funderCount = this.funder.number;
556
    this.funderContentType = contentType;
557 56644 k.triantaf
  }
558 58275 k.triantaf
559
  public confirmCloseApplyAll() {
560
    this.downloadFileByFunder();
561 56644 k.triantaf
  }
562 58275 k.triantaf
563 56644 k.triantaf
  public confirmOpenCsvError() {
564
    this.alertCsvError.cancelButton = false;
565
    this.alertCsvError.okButton = true;
566
    this.alertCsvError.alertTitle = "ERROR DOWNLOADING CSV FILE";
567
    this.alertCsvError.message = "There was an error in csv downloading. Please try again later.";
568
    this.alertCsvError.okButtonText = "OK";
569
    this.alertCsvError.open();
570
  }
571 58275 k.triantaf
572 56644 k.triantaf
  encodeURI(input: string): string {
573
    return StringUtils.URIEncode(input);
574
  }
575 58275 k.triantaf
576 56644 k.triantaf
  private handleError(message: string, error) {
577
    console.error("Organizaton Landing Page: " + message, error);
578
  }
579 58275 k.triantaf
580 57238 konstantin
  openDeletedByInference() {
581
    this.deleteByInferenceOpened = true;
582
    this.alertModalDeletedByInference.cancelButton = false;
583
    this.alertModalDeletedByInference.okButton = false;
584 58275 k.triantaf
    this.alertModalDeletedByInference.alertTitle = "Other versions of";
585 57238 konstantin
    this.alertModalDeletedByInference.open();
586
  }
587 58275 k.triantaf
588
  public getTypeParam(type: string): string {
589 58790 k.triantaf
    if (type == 'results') {
590 58275 k.triantaf
      type = 'publications&type=datasets&type=software&type=other';
591
    }
592 58790 k.triantaf
    return 'type=' + type;
593 58275 k.triantaf
  }
594
595
  getCSVAffiliated(contentType: string): string {
596
    return this.downloadURLAPI + '?format=csv&' + this.getTypeParam(contentType) + '&fq=(relorganizationid exact "' + this.organizationId + '")';
597
  }
598
599
  getFunderProjects(): string {
600 58790 k.triantaf
    return this.downloadURLAPI + '?' + this.csvProjectParamsHead + encodeURI(this.funder.id) + this.csvParamsTail;
601 58275 k.triantaf
  }
602 58318 k.triantaf
603
  open(value: any) {
604
    console.log(value);
605
  }
606 58778 k.triantaf
607
  openDownloadReportModal() {
608
    this.downloadReportModal.cancelButton = false;
609
    this.downloadReportModal.okButton = false;
610
    this.downloadReportModal.alertTitle = "Download content report";
611
    this.downloadReportModal.open();
612
  }
613 61249 konstantin
614
  closeDownloadReportModal() {
615
    this.downloadReportModal.cancel();
616
  }
617 58778 k.triantaf
618
  openDownloadFunderReportModal() {
619
    this.funder = this.fetchProjects.funders[0];
620
    this.downloadFunderReportModal.cancelButton = false;
621
    this.downloadFunderReportModal.okButton = false;
622
    this.downloadFunderReportModal.alertTitle = "Download funder report";
623
    this.downloadFunderReportModal.open();
624
  }
625 58813 konstantin
626 61249 konstantin
  closeDownloadFunderReportModal() {
627
    this.downloadFunderReportModal.cancel();
628
  }
629
630 58813 konstantin
  public getParamsForSearchLink(type: string = "") {
631
    if(type) {
632
      return this.routerHelper.createQueryParams(['f0', 'fv0', 'type', 'qf', 'sortBy'], ['relorganizationid', this.organizationId, type, 'false', 'resultdateofacceptance,descending']);
633
    } else {
634
      return this.routerHelper.createQueryParams(['f0', 'fv0'], ['relorganizationid', this.organizationId]);
635
    }
636
  }
637 58778 k.triantaf
638 58790 k.triantaf
  public onSelectActiveTab(activeTabId) {
639
    if (this.activeTab != activeTabId) {   // tab really changed
640
      if (activeTabId == 'projects') {
641
        this.activeTab = 'projects';
642
      } else if (activeTabId == 'dataProviders') {
643
        this.activeTab = 'dataProviders';
644 58807 konstantin
        this.searchContentProviders(1, this.searchNumber);
645 58790 k.triantaf
      } else if (activeTabId == 'publications') {
646
        this.activeTab = 'publications';
647 58807 konstantin
        this.searchPublications(1, this.searchNumber);
648 58790 k.triantaf
      } else if (activeTabId == 'datasets') {
649
        this.activeTab = 'datasets';
650 58807 konstantin
        this.searchDatasets(1, this.searchNumber);
651 58790 k.triantaf
      } else if (activeTabId == 'software') {
652
        this.activeTab = 'software';
653 58807 konstantin
        this.searchSoftware(1, this.searchNumber);
654 58790 k.triantaf
      } else if (activeTabId == 'other') {
655
        this.activeTab = "other";
656 58807 konstantin
        this.searchOrps(1, this.searchNumber);
657 58790 k.triantaf
      }
658
    }
659
  }
660
661
  public get total(): number {
662
    let total = this.fetchPublications.searchUtils.totalResults;
663
    total += this.fetchDatasets.searchUtils.totalResults;
664
    total += this.fetchSoftware.searchUtils.totalResults;
665
    total += this.fetchOrps.searchUtils.totalResults;
666
    return total;
667
  }
668
669 58807 konstantin
  // public get numberOfTabs(): number {
670
  //   if (this.tabsAreInitialized) {
671
  //     return this._numberOfTabs;
672
  //   }
673
  //   if (!this.organizationInfo
674
  //     || this.fetchProjects.searchUtils.status === this.errorCodes.LOADING
675
  //     || this.fetchDataproviders.searchUtils.status === this.errorCodes.LOADING
676
  //     || this.fetchPublications.searchUtils.status == this.errorCodes.LOADING
677
  //     || this.fetchDatasets.searchUtils.status == this.errorCodes.LOADING
678
  //     || this.fetchSoftware.searchUtils.status == this.errorCodes.LOADING
679
  //     || this.fetchOrps.searchUtils.status == this.errorCodes.LOADING) {
680
  //     return 0;
681
  //   }
682
  //   if (this.fetchProjects.searchUtils.totalResults > 0) {
683
  //     if (this._numberOfTabs == 0) {
684
  //       this.firstTab = 'projects';
685
  //     }
686
  //     this._numberOfTabs++;
687
  //   }
688
  //   if (this.fetchDataproviders.searchUtils.totalResults > 0) {
689
  //     if (this._numberOfTabs == 0) {
690
  //       this.firstTab = 'dataProviders';
691
  //       this.searchContentProviders(1, this.searchNumber);
692
  //     }
693
  //     this._numberOfTabs++;
694
  //   }
695
  //   if (this.fetchPublications.searchUtils.totalResults > 0) {
696
  //     if (this._numberOfTabs == 0) {
697
  //       this.firstTab = 'publications';
698
  //       this.searchPublications(1, this.searchNumber);
699
  //     }
700
  //     this._numberOfTabs++;
701
  //   }
702
  //   if (this.fetchDatasets.searchUtils.totalResults > 0) {
703
  //     if (this._numberOfTabs == 0) {
704
  //       this.firstTab = 'datasets';
705
  //       this.searchDatasets(1, this.searchNumber);
706
  //     }
707
  //     this._numberOfTabs++;
708
  //   }
709
  //   if (this.fetchSoftware.searchUtils.totalResults > 0) {
710
  //     if (this._numberOfTabs == 0) {
711
  //       this.firstTab = 'software';
712
  //       this.searchSoftware(1, this.searchNumber);
713
  //     }
714
  //     this._numberOfTabs++;
715
  //   }
716
  //   if (this.fetchOrps.searchUtils.totalResults > 0) {
717
  //     if (this._numberOfTabs == 0) {
718
  //       this.firstTab = 'other';
719
  //       this.searchOrps(1, this.searchNumber);
720
  //     }
721
  //     this._numberOfTabs++;
722
  //   }
723
  //   this.activeTab = this.firstTab;
724
  //   this.tabsAreInitialized = true;
725
  //   return this._numberOfTabs;
726
  // }
727 58790 k.triantaf
728
  private getEntityName(entityType: string, plural: boolean, full: boolean): string {
729
    if (entityType == "publication") {
730
      return "publication" + (plural ? "s" : "");
731
    } else if (entityType == "dataset") {
732
      return (full ? "research data" : ("dataset" + (plural ? "s" : "")));
733
    } else if (entityType == "software") {
734
      return "software";
735
    } else if (entityType == "other") {
736
      return (full ? ("other research product" + (plural ? "s" : "")) : "other");
737
    } else if (entityType == "dataprovider") {
738
      return (full ? ("content provider" + (plural ? "s" : "")) : "dataprovider" + (plural ? "s" : ""));
739
    } else {
740
      return entityType + (plural ? "s" : "");
741
    }
742
  }
743
744 58778 k.triantaf
  public scroll() {
745
    HelperFunctions.scroll();
746
  }
747 50169 argiro.kok
}