open-consul/ui-v2/app/models/service.js
John Cowen f9710c2c92 ui: Reconcile ember-data store when records are deleted via blocking (#5745)
* ui: Reconciliate ember-data store when records are deleted via blocking

Currently we are barely using the ember-data store/cache, but it will
still cache records in the store even though technically we aren't using
it.

This adds a SyncTime to every record that uses blocking queries so we
can delete older records from the ember-data cache to prevent them
building up

* ui: Add basic timestamp method we can access from tests, fixup tests

Adds a timestamp method that we can access from within tests so we can
test that the SyncTime is being set.

There is probably a better way to do this, but this is also probably the
simplest approach - we are also likely to revisit this at a later date
2019-09-04 08:34:57 +00:00

67 lines
1.6 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'),
TaggedAddresses: attr(),
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(),
SyncTime: attr('number'),
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;
},
});