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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

174 lines
4.2 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-12-28 16:08:12 +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(
2021-12-28 14:45:20 +00:00
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',
},
'activeTask',
];
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;
activeTask = null;
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
2021-12-28 16:08:12 +00:00
@computed(
'allocations.[]',
'selectionStatus',
'selectionClient',
'selectionTaskGroup'
)
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;
});
}
@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' },
{ 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
// 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));
}
@action
setActiveTaskQueryParam(task) {
if (task) {
this.set('activeTask', `${task.allocation.id}-${task.name}`);
} else {
this.set('activeTask', null);
}
}
}