]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/ceph/block/rbd-snapshot-list/rbd-snapshot-actions.model.ts
9b3b7d1d6cdd0d1ce849876c58076c57da9e03f3
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / ceph / block / rbd-snapshot-list / rbd-snapshot-actions.model.ts
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 disable: (selection: CdTableSelection) =>
39 this.disableForMirrorSnapshot(selection) || !selection.hasSingleSelection
40 };
41 this.protect = {
42 permission: 'update',
43 icon: Icons.lock,
44 visible: (selection: CdTableSelection) =>
45 selection.hasSingleSelection && !selection.first().is_protected,
46 name: actionLabels.PROTECT,
47 disable: (selection: CdTableSelection) =>
48 this.disableForMirrorSnapshot(selection) ||
49 this.getProtectDisableDesc(selection, this.featuresName)
50 };
51 this.unprotect = {
52 permission: 'update',
53 icon: Icons.unlock,
54 visible: (selection: CdTableSelection) =>
55 selection.hasSingleSelection && selection.first().is_protected,
56 name: actionLabels.UNPROTECT,
57 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
58 };
59 this.clone = {
60 permission: 'create',
61 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
62 disable: (selection: CdTableSelection) =>
63 this.getCloneDisableDesc(selection) || this.disableForMirrorSnapshot(selection),
64 icon: Icons.clone,
65 name: actionLabels.CLONE
66 };
67 this.copy = {
68 permission: 'create',
69 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
70 disable: (selection: CdTableSelection) =>
71 !selection.hasSingleSelection ||
72 selection.first().cdExecuting ||
73 this.disableForMirrorSnapshot(selection),
74 icon: Icons.copy,
75 name: actionLabels.COPY
76 };
77 this.rollback = {
78 permission: 'update',
79 icon: Icons.undo,
80 name: actionLabels.ROLLBACK,
81 disable: (selection: CdTableSelection) =>
82 this.disableForMirrorSnapshot(selection) || !selection.hasSingleSelection
83 };
84 this.deleteSnap = {
85 permission: 'delete',
86 icon: Icons.destroy,
87 disable: (selection: CdTableSelection) => {
88 const first = selection.first();
89 return (
90 !selection.hasSingleSelection ||
91 first.cdExecuting ||
92 first.is_protected ||
93 this.disableForMirrorSnapshot(selection)
94 );
95 },
96 name: actionLabels.DELETE
97 };
98
99 this.ordering = [
100 this.create,
101 this.rename,
102 this.protect,
103 this.unprotect,
104 this.clone,
105 this.copy,
106 this.rollback,
107 this.deleteSnap
108 ];
109 }
110
111 getProtectDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
112 if (selection.hasSingleSelection && !selection.first().cdExecuting) {
113 if (!featuresName?.includes('layering')) {
114 return $localize`The layering feature needs to be enabled on parent image`;
115 }
116 return false;
117 }
118 return true;
119 }
120
121 getCloneDisableDesc(selection: CdTableSelection): boolean | string {
122 if (selection.hasSingleSelection && !selection.first().cdExecuting) {
123 if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
124 return $localize`Snapshot must be protected in order to clone.`;
125 }
126 return false;
127 }
128 return true;
129 }
130
131 disableForMirrorSnapshot(selection: CdTableSelection) {
132 return (
133 selection.hasSingleSelection &&
134 selection.first().mirror_mode === 'snapshot' &&
135 selection.first().name.includes('.mirror.')
136 );
137 }
138 }