]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/overview/overview.component.ts
bump version to 15.2.1-pve1
[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();
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}