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.getProtectDisableDesc(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.getCloneDisableDesc(selection) || this.disableForMirrorSnapshot(selection),
65 name: actionLabels.CLONE
69 canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
70 disable: (selection: CdTableSelection) =>
71 !selection.hasSingleSelection ||
72 selection.first().cdExecuting ||
73 this.disableForMirrorSnapshot(selection),
75 name: actionLabels.COPY
80 name: actionLabels.ROLLBACK,
81 disable: (selection: CdTableSelection) =>
82 this.disableForMirrorSnapshot(selection) || !selection.hasSingleSelection
87 disable: (selection: CdTableSelection) => {
88 const first = selection.first();
90 !selection.hasSingleSelection ||
93 this.disableForMirrorSnapshot(selection)
96 name: actionLabels.DELETE
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`;
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.`;
131 disableForMirrorSnapshot(selection: CdTableSelection) {
133 selection.hasSingleSelection &&
134 selection.first().mirror_mode === 'snapshot' &&
135 selection.first().name.includes('.mirror.')