2023-11-13 14:00:05 +01:00
|
|
|
import {ChangeDetectorRef, Component, OnInit, ViewChild} from "@angular/core";
|
2023-10-20 18:07:33 +02:00
|
|
|
import {StakeholderService} from "../../monitor/services/stakeholder.service";
|
|
|
|
import {Stakeholder} from "../../monitor/entities/stakeholder";
|
2023-11-13 14:00:05 +01:00
|
|
|
import {zip} from "rxjs";
|
2023-10-19 15:33:04 +02:00
|
|
|
import {EditStakeholderComponent} from "./edit-stakeholder/edit-stakeholder.component";
|
|
|
|
import {Title} from "@angular/platform-browser";
|
2023-11-13 14:00:05 +01:00
|
|
|
import {BaseComponent} from "../../sharedComponents/base/base.component";
|
|
|
|
import {ActivatedRoute} from "@angular/router";
|
2023-10-19 15:33:04 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'general',
|
|
|
|
templateUrl: "./general.component.html"
|
|
|
|
})
|
2023-11-13 14:00:05 +01:00
|
|
|
export class GeneralComponent extends BaseComponent implements OnInit {
|
2023-10-19 15:33:04 +02:00
|
|
|
public stakeholder: Stakeholder;
|
|
|
|
public alias: string[];
|
|
|
|
public defaultStakeholders: Stakeholder[];
|
|
|
|
public loading: boolean = false;
|
|
|
|
@ViewChild('editStakeholderComponent') editStakeholderComponent: EditStakeholderComponent;
|
|
|
|
|
|
|
|
constructor(private stakeholderService: StakeholderService,
|
|
|
|
private cdr: ChangeDetectorRef,
|
2023-11-13 14:00:05 +01:00
|
|
|
protected _route: ActivatedRoute,
|
|
|
|
protected _title: Title) {
|
|
|
|
super();
|
2023-10-19 15:33:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
this.loading = true;
|
|
|
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
if(this.stakeholder) {
|
2023-11-13 14:00:05 +01:00
|
|
|
this.title = this.stakeholder.name + " | General";
|
|
|
|
this.setMetadata();
|
2023-10-19 15:33:04 +02:00
|
|
|
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() {
|
2024-04-12 10:14:26 +02:00
|
|
|
this.editStakeholderComponent.init(this.stakeholder, this.alias, this.defaultStakeholders, this.stakeholder.defaultId == null, false, true)
|
2023-10-19 15:33:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public save() {
|
|
|
|
this.loading = true;
|
2023-11-13 14:00:05 +01:00
|
|
|
this.editStakeholderComponent.save(stakeholder => {
|
2023-10-19 15:33:04 +02:00
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.stakeholderService.setStakeholder(this.stakeholder);
|
|
|
|
this.reset();
|
|
|
|
this.loading = false;
|
|
|
|
}, (error) => {
|
|
|
|
console.error(error);
|
|
|
|
this.loading = false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|