]>
Commit | Line | Data |
---|---|---|
11fdf7f2 TL |
1 | import { Component, OnDestroy, OnInit } from '@angular/core'; |
2 | ||
9f95a23c TL |
3 | import { I18n } from '@ngx-translate/i18n-polyfill'; |
4 | import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal'; | |
11fdf7f2 TL |
5 | import { Subscription } from 'rxjs'; |
6 | ||
7 | import { RbdMirroringService } from '../../../../shared/api/rbd-mirroring.service'; | |
9f95a23c | 8 | import { Icons } from '../../../../shared/enum/icons.enum'; |
11fdf7f2 | 9 | import { ViewCacheStatus } from '../../../../shared/enum/view-cache-status.enum'; |
9f95a23c TL |
10 | import { CdTableAction } from '../../../../shared/models/cd-table-action'; |
11 | import { CdTableSelection } from '../../../../shared/models/cd-table-selection'; | |
12 | import { Permission } from '../../../../shared/models/permissions'; | |
13 | import { AuthStorageService } from '../../../../shared/services/auth-storage.service'; | |
14 | import { Pool } from '../../../pool/pool'; | |
15 | import { BootstrapCreateModalComponent } from '../bootstrap-create-modal/bootstrap-create-modal.component'; | |
16 | import { BootstrapImportModalComponent } from '../bootstrap-import-modal/bootstrap-import-modal.component'; | |
17 | import { EditSiteNameModalComponent } from '../edit-site-name-modal/edit-site-name-modal.component'; | |
11fdf7f2 TL |
18 | |
19 | @Component({ | |
20 | selector: 'cd-mirroring', | |
21 | templateUrl: './overview.component.html', | |
22 | styleUrls: ['./overview.component.scss'] | |
23 | }) | |
24 | export class OverviewComponent implements OnInit, OnDestroy { | |
9f95a23c TL |
25 | permission: Permission; |
26 | tableActions: CdTableAction[]; | |
27 | selection = new CdTableSelection(); | |
28 | ||
11fdf7f2 TL |
29 | subs: Subscription; |
30 | ||
9f95a23c TL |
31 | modalRef: BsModalRef; |
32 | ||
33 | peersExist = true; | |
34 | siteName: any; | |
11fdf7f2 TL |
35 | status: ViewCacheStatus; |
36 | ||
9f95a23c TL |
37 | constructor( |
38 | private authStorageService: AuthStorageService, | |
39 | private rbdMirroringService: RbdMirroringService, | |
40 | private modalService: BsModalService, | |
41 | private i18n: I18n | |
42 | ) { | |
43 | this.permission = this.authStorageService.getPermissions().rbdMirroring; | |
44 | ||
45 | const editSiteNameAction: CdTableAction = { | |
46 | permission: 'update', | |
47 | icon: Icons.edit, | |
48 | click: () => this.editSiteNameModal(), | |
49 | name: this.i18n('Edit Site Name'), | |
50 | canBePrimary: () => true, | |
51 | disable: () => false | |
52 | }; | |
53 | const createBootstrapAction: CdTableAction = { | |
54 | permission: 'update', | |
55 | icon: Icons.upload, | |
56 | click: () => this.createBootstrapModal(), | |
57 | name: this.i18n('Create Bootstrap Token'), | |
58 | disable: () => false | |
59 | }; | |
60 | const importBootstrapAction: CdTableAction = { | |
61 | permission: 'update', | |
62 | icon: Icons.download, | |
63 | click: () => this.importBootstrapModal(), | |
64 | name: this.i18n('Import Bootstrap Token'), | |
65 | disable: () => this.peersExist | |
66 | }; | |
67 | this.tableActions = [editSiteNameAction, createBootstrapAction, importBootstrapAction]; | |
68 | } | |
11fdf7f2 TL |
69 | |
70 | ngOnInit() { | |
71 | this.subs = this.rbdMirroringService.subscribeSummary((data: any) => { | |
72 | if (!data) { | |
73 | return; | |
74 | } | |
75 | this.status = data.content_data.status; | |
9f95a23c TL |
76 | this.siteName = data.site_name; |
77 | ||
78 | this.peersExist = !!data.content_data.pools.find((o: Pool) => o['peer_uuids'].length > 0); | |
11fdf7f2 TL |
79 | }); |
80 | } | |
81 | ||
82 | ngOnDestroy(): void { | |
83 | this.subs.unsubscribe(); | |
84 | } | |
9f95a23c TL |
85 | |
86 | editSiteNameModal() { | |
87 | const initialState = { | |
88 | siteName: this.siteName | |
89 | }; | |
90 | this.modalRef = this.modalService.show(EditSiteNameModalComponent, { initialState }); | |
91 | } | |
92 | ||
93 | createBootstrapModal() { | |
94 | const initialState = { | |
95 | siteName: this.siteName | |
96 | }; | |
97 | this.modalRef = this.modalService.show(BootstrapCreateModalComponent, { initialState }); | |
98 | } | |
99 | ||
100 | importBootstrapModal() { | |
101 | const initialState = { | |
102 | siteName: this.siteName | |
103 | }; | |
104 | this.modalRef = this.modalService.show(BootstrapImportModalComponent, { initialState }); | |
105 | } | |
11fdf7f2 | 106 | } |