]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/blob
040f5824de34e34bd803cb6c382f0cbc481684b2
[ceph-ci.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) =>
48         !selection.hasSingleSelection ||
49         selection.first().cdExecuting ||
50         !_.isUndefined(this.getCloneDisableDesc(featuresName)),
51       disableDesc: () => this.getCloneDisableDesc(featuresName),
52       icon: Icons.clone,
53       name: actionLabels.CLONE
54     };
55     this.copy = {
56       permission: 'create',
57       canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
58       disable: (selection: CdTableSelection) =>
59         !selection.hasSingleSelection || selection.first().cdExecuting,
60       icon: Icons.copy,
61       name: actionLabels.COPY
62     };
63     this.rollback = {
64       permission: 'update',
65       icon: Icons.undo,
66       name: actionLabels.ROLLBACK
67     };
68     this.deleteSnap = {
69       permission: 'delete',
70       icon: Icons.destroy,
71       disable: (selection: CdTableSelection) => {
72         const first = selection.first();
73         return !selection.hasSingleSelection || first.cdExecuting || first.is_protected;
74       },
75       name: actionLabels.DELETE
76     };
77
78     this.ordering = [
79       this.create,
80       this.rename,
81       this.protect,
82       this.unprotect,
83       this.clone,
84       this.copy,
85       this.rollback,
86       this.deleteSnap
87     ];
88   }
89
90   getCloneDisableDesc(featuresName: string[]): string | undefined {
91     if (!featuresName?.includes('layering')) {
92       return $localize`Parent image must support Layering`;
93     }
94
95     return undefined;
96   }
97 }