2021-11-20 15:21:28 +00:00
|
|
|
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
|
2018-07-19 23:57:44 +00:00
|
|
|
import { alias } from '@ember/object/computed';
|
|
|
|
import Controller from '@ember/controller';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { action, computed } from '@ember/object';
|
2021-11-20 15:21:28 +00:00
|
|
|
import { scheduleOnce } from '@ember/runloop';
|
|
|
|
import intersection from 'lodash.intersection';
|
2018-07-19 23:57:44 +00:00
|
|
|
import Sortable from 'nomad-ui/mixins/sortable';
|
|
|
|
import Searchable from 'nomad-ui/mixins/searchable';
|
|
|
|
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
|
2021-12-28 16:08:12 +00:00
|
|
|
import {
|
|
|
|
serialize,
|
|
|
|
deserializedQueryParam as selection,
|
|
|
|
} from 'nomad-ui/utils/qp-serialize';
|
2020-06-10 13:49:16 +00:00
|
|
|
import classic from 'ember-classic-decorator';
|
|
|
|
|
|
|
|
@classic
|
|
|
|
export default class AllocationsController extends Controller.extend(
|
2021-12-28 14:45:20 +00:00
|
|
|
Sortable,
|
|
|
|
Searchable,
|
|
|
|
WithNamespaceResetting
|
|
|
|
) {
|
2020-06-11 13:38:33 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
currentPage: 'page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
searchTerm: 'search',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortProperty: 'sort',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortDescending: 'desc',
|
|
|
|
},
|
2021-11-20 15:04:15 +00:00
|
|
|
{
|
|
|
|
qpStatus: 'status',
|
|
|
|
},
|
2021-11-20 15:21:28 +00:00
|
|
|
{
|
|
|
|
qpClient: 'client',
|
|
|
|
},
|
2021-11-20 15:30:48 +00:00
|
|
|
{
|
|
|
|
qpTaskGroup: 'taskGroup',
|
|
|
|
},
|
2022-09-22 14:58:52 +00:00
|
|
|
'activeTask',
|
2020-06-11 13:38:33 +00:00
|
|
|
];
|
2018-07-19 23:57:44 +00:00
|
|
|
|
2021-11-20 15:04:15 +00:00
|
|
|
qpStatus = '';
|
2021-11-20 15:21:28 +00:00
|
|
|
qpClient = '';
|
2021-11-20 15:30:48 +00:00
|
|
|
qpTaskGroup = '';
|
2020-06-10 13:49:16 +00:00
|
|
|
currentPage = 1;
|
|
|
|
pageSize = 25;
|
2022-09-22 14:58:52 +00:00
|
|
|
activeTask = null;
|
2018-07-19 23:57:44 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
sortProperty = 'modifyIndex';
|
|
|
|
sortDescending = true;
|
2018-07-19 23:57:44 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@alias('model') job;
|
2018-07-19 23:57:44 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get searchProps() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return ['shortId', 'name', 'taskGroupName'];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2018-07-19 23:57:44 +00:00
|
|
|
|
2021-12-18 00:49:05 +00:00
|
|
|
@computed('model.allocations.[]')
|
2020-06-10 13:49:16 +00:00
|
|
|
get allocations() {
|
2021-12-18 00:49:05 +00:00
|
|
|
return this.get('model.allocations') || [];
|
|
|
|
}
|
2021-11-20 15:04:15 +00:00
|
|
|
|
2021-12-28 16:08:12 +00:00
|
|
|
@computed(
|
|
|
|
'allocations.[]',
|
|
|
|
'selectionStatus',
|
|
|
|
'selectionClient',
|
|
|
|
'selectionTaskGroup'
|
|
|
|
)
|
2021-12-18 00:49:05 +00:00
|
|
|
get filteredAllocations() {
|
|
|
|
const { selectionStatus, selectionClient, selectionTaskGroup } = this;
|
2021-11-20 15:04:15 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return this.allocations.filter((alloc) => {
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionStatus.length &&
|
|
|
|
!selectionStatus.includes(alloc.clientStatus)
|
|
|
|
) {
|
2021-11-20 15:04:15 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionClient.length &&
|
|
|
|
!selectionClient.includes(alloc.get('node.shortId'))
|
|
|
|
) {
|
2021-11-20 15:21:28 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-12-28 16:08:12 +00:00
|
|
|
if (
|
|
|
|
selectionTaskGroup.length &&
|
|
|
|
!selectionTaskGroup.includes(alloc.taskGroupName)
|
|
|
|
) {
|
2021-11-20 15:30:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-11-20 15:04:15 +00:00
|
|
|
return true;
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
2021-12-18 00:49:05 +00:00
|
|
|
@alias('filteredAllocations') listToSort;
|
|
|
|
@alias('listSorted') listToSearch;
|
|
|
|
@alias('listSearched') sortedAllocations;
|
|
|
|
|
2021-11-20 15:04:15 +00:00
|
|
|
@selection('qpStatus') selectionStatus;
|
2021-11-20 15:21:28 +00:00
|
|
|
@selection('qpClient') selectionClient;
|
2021-11-20 15:30:48 +00:00
|
|
|
@selection('qpTaskGroup') selectionTaskGroup;
|
2020-06-10 13:49:16 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
gotoAllocation(allocation) {
|
|
|
|
this.transitionToRoute('allocations.allocation', allocation);
|
|
|
|
}
|
2021-11-20 15:04:15 +00:00
|
|
|
|
|
|
|
get optionsAllocationStatus() {
|
|
|
|
return [
|
2021-12-18 00:49:05 +00:00
|
|
|
{ key: 'pending', label: 'Pending' },
|
2021-11-20 15:04:15 +00:00
|
|
|
{ key: 'running', label: 'Running' },
|
|
|
|
{ key: 'complete', label: 'Complete' },
|
|
|
|
{ key: 'failed', label: 'Failed' },
|
|
|
|
{ key: 'lost', label: 'Lost' },
|
2022-04-22 15:25:02 +00:00
|
|
|
{ key: 'unknown', label: 'Unknown' },
|
2021-11-20 15:04:15 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2021-11-20 15:21:28 +00:00
|
|
|
@computed('model.allocations.[]', 'selectionClient')
|
|
|
|
get optionsClients() {
|
2021-12-28 16:08:12 +00:00
|
|
|
const clients = Array.from(
|
|
|
|
new Set(this.model.allocations.mapBy('node.shortId'))
|
|
|
|
).compact();
|
2021-11-20 15:21:28 +00:00
|
|
|
|
|
|
|
// Update query param when the list of clients changes.
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
2021-12-28 16:08:12 +00:00
|
|
|
this.set(
|
|
|
|
'qpClient',
|
|
|
|
serialize(intersection(clients, this.selectionClient))
|
|
|
|
);
|
2021-11-20 15:21:28 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return clients.sort().map((c) => ({ key: c, label: c }));
|
2021-11-20 15:21:28 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 15:30:48 +00:00
|
|
|
@computed('model.allocations.[]', 'selectionTaskGroup')
|
|
|
|
get optionsTaskGroups() {
|
2021-12-28 16:08:12 +00:00
|
|
|
const taskGroups = Array.from(
|
|
|
|
new Set(this.model.allocations.mapBy('taskGroupName'))
|
|
|
|
).compact();
|
2021-11-20 15:30:48 +00:00
|
|
|
|
2021-12-18 00:49:05 +00:00
|
|
|
// Update query param when the list of task groups changes.
|
2021-11-20 15:30:48 +00:00
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
2021-12-28 16:08:12 +00:00
|
|
|
this.set(
|
|
|
|
'qpTaskGroup',
|
|
|
|
serialize(intersection(taskGroups, this.selectionTaskGroup))
|
|
|
|
);
|
2021-11-20 15:30:48 +00:00
|
|
|
});
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
return taskGroups.sort().map((tg) => ({ key: tg, label: tg }));
|
2021-11-20 15:30:48 +00:00
|
|
|
}
|
|
|
|
|
2021-11-20 15:04:15 +00:00
|
|
|
setFacetQueryParam(queryParam, selection) {
|
|
|
|
this.set(queryParam, serialize(selection));
|
|
|
|
}
|
2022-09-22 14:58:52 +00:00
|
|
|
|
|
|
|
@action
|
|
|
|
setActiveTaskQueryParam(task) {
|
|
|
|
if (task) {
|
|
|
|
this.set('activeTask', `${task.allocation.id}-${task.name}`);
|
|
|
|
} else {
|
|
|
|
this.set('activeTask', null);
|
|
|
|
}
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|