Data modeling for node events and node drivers

This commit is contained in:
Michael Lange 2018-05-08 09:39:27 -07:00
parent 4d9859103f
commit d6ebf77b08
5 changed files with 45 additions and 1 deletions

View file

@ -0,0 +1,15 @@
import Fragment from 'ember-data-model-fragments/fragment';
import attr from 'ember-data/attr';
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
import { fragment } from 'ember-data-model-fragments/attributes';
export default Fragment.extend({
node: fragmentOwner(),
attributes: fragment('node-attributes'),
name: attr('string'),
detected: attr('boolean', { defaultValue: false }),
healthy: attr('boolean', { defaultValue: false }),
healthDescription: attr('string'),
updateTime: attr('date'),
});

View file

@ -0,0 +1,12 @@
import Fragment from 'ember-data-model-fragments/fragment';
import attr from 'ember-data/attr';
import { fragmentOwner } from 'ember-data-model-fragments/attributes';
export default Fragment.extend({
node: fragmentOwner(),
message: attr('string'),
subsystem: attr('string'),
details: attr(),
time: attr('date'),
});

View file

@ -2,7 +2,7 @@ import { computed } from '@ember/object';
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { hasMany } from 'ember-data/relationships';
import { fragment } from 'ember-data-model-fragments/attributes';
import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
import shortUUIDProperty from '../utils/properties/short-uuid';
import ipParts from '../utils/ip-parts';
@ -37,4 +37,7 @@ export default Model.extend({
}),
allocations: hasMany('allocations', { inverse: 'node' }),
drivers: fragmentArray('node-driver'),
events: fragmentArray('node-event'),
});

View file

@ -0,0 +1,7 @@
import ApplicationSerializer from './application';
export default ApplicationSerializer.extend({
attrs: {
time: 'Timestamp',
},
});

View file

@ -1,3 +1,5 @@
import { get } from '@ember/object';
import { assign } from '@ember/polyfills';
import { inject as service } from '@ember/service';
import ApplicationSerializer from './application';
@ -9,6 +11,11 @@ export default ApplicationSerializer.extend({
},
normalize(modelClass, hash) {
// Transform the map-based Drivers object into an array-based NodeDriver fragment list
hash.Drivers = Object.keys(get(hash, 'Drivers') || {}).map(key => {
return assign({}, get(hash, `Drivers.${key}`), { Name: key });
});
return this._super(modelClass, hash);
},