Data modeling for preemptions
This commit is contained in:
parent
812abe153f
commit
cb11f46ecf
|
@ -3,7 +3,7 @@ import { computed } from '@ember/object';
|
||||||
import { equal } from '@ember/object/computed';
|
import { equal } from '@ember/object/computed';
|
||||||
import Model from 'ember-data/model';
|
import Model from 'ember-data/model';
|
||||||
import attr from 'ember-data/attr';
|
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 { fragment, fragmentArray } from 'ember-data-model-fragments/attributes';
|
||||||
import intersection from 'lodash.intersection';
|
import intersection from 'lodash.intersection';
|
||||||
import shortUUIDProperty from '../utils/properties/short-uuid';
|
import shortUUIDProperty from '../utils/properties/short-uuid';
|
||||||
|
@ -46,6 +46,9 @@ export default Model.extend({
|
||||||
previousAllocation: belongsTo('allocation', { inverse: 'nextAllocation' }),
|
previousAllocation: belongsTo('allocation', { inverse: 'nextAllocation' }),
|
||||||
nextAllocation: belongsTo('allocation', { inverse: 'previousAllocation' }),
|
nextAllocation: belongsTo('allocation', { inverse: 'previousAllocation' }),
|
||||||
|
|
||||||
|
preemptedAllocations: hasMany('allocation', { inverse: 'preemptedByAllocation' }),
|
||||||
|
preemptedByAllocation: belongsTo('allocation', { inverse: 'preemptedAllocations' }),
|
||||||
|
|
||||||
followUpEvaluation: belongsTo('evaluation'),
|
followUpEvaluation: belongsTo('evaluation'),
|
||||||
|
|
||||||
statusClass: computed('clientStatus', function() {
|
statusClass: computed('clientStatus', function() {
|
||||||
|
@ -88,9 +91,11 @@ export default Model.extend({
|
||||||
'clientStatus',
|
'clientStatus',
|
||||||
'followUpEvaluation.content',
|
'followUpEvaluation.content',
|
||||||
function() {
|
function() {
|
||||||
return !this.get('nextAllocation.content') &&
|
return (
|
||||||
!this.get('followUpEvaluation.content') &&
|
!this.get('nextAllocation.content') &&
|
||||||
this.clientStatus === 'failed';
|
!this.get('followUpEvaluation.content') &&
|
||||||
|
this.clientStatus === 'failed'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
import Model from 'ember-data/model';
|
import Model from 'ember-data/model';
|
||||||
import attr from 'ember-data/attr';
|
import attr from 'ember-data/attr';
|
||||||
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
import { fragmentArray } from 'ember-data-model-fragments/attributes';
|
||||||
|
import { hasMany } from 'ember-data/relationships';
|
||||||
|
|
||||||
export default Model.extend({
|
export default Model.extend({
|
||||||
diff: attr(),
|
diff: attr(),
|
||||||
failedTGAllocs: fragmentArray('placement-failure', { defaultValue: () => [] }),
|
failedTGAllocs: fragmentArray('placement-failure', { defaultValue: () => [] }),
|
||||||
|
preemptions: hasMany('allocation'),
|
||||||
});
|
});
|
||||||
|
|
|
@ -45,6 +45,9 @@ export default ApplicationSerializer.extend({
|
||||||
hash.NextAllocationID = hash.NextAllocation ? hash.NextAllocation : null;
|
hash.NextAllocationID = hash.NextAllocation ? hash.NextAllocation : null;
|
||||||
hash.FollowUpEvaluationID = hash.FollowupEvalID ? hash.FollowupEvalID : null;
|
hash.FollowUpEvaluationID = hash.FollowupEvalID ? hash.FollowupEvalID : null;
|
||||||
|
|
||||||
|
hash.PreemptedAllocationIDs = hash.PreemptedAllocations || [];
|
||||||
|
hash.PreemptedByAllocationID = hash.PreemptedByAllocation || null;
|
||||||
|
|
||||||
return this._super(typeHash, hash);
|
return this._super(typeHash, hash);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { assign } from '@ember/polyfills';
|
import { assign } from '@ember/polyfills';
|
||||||
import ApplicationSerializer from './application';
|
import ApplicationSerializer from './application';
|
||||||
|
import { get } from '@ember/object';
|
||||||
|
|
||||||
export default ApplicationSerializer.extend({
|
export default ApplicationSerializer.extend({
|
||||||
normalize(typeHash, hash) {
|
normalize(typeHash, hash) {
|
||||||
|
@ -7,6 +8,7 @@ export default ApplicationSerializer.extend({
|
||||||
hash.FailedTGAllocs = Object.keys(failures).map(key => {
|
hash.FailedTGAllocs = Object.keys(failures).map(key => {
|
||||||
return assign({ Name: key }, failures[key] || {});
|
return assign({ Name: key }, failures[key] || {});
|
||||||
});
|
});
|
||||||
|
hash.PreemptionIDs = (get(hash, 'Annotations.PreemptedAllocs') || []).mapBy('ID');
|
||||||
return this._super(...arguments);
|
return this._super(...arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue