]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.ts
0d55845ab594912a7a1b2690fc3d195f9ea0150c
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cephfs / cephfs-list / cephfs-list.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { Permissions } from '~/app/shared/models/permissions';
3 import { Router } from '@angular/router';
4
5 import _ from 'lodash';
6
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';
24
25 const BASE_URL = 'cephfs';
26
27 @Component({
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) }]
32 })
33 export class CephfsListComponent extends ListWithDetails implements OnInit {
34 columns: CdTableColumn[];
35 filesystems: any = [];
36 selection = new CdTableSelection();
37 tableActions: CdTableAction[];
38 permissions: Permissions;
39 icons = Icons;
40 monAllowPoolDelete = false;
41
42 constructor(
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
52 ) {
53 super();
54 this.permissions = this.authStorageService.getPermissions();
55 }
56
57 ngOnInit() {
58 this.columns = [
59 {
60 name: $localize`Name`,
61 prop: 'mdsmap.fs_name',
62 flexGrow: 2
63 },
64 {
65 name: $localize`Enabled`,
66 prop: 'mdsmap.enabled',
67 flexGrow: 2,
68 cellTransformation: CellTemplate.checkIcon
69 },
70 {
71 name: $localize`Created`,
72 prop: 'mdsmap.created',
73 flexGrow: 1,
74 cellTransformation: CellTemplate.timeAgo
75 }
76 ];
77 this.tableActions = [
78 {
79 name: this.actionLabels.CREATE,
80 permission: 'create',
81 icon: Icons.add,
82 click: () => this.router.navigate([this.urlBuilder.getCreate()]),
83 canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
84 },
85 {
86 name: this.actionLabels.EDIT,
87 permission: 'update',
88 icon: Icons.edit,
89 click: () =>
90 this.router.navigate([this.urlBuilder.getEdit(this.selection.first().mdsmap.fs_name)])
91 },
92 {
93 permission: 'delete',
94 icon: Icons.destroy,
95 click: () => this.removeVolumeModal(),
96 name: this.actionLabels.REMOVE,
97 disable: this.getDisableDesc.bind(this)
98 }
99 ];
100
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;
108 }
109 });
110 }
111 }
112
113 loadFilesystems(context: CdTableFetchDataContext) {
114 this.cephfsService.list().subscribe(
115 (resp: any[]) => {
116 this.filesystems = resp;
117 },
118 () => {
119 context.error();
120 }
121 );
122 }
123
124 updateSelection(selection: CdTableSelection) {
125 this.selection = selection;
126 }
127
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)
138 })
139 });
140 }
141
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.`;
146 }
147
148 return false;
149 }
150
151 return true;
152 }
153 }