006b6000a8
This commit includes several pieces of functionality to enable services to be removed and the page to present information that this has happened but also keep the deleted information on the page. Along with the more usual blocking query based listing. To enable this: 1. Implements `meta` on the model (only available on collections in ember) 2. Adds new `catchable` ComputedProperty alongside a `listen` helper for working with specific errors that can be thrown from EventSources in an ember-like way. Briefly, normal computed properties update when a property changes, EventSources can additionally throw errors so we can catch them and show different visuals based on that. Also: Add support for blocking queries on the service instance detail page 1. Previous we could return undefined when a service instance has no proxy, but this means we have nothing to attach `meta` to. We've changed this to return an almost empty object, so with only a meta property. At first glance there doesn't seem to be any way to provide a proxy object to templates and be able to detect whether it is actually null or not so we instead change some conditional logic in the templates to detect the property we are using to generate the anchor. 2. Made a `pauseUntil` test helper function for steps where we wait for things. This helps for DRYness but also means if we can move away from setInterval to something else later, we can do it in one place 3. Whilst running into point 1 here, we managed to make the blocking queries eternally loop. Whilst this is due to an error in the code and shouldn't ever happen whilst in actual use, we've added an extra check so that we only recur/loop the blocking query if the previous response has a `meta.cursor` Adds support for blocking queries on the node detail page (#5489) 1. Moves data re-shaping for the templates variables into a repository so they are easily covered by blocking queries (into coordinatesRepo) 2. The node API returns a 404 as signal for deregistration, we also close the sessions and coordinates blocking queries when this happens
96 lines
3.1 KiB
JavaScript
96 lines
3.1 KiB
JavaScript
import Controller from '@ember/controller';
|
|
import { inject as service } from '@ember/service';
|
|
import { get, set, computed } from '@ember/object';
|
|
import { alias } from '@ember/object/computed';
|
|
import WithSearching from 'consul-ui/mixins/with-searching';
|
|
import WithEventSource, { listen } from 'consul-ui/mixins/with-event-source';
|
|
|
|
export default Controller.extend(WithEventSource, WithSearching, {
|
|
dom: service('dom'),
|
|
notify: service('flashMessages'),
|
|
items: alias('item.Services'),
|
|
queryParams: {
|
|
s: {
|
|
as: 'filter',
|
|
replace: true,
|
|
},
|
|
},
|
|
init: function() {
|
|
this.searchParams = {
|
|
nodeservice: 's',
|
|
};
|
|
this._super(...arguments);
|
|
},
|
|
item: listen('item').catch(function(e) {
|
|
if (e.target.readyState === 1) {
|
|
// OPEN
|
|
if (get(e, 'error.errors.firstObject.status') === '404') {
|
|
get(this, 'notify').add({
|
|
destroyOnClick: false,
|
|
sticky: true,
|
|
type: 'warning',
|
|
action: 'update',
|
|
});
|
|
get(this, 'tomography').close();
|
|
get(this, 'sessions').close();
|
|
}
|
|
}
|
|
}),
|
|
searchable: computed('items', function() {
|
|
return get(this, 'searchables.nodeservice')
|
|
.add(get(this, 'items'))
|
|
.search(get(this, this.searchParams.nodeservice));
|
|
}),
|
|
setProperties: function() {
|
|
this._super(...arguments);
|
|
// the default selected tab depends on whether you have any healthchecks or not
|
|
// so check the length here.
|
|
// This method is called immediately after `Route::setupController`, and done here rather than there
|
|
// as this is a variable used purely for view level things, if the view was different we might not
|
|
// need this variable
|
|
set(this, 'selectedTab', get(this, 'item.Checks.length') > 0 ? 'health-checks' : 'services');
|
|
},
|
|
actions: {
|
|
change: function(e) {
|
|
set(this, 'selectedTab', e.target.value);
|
|
// Ensure tabular-collections sizing is recalculated
|
|
// now it is visible in the DOM
|
|
get(this, 'dom')
|
|
.components('.tab-section input[type="radio"]:checked + div table')
|
|
.forEach(function(item) {
|
|
if (typeof item.didAppear === 'function') {
|
|
item.didAppear();
|
|
}
|
|
});
|
|
},
|
|
sortChecksByImportance: function(a, b) {
|
|
const statusA = get(a, 'Status');
|
|
const statusB = get(b, 'Status');
|
|
switch (statusA) {
|
|
case 'passing':
|
|
// a = passing
|
|
// unless b is also passing then a is less important
|
|
return statusB === 'passing' ? 0 : 1;
|
|
case 'critical':
|
|
// a = critical
|
|
// unless b is also critical then a is more important
|
|
return statusB === 'critical' ? 0 : -1;
|
|
case 'warning':
|
|
// a = warning
|
|
switch (statusB) {
|
|
// b is passing so a is more important
|
|
case 'passing':
|
|
return -1;
|
|
// b is critical so a is less important
|
|
case 'critical':
|
|
return 1;
|
|
// a and b are both warning, therefore equal
|
|
default:
|
|
return 0;
|
|
}
|
|
}
|
|
return 0;
|
|
},
|
|
},
|
|
});
|