mirror of
https://github.com/status-im/consul.git
synced 2025-01-09 21:35:52 +00:00
9daf8f53d9
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.
65 lines
1.5 KiB
JavaScript
65 lines
1.5 KiB
JavaScript
import Model from 'ember-data/model';
|
|
import attr from 'ember-data/attr';
|
|
import { computed, get } from '@ember/object';
|
|
|
|
export const PRIMARY_KEY = 'uid';
|
|
export const SLUG_KEY = 'Name';
|
|
|
|
export default Model.extend({
|
|
[PRIMARY_KEY]: attr('string'),
|
|
[SLUG_KEY]: attr('string'),
|
|
Tags: attr({
|
|
defaultValue: function() {
|
|
return [];
|
|
},
|
|
}),
|
|
Kind: attr('string'),
|
|
ExternalSources: attr(),
|
|
Meta: attr(),
|
|
Address: attr('string'),
|
|
Port: attr('number'),
|
|
EnableTagOverride: attr('boolean'),
|
|
CreateIndex: attr('number'),
|
|
ModifyIndex: attr('number'),
|
|
// TODO: These should be typed
|
|
ChecksPassing: attr(),
|
|
ChecksCritical: attr(),
|
|
ChecksWarning: attr(),
|
|
Nodes: attr(),
|
|
Datacenter: attr('string'),
|
|
Node: attr(),
|
|
Service: attr(),
|
|
Checks: attr(),
|
|
meta: attr(),
|
|
passing: computed('ChecksPassing', 'Checks', function() {
|
|
let num = 0;
|
|
// TODO: use typeof
|
|
if (get(this, 'ChecksPassing') !== undefined) {
|
|
num = get(this, 'ChecksPassing');
|
|
} else {
|
|
num = get(get(this, 'Checks').filterBy('Status', 'passing'), 'length');
|
|
}
|
|
return {
|
|
length: num,
|
|
};
|
|
}),
|
|
hasStatus: function(status) {
|
|
let num = 0;
|
|
switch (status) {
|
|
case 'passing':
|
|
num = get(this, 'ChecksPassing');
|
|
break;
|
|
case 'critical':
|
|
num = get(this, 'ChecksCritical');
|
|
break;
|
|
case 'warning':
|
|
num = get(this, 'ChecksWarning');
|
|
break;
|
|
case '': // all
|
|
num = 1;
|
|
break;
|
|
}
|
|
return num > 0;
|
|
},
|
|
});
|