2020-05-19 06:24:20 +00:00
|
|
|
import Controller from '@ember/controller';
|
|
|
|
import { inject as service } from '@ember/service';
|
2020-06-10 13:49:16 +00:00
|
|
|
import { action, computed } from '@ember/object';
|
2020-05-19 06:24:20 +00:00
|
|
|
import { alias, readOnly } from '@ember/object/computed';
|
|
|
|
import SortableFactory from 'nomad-ui/mixins/sortable-factory';
|
|
|
|
import { lazyClick } from 'nomad-ui/helpers/lazy-click';
|
2020-05-19 06:55:52 +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';
|
2020-05-19 06:24:20 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@classic
|
|
|
|
export default class AllocationsController extends Controller.extend(
|
|
|
|
SortableFactory(['updateTime', 'healthy'])
|
|
|
|
) {
|
|
|
|
@service userSettings;
|
2020-05-19 06:24:20 +00:00
|
|
|
|
2020-06-11 13:38:33 +00:00
|
|
|
queryParams = [
|
|
|
|
{
|
|
|
|
currentPage: 'page',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortProperty: 'sort',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
sortDescending: 'desc',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpHealth: 'healthy',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
qpType: 'type',
|
|
|
|
},
|
|
|
|
];
|
2020-05-19 06:24:20 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
currentPage = 1;
|
|
|
|
@readOnly('userSettings.pageSize') pageSize;
|
2020-05-19 06:24:20 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
sortProperty = 'updateTime';
|
|
|
|
sortDescending = false;
|
2020-05-19 06:24:20 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
qpType = '';
|
|
|
|
qpHealth = '';
|
2020-05-19 06:55:52 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@selection('qpType') selectionType;
|
|
|
|
@selection('qpHealth') selectionHealth;
|
2020-05-19 06:55:52 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get optionsType() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return [{ key: 'controller', label: 'Controller' }, { key: 'node', label: 'Node' }];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-19 06:55:52 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed
|
|
|
|
get optionsHealth() {
|
2020-06-09 21:03:28 +00:00
|
|
|
return [{ key: 'true', label: 'Healthy' }, { key: 'false', label: 'Unhealthy' }];
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-19 06:55:52 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed('model.{controllers.[],nodes.[]}')
|
|
|
|
get combinedAllocations() {
|
2020-05-19 06:24:20 +00:00
|
|
|
return this.model.controllers.toArray().concat(this.model.nodes.toArray());
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-19 06:24:20 +00:00
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
@computed(
|
2020-05-19 06:55:52 +00:00
|
|
|
'combinedAllocations.[]',
|
2020-06-09 21:03:28 +00:00
|
|
|
'model.{controllers.[],nodes.[]}',
|
2020-05-19 06:55:52 +00:00
|
|
|
'selectionType',
|
2020-06-10 13:49:16 +00:00
|
|
|
'selectionHealth'
|
|
|
|
)
|
|
|
|
get filteredAllocations() {
|
|
|
|
const { selectionType: types, selectionHealth: healths } = this;
|
|
|
|
|
|
|
|
// Instead of filtering the combined list, revert back to one of the two
|
|
|
|
// pre-existing lists.
|
|
|
|
let listToFilter = this.combinedAllocations;
|
|
|
|
if (types.length === 1 && types[0] === 'controller') {
|
|
|
|
listToFilter = this.model.controllers;
|
|
|
|
} else if (types.length === 1 && types[0] === 'node') {
|
|
|
|
listToFilter = this.model.nodes;
|
2020-05-19 06:55:52 +00:00
|
|
|
}
|
|
|
|
|
2020-06-10 13:49:16 +00:00
|
|
|
if (healths.length === 1 && healths[0] === 'true') return listToFilter.filterBy('healthy');
|
|
|
|
if (healths.length === 1 && healths[0] === 'false')
|
|
|
|
return listToFilter.filterBy('healthy', false);
|
|
|
|
return listToFilter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@alias('filteredAllocations') listToSort;
|
|
|
|
@alias('listSorted') sortedAllocations;
|
2020-05-19 06:24:20 +00:00
|
|
|
|
|
|
|
resetPagination() {
|
|
|
|
if (this.currentPage != null) {
|
|
|
|
this.set('currentPage', 1);
|
|
|
|
}
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
2020-05-19 06:24:20 +00:00
|
|
|
|
2020-05-19 06:55:52 +00:00
|
|
|
setFacetQueryParam(queryParam, selection) {
|
|
|
|
this.set(queryParam, serialize(selection));
|
2020-06-10 13:49:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
gotoAllocation(allocation, event) {
|
|
|
|
lazyClick([() => this.transitionToRoute('allocations.allocation', allocation), event]);
|
|
|
|
}
|
|
|
|
}
|