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