1
|
import {Component, OnDestroy, OnInit, ViewChild} from "@angular/core";
|
2
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
3
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
4
|
import {Stakeholder} from "../openaireLibrary/monitor/entities/stakeholder";
|
5
|
import { Subscription, zip} from "rxjs";
|
6
|
import {EditStakeholderComponent} from "./edit-stakeholder/edit-stakeholder.component";
|
7
|
import {properties} from "../../environments/environment";
|
8
|
import {Title} from "@angular/platform-browser";
|
9
|
|
10
|
@Component({
|
11
|
selector: 'general',
|
12
|
templateUrl: "./general.component.html",
|
13
|
styleUrls: ['general.component.css']
|
14
|
})
|
15
|
export class GeneralComponent implements OnInit, OnDestroy {
|
16
|
|
17
|
public stakeholder: Stakeholder;
|
18
|
public stakeholders: Stakeholder[];
|
19
|
public properties: EnvProperties = properties;
|
20
|
public defaultStakeholders: Stakeholder[];
|
21
|
public loading: boolean = false;
|
22
|
private subscriptions: any[] = [];
|
23
|
@ViewChild('editStakeholderComponent') editStakeholderComponent: EditStakeholderComponent;
|
24
|
|
25
|
constructor(private stakeholderService: StakeholderService,
|
26
|
private title: Title) {
|
27
|
}
|
28
|
|
29
|
ngOnInit() {
|
30
|
this.loading = true;
|
31
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
32
|
this.stakeholder = stakeholder;
|
33
|
if(this.stakeholder) {
|
34
|
this.title.setTitle(this.stakeholder.name + " | General");
|
35
|
let data = zip(
|
36
|
this.stakeholderService.getDefaultStakeholders(this.properties.monitorServiceAPIURL),
|
37
|
this.stakeholderService.getStakeholders(this.properties.monitorServiceAPIURL)
|
38
|
);
|
39
|
this.subscriptions.push(data.subscribe(res => {
|
40
|
this.defaultStakeholders = res[0];
|
41
|
this.stakeholders = res[1];
|
42
|
this.reset();
|
43
|
this.loading = false;
|
44
|
}));
|
45
|
}
|
46
|
}));
|
47
|
}
|
48
|
|
49
|
public reset() {
|
50
|
this.editStakeholderComponent.init(this.stakeholder, this.stakeholders, this.defaultStakeholders, this.stakeholder.defaultId == null, false)
|
51
|
}
|
52
|
|
53
|
|
54
|
public save() {
|
55
|
this.loading = true;
|
56
|
this.editStakeholderComponent.save((stakeholder) => {
|
57
|
this.stakeholder = stakeholder;
|
58
|
this.reset();
|
59
|
this.loading = false;
|
60
|
}, (error) => {
|
61
|
this.loading = false;
|
62
|
});
|
63
|
}
|
64
|
|
65
|
ngOnDestroy() {
|
66
|
this.subscriptions.forEach(subscription => {
|
67
|
if(subscription instanceof Subscription) {
|
68
|
subscription.unsubscribe();
|
69
|
}
|
70
|
});
|
71
|
}
|
72
|
}
|