openaire-library/sdg/sdg-selection/sdg-selection.component.ts

50 lines
1.6 KiB
TypeScript

import {HttpClient} from "@angular/common/http";
import {Component, Input} from "@angular/core";
import {properties} from "../../../../environments/environment";
import {EnvProperties} from "../../utils/properties/env-properties";
import {StringUtils} from "../../utils/string-utils.class";
@Component({
selector: 'sdg-selection',
templateUrl: 'sdg-selection.component.html',
styleUrls: ['sdg-selection.component.less']
})
export class SdgSelectionComponent {
public properties: EnvProperties = properties;
@Input() subjects: string[];
@Input() entityType: string;
public loading: boolean;
public sdgs: any = [];
constructor(
private httpClient: HttpClient
) {}
ngOnInit() {
this.loading = true;
this.httpClient.get(this.properties.domain+'/assets/common-assets/vocabulary/sdg.json').subscribe(data => {
data['sdg'].forEach(element => {
this.sdgs.push({code: element.code, id: element.id, label: element.label, html: element.html, checked: this.subjects?.includes(element.id)});
});
this.sdgs.push({code: '18', id: 'No SDGs are relevant for this ' + this.getEntityName(this.entityType), label: 'Not relevant', html: 'Not relevant', checked: false});
this.loading = false;
});
}
public get firstColumn() {
return this.sdgs.slice(0, this.sdgs.length/2);
}
public get secondColumn() {
return this.sdgs.slice(this.sdgs.length/2, this.sdgs.length);
}
public getSelectedSubjects() {
return this.sdgs.filter(sub => sub.checked == true);
}
private getEntityName (entityType:string) {
return StringUtils.getEntityName(entityType, false);
}
}