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
|
import _ from 'lodash';
import { CdTableColumnFiltersChange } from '~/app/shared/models/cd-table-column-filters-change';
import { FormatterService } from '~/app/shared/services/formatter.service';
export class DriveGroup {
spec: Object;
// Map from filter column prop to device selection attribute name
private deviceSelectionAttrs: {
[key: string]: {
name: string;
formatter?: Function;
};
};
private formatterService: FormatterService;
constructor() {
this.reset();
this.formatterService = new FormatterService();
this.deviceSelectionAttrs = {
'sys_api.vendor': {
name: 'vendor'
},
'sys_api.model': {
name: 'model'
},
device_id: {
name: 'device_id'
},
human_readable_type: {
name: 'rotational',
formatter: (value: string) => {
return value.toLowerCase() === 'hdd';
}
},
'sys_api.size': {
name: 'size',
formatter: (value: string) => {
return this.formatterService
.format_number(value, 1024, ['B', 'KB', 'MB', 'GB', 'TB', 'PB'])
.replace(' ', '');
}
}
};
}
reset() {
this.spec = {
service_type: 'osd',
service_id: `dashboard-${_.now()}`
};
}
setName(name: string) {
this.spec['service_id'] = name;
}
setHostPattern(pattern: string) {
this.spec['host_pattern'] = pattern;
}
setDeviceSelection(type: string, appliedFilters: CdTableColumnFiltersChange['filters']) {
const key = `${type}_devices`;
this.spec[key] = {};
appliedFilters.forEach((filter) => {
const attr = this.deviceSelectionAttrs[filter.prop];
if (attr) {
const name = attr.name;
this.spec[key][name] = attr.formatter ? attr.formatter(filter.value.raw) : filter.value.raw;
}
});
}
clearDeviceSelection(type: string) {
const key = `${type}_devices`;
delete this.spec[key];
}
setSlots(type: string, slots: number) {
const key = `${type}_slots`;
if (slots === 0) {
delete this.spec[key];
} else {
this.spec[key] = slots;
}
}
setFeature(feature: string, enabled: boolean) {
if (enabled) {
this.spec[feature] = true;
} else {
delete this.spec[feature];
}
}
}
|