2023-10-19 15:33:04 +02:00
|
|
|
import {ChangeDetectorRef, Component, OnDestroy, OnInit, ViewChild} from "@angular/core";
|
2023-10-20 18:07:33 +02:00
|
|
|
import {StakeholderService} from "../../monitor/services/stakeholder.service";
|
|
|
|
import {EnvProperties} from "../../utils/properties/env-properties";
|
|
|
|
import {Stakeholder} from "../../monitor/entities/stakeholder";
|
2023-10-19 15:33:04 +02:00
|
|
|
import { Subscription, zip} from "rxjs";
|
|
|
|
import {EditStakeholderComponent} from "./edit-stakeholder/edit-stakeholder.component";
|
2023-10-20 18:07:33 +02:00
|
|
|
import {properties} from "src/environments/environment";
|
2023-10-19 15:33:04 +02:00
|
|
|
import {Title} from "@angular/platform-browser";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'general',
|
|
|
|
templateUrl: "./general.component.html"
|
|
|
|
})
|
|
|
|
export class GeneralComponent implements OnInit, OnDestroy {
|
|
|
|
|
|
|
|
public stakeholder: Stakeholder;
|
|
|
|
public alias: string[];
|
|
|
|
public properties: EnvProperties = properties;
|
|
|
|
public defaultStakeholders: Stakeholder[];
|
|
|
|
public loading: boolean = false;
|
|
|
|
private subscriptions: any[] = [];
|
|
|
|
@ViewChild('editStakeholderComponent') editStakeholderComponent: EditStakeholderComponent;
|
|
|
|
|
|
|
|
constructor(private stakeholderService: StakeholderService,
|
|
|
|
private cdr: ChangeDetectorRef,
|
|
|
|
private title: Title) {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.loading = true;
|
|
|
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
if(this.stakeholder) {
|
|
|
|
this.title.setTitle(this.stakeholder.name + " | General");
|
|
|
|
let data = zip(
|
|
|
|
this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL),
|
|
|
|
this.stakeholderService.getAlias(this.properties.monitorServiceAPIURL)
|
|
|
|
);
|
|
|
|
this.subscriptions.push(data.subscribe(res => {
|
|
|
|
this.defaultStakeholders = res[0];
|
|
|
|
this.alias = res[1];
|
|
|
|
this.reset();
|
|
|
|
this.loading = false;
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
|
|
|
|
public reset() {
|
|
|
|
this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public save() {
|
|
|
|
this.loading = true;
|
|
|
|
this.editStakeholderComponent.save((stakeholder) => {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.stakeholderService.setStakeholder(this.stakeholder);
|
|
|
|
this.reset();
|
|
|
|
this.loading = false;
|
|
|
|
}, (error) => {
|
|
|
|
console.error(error);
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy() {
|
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if(subscription instanceof Subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|