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
42 visible: (selection: CdTableSelection) =>
43 selection.hasSingleSelection && !selection.first().is_protected,
44 name: actionLabels.PROTECT
49 visible: (selection: CdTableSelection) =>
50 selection.hasSingleSelection && selection.first().is_protected,
51 name: actionLabels.UNPROTECT
55 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
56 disable: (selection: CdTableSelection) =>
57 this.getCloneDisableDesc(selection, this.featuresName),
59 name: actionLabels.CLONE
63 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
64 disable: (selection: CdTableSelection) =>
65 !selection.hasSingleSelection || selection.first().cdExecuting,
67 name: actionLabels.COPY
72 name: actionLabels.ROLLBACK
77 disable: (selection: CdTableSelection) => {
78 const first = selection.first();
79 return !selection.hasSingleSelection || first.cdExecuting || first.is_protected;
81 name: actionLabels.DELETE
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`;
102 if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
103 return $localize`Snapshot must be protected in order to clone.`;