Data modeling for preemptions

This commit is contained in:
Michael Lange 2019-04-16 12:11:43 -07:00
parent 812abe153f
commit cb11f46ecf
4 changed files with 16 additions and 4 deletions

View file

@ -3,7 +3,7 @@ import { computed } from '@ember/object';
import { equal } from '@ember/object/computed';
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { belongsTo } from 'ember-data/relationships';
import { belongsTo, hasMany } from 'ember-data/relationships';
import { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
import intersection from 'lodash.intersection';
import shortUUIDProperty from '../utils/properties/short-uuid';
@ -46,6 +46,9 @@ export default Model.extend({
previousAllocation: belongsTo('allocation', { inverse: 'nextAllocation' }),
nextAllocation: belongsTo('allocation', { inverse: 'previousAllocation' }),
preemptedAllocations: hasMany('allocation', { inverse: 'preemptedByAllocation' }),
preemptedByAllocation: belongsTo('allocation', { inverse: 'preemptedAllocations' }),
followUpEvaluation: belongsTo('evaluation'),
statusClass: computed('clientStatus', function() {
@ -88,9 +91,11 @@ export default Model.extend({
'clientStatus',
'followUpEvaluation.content',
function() {
return !this.get('nextAllocation.content') &&
return (
!this.get('nextAllocation.content') &&
!this.get('followUpEvaluation.content') &&
this.clientStatus === 'failed';
this.clientStatus === 'failed'
);
}
),
});

View file

@ -1,8 +1,10 @@
import Model from 'ember-data/model';
import attr from 'ember-data/attr';
import { fragmentArray } from 'ember-data-model-fragments/attributes';
import { hasMany } from 'ember-data/relationships';
export default Model.extend({
diff: attr(),
failedTGAllocs: fragmentArray('placement-failure', { defaultValue: () => [] }),
preemptions: hasMany('allocation'),
});

View file

@ -45,6 +45,9 @@ export default ApplicationSerializer.extend({
hash.NextAllocationID = hash.NextAllocation ? hash.NextAllocation : null;
hash.FollowUpEvaluationID = hash.FollowupEvalID ? hash.FollowupEvalID : null;
hash.PreemptedAllocationIDs = hash.PreemptedAllocations || [];
hash.PreemptedByAllocationID = hash.PreemptedByAllocation || null;
return this._super(typeHash, hash);
},
});

View file

@ -1,5 +1,6 @@
import { assign } from '@ember/polyfills';
import ApplicationSerializer from './application';
import { get } from '@ember/object';
export default ApplicationSerializer.extend({
normalize(typeHash, hash) {
@ -7,6 +8,7 @@ export default ApplicationSerializer.extend({
hash.FailedTGAllocs = Object.keys(failures).map(key => {
return assign({ Name: key }, failures[key] || {});
});
hash.PreemptionIDs = (get(hash, 'Annotations.PreemptedAllocs') || []).mapBy('ID');
return this._super(...arguments);
},
});