open-nomad/ui/app/controllers/jobs/job/allocations.js

135 lines
3.8 KiB
JavaScript
Raw Normal View History

2021-11-20 15:21:28 +00:00
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
import { alias } from '@ember/object/computed';
import Controller from '@ember/controller';
import { action, computed } from '@ember/object';
2021-11-20 15:21:28 +00:00
import { scheduleOnce } from '@ember/runloop';
import intersection from 'lodash.intersection';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
import WithNamespaceResetting from 'nomad-ui/mixins/with-namespace-resetting';
2021-11-20 15:04:15 +00:00
import { serialize, deserializedQueryParam as selection } from 'nomad-ui/utils/qp-serialize';
import classic from 'ember-classic-decorator';
@classic
export default class AllocationsController extends Controller.extend(
Sortable,
Searchable,
WithNamespaceResetting
) {
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',
},
];
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 = '';
currentPage = 1;
pageSize = 25;
sortProperty = 'modifyIndex';
sortDescending = true;
@alias('model') job;
@computed
get searchProps() {
return ['shortId', 'name', 'taskGroupName'];
}
@computed('model.allocations.[]')
get allocations() {
return this.get('model.allocations') || [];
}
2021-11-20 15:04:15 +00:00
@computed('allocations.[]', 'selectionStatus', 'selectionClient', 'selectionTaskGroup')
get filteredAllocations() {
const { selectionStatus, selectionClient, selectionTaskGroup } = this;
2021-11-20 15:04:15 +00:00
return this.allocations.filter(alloc => {
if (selectionStatus.length && !selectionStatus.includes(alloc.clientStatus)) {
2021-11-20 15:04:15 +00:00
return false;
}
2021-11-20 15:21:28 +00:00
if (selectionClient.length && !selectionClient.includes(alloc.get('node.shortId'))) {
return false;
}
2021-11-20 15:30:48 +00:00
if (selectionTaskGroup.length && !selectionTaskGroup.includes(alloc.taskGroupName)) {
return false;
}
2021-11-20 15:04:15 +00:00
return true;
});
}
@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;
@action
gotoAllocation(allocation) {
this.transitionToRoute('allocations.allocation', allocation);
}
2021-11-20 15:04:15 +00:00
get optionsAllocationStatus() {
return [
{ 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' },
];
}
2021-11-20 15:21:28 +00:00
@computed('model.allocations.[]', 'selectionClient')
get optionsClients() {
const clients = Array.from(new Set(this.model.allocations.mapBy('node.shortId'))).compact();
// Update query param when the list of clients changes.
scheduleOnce('actions', () => {
// eslint-disable-next-line ember/no-side-effects
this.set('qpClient', serialize(intersection(clients, this.selectionClient)));
});
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() {
const taskGroups = Array.from(new Set(this.model.allocations.mapBy('taskGroupName'))).compact();
// 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
this.set('qpTaskGroup', serialize(intersection(taskGroups, this.selectionTaskGroup)));
});
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));
}
}