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) => this.disableForMirrorSnapshot(selection)
52 visible: (selection: CdTableSelection) =>
53 selection.hasSingleSelection && selection.first().is_protected,
54 name: actionLabels.UNPROTECT,
55 disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
59 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
60 disable: (selection: CdTableSelection) =>
61 this.getCloneDisableDesc(selection, this.featuresName) ||
62 this.disableForMirrorSnapshot(selection),
64 name: actionLabels.CLONE
68 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
69 disable: (selection: CdTableSelection) =>
70 !selection.hasSingleSelection ||
71 selection.first().cdExecuting ||
72 this.disableForMirrorSnapshot(selection),
74 name: actionLabels.COPY
79 name: actionLabels.ROLLBACK,
80 disable: (selection: CdTableSelection) =>
81 this.disableForMirrorSnapshot(selection) || !selection.hasSingleSelection
86 disable: (selection: CdTableSelection) => {
87 const first = selection.first();
89 !selection.hasSingleSelection ||
92 this.disableForMirrorSnapshot(selection)
95 name: actionLabels.DELETE
110 getCloneDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
111 if (selection.hasSingleSelection && !selection.first().cdExecuting) {
112 if (!featuresName?.includes('layering')) {
113 return $localize`Parent image must support Layering`;
116 if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
117 return $localize`Snapshot must be protected in order to clone.`;
126 disableForMirrorSnapshot(selection: CdTableSelection) {
128 selection.hasSingleSelection &&
129 selection.first().mirror_mode === 'snapshot' &&
130 selection.first().name.includes('.mirror.')