diff --git a/app/initializers/base-route.js b/app/initializers/base-route.js deleted file mode 100644 index b2a72fa60b8c..000000000000 --- a/app/initializers/base-route.js +++ /dev/null @@ -1,39 +0,0 @@ -import Route from '@ember/routing/route'; -import { inject as service } from '@ember/service'; - -export function initialize(application) { - Route.reopen({ - feedback: service('feedback'), - init: function() { - this._super(...arguments); - this.set('feedback', { - execute: this.get('feedback').execute.bind(this), - }); - }, - // Don't record characters in browser history - // for the "search" query item (filter) - // queryParams: { - // filter: { - // replace: true - // } - // }, - // this is only KV not all Routes - rootKey: '-', - actions: { - // Used to link to keys that are not objects, - // like parents and grandParents - // TODO: This is a view thing, should possibly be a helper - linkToKey: function(key) { - if (key.slice(-1) === '/' || key === this.rootKey) { - this.transitionTo('dc.kv.show', key); - } else { - this.transitionTo('dc.kv.edit', key); - } - }, - }, - }); -} - -export default { - initialize, -}; diff --git a/app/mixins/with-feedback.js b/app/mixins/with-feedback.js new file mode 100644 index 000000000000..c2ab02754495 --- /dev/null +++ b/app/mixins/with-feedback.js @@ -0,0 +1,12 @@ +import Mixin from '@ember/object/mixin'; +import { inject as service } from '@ember/service'; + +export default Mixin.create({ + feedback: service('feedback'), + init: function() { + this._super(...arguments); + this.set('feedback', { + execute: this.get('feedback').execute.bind(this), + }); + }, +}); diff --git a/app/mixins/with-key-utils.js b/app/mixins/with-key-utils.js new file mode 100644 index 000000000000..5a16bee8b0fe --- /dev/null +++ b/app/mixins/with-key-utils.js @@ -0,0 +1,17 @@ +import Mixin from '@ember/object/mixin'; + +export default Mixin.create({ + rootKey: '-', + actions: { + // Used to link to keys that are not objects, + // like parents and grandParents + // TODO: This is a view thing, should possibly be a helper + linkToKey: function(key) { + if (key.slice(-1) === '/' || key === this.rootKey) { + this.transitionTo('dc.kv.show', key); + } else { + this.transitionTo('dc.kv.edit', key); + } + }, + }, +}); diff --git a/app/routes/dc/acls.js b/app/routes/dc/acls.js index 3b0580c30054..668c037f13d3 100644 --- a/app/routes/dc/acls.js +++ b/app/routes/dc/acls.js @@ -3,7 +3,8 @@ import { inject as service } from '@ember/service'; import { hash } from 'rsvp'; import { next } from '@ember/runloop'; -export default Route.extend({ +import WithFeedback from 'consul-ui/mixins/with-feedback'; +export default Route.extend(WithFeedback, { repo: service('acls'), model: function(params) { const repo = this.get('repo'); diff --git a/app/routes/dc/acls/show.js b/app/routes/dc/acls/show.js index 818b4f6f48f9..65124f307e55 100644 --- a/app/routes/dc/acls/show.js +++ b/app/routes/dc/acls/show.js @@ -1,7 +1,8 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; import { hash } from 'rsvp'; -export default Route.extend({ +import WithFeedback from 'consul-ui/mixins/with-feedback'; +export default Route.extend(WithFeedback, { repo: service('acls'), model: function(params) { const dc = this.modelFor('dc').dc; diff --git a/app/routes/dc/kv/edit.js b/app/routes/dc/kv/edit.js index dd17f45a9635..5682094d709d 100644 --- a/app/routes/dc/kv/edit.js +++ b/app/routes/dc/kv/edit.js @@ -4,10 +4,12 @@ import { assign } from '@ember/polyfills'; import { hash } from 'rsvp'; import { get } from '@ember/object'; +import WithFeedback from 'consul-ui/mixins/with-feedback'; +import WithKeyUtils from 'consul-ui/mixins/with-key-utils'; import transitionToNearestParent from 'consul-ui/utils/transitionToNearestParent'; import ascend from 'consul-ui/utils/ascend'; -export default Route.extend({ +export default Route.extend(WithFeedback, WithKeyUtils, { repo: service('kv'), sessionRepo: service('session'), model: function(params) { diff --git a/app/routes/dc/kv/index.js b/app/routes/dc/kv/index.js index b532b5280a17..535943da8be8 100644 --- a/app/routes/dc/kv/index.js +++ b/app/routes/dc/kv/index.js @@ -1,6 +1,7 @@ import Route from '@ember/routing/route'; -export default Route.extend({ +import WithKeyUtils from 'consul-ui/mixins/with-key-utils'; +export default Route.extend(WithKeyUtils, { beforeModel: function() { this.transitionTo('dc.kv.show', this.rootKey); }, diff --git a/app/routes/dc/kv/show.js b/app/routes/dc/kv/show.js index 156d250a0fb1..1ab277600c04 100644 --- a/app/routes/dc/kv/show.js +++ b/app/routes/dc/kv/show.js @@ -1,6 +1,8 @@ import Route from '@ember/routing/route'; import { inject as service } from '@ember/service'; import { hash } from 'rsvp'; +import WithFeedback from 'consul-ui/mixins/with-feedback'; +import WithKeyUtils from 'consul-ui/mixins/with-key-utils'; import rootKey from 'consul-ui/utils/rootKey'; import transitionToNearestParent from 'consul-ui/utils/transitionToNearestParent'; import ascend from 'consul-ui/utils/ascend'; @@ -14,7 +16,7 @@ const prefix = function(key, prefix) { } return key; }; -export default Route.extend({ +export default Route.extend(WithFeedback, WithKeyUtils, { repo: service('kv'), model: function(params) { const repo = this.get('repo'); diff --git a/tests/unit/initializers/base-route-test.js b/tests/unit/initializers/base-route-test.js deleted file mode 100644 index 1a734e72d7bc..000000000000 --- a/tests/unit/initializers/base-route-test.js +++ /dev/null @@ -1,26 +0,0 @@ -import Application from '@ember/application'; -import { run } from '@ember/runloop'; - -import { initialize } from 'consul-ui/initializers/base-route'; -import { module, test } from 'qunit'; -import destroyApp from '../../helpers/destroy-app'; - -module('Unit | Initializer | base route', { - beforeEach() { - run(() => { - this.application = Application.create(); - this.application.deferReadiness(); - }); - }, - afterEach() { - destroyApp(this.application); - }, -}); - -// Replace this with your real tests. -test('it works', function(assert) { - initialize(this.application); - - // you would normally confirm the results of the initializer here - assert.ok(true); -}); diff --git a/tests/unit/mixins/with-feedback-test.js b/tests/unit/mixins/with-feedback-test.js new file mode 100644 index 000000000000..c7119dda6e6b --- /dev/null +++ b/tests/unit/mixins/with-feedback-test.js @@ -0,0 +1,12 @@ +import EmberObject from '@ember/object'; +import WithFeedbackMixin from 'consul-ui/mixins/with-feedback'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | with feedback'); + +// Replace this with your real tests. +test('it works', function(assert) { + let WithFeedbackObject = EmberObject.extend(WithFeedbackMixin); + let subject = WithFeedbackObject.create(); + assert.ok(subject); +}); diff --git a/tests/unit/mixins/with-key-utils-test.js b/tests/unit/mixins/with-key-utils-test.js new file mode 100644 index 000000000000..628cf033402c --- /dev/null +++ b/tests/unit/mixins/with-key-utils-test.js @@ -0,0 +1,12 @@ +import EmberObject from '@ember/object'; +import WithKeyUtilsMixin from 'consul-ui/mixins/with-key-utils'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | with key utils'); + +// Replace this with your real tests. +test('it works', function(assert) { + let WithKeyUtilsObject = EmberObject.extend(WithKeyUtilsMixin); + let subject = WithKeyUtilsObject.create(); + assert.ok(subject); +});