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';
|
|
|
|
|
2017-10-11 20:44:27 +00:00
|
|
|
const { Controller, computed, observer, inject } = Ember;
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
export default Controller.extend(Sortable, Searchable, {
|
2017-10-11 20:44:27 +00:00
|
|
|
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',
|
2017-10-11 20:44:27 +00:00
|
|
|
jobNamespace: 'namespace',
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
currentPage: 1,
|
|
|
|
pageSize: 10,
|
2017-10-11 20:44:27 +00:00
|
|
|
jobNamespace: 'default',
|
2017-09-19 14:47:10 +00:00
|
|
|
|
|
|
|
sortProperty: 'modifyIndex',
|
|
|
|
sortDescending: true,
|
|
|
|
|
|
|
|
searchProps: computed(() => ['id', 'name']),
|
|
|
|
|
2017-10-11 20:44:27 +00:00
|
|
|
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,
|
|
|
|
|
2017-10-11 20:44:27 +00:00
|
|
|
// 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);
|
|
|
|
},
|
2017-10-10 02:00:40 +00:00
|
|
|
|
|
|
|
refresh() {
|
|
|
|
this.send('refreshRoute');
|
|
|
|
},
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
|
|
|
});
|