open-nomad/ui/app/controllers/jobs/index.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

import { inject as service } from '@ember/service';
import { alias } from '@ember/object/computed';
import Controller, { inject as controller } from '@ember/controller';
import { computed } from '@ember/object';
2017-09-19 14:47:10 +00:00
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
export default Controller.extend(Sortable, Searchable, {
system: service(),
jobsController: controller('jobs'),
isForbidden: alias('jobsController.isForbidden'),
2017-09-19 14:47:10 +00:00
queryParams: {
currentPage: 'page',
searchTerm: 'search',
sortProperty: 'sort',
sortDescending: 'desc',
},
currentPage: 1,
pageSize: 10,
sortProperty: 'modifyIndex',
sortDescending: true,
searchProps: computed(() => ['id', 'name']),
/**
Filtered jobs are those that match the selected namespace and aren't children
of periodic or parameterized jobs.
*/
filteredJobs: computed(
'model.[]',
'model.@each.parent',
'system.activeNamespace',
'system.namespaces.length',
function() {
const hasNamespaces = this.get('system.namespaces.length');
const activeNamespace = this.get('system.activeNamespace.id') || 'default';
return this.get('model')
.filter(job => !hasNamespaces || job.get('namespace.id') === activeNamespace)
.filter(job => !job.get('parent.content'));
}
),
listToSort: alias('filteredJobs'),
listToSearch: alias('listSorted'),
sortedJobs: alias('listSearched'),
2017-09-19 14:47:10 +00:00
isShowingDeploymentDetails: false,
actions: {
gotoJob(job) {
this.transitionToRoute('jobs.job', job);
},
refresh() {
this.send('refreshRoute');
},
2017-09-19 14:47:10 +00:00
},
});