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';
export default Mixin.create({
feedback: service('feedback'),
_feedback: service('feedback'),
init: function() {
this._super(...arguments);
const feedback = get(this, '_feedback');
const route = this;
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 { inject as service } from '@ember/service';
import { get } from '@ember/object';
import Service, { inject as service } from '@ember/service';
import { get, set } from '@ember/object';
export default Service.extend({
// TODO: Why can't I name this `notify`?
flashMessages: service('flashMessages'),
execute: function(handle, success, error) {
const controller = this.controller;
controller.set('isLoading', true);
notify: service('flashMessages'),
logger: service('logger'),
execute: function(handle, success, error, controller) {
set(controller, 'isLoading', true);
const notify = get(this, 'notify');
return handle()
.then(() => {
get(this, 'flashMessages').add({
notify.add({
type: 'success',
message: success,
});
})
.catch(e => {
get(this, 'logger').execute(e);
if (e.name === 'TransitionAborted') {
get(this, 'flashMessages').add({
notify.add({
type: 'success',
message: success,
});
} else {
get(this, 'flashMessages').add({
notify.add({
type: 'error',
message: error,
});
}
})
.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', {
// 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) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/acls/edit', 'Unit | Route | dc/acls/edit', {
// 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) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/acls/index', 'Unit | Route | dc/acls/index', {
// 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) {

View File

@ -2,7 +2,7 @@ import { moduleFor, skip } from 'ember-qunit';
moduleFor('route:dc/kv/create', 'Unit | Route | dc/kv/create', {
// 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) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/kv/edit', 'Unit | Route | dc/kv/edit', {
// 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) {

View File

@ -2,7 +2,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/kv/index', 'Unit | Route | dc/kv/index', {
// 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) {

View File

@ -2,7 +2,7 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/kv/root-create', 'Unit | Route | dc/kv/root create', {
// 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) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:dc/nodes/show', 'Unit | Route | dc/nodes/show', {
// 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) {

View File

@ -2,7 +2,13 @@ import { moduleFor, test } from 'ember-qunit';
moduleFor('route:settings', 'Unit | Route | settings', {
// 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) {

View File

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