2020-06-09 21:03:28 +00:00
|
|
|
/* eslint-disable ember/no-incorrect-calls-with-inline-anonymous-functions */
|
2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
2020-03-31 04:13:32 +00:00
|
|
|
import { alias, readOnly } from '@ember/object/computed';
|
2021-04-29 20:00:59 +00:00
|
|
|
import Controller from '@ember/controller';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { action, computed } from '@ember/object';
|
2019-01-23 21:56:32 +00:00
|
|
|
import { scheduleOnce } from '@ember/runloop';
|
|
|
|
import intersection from 'lodash.intersection';
|
2017-09-19 14:47:10 +00:00
|
|
|
import Sortable from 'nomad-ui/mixins/sortable';
|
|
|
|
import Searchable from 'nomad-ui/mixins/searchable';
|
2019-02-12 04:00:45 +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';
|
2019-01-23 21:56:32 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class IndexController extends Controller.extend(Sortable, Searchable) {
|
|
|
|
@service system;
|
|
|
|
@service userSettings;
|
2017-10-24 23:07:43 +00:00
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
isForbidden = false;
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2020-06-11 13:38:33 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
currentPage: 'page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
searchTerm: 'search',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortProperty: 'sort',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortDescending: 'desc',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpType: 'type',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpStatus: 'status',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpDatacenter: 'dc',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpPrefix: 'prefix',
|
|
|
|
},
|
2021-04-29 20:00:59 +00:00
|
|
|
{
|
|
|
|
qpNamespace: 'namespace',
|
|
|
|
},
|
2020-06-11 13:38:33 +00:00
|
|
|
];
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
currentPage = 1;
|
|
|
|
@readOnly('userSettings.pageSize') pageSize;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
sortProperty = 'modifyIndex';
|
|
|
|
sortDescending = true;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get searchProps() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return ['id', 'name'];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@computed
|
|
|
|
get fuzzySearchProps() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return ['name'];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fuzzySearchEnabled = true;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
qpType = '';
|
|
|
|
qpStatus = '';
|
|
|
|
qpDatacenter = '';
|
|
|
|
qpPrefix = '';
|
2019-02-11 22:37:36 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@selection('qpType') selectionType;
|
|
|
|
@selection('qpStatus') selectionStatus;
|
|
|
|
@selection('qpDatacenter') selectionDatacenter;
|
|
|
|
@selection('qpPrefix') selectionPrefix;
|
2019-02-11 22:37:36 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get optionsType() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return [
|
|
|
|
{ key: 'batch', label: 'Batch' },
|
|
|
|
{ key: 'parameterized', label: 'Parameterized' },
|
|
|
|
{ key: 'periodic', label: 'Periodic' },
|
|
|
|
{ key: 'service', label: 'Service' },
|
|
|
|
{ key: 'system', label: 'System' },
|
2021-10-07 21:11:38 +00:00
|
|
|
{ key: 'sysbatch', label: 'System Batch' },
|
2020-06-09 21:03:28 +00:00
|
|
|
];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-01-17 00:29:31 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get optionsStatus() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return [
|
|
|
|
{ key: 'pending', label: 'Pending' },
|
|
|
|
{ key: 'running', label: 'Running' },
|
|
|
|
{ key: 'dead', label: 'Dead' },
|
|
|
|
];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-01-17 00:29:31 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('selectionDatacenter', 'visibleJobs.[]')
|
2020-06-10 13:49:16 +00:00
|
|
|
get optionsDatacenter() {
|
2019-01-17 19:10:42 +00:00
|
|
|
const flatten = (acc, val) => acc.concat(val);
|
2019-05-21 21:20:40 +00:00
|
|
|
const allDatacenters = new Set(this.visibleJobs.mapBy('datacenters').reduce(flatten, []));
|
2019-01-17 19:10:42 +00:00
|
|
|
|
2019-01-23 21:56:32 +00:00
|
|
|
// Remove any invalid datacenters from the query param/selection
|
|
|
|
const availableDatacenters = Array.from(allDatacenters).compact();
|
|
|
|
scheduleOnce('actions', () => {
|
2020-06-09 21:03:28 +00:00
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
2019-01-23 21:56:32 +00:00
|
|
|
this.set(
|
|
|
|
'qpDatacenter',
|
2019-03-26 07:46:44 +00:00
|
|
|
serialize(intersection(availableDatacenters, this.selectionDatacenter))
|
2019-01-23 21:56:32 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
return availableDatacenters.sort().map(dc => ({ key: dc, label: dc }));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-01-17 00:29:31 +00:00
|
|
|
|
2021-02-17 21:01:44 +00:00
|
|
|
@computed('selectionPrefix', 'visibleJobs.[]')
|
2020-06-10 13:49:16 +00:00
|
|
|
get optionsPrefix() {
|
2019-01-17 19:10:42 +00:00
|
|
|
// A prefix is defined as the start of a job name up to the first - or .
|
|
|
|
// ex: mktg-analytics -> mktg, ds.supermodel.classifier -> ds
|
|
|
|
const hasPrefix = /.[-._]/;
|
|
|
|
|
|
|
|
// Collect and count all the prefixes
|
2019-03-26 07:46:44 +00:00
|
|
|
const allNames = this.visibleJobs.mapBy('name');
|
2019-01-17 19:10:42 +00:00
|
|
|
const nameHistogram = allNames.reduce((hist, name) => {
|
|
|
|
if (hasPrefix.test(name)) {
|
2019-05-21 21:20:40 +00:00
|
|
|
const prefix = name.match(/(.+?)[-._]/)[1];
|
2019-01-17 19:10:42 +00:00
|
|
|
hist[prefix] = hist[prefix] ? hist[prefix] + 1 : 1;
|
|
|
|
}
|
|
|
|
return hist;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
// Convert to an array
|
|
|
|
const nameTable = Object.keys(nameHistogram).map(key => ({
|
|
|
|
prefix: key,
|
|
|
|
count: nameHistogram[key],
|
|
|
|
}));
|
|
|
|
|
2019-01-23 21:56:32 +00:00
|
|
|
// Only consider prefixes that match more than one name
|
|
|
|
const prefixes = nameTable.filter(name => name.count > 1);
|
|
|
|
|
|
|
|
// Remove any invalid prefixes from the query param/selection
|
|
|
|
const availablePrefixes = prefixes.mapBy('prefix');
|
|
|
|
scheduleOnce('actions', () => {
|
2020-06-09 21:03:28 +00:00
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
2019-03-26 07:46:44 +00:00
|
|
|
this.set('qpPrefix', serialize(intersection(availablePrefixes, this.selectionPrefix)));
|
2019-01-23 21:56:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
// Sort, format, and include the count in the label
|
2019-01-24 04:35:51 +00:00
|
|
|
return prefixes.sortBy('prefix').map(name => ({
|
|
|
|
key: name.prefix,
|
|
|
|
label: `${name.prefix} (${name.count})`,
|
|
|
|
}));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2019-01-17 00:29:31 +00:00
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
@computed('qpNamespace', 'model.namespaces.[]', 'system.cachedNamespace')
|
|
|
|
get optionsNamespaces() {
|
|
|
|
const availableNamespaces = this.model.namespaces.map(namespace => ({
|
|
|
|
key: namespace.name,
|
|
|
|
label: namespace.name,
|
|
|
|
}));
|
|
|
|
|
|
|
|
availableNamespaces.unshift({
|
|
|
|
key: '*',
|
|
|
|
label: 'All (*)',
|
|
|
|
});
|
|
|
|
|
|
|
|
// Unset the namespace selection if it was server-side deleted
|
|
|
|
if (!availableNamespaces.mapBy('key').includes(this.qpNamespace)) {
|
|
|
|
scheduleOnce('actions', () => {
|
|
|
|
// eslint-disable-next-line ember/no-side-effects
|
2021-10-21 14:24:07 +00:00
|
|
|
this.set('qpNamespace', this.system.cachedNamespace || '*');
|
2021-04-29 20:00:59 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return availableNamespaces;
|
|
|
|
}
|
|
|
|
|
2018-01-23 21:23:16 +00:00
|
|
|
/**
|
2019-02-11 22:37:36 +00:00
|
|
|
Visible jobs are those that match the selected namespace and aren't children
|
2018-01-23 21:23:16 +00:00
|
|
|
of periodic or parameterized jobs.
|
|
|
|
*/
|
2021-04-29 20:00:59 +00:00
|
|
|
@computed('model.jobs.@each.parent')
|
2020-06-10 13:49:16 +00:00
|
|
|
get visibleJobs() {
|
2021-04-29 20:00:59 +00:00
|
|
|
if (!this.model || !this.model.jobs) return [];
|
|
|
|
return this.model.jobs
|
2018-08-09 18:02:50 +00:00
|
|
|
.compact()
|
2020-07-10 00:01:34 +00:00
|
|
|
.filter(job => !job.isNew)
|
2018-08-09 18:02:50 +00:00
|
|
|
.filter(job => !job.get('parent.content'));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2017-10-11 20:44:27 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed(
|
2019-01-17 19:11:17 +00:00
|
|
|
'visibleJobs.[]',
|
2019-02-01 22:08:55 +00:00
|
|
|
'selectionType',
|
|
|
|
'selectionStatus',
|
|
|
|
'selectionDatacenter',
|
2020-06-10 13:49:16 +00:00
|
|
|
'selectionPrefix'
|
|
|
|
)
|
|
|
|
get filteredJobs() {
|
|
|
|
const {
|
|
|
|
selectionType: types,
|
|
|
|
selectionStatus: statuses,
|
|
|
|
selectionDatacenter: datacenters,
|
|
|
|
selectionPrefix: prefixes,
|
|
|
|
} = this;
|
|
|
|
|
|
|
|
// A job must match ALL filter facets, but it can match ANY selection within a facet
|
|
|
|
// Always return early to prevent unnecessary facet predicates.
|
|
|
|
return this.visibleJobs.filter(job => {
|
|
|
|
if (types.length && !types.includes(job.get('displayType'))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (statuses.length && !statuses.includes(job.get('status'))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (datacenters.length && !job.get('datacenters').find(dc => datacenters.includes(dc))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const name = job.get('name');
|
|
|
|
if (prefixes.length && !prefixes.find(prefix => name.startsWith(prefix))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@alias('filteredJobs') listToSort;
|
|
|
|
@alias('listSorted') listToSearch;
|
|
|
|
@alias('listSearched') sortedJobs;
|
|
|
|
|
|
|
|
isShowingDeploymentDetails = false;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-04-29 20:00:59 +00:00
|
|
|
@action
|
|
|
|
cacheNamespace(namespace) {
|
|
|
|
this.system.cachedNamespace = namespace;
|
|
|
|
}
|
|
|
|
|
2019-01-23 21:56:32 +00:00
|
|
|
setFacetQueryParam(queryParam, selection) {
|
2019-02-12 04:00:45 +00:00
|
|
|
this.set(queryParam, serialize(selection));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
gotoJob(job) {
|
2021-04-29 20:00:59 +00:00
|
|
|
this.transitionToRoute('jobs.job', job.get('plainId'), {
|
|
|
|
queryParams: { namespace: job.get('namespace.name') },
|
|
|
|
});
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
}
|