]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/overview/overview.component.ts
import 15.2.5
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / mirroring / overview / overview.component.ts
CommitLineData
11fdf7f2
TL
1import { Component, OnDestroy, OnInit } from '@angular/core';
2
9f95a23c
TL
3import { I18n } from '@ngx-translate/i18n-polyfill';
4import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
11fdf7f2
TL
5import { Subscription } from 'rxjs';
6
7import { RbdMirroringService } from '../../../../shared/api/rbd-mirroring.service';
9f95a23c 8import { Icons } from '../../../../shared/enum/icons.enum';
11fdf7f2 9import { ViewCacheStatus } from '../../../../shared/enum/view-cache-status.enum';
9f95a23c
TL
10import { CdTableAction } from '../../../../shared/models/cd-table-action';
11import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
12import { Permission } from '../../../../shared/models/permissions';
13import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
14import { Pool } from '../../../pool/pool';
15import { BootstrapCreateModalComponent } from '../bootstrap-create-modal/bootstrap-create-modal.component';
16import { BootstrapImportModalComponent } from '../bootstrap-import-modal/bootstrap-import-modal.component';
17import { 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})
24export 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}