John Cowen 5c0ec13fb9
ui: Run Ember native class code mod (#9093)
* ui: Apply native class codemod to all services

* ui: Apply native class codemod to routes

* ui: Apply native class codemod to controllers

* Fix up ember proxy `content` issue

* Add a CreateTime on policy creation

* Minor formatting

* Convert child based saving to use ec instead of custom approach

* Remove custom event source repo wrapping initializer

* Repos here are no longer proxy objects revert to using them normally

* Remove areas of code that were used to set up source backed repos
2020-11-09 09:25:35 +00:00

67 lines
1.9 KiB
JavaScript

import Service, { inject as service } from '@ember/service';
import callableType from 'consul-ui/utils/callable-type';
const TYPE_SUCCESS = 'success';
const TYPE_ERROR = 'error';
const defaultStatus = function(type, obj) {
return type;
};
const notificationDefaults = function() {
return {
timeout: 6000,
extendedTimeout: 300,
};
};
export default class FeedbackService extends Service {
@service('flashMessages')
notify;
@service('logger')
logger;
execute(handle, action, status = defaultStatus, controller) {
const getAction = callableType(action);
const getStatus = callableType(status);
const notify = this.notify;
return (
handle()
//TODO: pass this through to getAction..
.then(item => {
// returning exactly `false` for a feedback action means even though
// its successful, please skip this notification and don't display it
if (item !== false) {
notify.clearMessages();
// TODO right now the majority of `item` is a Transition
// but you can resolve an object
notify.add({
...notificationDefaults(),
type: getStatus(TYPE_SUCCESS),
// here..
action: getAction(),
item: item,
});
}
})
.catch(e => {
notify.clearMessages();
this.logger.execute(e);
if (e.name === 'TransitionAborted') {
notify.add({
...notificationDefaults(),
type: getStatus(TYPE_SUCCESS),
// and here
action: getAction(),
});
} else {
notify.add({
...notificationDefaults(),
type: getStatus(TYPE_ERROR, e),
action: getAction(),
error: e,
});
}
})
);
}
}