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) => this.disableForMirrorSnapshot(selection)
43 visible: (selection: CdTableSelection) =>
44 selection.hasSingleSelection && !selection.first().is_protected,
45 name: actionLabels.PROTECT,
46 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
51 visible: (selection: CdTableSelection) =>
52 selection.hasSingleSelection && selection.first().is_protected,
53 name: actionLabels.UNPROTECT,
54 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
58 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
59 disable: (selection: CdTableSelection) =>
60 this.getCloneDisableDesc(selection, this.featuresName) ||
61 this.disableForMirrorSnapshot(selection),
63 name: actionLabels.CLONE
67 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
68 disable: (selection: CdTableSelection) =>
69 !selection.hasSingleSelection ||
70 selection.first().cdExecuting ||
71 this.disableForMirrorSnapshot(selection),
73 name: actionLabels.COPY
78 name: actionLabels.ROLLBACK,
79 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
84 disable: (selection: CdTableSelection) => {
85 const first = selection.first();
87 !selection.hasSingleSelection ||
90 this.disableForMirrorSnapshot(selection)
93 name: actionLabels.DELETE
108 getCloneDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
109 if (selection.hasSingleSelection && !selection.first().cdExecuting) {
110 if (!featuresName?.includes('layering')) {
111 return $localize`Parent image must support Layering`;
114 if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
115 return $localize`Snapshot must be protected in order to clone.`;
124 disableForMirrorSnapshot(selection: CdTableSelection) {
126 selection.hasSingleSelection &&
127 selection.first().mirror_mode === 'snapshot' &&
128 selection.first().name.includes('.mirror.')