github.com/outbrain/consul@v1.4.5/ui-v2/app/routes/dc/kv/create.js (about) 1 import Route from '@ember/routing/route'; 2 import { inject as service } from '@ember/service'; 3 import { hash } from 'rsvp'; 4 import { get, set } from '@ember/object'; 5 import WithKvActions from 'consul-ui/mixins/kv/with-actions'; 6 7 export default Route.extend(WithKvActions, { 8 templateName: 'dc/kv/edit', 9 repo: service('repository/kv'), 10 beforeModel: function() { 11 get(this, 'repo').invalidate(); 12 }, 13 model: function(params) { 14 const key = params.key || '/'; 15 const repo = get(this, 'repo'); 16 const dc = this.modelFor('dc').dc.Name; 17 this.item = repo.create(); 18 set(this.item, 'Datacenter', dc); 19 return hash({ 20 create: true, 21 isLoading: false, 22 item: this.item, 23 parent: repo.findBySlug(key, dc), 24 }); 25 }, 26 setupController: function(controller, model) { 27 this._super(...arguments); 28 controller.setProperties(model); 29 }, 30 deactivate: function() { 31 if (get(this.item, 'isNew')) { 32 this.item.destroyRecord(); 33 } 34 }, 35 });