09067b4eb7
There are two changes here, and some caveats/commentary: 1. The “State“ table column was actually sorting only by status. The state was not an actual property, just something calculated in each client row, as a product of status, isEligible, and isDraining. This PR adds isDraining as a component of compositeState so it can be used for sorting. 2. The Sortable mixin declares dependent keys that cause the sort to be live-updating, but only if the members of the array change, such as if a new client is added, but not if any of the sortable properties change. This PR adds a SortableFactory function that generates a mixin whose listSorted computed property includes dependent keys for the sortable properties, so the table will live-update if any of the sortable properties change, not just the array members. There’s a warning if you use SortableFactory without dependent keys and via the original Sortable interface, so we can eventually migrate away from it.
74 lines
2.2 KiB
JavaScript
74 lines
2.2 KiB
JavaScript
import { computed } from '@ember/object';
|
|
import { equal } from '@ember/object/computed';
|
|
import Model from 'ember-data/model';
|
|
import attr from 'ember-data/attr';
|
|
import { hasMany } from 'ember-data/relationships';
|
|
import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
|
|
import shortUUIDProperty from '../utils/properties/short-uuid';
|
|
import ipParts from '../utils/ip-parts';
|
|
|
|
export default Model.extend({
|
|
// Available from list response
|
|
name: attr('string'),
|
|
datacenter: attr('string'),
|
|
nodeClass: attr('string'),
|
|
isDraining: attr('boolean'),
|
|
schedulingEligibility: attr('string'),
|
|
status: attr('string'),
|
|
statusDescription: attr('string'),
|
|
shortId: shortUUIDProperty('id'),
|
|
modifyIndex: attr('number'),
|
|
|
|
// Available from single response
|
|
httpAddr: attr('string'),
|
|
tlsEnabled: attr('boolean'),
|
|
attributes: fragment('node-attributes'),
|
|
meta: fragment('node-attributes'),
|
|
resources: fragment('resources'),
|
|
reserved: fragment('resources'),
|
|
drainStrategy: fragment('drain-strategy'),
|
|
|
|
isEligible: equal('schedulingEligibility', 'eligible'),
|
|
|
|
address: computed('httpAddr', function() {
|
|
return ipParts(this.httpAddr).address;
|
|
}),
|
|
|
|
port: computed('httpAddr', function() {
|
|
return ipParts(this.httpAddr).port;
|
|
}),
|
|
|
|
isPartial: computed('httpAddr', function() {
|
|
return this.httpAddr == null;
|
|
}),
|
|
|
|
allocations: hasMany('allocations', { inverse: 'node' }),
|
|
|
|
drivers: fragmentArray('node-driver'),
|
|
events: fragmentArray('node-event'),
|
|
|
|
detectedDrivers: computed('drivers.@each.detected', function() {
|
|
return this.drivers.filterBy('detected');
|
|
}),
|
|
|
|
unhealthyDrivers: computed('detectedDrivers.@each.healthy', function() {
|
|
return this.detectedDrivers.filterBy('healthy', false);
|
|
}),
|
|
|
|
unhealthyDriverNames: computed('unhealthyDrivers.@each.name', function() {
|
|
return this.unhealthyDrivers.mapBy('name');
|
|
}),
|
|
|
|
// A status attribute that includes states not included in node status.
|
|
// Useful for coloring and sorting nodes
|
|
compositeStatus: computed('isDraining', 'isEligible', 'status', function() {
|
|
if (this.isDraining) {
|
|
return 'draining';
|
|
} else if (!this.isEligible) {
|
|
return 'ineligible';
|
|
} else {
|
|
return this.status;
|
|
}
|
|
}),
|
|
});
|