import Component from '@ember/component'; import { getOwner } from '@ember/application'; import { inject as service } from '@ember/service'; import { computed } from '@ember/object'; import { alias } from '@ember/object/computed'; export default Component.extend({ toolService: service('tool-service'), routeName: alias('router.currentRouteName'), 'trim-index': true, route: computed('routeName', function() { const me = this; const routeName = me.get('routeName'); return me.getRoute(me.get('trim-index') ? routeName.replace(/\.index$/, '') : routeName); }), service: computed('routeName', function() { return this.getService(); }), params: computed('router.location.lastSetURL', function() { const me = this; const routeName = me.get('routeName'); return me.getRouteParams(me.get('trim-index') ? routeName.replace(/\.index$/, '') : routeName); }), getRouteParams(routeName) { return this.get('route').paramsFor(routeName || this.get('trim-index') ? this.get('routeName').replace(/\.index$/, '') : this.get('routeName')); }, getRoute(routeName) { return getOwner(this).lookup( 'route:' + (routeName || this.get('routeName'))); }, getParentRouteName(routeName) { return routeName.replace(/\.[^.]+$/, ''); }, getService(name) { const me = this; return name ? me.get('toolService').getServiceByRouteName(name) : me.getRoute().get('service') || me.get('toolService').getServiceByRouteName(me.get('routeName')); }, didReceiveAttrs() { const me = this; me._super(...arguments); me.get('model') || me.set('model', me.get('route.controller.model')); }, getVal() { const me = this; const name = me.get('name'); return me.get(name ? 'model.' + name : '__value__'); }, setVal(val) { const me = this; const name = me.get('name'); me.set(name ? 'model.' + name : '__value__', val); } });