1 import { Component, OnDestroy, OnInit } from '@angular/core';
2 import { FormControl } from '@angular/forms';
4 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
5 import { Subscription } from 'rxjs';
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';
23 selector: 'cd-mirroring',
24 templateUrl: './overview.component.html',
25 styleUrls: ['./overview.component.scss']
27 export class OverviewComponent implements OnInit, OnDestroy {
28 rbdmirroringForm: CdFormGroup;
29 permission: Permission;
30 tableActions: CdTableAction[];
31 selection = new CdTableSelection();
32 modalRef: NgbModalRef;
35 status: ViewCacheStatus;
36 private subs = new Subscription();
42 private authStorageService: AuthStorageService,
43 private rbdMirroringService: RbdMirroringService,
44 private modalService: ModalService,
45 private taskWrapper: TaskWrapperService
47 this.permission = this.authStorageService.getPermissions().rbdMirroring;
49 const createBootstrapAction: CdTableAction = {
52 click: () => this.createBootstrapModal(),
53 name: $localize`Create Bootstrap Token`,
54 canBePrimary: () => true,
57 const importBootstrapAction: CdTableAction = {
60 click: () => this.importBootstrapModal(),
61 name: $localize`Import Bootstrap Token`,
62 disable: () => this.peersExist
64 this.tableActions = [createBootstrapAction, importBootstrapAction];
69 this.subs.add(this.rbdMirroringService.startPolling());
71 this.rbdMirroringService.subscribeSummary((data) => {
72 this.status = data.content_data.status;
74 this.peersExist = !!data.content_data.pools.find((o: Pool) => o['peer_uuids'].length > 0);
77 this.rbdMirroringService.getSiteName().subscribe((response: any) => {
78 this.siteName = response.site_name;
79 this.rbdmirroringForm.get('siteName').setValue(this.siteName);
83 private createForm() {
84 this.rbdmirroringForm = new CdFormGroup({
85 siteName: new FormControl({ value: '', disabled: true })
90 this.subs.unsubscribe();
95 const action = this.taskWrapper.wrapTaskAroundCall({
96 task: new FinishedTask('rbd/mirroring/site_name/edit', {}),
97 call: this.rbdMirroringService.setSiteName(this.rbdmirroringForm.getValue('siteName'))
102 this.rbdMirroringService.refresh();
106 this.editing = !this.editing;
109 createBootstrapModal() {
110 const initialState = {
111 siteName: this.siteName
113 this.modalRef = this.modalService.show(BootstrapCreateModalComponent, initialState);
116 importBootstrapModal() {
117 const initialState = {
118 siteName: this.siteName
120 this.modalRef = this.modalService.show(BootstrapImportModalComponent, initialState);