2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2021-11-24 18:14:07 +00:00
|
|
|
import Modifier from 'ember-modifier';
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
|
|
|
export default class NotificationModifier extends Modifier {
|
|
|
|
@service('flashMessages') notify;
|
|
|
|
|
|
|
|
didInstall() {
|
|
|
|
this.element.setAttribute('role', 'alert');
|
|
|
|
this.element.dataset['notification'] = null;
|
|
|
|
const options = {
|
|
|
|
timeout: 6000,
|
|
|
|
extendedTimeout: 300,
|
|
|
|
...this.args.named,
|
|
|
|
};
|
|
|
|
options.dom = this.element.outerHTML;
|
|
|
|
this.element.remove();
|
|
|
|
this.notify.clearMessages();
|
|
|
|
if (typeof options.after === 'function') {
|
2022-09-15 08:43:17 +00:00
|
|
|
Promise.resolve()
|
|
|
|
.then((_) => options.after())
|
|
|
|
.catch((e) => {
|
2021-11-24 18:14:07 +00:00
|
|
|
if (e.name !== 'TransitionAborted') {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
})
|
2022-09-15 08:43:17 +00:00
|
|
|
.then((res) => {
|
2021-11-24 18:14:07 +00:00
|
|
|
this.notify.add(options);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
this.notify.add(options);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
willDestroy() {
|
2022-09-15 08:43:17 +00:00
|
|
|
if (this.args.named.sticky) {
|
2021-11-24 18:14:07 +00:00
|
|
|
this.notify.clearMessages();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|