]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/overview/overview.component.ts
c919e03cdbb82680370a4ab4a603a1f19e4641f4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / mirroring / overview / overview.component.ts
1 import { Component, OnDestroy, OnInit } from '@angular/core';
2
3 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
4 import { Subscription } from 'rxjs';
5
6 import { Pool } from '~/app/ceph/pool/pool';
7 import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
8 import { Icons } from '~/app/shared/enum/icons.enum';
9 import { ViewCacheStatus } from '~/app/shared/enum/view-cache-status.enum';
10 import { CdTableAction } from '~/app/shared/models/cd-table-action';
11 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
12 import { Permission } from '~/app/shared/models/permissions';
13 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
14 import { ModalService } from '~/app/shared/services/modal.service';
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';
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 {
25 permission: Permission;
26 tableActions: CdTableAction[];
27 selection = new CdTableSelection();
28 modalRef: NgbModalRef;
29 peersExist = true;
30 siteName: any;
31 status: ViewCacheStatus;
32 private subs = new Subscription();
33
34 constructor(
35 private authStorageService: AuthStorageService,
36 private rbdMirroringService: RbdMirroringService,
37 private modalService: ModalService
38 ) {
39 this.permission = this.authStorageService.getPermissions().rbdMirroring;
40
41 const editSiteNameAction: CdTableAction = {
42 permission: 'update',
43 icon: Icons.edit,
44 click: () => this.editSiteNameModal(),
45 name: $localize`Edit Site Name`,
46 canBePrimary: () => true,
47 disable: () => false
48 };
49 const createBootstrapAction: CdTableAction = {
50 permission: 'update',
51 icon: Icons.upload,
52 click: () => this.createBootstrapModal(),
53 name: $localize`Create Bootstrap Token`,
54 disable: () => false
55 };
56 const importBootstrapAction: CdTableAction = {
57 permission: 'update',
58 icon: Icons.download,
59 click: () => this.importBootstrapModal(),
60 name: $localize`Import Bootstrap Token`,
61 disable: () => this.peersExist
62 };
63 this.tableActions = [editSiteNameAction, createBootstrapAction, importBootstrapAction];
64 }
65
66 ngOnInit() {
67 this.subs.add(this.rbdMirroringService.startPolling());
68 this.subs.add(
69 this.rbdMirroringService.subscribeSummary((data) => {
70 this.status = data.content_data.status;
71 this.siteName = data.site_name;
72
73 this.peersExist = !!data.content_data.pools.find((o: Pool) => o['peer_uuids'].length > 0);
74 })
75 );
76 }
77
78 ngOnDestroy(): void {
79 this.subs.unsubscribe();
80 }
81
82 editSiteNameModal() {
83 const initialState = {
84 siteName: this.siteName
85 };
86 this.modalRef = this.modalService.show(EditSiteNameModalComponent, initialState);
87 }
88
89 createBootstrapModal() {
90 const initialState = {
91 siteName: this.siteName
92 };
93 this.modalRef = this.modalService.show(BootstrapCreateModalComponent, initialState);
94 }
95
96 importBootstrapModal() {
97 const initialState = {
98 siteName: this.siteName
99 };
100 this.modalRef = this.modalService.show(BootstrapImportModalComponent, initialState);
101 }
102 }