open-consul/ui-v2/app/services/feedback.js
John Cowen cec146d2a3
Session Delete confirmation button and KV console error message (#4109)
Fix session invalidation in table confirmation dialog, plus console error message when deleting deep KV's
2018-05-11 16:25:35 +01:00

36 lines
949 B
JavaScript

import Service from '@ember/service';
import { inject as service } from '@ember/service';
import { get } 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);
return handle()
.then(() => {
get(this, 'flashMessages').add({
type: 'success',
message: success,
});
})
.catch(e => {
if (e.name === 'TransitionAborted') {
get(this, 'flashMessages').add({
type: 'success',
message: success,
});
} else {
get(this, 'flashMessages').add({
type: 'error',
message: error,
});
}
})
.finally(function() {
controller.set('isLoading', false);
});
},
});