WIP: Logger

This commit is contained in:
John Cowen 2018-05-22 16:11:30 +01:00 committed by Jack Pearkes
parent 6b1e0a3003
commit c3e92a236f
13 changed files with 69 additions and 24 deletions

View File

@ -3,11 +3,15 @@ import { inject as service } from '@ember/service';
import { get, set } from '@ember/object'; import { get, set } from '@ember/object';
export default Mixin.create({ export default Mixin.create({
feedback: service('feedback'), _feedback: service('feedback'),
init: function() { init: function() {
this._super(...arguments); this._super(...arguments);
const feedback = get(this, '_feedback');
const route = this;
set(this, 'feedback', { set(this, 'feedback', {
execute: get(this, 'feedback').execute.bind(this), execute: function() {
feedback.execute(...[...arguments, route.controller]);
},
}); });
}, },
}); });

View File

@ -1,35 +1,35 @@
import Service from '@ember/service'; import Service, { inject as service } from '@ember/service';
import { inject as service } from '@ember/service'; import { get, set } from '@ember/object';
import { get } from '@ember/object';
export default Service.extend({ export default Service.extend({
// TODO: Why can't I name this `notify`? notify: service('flashMessages'),
flashMessages: service('flashMessages'), logger: service('logger'),
execute: function(handle, success, error) { execute: function(handle, success, error, controller) {
const controller = this.controller; set(controller, 'isLoading', true);
controller.set('isLoading', true); const notify = get(this, 'notify');
return handle() return handle()
.then(() => { .then(() => {
get(this, 'flashMessages').add({ notify.add({
type: 'success', type: 'success',
message: success, message: success,
}); });
}) })
.catch(e => { .catch(e => {
get(this, 'logger').execute(e);
if (e.name === 'TransitionAborted') { if (e.name === 'TransitionAborted') {
get(this, 'flashMessages').add({ notify.add({
type: 'success', type: 'success',
message: success, message: success,
}); });
} else { } else {
get(this, 'flashMessages').add({ notify.add({
type: 'error', type: 'error',
message: error, message: error,
}); });
} }
}) })
.finally(function() { .finally(function() {
controller.set('isLoading', false); set(controller, 'isLoading', false);
}); });
}, },
}); });

View File

@ -0,0 +1,5 @@
import Service from '@ember/service';
export default Service.extend({
execute: function(obj) {},
});

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/acls/create', 'Unit | Route | dc/acls/create', { moduleFor('route:dc/acls/create', 'Unit | Route | dc/acls/create', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:acls', 'service:feedback', 'service:settings', 'service:flashMessages'], needs: [
'service:acls',
'service:feedback',
'service:logger',
'service:settings',
'service:flashMessages',
],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/acls/edit', 'Unit | Route | dc/acls/edit', { moduleFor('route:dc/acls/edit', 'Unit | Route | dc/acls/edit', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:acls', 'service:settings', 'service:feedback', 'service:flashMessages'], needs: [
'service:acls',
'service:settings',
'service:logger',
'service:feedback',
'service:flashMessages',
],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/acls/index', 'Unit | Route | dc/acls/index', { moduleFor('route:dc/acls/index', 'Unit | Route | dc/acls/index', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:acls', 'service:feedback', 'service:settings', 'service:flashMessages'], needs: [
'service:acls',
'service:feedback',
'service:logger',
'service:settings',
'service:flashMessages',
],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,7 @@ import { moduleFor, skip } from 'ember-qunit';
moduleFor('route:dc/kv/create', 'Unit | Route | dc/kv/create', { moduleFor('route:dc/kv/create', 'Unit | Route | dc/kv/create', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:kv', 'service:feedback'] needs: ['service:kv', 'service:feedback', 'service:logger'],
}); });
skip('it exists', function(assert) { skip('it exists', function(assert) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/kv/edit', 'Unit | Route | dc/kv/edit', { moduleFor('route:dc/kv/edit', 'Unit | Route | dc/kv/edit', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:kv', 'service:session', 'service:feedback', 'service:flashMessages'], needs: [
'service:kv',
'service:session',
'service:feedback',
'service:logger',
'service:flashMessages',
],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/kv/index', 'Unit | Route | dc/kv/index', { moduleFor('route:dc/kv/index', 'Unit | Route | dc/kv/index', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:kv', 'service:feedback', 'service:flashMessages'], needs: ['service:kv', 'service:feedback', 'service:logger', 'service:flashMessages'],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/kv/root-create', 'Unit | Route | dc/kv/root create', { moduleFor('route:dc/kv/root-create', 'Unit | Route | dc/kv/root create', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:kv', 'service:feedback', 'service:flashMessages'], needs: ['service:kv', 'service:feedback', 'service:logger', 'service:flashMessages'],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/nodes/show', 'Unit | Route | dc/nodes/show', { moduleFor('route:dc/nodes/show', 'Unit | Route | dc/nodes/show', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:nodes', 'service:session', 'service:feedback', 'service:flashMessages'], needs: [
'service:nodes',
'service:session',
'service:feedback',
'service:logger',
'service:flashMessages',
],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:settings', 'Unit | Route | settings', { moduleFor('route:settings', 'Unit | Route | settings', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:dc', 'service:settings', 'service:feedback', 'service:flashMessages'], needs: [
'service:dc',
'service:settings',
'service:logger',
'service:feedback',
'service:flashMessages',
],
}); });
test('it exists', function(assert) { test('it exists', function(assert) {

View File

@ -2,7 +2,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('service:feedback', 'Unit | Service | feedback', { moduleFor('service:feedback', 'Unit | Service | feedback', {
// Specify the other units that are required for this test. // Specify the other units that are required for this test.
needs: ['service:flashMessages'], needs: ['service:logger', 'service:flashMessages'],
}); });
// Replace this with your real tests. // Replace this with your real tests.