118 lines
4.4 KiB
TypeScript
118 lines
4.4 KiB
TypeScript
import {Component} from '@angular/core';
|
|
import {Observable} from 'rxjs/Observable';
|
|
import {ActivatedRoute} from '@angular/router';
|
|
import {OrganizationService} from '../../services/organization.service';
|
|
import {OrganizationInfo} from '../../utils/entities/organizationInfo';
|
|
|
|
@Component({
|
|
selector: 'organization',
|
|
templateUrl: 'organization.component.html',
|
|
})
|
|
|
|
export class OrganizationComponent {
|
|
constructor (private _organizationService: OrganizationService,
|
|
private route: ActivatedRoute) {
|
|
console.info('organization constructor');
|
|
}
|
|
|
|
ngOnInit() {
|
|
console.info('organization init');
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
this.organizationId = params['organizationId'];
|
|
console.info("Id is :"+this.organizationId);
|
|
if(this.organizationId){
|
|
this.getOrganizationInfo();
|
|
}else{
|
|
this.warningMessage="No valid project id";
|
|
}
|
|
});
|
|
}
|
|
|
|
organizationInfo: OrganizationInfo;
|
|
private organizationId: string;
|
|
private projectsNum : number = 0;
|
|
private fundersSet: Set<string>;
|
|
private emptyFundersSet: boolean = true;
|
|
public warningMessage = "";
|
|
public errorMessage = "";
|
|
private data : any = { "export":[] };
|
|
|
|
|
|
ngOnDestroy() {
|
|
this.sub.unsubscribe();
|
|
}
|
|
sub: any;
|
|
|
|
private getOrganizationInfo () {
|
|
console.info("inside getProjectInfo of component");
|
|
|
|
this.warningMessage = '';
|
|
this.errorMessage=""
|
|
console.info("do request");
|
|
|
|
this._organizationService.getOrganizationInfo(this.organizationId).subscribe(
|
|
data => {
|
|
this.organizationInfo = data;
|
|
|
|
let projectsNum = 0;
|
|
if(this.organizationInfo.projects != undefined) {
|
|
this.fundersSet = new Set<string>();
|
|
this.organizationInfo.projects.forEach(function (value, key, map) {
|
|
projectsNum += value.length;
|
|
this.fundersSet.add(key);
|
|
|
|
for(let project of value) {
|
|
this.data.export[this.data.export.length] =
|
|
{
|
|
'Project title': this.quote(project.name),
|
|
'Project Acronym': this.quote(project.acronym),
|
|
'Project ID': this.quote(project.code),
|
|
'Funder': this.quote(project.funder),
|
|
'Funding Stream':this.quote(project.fundingStream),
|
|
'Funding Substream level 1': this.quote(project.fundingLevel1),
|
|
'Funding Substream level 2': this.quote(project.fundingLevel2),
|
|
'SC39': this.quote(project.sc39),
|
|
'Start Date': this.quote(project.startDate),
|
|
'End Date': this.quote(project.endDate)
|
|
};
|
|
}
|
|
}.bind(this));
|
|
}
|
|
this.projectsNum = projectsNum;
|
|
},
|
|
err => {
|
|
console.error(err)
|
|
console.info("error");
|
|
|
|
this.errorMessage = 'No organization found';
|
|
}
|
|
);
|
|
}
|
|
|
|
handleClick(funder: string) {
|
|
if(this.emptyFundersSet) {
|
|
this.fundersSet.clear();
|
|
this.emptyFundersSet = false;
|
|
}
|
|
|
|
if(this.fundersSet.has(funder)) {
|
|
this.fundersSet.delete(funder);
|
|
|
|
if(this.fundersSet.size == 0) {
|
|
this.organizationInfo.projects.forEach(function (value, key, map) {
|
|
this.fundersSet.add(key);
|
|
}.bind(this));
|
|
this.emptyFundersSet = true;
|
|
}
|
|
console.info(funder+" funder deleted");
|
|
} else {
|
|
this.fundersSet.add(funder);
|
|
console.info(funder+" funder added");
|
|
}
|
|
}
|
|
|
|
quote(word: string): string {
|
|
return '"'+word+'"';
|
|
}
|
|
}
|