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