-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathindex.js
150 lines (128 loc) · 3.69 KB
/
index.js
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* eslint-disable ember/no-observers */
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
import { observes } from '@ember-decorators/object';
import { task } from 'ember-concurrency';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import messageFromAdapterError from 'nomad-ui/utils/message-from-adapter-error';
import classic from 'ember-classic-decorator';
@classic
export default class ClientController extends Controller.extend(Sortable, Searchable) {
queryParams = [
{
currentPage: 'page',
},
{
searchTerm: 'search',
},
{
sortProperty: 'sort',
},
{
sortDescending: 'desc',
},
{
onlyPreemptions: 'preemptions',
},
];
// Set in the route
flagAsDraining = false;
currentPage = 1;
pageSize = 8;
sortProperty = 'modifyIndex';
sortDescending = true;
@computed()
get searchProps() {
return ['shortId', 'name'];
}
onlyPreemptions = false;
@computed('model.allocations.[]', 'preemptions.[]', 'onlyPreemptions')
get visibleAllocations() {
return this.onlyPreemptions ? this.preemptions : this.model.allocations;
}
@alias('visibleAllocations') listToSort;
@alias('listSorted') listToSearch;
@alias('listSearched') sortedAllocations;
eligibilityError = null;
stopDrainError = null;
drainError = null;
showDrainNotification = false;
showDrainUpdateNotification = false;
showDrainStoppedNotification = false;
@computed('[email protected]')
get preemptions() {
return this.model.allocations.filterBy('wasPreempted');
}
@computed('[email protected]')
get sortedEvents() {
return this.get('model.events')
.sortBy('time')
.reverse();
}
@computed('[email protected]')
get sortedDrivers() {
return this.get('model.drivers').sortBy('name');
}
@computed('[email protected]')
get sortedHostVolumes() {
return this.model.hostVolumes.sortBy('name');
}
@(task(function*(value) {
try {
yield value ? this.model.setEligible() : this.model.setIneligible();
} catch (err) {
const error = messageFromAdapterError(err) || 'Could not set eligibility';
this.set('eligibilityError', error);
}
}).drop())
setEligibility;
@(task(function*() {
try {
this.set('flagAsDraining', false);
yield this.model.cancelDrain();
this.set('showDrainStoppedNotification', true);
} catch (err) {
this.set('flagAsDraining', true);
const error = messageFromAdapterError(err) || 'Could not stop drain';
this.set('stopDrainError', error);
}
}).drop())
stopDrain;
@(task(function*() {
try {
yield this.model.forceDrain({
IgnoreSystemJobs: this.model.drainStrategy.ignoreSystemJobs,
});
} catch (err) {
const error = messageFromAdapterError(err) || 'Could not force drain';
this.set('drainError', error);
}
}).drop())
forceDrain;
@observes('model.isDraining')
triggerDrainNotification() {
if (!this.model.isDraining && this.flagAsDraining) {
this.set('showDrainNotification', true);
}
this.set('flagAsDraining', this.model.isDraining);
}
@action
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
}
@action
setPreemptionFilter(value) {
this.set('onlyPreemptions', value);
}
@action
drainNotify(isUpdating) {
this.set('showDrainUpdateNotification', isUpdating);
}
@action
setDrainError(err) {
const error = messageFromAdapterError(err) || 'Could not run drain';
this.set('drainError', error);
}
}