]> git.apps.os.sepia.ceph.com Git - ceph.git/blob
c966c52974bb904c19294ac82e7b9015812b22bc
[ceph.git] /
1 import * as _ from 'lodash';
2
3 import { ActionLabelsI18n } from '../../../shared/constants/app.constants';
4 import { Icons } from '../../../shared/enum/icons.enum';
5 import { CdTableAction } from '../../../shared/models/cd-table-action';
6 import { CdTableSelection } from '../../../shared/models/cd-table-selection';
7
8 export class RbdSnapshotActionsModel {
9   create: CdTableAction;
10   rename: CdTableAction;
11   protect: CdTableAction;
12   unprotect: CdTableAction;
13   clone: CdTableAction;
14   copy: CdTableAction;
15   rollback: CdTableAction;
16   deleteSnap: CdTableAction;
17   ordering: CdTableAction[];
18
19   constructor(actionLabels: ActionLabelsI18n, featuresName: string[]) {
20     this.create = {
21       permission: 'create',
22       icon: Icons.add,
23       name: actionLabels.CREATE
24     };
25     this.rename = {
26       permission: 'update',
27       icon: Icons.edit,
28       name: actionLabels.RENAME
29     };
30     this.protect = {
31       permission: 'update',
32       icon: Icons.lock,
33       visible: (selection: CdTableSelection) =>
34         selection.hasSingleSelection && !selection.first().is_protected,
35       name: actionLabels.PROTECT
36     };
37     this.unprotect = {
38       permission: 'update',
39       icon: Icons.unlock,
40       visible: (selection: CdTableSelection) =>
41         selection.hasSingleSelection && selection.first().is_protected,
42       name: actionLabels.UNPROTECT
43     };
44     this.clone = {
45       permission: 'create',
46       canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
47       disable: (selection: CdTableSelection) => this.getCloneDisableDesc(selection, featuresName),
48       icon: Icons.clone,
49       name: actionLabels.CLONE
50     };
51     this.copy = {
52       permission: 'create',
53       canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
54       disable: (selection: CdTableSelection) =>
55         !selection.hasSingleSelection || selection.first().cdExecuting,
56       icon: Icons.copy,
57       name: actionLabels.COPY
58     };
59     this.rollback = {
60       permission: 'update',
61       icon: Icons.undo,
62       name: actionLabels.ROLLBACK
63     };
64     this.deleteSnap = {
65       permission: 'delete',
66       icon: Icons.destroy,
67       disable: (selection: CdTableSelection) => {
68         const first = selection.first();
69         return !selection.hasSingleSelection || first.cdExecuting || first.is_protected;
70       },
71       name: actionLabels.DELETE
72     };
73
74     this.ordering = [
75       this.create,
76       this.rename,
77       this.protect,
78       this.unprotect,
79       this.clone,
80       this.copy,
81       this.rollback,
82       this.deleteSnap
83     ];
84   }
85
86   getCloneDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
87     if (selection.hasSingleSelection && !selection.first().cdExecuting) {
88       if (!featuresName?.includes('layering')) {
89         return $localize`Parent image must support Layering`;
90       }
91
92       return false;
93     }
94
95     return true;
96   }
97 }