]> git.proxmox.com Git - ceph.git/blame - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/mirroring/overview/overview.component.ts
import ceph quincy 17.2.4
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / mirroring / overview / overview.component.ts
CommitLineData
11fdf7f2 1import { Component, OnDestroy, OnInit } from '@angular/core';
2a845540 2import { FormControl } from '@angular/forms';
11fdf7f2 3
f67539c2 4import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
11fdf7f2
TL
5import { Subscription } from 'rxjs';
6
f67539c2
TL
7import { Pool } from '~/app/ceph/pool/pool';
8import { RbdMirroringService } from '~/app/shared/api/rbd-mirroring.service';
9import { Icons } from '~/app/shared/enum/icons.enum';
10import { ViewCacheStatus } from '~/app/shared/enum/view-cache-status.enum';
2a845540 11import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
f67539c2
TL
12import { CdTableAction } from '~/app/shared/models/cd-table-action';
13import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
2a845540 14import { FinishedTask } from '~/app/shared/models/finished-task';
f67539c2
TL
15import { Permission } from '~/app/shared/models/permissions';
16import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
17import { ModalService } from '~/app/shared/services/modal.service';
2a845540 18import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
9f95a23c
TL
19import { BootstrapCreateModalComponent } from '../bootstrap-create-modal/bootstrap-create-modal.component';
20import { BootstrapImportModalComponent } from '../bootstrap-import-modal/bootstrap-import-modal.component';
11fdf7f2
TL
21
22@Component({
23 selector: 'cd-mirroring',
24 templateUrl: './overview.component.html',
25 styleUrls: ['./overview.component.scss']
26})
27export class OverviewComponent implements OnInit, OnDestroy {
2a845540 28 rbdmirroringForm: CdFormGroup;
9f95a23c
TL
29 permission: Permission;
30 tableActions: CdTableAction[];
31 selection = new CdTableSelection();
f67539c2 32 modalRef: NgbModalRef;
9f95a23c
TL
33 peersExist = true;
34 siteName: any;
11fdf7f2 35 status: ViewCacheStatus;
1911f103 36 private subs = new Subscription();
2a845540
TL
37 editing = false;
38
39 icons = Icons;
11fdf7f2 40
9f95a23c
TL
41 constructor(
42 private authStorageService: AuthStorageService,
43 private rbdMirroringService: RbdMirroringService,
2a845540
TL
44 private modalService: ModalService,
45 private taskWrapper: TaskWrapperService
9f95a23c
TL
46 ) {
47 this.permission = this.authStorageService.getPermissions().rbdMirroring;
48
9f95a23c
TL
49 const createBootstrapAction: CdTableAction = {
50 permission: 'update',
51 icon: Icons.upload,
52 click: () => this.createBootstrapModal(),
f67539c2 53 name: $localize`Create Bootstrap Token`,
2a845540 54 canBePrimary: () => true,
9f95a23c
TL
55 disable: () => false
56 };
57 const importBootstrapAction: CdTableAction = {
58 permission: 'update',
59 icon: Icons.download,
60 click: () => this.importBootstrapModal(),
f67539c2 61 name: $localize`Import Bootstrap Token`,
9f95a23c
TL
62 disable: () => this.peersExist
63 };
2a845540 64 this.tableActions = [createBootstrapAction, importBootstrapAction];
9f95a23c 65 }
11fdf7f2
TL
66
67 ngOnInit() {
2a845540 68 this.createForm();
1911f103
TL
69 this.subs.add(this.rbdMirroringService.startPolling());
70 this.subs.add(
f6b5b4d7 71 this.rbdMirroringService.subscribeSummary((data) => {
1911f103 72 this.status = data.content_data.status;
9f95a23c 73
1911f103
TL
74 this.peersExist = !!data.content_data.pools.find((o: Pool) => o['peer_uuids'].length > 0);
75 })
76 );
2a845540
TL
77 this.rbdMirroringService.getSiteName().subscribe((response: any) => {
78 this.siteName = response.site_name;
79 this.rbdmirroringForm.get('siteName').setValue(this.siteName);
80 });
81 }
82
83 private createForm() {
84 this.rbdmirroringForm = new CdFormGroup({
85 siteName: new FormControl({ value: '', disabled: true })
86 });
11fdf7f2
TL
87 }
88
89 ngOnDestroy(): void {
90 this.subs.unsubscribe();
91 }
9f95a23c 92
2a845540
TL
93 updateSiteName() {
94 if (this.editing) {
95 const action = this.taskWrapper.wrapTaskAroundCall({
96 task: new FinishedTask('rbd/mirroring/site_name/edit', {}),
97 call: this.rbdMirroringService.setSiteName(this.rbdmirroringForm.getValue('siteName'))
98 });
99
100 action.subscribe({
101 complete: () => {
102 this.rbdMirroringService.refresh();
103 }
104 });
105 }
106 this.editing = !this.editing;
9f95a23c
TL
107 }
108
109 createBootstrapModal() {
110 const initialState = {
111 siteName: this.siteName
112 };
f67539c2 113 this.modalRef = this.modalService.show(BootstrapCreateModalComponent, initialState);
9f95a23c
TL
114 }
115
116 importBootstrapModal() {
117 const initialState = {
118 siteName: this.siteName
119 };
f67539c2 120 this.modalRef = this.modalService.show(BootstrapImportModalComponent, initialState);
9f95a23c 121 }
11fdf7f2 122}