github.com/outbrain/consul@v1.4.5/ui-v2/app/routes/dc/kv/index.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 } from '@ember/object'; 5 import isFolder from 'consul-ui/utils/isFolder'; 6 import WithKvActions from 'consul-ui/mixins/kv/with-actions'; 7 8 export default Route.extend(WithKvActions, { 9 queryParams: { 10 s: { 11 as: 'filter', 12 replace: true, 13 }, 14 }, 15 repo: service('repository/kv'), 16 beforeModel: function() { 17 // we are index or folder, so if the key doesn't have a trailing slash 18 // add one to force a fake findBySlug 19 const params = this.paramsFor(this.routeName); 20 const key = params.key || '/'; 21 if (!isFolder(key)) { 22 return this.replaceWith(this.routeName, key + '/'); 23 } 24 }, 25 model: function(params) { 26 let key = params.key || '/'; 27 const dc = this.modelFor('dc').dc.Name; 28 const repo = get(this, 'repo'); 29 return hash({ 30 isLoading: false, 31 parent: repo.findBySlug(key, dc), 32 }).then(model => { 33 return hash({ 34 ...model, 35 ...{ 36 items: repo.findAllBySlug(get(model.parent, 'Key'), dc).catch(e => { 37 const status = get(e, 'errors.firstObject.status'); 38 switch (status) { 39 case '403': 40 return this.transitionTo('dc.acls.tokens'); 41 default: 42 return this.transitionTo('dc.kv.index'); 43 } 44 }), 45 }, 46 }); 47 }); 48 }, 49 actions: { 50 error: function(e) { 51 if (e.errors && e.errors[0] && e.errors[0].status == '404') { 52 return this.transitionTo('dc.kv.index'); 53 } 54 throw e; 55 }, 56 }, 57 setupController: function(controller, model) { 58 this._super(...arguments); 59 controller.setProperties(model); 60 }, 61 });