|
1 |
| -import { Component, OnInit, ViewChild } from '@angular/core'; |
2 |
| -import { SelectionModel } from '@angular/cdk/collections'; |
3 |
| -import { |
4 |
| - Attribute, |
5 |
| - AttributesManagerService, |
6 |
| - FacilitiesManagerService, |
7 |
| - Host, |
8 |
| -} from '@perun-web-apps/perun/openapi'; |
9 |
| -import { MatDialog } from '@angular/material/dialog'; |
10 |
| -import { TABLE_ATTRIBUTES_SETTINGS } from '@perun-web-apps/config/table-config'; |
| 1 | +import { Component, OnInit } from '@angular/core'; |
| 2 | +import { FacilitiesManagerService, Host } from '@perun-web-apps/perun/openapi'; |
11 | 3 | import { ActivatedRoute } from '@angular/router';
|
12 |
| -import { filterCoreAttributes, getDefaultDialogConfig } from '@perun-web-apps/perun/utils'; |
13 |
| -import { AttributesListComponent } from '@perun-web-apps/perun/components'; |
14 |
| -import { DeleteAttributeDialogComponent } from '../../../../../shared/components/dialogs/delete-attribute-dialog/delete-attribute-dialog.component'; |
15 |
| -import { EditAttributeDialogComponent } from '@perun-web-apps/perun/dialogs'; |
16 |
| -import { CreateAttributeDialogComponent } from '../../../../../shared/components/dialogs/create-attribute-dialog/create-attribute-dialog.component'; |
17 | 4 |
|
18 | 5 | @Component({
|
19 | 6 | selector: 'app-facility-hosts-detail',
|
20 | 7 | templateUrl: './facility-hosts-detail.component.html',
|
21 | 8 | styleUrls: ['./facility-hosts-detail.component.scss'],
|
22 | 9 | })
|
23 | 10 | export class FacilityHostsDetailComponent implements OnInit {
|
24 |
| - @ViewChild('list') |
25 |
| - list: AttributesListComponent; |
26 |
| - |
27 |
| - attributes: Attribute[] = []; |
28 |
| - selected = new SelectionModel<Attribute>(true, []); |
29 | 11 | hostId: number;
|
30 | 12 | host: Host = { beanName: '', id: 0 };
|
31 |
| - loading: boolean; |
32 |
| - tableId = TABLE_ATTRIBUTES_SETTINGS; |
33 | 13 |
|
34 |
| - constructor( |
35 |
| - private dialog: MatDialog, |
36 |
| - private attributesManager: AttributesManagerService, |
37 |
| - private facilityManager: FacilitiesManagerService, |
38 |
| - private route: ActivatedRoute |
39 |
| - ) {} |
| 14 | + constructor(private facilityManager: FacilitiesManagerService, private route: ActivatedRoute) {} |
40 | 15 |
|
41 | 16 | ngOnInit(): void {
|
42 | 17 | this.route.params.subscribe((params) => {
|
43 | 18 | this.hostId = Number(params['hostId']);
|
44 | 19 | this.facilityManager.getHostById(this.hostId).subscribe((host) => {
|
45 | 20 | this.host = host;
|
46 | 21 | });
|
47 |
| - this.refreshTable(); |
48 |
| - }); |
49 |
| - } |
50 |
| - |
51 |
| - refreshTable(): void { |
52 |
| - this.loading = true; |
53 |
| - this.attributesManager.getHostAttributes(this.hostId).subscribe((attributes) => { |
54 |
| - this.attributes = filterCoreAttributes(attributes); |
55 |
| - this.selected.clear(); |
56 |
| - this.loading = false; |
57 |
| - }); |
58 |
| - } |
59 |
| - |
60 |
| - onSave(): void { |
61 |
| - this.list.updateMapAttributes(); |
62 |
| - |
63 |
| - const config = getDefaultDialogConfig(); |
64 |
| - config.width = '450px'; |
65 |
| - config.data = { |
66 |
| - entityId: this.hostId, |
67 |
| - entity: 'host', |
68 |
| - attributes: this.selected.selected, |
69 |
| - }; |
70 |
| - |
71 |
| - const dialogRef = this.dialog.open(EditAttributeDialogComponent, config); |
72 |
| - |
73 |
| - dialogRef.afterClosed().subscribe((result) => { |
74 |
| - if (result) { |
75 |
| - this.refreshTable(); |
76 |
| - } |
77 |
| - }); |
78 |
| - } |
79 |
| - |
80 |
| - addAttribute(): void { |
81 |
| - const config = getDefaultDialogConfig(); |
82 |
| - config.width = '1050px'; |
83 |
| - config.data = { |
84 |
| - entityId: this.hostId, |
85 |
| - entity: 'host', |
86 |
| - notEmptyAttributes: this.attributes, |
87 |
| - style: 'facility-theme', |
88 |
| - }; |
89 |
| - |
90 |
| - const dialogRef = this.dialog.open(CreateAttributeDialogComponent, config); |
91 |
| - |
92 |
| - dialogRef.afterClosed().subscribe((result) => { |
93 |
| - if (result === 'saved') { |
94 |
| - this.refreshTable(); |
95 |
| - } |
96 |
| - }); |
97 |
| - } |
98 |
| - |
99 |
| - removeAttribute(): void { |
100 |
| - const config = getDefaultDialogConfig(); |
101 |
| - config.width = '450px'; |
102 |
| - config.data = { |
103 |
| - entityId: this.hostId, |
104 |
| - entity: 'host', |
105 |
| - attributes: this.selected.selected, |
106 |
| - theme: 'facility-theme', |
107 |
| - }; |
108 |
| - |
109 |
| - const dialogRef = this.dialog.open(DeleteAttributeDialogComponent, config); |
110 |
| - |
111 |
| - dialogRef.afterClosed().subscribe((result) => { |
112 |
| - if (result) { |
113 |
| - this.refreshTable(); |
114 |
| - } |
115 | 22 | });
|
116 | 23 | }
|
117 | 24 | }
|
0 commit comments