2017-12-15 21:39:18 +00:00
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
import Route from '@ember/routing/route';
|
2018-03-01 00:27:15 +00:00
|
|
|
import { collect } from '@ember/object/computed';
|
2017-09-28 17:06:24 +00:00
|
|
|
import notifyError from 'nomad-ui/utils/notify-error';
|
2018-02-28 20:15:39 +00:00
|
|
|
import { watchRecord, watchRelationship } from 'nomad-ui/utils/properties/watch';
|
2018-03-01 00:27:15 +00:00
|
|
|
import WithWatchers from 'nomad-ui/mixins/with-watchers';
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2018-03-01 00:27:15 +00:00
|
|
|
export default Route.extend(WithWatchers, {
|
2017-12-15 21:39:18 +00:00
|
|
|
store: service(),
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2017-09-28 17:06:24 +00:00
|
|
|
model() {
|
|
|
|
return this._super(...arguments).catch(notifyError(this));
|
|
|
|
},
|
|
|
|
|
2017-09-19 14:47:10 +00:00
|
|
|
afterModel(model) {
|
2017-09-28 17:06:24 +00:00
|
|
|
if (model && model.get('isPartial')) {
|
2017-09-19 14:47:10 +00:00
|
|
|
return model.reload().then(node => node.get('allocations'));
|
|
|
|
}
|
2017-09-28 17:06:24 +00:00
|
|
|
return model && model.get('allocations');
|
2017-09-19 14:47:10 +00:00
|
|
|
},
|
2018-02-28 20:15:39 +00:00
|
|
|
|
2018-03-06 22:27:01 +00:00
|
|
|
startWatchers(controller, model) {
|
2018-02-28 20:15:39 +00:00
|
|
|
controller.set('watchModel', this.get('watch').perform(model));
|
|
|
|
controller.set('watchAllocations', this.get('watchAllocations').perform(model));
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: watchRecord('node'),
|
|
|
|
watchAllocations: watchRelationship('allocations'),
|
2018-03-01 00:27:15 +00:00
|
|
|
|
|
|
|
watchers: collect('watch', 'watchAllocations'),
|
2017-09-19 14:47:10 +00:00
|
|
|
});
|