2020-10-19 23:18:09 +02:00
|
|
|
import {Component, OnDestroy, OnInit, ViewChild} from "@angular/core";
|
|
|
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
|
|
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
|
|
|
import {Stakeholder} from "../openaireLibrary/monitor/entities/stakeholder";
|
2020-11-13 17:42:12 +01:00
|
|
|
import { Subscription, zip} from "rxjs";
|
2020-10-19 23:18:09 +02:00
|
|
|
import {EditStakeholderComponent} from "./edit-stakeholder/edit-stakeholder.component";
|
|
|
|
import {properties} from "../../environments/environment";
|
2020-11-19 18:14:12 +01:00
|
|
|
import {Title} from "@angular/platform-browser";
|
2020-10-19 23:18:09 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'general',
|
2021-01-28 17:55:46 +01:00
|
|
|
templateUrl: "./general.component.html"
|
2020-10-19 23:18:09 +02:00
|
|
|
})
|
|
|
|
export class GeneralComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
public stakeholder: Stakeholder;
|
2020-12-08 17:40:11 +01:00
|
|
|
public alias: string[];
|
2020-10-19 23:18:09 +02:00
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
public defaultStakeholders: Stakeholder[];
|
|
|
|
public loading: boolean = false;
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
@ViewChild('editStakeholderComponent') editStakeholderComponent: EditStakeholderComponent;
|
2020-11-13 17:42:12 +01:00
|
|
|
|
2020-11-19 18:14:12 +01:00
|
|
|
constructor(private stakeholderService: StakeholderService,
|
|
|
|
private title: Title) {
|
2020-10-19 23:18:09 +02:00
|
|
|
}
|
2020-11-13 17:42:12 +01:00
|
|
|
|
2020-10-19 23:18:09 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.loading = true;
|
|
|
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
if(this.stakeholder) {
|
2020-11-19 18:14:12 +01:00
|
|
|
this.title.setTitle(this.stakeholder.name + " | General");
|
2020-10-19 23:18:09 +02:00
|
|
|
let data = zip(
|
|
|
|
this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL),
|
2020-12-08 17:40:11 +01:00
|
|
|
this.stakeholderService.getAlias(this.properties.monitorServiceAPIURL)
|
2020-10-19 23:18:09 +02:00
|
|
|
);
|
|
|
|
this.subscriptions.push(data.subscribe(res => {
|
|
|
|
this.defaultStakeholders = res[0];
|
2020-12-08 17:40:11 +01:00
|
|
|
this.alias = res[1];
|
2020-10-19 23:18:09 +02:00
|
|
|
this.reset();
|
|
|
|
this.loading = false;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2020-11-13 17:42:12 +01:00
|
|
|
|
2020-10-19 23:18:09 +02:00
|
|
|
public reset() {
|
2020-12-08 17:40:11 +01:00
|
|
|
this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false)
|
2020-10-19 23:18:09 +02:00
|
|
|
}
|
2020-11-13 17:42:12 +01:00
|
|
|
|
|
|
|
|
2020-10-19 23:18:09 +02:00
|
|
|
public save() {
|
|
|
|
this.loading = true;
|
|
|
|
this.editStakeholderComponent.save((stakeholder) => {
|
|
|
|
this.stakeholder = stakeholder;
|
2020-12-10 17:38:23 +01:00
|
|
|
this.stakeholderService.setStakeholder(this.stakeholder);
|
2020-10-19 23:18:09 +02:00
|
|
|
this.reset();
|
|
|
|
this.loading = false;
|
2020-11-03 11:04:45 +01:00
|
|
|
}, (error) => {
|
|
|
|
this.loading = false;
|
2020-10-19 23:18:09 +02:00
|
|
|
});
|
|
|
|
}
|
2020-11-13 17:42:12 +01:00
|
|
|
|
2020-10-19 23:18:09 +02:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if(subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|