]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/cephfs/cephfs-list/cephfs-list.component.ts
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / cephfs / cephfs-list / cephfs-list.component.ts
index 8d19d394c3455de717aeee7ac9b09daa1468ca71..0d55845ab594912a7a1b2690fc3d195f9ea0150c 100644 (file)
@@ -1,25 +1,57 @@
 import { Component, OnInit } from '@angular/core';
+import { Permissions } from '~/app/shared/models/permissions';
+import { Router } from '@angular/router';
+
+import _ from 'lodash';
 
 import { CephfsService } from '~/app/shared/api/cephfs.service';
+import { ConfigurationService } from '~/app/shared/api/configuration.service';
 import { ListWithDetails } from '~/app/shared/classes/list-with-details.class';
 import { CellTemplate } from '~/app/shared/enum/cell-template.enum';
+import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
+import { Icons } from '~/app/shared/enum/icons.enum';
+import { CriticalConfirmationModalComponent } from '~/app/shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
+import { CdTableAction } from '~/app/shared/models/cd-table-action';
 import { CdTableColumn } from '~/app/shared/models/cd-table-column';
 import { CdTableFetchDataContext } from '~/app/shared/models/cd-table-fetch-data-context';
 import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
-import { CdDatePipe } from '~/app/shared/pipes/cd-date.pipe';
+import { AuthStorageService } from '~/app/shared/services/auth-storage.service';
+import { URLBuilderService } from '~/app/shared/services/url-builder.service';
+import { ModalService } from '~/app/shared/services/modal.service';
+import { TaskWrapperService } from '~/app/shared/services/task-wrapper.service';
+import { FinishedTask } from '~/app/shared/models/finished-task';
+import { NotificationService } from '~/app/shared/services/notification.service';
+
+const BASE_URL = 'cephfs';
 
 @Component({
   selector: 'cd-cephfs-list',
   templateUrl: './cephfs-list.component.html',
-  styleUrls: ['./cephfs-list.component.scss']
+  styleUrls: ['./cephfs-list.component.scss'],
+  providers: [{ provide: URLBuilderService, useValue: new URLBuilderService(BASE_URL) }]
 })
 export class CephfsListComponent extends ListWithDetails implements OnInit {
   columns: CdTableColumn[];
   filesystems: any = [];
   selection = new CdTableSelection();
+  tableActions: CdTableAction[];
+  permissions: Permissions;
+  icons = Icons;
+  monAllowPoolDelete = false;
 
-  constructor(private cephfsService: CephfsService, private cdDatePipe: CdDatePipe) {
+  constructor(
+    private authStorageService: AuthStorageService,
+    private cephfsService: CephfsService,
+    public actionLabels: ActionLabelsI18n,
+    private router: Router,
+    private urlBuilder: URLBuilderService,
+    private configurationService: ConfigurationService,
+    private modalService: ModalService,
+    private taskWrapper: TaskWrapperService,
+    public notificationService: NotificationService
+  ) {
     super();
+    this.permissions = this.authStorageService.getPermissions();
   }
 
   ngOnInit() {
@@ -30,18 +62,52 @@ export class CephfsListComponent extends ListWithDetails implements OnInit {
         flexGrow: 2
       },
       {
-        name: $localize`Created`,
-        prop: 'mdsmap.created',
+        name: $localize`Enabled`,
+        prop: 'mdsmap.enabled',
         flexGrow: 2,
-        pipe: this.cdDatePipe
+        cellTransformation: CellTemplate.checkIcon
       },
       {
-        name: $localize`Enabled`,
-        prop: 'mdsmap.enabled',
+        name: $localize`Created`,
+        prop: 'mdsmap.created',
         flexGrow: 1,
-        cellTransformation: CellTemplate.checkIcon
+        cellTransformation: CellTemplate.timeAgo
       }
     ];
+    this.tableActions = [
+      {
+        name: this.actionLabels.CREATE,
+        permission: 'create',
+        icon: Icons.add,
+        click: () => this.router.navigate([this.urlBuilder.getCreate()]),
+        canBePrimary: (selection: CdTableSelection) => !selection.hasSelection
+      },
+      {
+        name: this.actionLabels.EDIT,
+        permission: 'update',
+        icon: Icons.edit,
+        click: () =>
+          this.router.navigate([this.urlBuilder.getEdit(this.selection.first().mdsmap.fs_name)])
+      },
+      {
+        permission: 'delete',
+        icon: Icons.destroy,
+        click: () => this.removeVolumeModal(),
+        name: this.actionLabels.REMOVE,
+        disable: this.getDisableDesc.bind(this)
+      }
+    ];
+
+    if (this.permissions.configOpt.read) {
+      this.configurationService.get('mon_allow_pool_delete').subscribe((data: any) => {
+        if (_.has(data, 'value')) {
+          const monSection = _.find(data.value, (v) => {
+            return v.section === 'mon';
+          }) || { value: false };
+          this.monAllowPoolDelete = monSection.value === 'true' ? true : false;
+        }
+      });
+    }
   }
 
   loadFilesystems(context: CdTableFetchDataContext) {
@@ -58,4 +124,30 @@ export class CephfsListComponent extends ListWithDetails implements OnInit {
   updateSelection(selection: CdTableSelection) {
     this.selection = selection;
   }
+
+  removeVolumeModal() {
+    const volName = this.selection.first().mdsmap['fs_name'];
+    this.modalService.show(CriticalConfirmationModalComponent, {
+      itemDescription: 'File System',
+      itemNames: [volName],
+      actionDescription: 'remove',
+      submitActionObservable: () =>
+        this.taskWrapper.wrapTaskAroundCall({
+          task: new FinishedTask('cephfs/remove', { volumeName: volName }),
+          call: this.cephfsService.remove(volName)
+        })
+    });
+  }
+
+  getDisableDesc(): boolean | string {
+    if (this.selection?.hasSelection) {
+      if (!this.monAllowPoolDelete) {
+        return $localize`File System deletion is disabled by the mon_allow_pool_delete configuration setting.`;
+      }
+
+      return false;
+    }
+
+    return true;
+  }
 }