/
manage-participants.component.ts
57 lines (48 loc) · 2.35 KB
/
manage-participants.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { Component, OnInit, ViewChild } from '@angular/core';
import { IWineryState } from '../redux/store/winery.store';
import { NgRedux } from '@angular-redux/store';
import { OTParticipant } from '../models/ttopology-template';
import { WineryActions } from '../redux/actions/winery.actions';
import { DynamicTextData } from '../../../../tosca-management/src/app/wineryDynamicTable/formComponents/dynamicText.component';
import { WineryDynamicTableMetadata } from '../../../../tosca-management/src/app/wineryDynamicTable/wineryDynamicTableMetadata';
import { WineryDynamicFormModalComponent } from '../../../../tosca-management/src/app/wineryDynamicTable/modal/wineryDynamicFormModal.component';
@Component({
selector: 'winery-manage-participants',
templateUrl: './manage-participants.component.html',
styleUrls: ['./manage-participants.component.css']
})
export class ManageParticipantsComponent implements OnInit {
participants: OTParticipant[] = [];
formMetadata: Array<WineryDynamicTableMetadata> = [];
@ViewChild('generatedModal') generatedModal: WineryDynamicFormModalComponent;
constructor(private ngRedux: NgRedux<IWineryState>,
private ngActions: WineryActions) {
this.ngRedux.select((state) => state.wineryState.currentJsonTopology)
.subscribe((topology) => this.participants = topology.participants);
}
ngOnInit() {
this.formMetadata = [
new DynamicTextData('name', 'Name',
0, [], '', false, false, true),
new DynamicTextData('url', 'URL',
1, [], '', false, false, true),
];
}
openModal() {
this.generatedModal.show({});
}
save(param: any) {
const newParticipants = Object.assign([], this.participants);
newParticipants.push({ name: param.name, url: param.url } as OTParticipant);
this.ngRedux.dispatch(this.ngActions.updateParticipants(newParticipants));
}
remove(participant: OTParticipant) {
const newParticipants = Object.assign([], this.participants);
const index = newParticipants.findIndex((p) => p.name === participant.name);
newParticipants.splice(index, 1);
this.ngRedux.dispatch(this.ngActions.updateParticipants(newParticipants));
}
isEmpty(): boolean {
return !this.participants || this.participants.length === 0;
}
}