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';
7 export class RbdSnapshotActionsModel {
10 protect: CdTableAction;
11 unprotect: CdTableAction;
14 rollback: CdTableAction;
15 deleteSnap: CdTableAction;
16 ordering: CdTableAction[];
18 cloneFormatVersion = 1;
21 actionLabels: ActionLabelsI18n,
22 public featuresName: string[],
23 rbdService: RbdService
25 rbdService.cloneFormatVersion().subscribe((version: number) => {
26 this.cloneFormatVersion = version;
32 name: actionLabels.CREATE
37 name: actionLabels.RENAME,
38 disable: (selection: CdTableSelection) =>
39 this.disableForMirrorSnapshot(selection) || !selection.hasSingleSelection
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.getDisableDesc(selection, this.featuresName)
54 visible: (selection: CdTableSelection) =>
55 selection.hasSingleSelection && selection.first().is_protected,
56 name: actionLabels.UNPROTECT,
57 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
61 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
62 disable: (selection: CdTableSelection) =>
63 this.getDisableDesc(selection, this.featuresName) ||
64 this.disableForMirrorSnapshot(selection),
66 name: actionLabels.CLONE
70 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
71 disable: (selection: CdTableSelection) =>
72 !selection.hasSingleSelection ||
73 selection.first().cdExecuting ||
74 this.disableForMirrorSnapshot(selection),
76 name: actionLabels.COPY
81 name: actionLabels.ROLLBACK,
82 disable: (selection: CdTableSelection) =>
83 this.disableForMirrorSnapshot(selection) || !selection.hasSingleSelection
88 disable: (selection: CdTableSelection) => {
89 const first = selection.first();
91 !selection.hasSingleSelection ||
94 this.disableForMirrorSnapshot(selection)
97 name: actionLabels.DELETE
112 getDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
113 if (selection.hasSingleSelection && !selection.first().cdExecuting) {
114 if (!featuresName?.includes('layering')) {
115 return $localize`The layering feature needs to be enabled on parent image`;
118 if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
119 return $localize`Snapshot must be protected in order to clone.`;
128 disableForMirrorSnapshot(selection: CdTableSelection) {
130 selection.hasSingleSelection &&
131 selection.first().mirror_mode === 'snapshot' &&
132 selection.first().name.includes('.mirror.')