1 import { Component, OnInit } from '@angular/core';
2 import { Permissions } from '~/app/shared/models/permissions';
3 import { Router } from '@angular/router';
5 import _ from 'lodash';
7 import { CephfsService } from '~/app/shared/api/cephfs.service';
8 import { ConfigurationService } from '~/app/shared/api/configuration.service';
9 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
10 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
11 import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
12 import { Icons } from '~/app/shared/enum/icons.enum';
13 import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
14 import { CdTableAction } from '~/app/shared/models/cd-table-action';
15 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
16 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
17 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
18 import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
19 import { URLBuilderService } from '~/app/shared/services/url-builder.service';
20 import { ModalService } from '~/app/shared/services/modal.service';
21 import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
22 import { FinishedTask } from '~/app/shared/models/finished-task';
23 import { NotificationService } from '~/app/shared/services/notification.service';
25 const BASE_URL = 'cephfs';
28 selector: 'cd-cephfs-list',
29 templateUrl: './cephfs-list.component.html',
30 styleUrls: ['./cephfs-list.component.scss'],
31 providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
33 export class CephfsListComponent extends ListWithDetails implements OnInit {
34 columns: CdTableColumn[];
35 filesystems: any = [];
36 selection = new CdTableSelection();
37 tableActions: CdTableAction[];
38 permissions: Permissions;
40 monAllowPoolDelete = false;
43 private authStorageService: AuthStorageService,
44 private cephfsService: CephfsService,
45 public actionLabels: ActionLabelsI18n,
46 private router: Router,
47 private urlBuilder: URLBuilderService,
48 private configurationService: ConfigurationService,
49 private modalService: ModalService,
50 private taskWrapper: TaskWrapperService,
51 public notificationService: NotificationService
54 this.permissions = this.authStorageService.getPermissions();
60 name: $localize`Name`,
61 prop: 'mdsmap.fs_name',
65 name: $localize`Enabled`,
66 prop: 'mdsmap.enabled',
68 cellTransformation: CellTemplate.checkIcon
71 name: $localize`Created`,
72 prop: 'mdsmap.created',
74 cellTransformation: CellTemplate.timeAgo
79 name: this.actionLabels.CREATE,
82 click: () => this.router.navigate([this.urlBuilder.getCreate()]),
83 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
86 name: this.actionLabels.EDIT,
90 this.router.navigate([this.urlBuilder.getEdit(this.selection.first().mdsmap.fs_name)])
95 click: () => this.removeVolumeModal(),
96 name: this.actionLabels.REMOVE,
97 disable: this.getDisableDesc.bind(this)
101 if (this.permissions.configOpt.read) {
102 this.configurationService.get('mon_allow_pool_delete').subscribe((data: any) => {
103 if (_.has(data, 'value')) {
104 const monSection = _.find(data.value, (v) => {
105 return v.section === 'mon';
106 }) || { value: false };
107 this.monAllowPoolDelete = monSection.value === 'true' ? true : false;
113 loadFilesystems(context: CdTableFetchDataContext) {
114 this.cephfsService.list().subscribe(
116 this.filesystems = resp;
124 updateSelection(selection: CdTableSelection) {
125 this.selection = selection;
128 removeVolumeModal() {
129 const volName = this.selection.first().mdsmap['fs_name'];
130 this.modalService.show(CriticalConfirmationModalComponent, {
131 itemDescription: 'File System',
132 itemNames: [volName],
133 actionDescription: 'remove',
134 submitActionObservable: () =>
135 this.taskWrapper.wrapTaskAroundCall({
136 task: new FinishedTask('cephfs/remove', { volumeName: volName }),
137 call: this.cephfsService.remove(volName)
142 getDisableDesc(): boolean | string {
143 if (this.selection?.hasSelection) {
144 if (!this.monAllowPoolDelete) {
145 return $localize`File System deletion is disabled by the mon_allow_pool_delete configuration setting.`;