Skip to content

Commit

Permalink
Merge pull request #11 from hashicorp/feature/initializers-mixins
Browse files Browse the repository at this point in the history
Move away from using `reopen` to using Mixins
  • Loading branch information
johncowen authored Apr 4, 2018
2 parents cba08ab + 0fdc560 commit 5d023c0
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 70 deletions.
39 changes: 0 additions & 39 deletions app/initializers/base-route.js

This file was deleted.

12 changes: 12 additions & 0 deletions app/mixins/with-feedback.js
Original file line number Diff line number Diff line change
@@ -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),
});
},
});
17 changes: 17 additions & 0 deletions app/mixins/with-key-utils.js
Original file line number Diff line number Diff line change
@@ -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);
}
},
},
});
3 changes: 2 additions & 1 deletion app/routes/dc/acls.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
3 changes: 2 additions & 1 deletion app/routes/dc/acls/show.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 3 additions & 1 deletion app/routes/dc/kv/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion app/routes/dc/kv/index.js
Original file line number Diff line number Diff line change
@@ -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);
},
Expand Down
4 changes: 3 additions & 1 deletion app/routes/dc/kv/show.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down
26 changes: 0 additions & 26 deletions tests/unit/initializers/base-route-test.js

This file was deleted.

12 changes: 12 additions & 0 deletions tests/unit/mixins/with-feedback-test.js
Original file line number Diff line number Diff line change
@@ -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);
});
12 changes: 12 additions & 0 deletions tests/unit/mixins/with-key-utils-test.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit 5d023c0

Please sign in to comment.