1 import { Component, OnDestroy, OnInit } from '@angular/core';
3 import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
4 import { Subscription } from 'rxjs';
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';
20 selector: 'cd-mirroring',
21 templateUrl: './overview.component.html',
22 styleUrls: ['./overview.component.scss']
24 export class OverviewComponent implements OnInit, OnDestroy {
25 permission: Permission;
26 tableActions: CdTableAction[];
27 selection = new CdTableSelection();
28 modalRef: NgbModalRef;
31 status: ViewCacheStatus;
32 private subs = new Subscription();
35 private authStorageService: AuthStorageService,
36 private rbdMirroringService: RbdMirroringService,
37 private modalService: ModalService
39 this.permission = this.authStorageService.getPermissions().rbdMirroring;
41 const editSiteNameAction: CdTableAction = {
44 click: () => this.editSiteNameModal(),
45 name: $localize`Edit Site Name`,
46 canBePrimary: () => true,
49 const createBootstrapAction: CdTableAction = {
52 click: () => this.createBootstrapModal(),
53 name: $localize`Create Bootstrap Token`,
56 const importBootstrapAction: CdTableAction = {
59 click: () => this.importBootstrapModal(),
60 name: $localize`Import Bootstrap Token`,
61 disable: () => this.peersExist
63 this.tableActions = [editSiteNameAction, createBootstrapAction, importBootstrapAction];
67 this.subs.add(this.rbdMirroringService.startPolling());
69 this.rbdMirroringService.subscribeSummary((data) => {
70 this.status = data.content_data.status;
71 this.siteName = data.site_name;
73 this.peersExist = !!data.content_data.pools.find((o: Pool) => o['peer_uuids'].length > 0);
79 this.subs.unsubscribe();
83 const initialState = {
84 siteName: this.siteName
86 this.modalRef = this.modalService.show(EditSiteNameModalComponent, initialState);
89 createBootstrapModal() {
90 const initialState = {
91 siteName: this.siteName
93 this.modalRef = this.modalService.show(BootstrapCreateModalComponent, initialState);
96 importBootstrapModal() {
97 const initialState = {
98 siteName: this.siteName
100 this.modalRef = this.modalService.show(BootstrapImportModalComponent, initialState);