]>
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(); | |
9f95a23c | 28 | modalRef: BsModalRef; |
9f95a23c TL |
29 | peersExist = true; |
30 | siteName: any; | |
11fdf7f2 | 31 | status: ViewCacheStatus; |
1911f103 | 32 | private subs = new Subscription(); |
11fdf7f2 | 33 | |
9f95a23c TL |
34 | constructor( |
35 | private authStorageService: AuthStorageService, | |
36 | private rbdMirroringService: RbdMirroringService, | |
37 | private modalService: BsModalService, | |
38 | private i18n: I18n | |
39 | ) { | |
40 | this.permission = this.authStorageService.getPermissions().rbdMirroring; | |
41 | ||
42 | const editSiteNameAction: CdTableAction = { | |
43 | permission: 'update', | |
44 | icon: Icons.edit, | |
45 | click: () => this.editSiteNameModal(), | |
46 | name: this.i18n('Edit Site Name'), | |
47 | canBePrimary: () => true, | |
48 | disable: () => false | |
49 | }; | |
50 | const createBootstrapAction: CdTableAction = { | |
51 | permission: 'update', | |
52 | icon: Icons.upload, | |
53 | click: () => this.createBootstrapModal(), | |
54 | name: this.i18n('Create Bootstrap Token'), | |
55 | disable: () => false | |
56 | }; | |
57 | const importBootstrapAction: CdTableAction = { | |
58 | permission: 'update', | |
59 | icon: Icons.download, | |
60 | click: () => this.importBootstrapModal(), | |
61 | name: this.i18n('Import Bootstrap Token'), | |
62 | disable: () => this.peersExist | |
63 | }; | |
64 | this.tableActions = [editSiteNameAction, createBootstrapAction, importBootstrapAction]; | |
65 | } | |
11fdf7f2 TL |
66 | |
67 | ngOnInit() { | |
1911f103 TL |
68 | this.subs.add(this.rbdMirroringService.startPolling()); |
69 | this.subs.add( | |
f6b5b4d7 | 70 | this.rbdMirroringService.subscribeSummary((data) => { |
1911f103 TL |
71 | this.status = data.content_data.status; |
72 | this.siteName = data.site_name; | |
9f95a23c | 73 | |
1911f103 TL |
74 | this.peersExist = !!data.content_data.pools.find((o: Pool) => o['peer_uuids'].length > 0); |
75 | }) | |
76 | ); | |
11fdf7f2 TL |
77 | } |
78 | ||
79 | ngOnDestroy(): void { | |
80 | this.subs.unsubscribe(); | |
81 | } | |
9f95a23c TL |
82 | |
83 | editSiteNameModal() { | |
84 | const initialState = { | |
85 | siteName: this.siteName | |
86 | }; | |
87 | this.modalRef = this.modalService.show(EditSiteNameModalComponent, { initialState }); | |
88 | } | |
89 | ||
90 | createBootstrapModal() { | |
91 | const initialState = { | |
92 | siteName: this.siteName | |
93 | }; | |
94 | this.modalRef = this.modalService.show(BootstrapCreateModalComponent, { initialState }); | |
95 | } | |
96 | ||
97 | importBootstrapModal() { | |
98 | const initialState = { | |
99 | siteName: this.siteName | |
100 | }; | |
101 | this.modalRef = this.modalService.show(BootstrapImportModalComponent, { initialState }); | |
102 | } | |
11fdf7f2 | 103 | } |