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

71 lines
2 KiB
JavaScript
Raw Normal View History

2017-09-19 14:47:10 +00:00
import Ember from 'ember';
import Sortable from 'nomad-ui/mixins/sortable';
import Searchable from 'nomad-ui/mixins/searchable';
const { Controller, computed, observer, inject } = Ember;
2017-09-19 14:47:10 +00:00
export default Controller.extend(Sortable, Searchable, {
system: inject.service(),
2017-09-19 14:47:10 +00:00
pendingJobs: computed.filterBy('model', 'status', 'pending'),
runningJobs: computed.filterBy('model', 'status', 'running'),
deadJobs: computed.filterBy('model', 'status', 'dead'),
queryParams: {
currentPage: 'page',
searchTerm: 'search',
sortProperty: 'sort',
sortDescending: 'desc',
jobNamespace: 'namespace',
2017-09-19 14:47:10 +00:00
},
currentPage: 1,
pageSize: 10,
jobNamespace: 'default',
2017-09-19 14:47:10 +00:00
sortProperty: 'modifyIndex',
sortDescending: true,
searchProps: computed(() => ['id', 'name']),
filteredJobs: computed('model.[]', 'jobNamespace', function() {
if (this.get('system.namespaces.length')) {
return this.get('model').filterBy('namespace.name', this.get('jobNamespace'));
} else {
return this.get('model');
}
}),
listToSort: computed.alias('filteredJobs'),
2017-09-19 14:47:10 +00:00
listToSearch: computed.alias('listSorted'),
sortedJobs: computed.alias('listSearched'),
isShowingDeploymentDetails: false,
// The namespace query param should act as an alias to the system active namespace.
// But query param defaults can't be CPs: https://github.com/emberjs/ember.js/issues/9819
syncNamespaceService: observer('jobNamespace', function() {
const newNamespace = this.get('jobNamespace');
const currentNamespace = this.get('system.activeNamespace.id');
const bothAreDefault =
currentNamespace == undefined ||
(currentNamespace === 'default' && newNamespace == undefined) ||
newNamespace === 'default';
if (currentNamespace !== newNamespace && !bothAreDefault) {
this.set('system.activeNamespace', newNamespace);
this.send('refreshRoute');
}
}),
2017-09-19 14:47:10 +00:00
actions: {
gotoJob(job) {
this.transitionToRoute('jobs.job', job);
},
refresh() {
this.send('refreshRoute');
},
2017-09-19 14:47:10 +00:00
},
});