1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
import { RbdService } from '~/app/shared/api/rbd.service';
import { ActionLabelsI18n } from '~/app/shared/constants/app.constants';
import { Icons } from '~/app/shared/enum/icons.enum';
import { CdTableAction } from '~/app/shared/models/cd-table-action';
import { CdTableSelection } from '~/app/shared/models/cd-table-selection';
export class RbdSnapshotActionsModel {
create: CdTableAction;
rename: CdTableAction;
protect: CdTableAction;
unprotect: CdTableAction;
clone: CdTableAction;
copy: CdTableAction;
rollback: CdTableAction;
deleteSnap: CdTableAction;
ordering: CdTableAction[];
cloneFormatVersion = 1;
constructor(
actionLabels: ActionLabelsI18n,
public featuresName: string[],
rbdService: RbdService
) {
rbdService.cloneFormatVersion().subscribe((version: number) => {
this.cloneFormatVersion = version;
});
this.create = {
permission: 'create',
icon: Icons.add,
name: actionLabels.CREATE
};
this.rename = {
permission: 'update',
icon: Icons.edit,
name: actionLabels.RENAME,
disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
};
this.protect = {
permission: 'update',
icon: Icons.lock,
visible: (selection: CdTableSelection) =>
selection.hasSingleSelection && !selection.first().is_protected,
name: actionLabels.PROTECT,
disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
};
this.unprotect = {
permission: 'update',
icon: Icons.unlock,
visible: (selection: CdTableSelection) =>
selection.hasSingleSelection && selection.first().is_protected,
name: actionLabels.UNPROTECT,
disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
};
this.clone = {
permission: 'create',
canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
disable: (selection: CdTableSelection) =>
this.getCloneDisableDesc(selection, this.featuresName) ||
this.disableForMirrorSnapshot(selection),
icon: Icons.clone,
name: actionLabels.CLONE
};
this.copy = {
permission: 'create',
canBePrimary: (selection: CdTableSelection) => selection.hasSingleSelection,
disable: (selection: CdTableSelection) =>
!selection.hasSingleSelection ||
selection.first().cdExecuting ||
this.disableForMirrorSnapshot(selection),
icon: Icons.copy,
name: actionLabels.COPY
};
this.rollback = {
permission: 'update',
icon: Icons.undo,
name: actionLabels.ROLLBACK,
disable: (selection: CdTableSelection) => this.disableForMirrorSnapshot(selection)
};
this.deleteSnap = {
permission: 'delete',
icon: Icons.destroy,
disable: (selection: CdTableSelection) => {
const first = selection.first();
return (
!selection.hasSingleSelection ||
first.cdExecuting ||
first.is_protected ||
this.disableForMirrorSnapshot(selection)
);
},
name: actionLabels.DELETE
};
this.ordering = [
this.create,
this.rename,
this.protect,
this.unprotect,
this.clone,
this.copy,
this.rollback,
this.deleteSnap
];
}
getCloneDisableDesc(selection: CdTableSelection, featuresName: string[]): boolean | string {
if (selection.hasSingleSelection && !selection.first().cdExecuting) {
if (!featuresName?.includes('layering')) {
return $localize`Parent image must support Layering`;
}
if (this.cloneFormatVersion === 1 && !selection.first().is_protected) {
return $localize`Snapshot must be protected in order to clone.`;
}
return false;
}
return true;
}
disableForMirrorSnapshot(selection: CdTableSelection) {
return (
selection.hasSingleSelection &&
selection.first().mirror_mode === 'snapshot' &&
selection.first().name.includes('.mirror.')
);
}
}
|