2020-10-13 18:39:59 +00:00
|
|
|
/* eslint-disable no-shadow */
|
|
|
|
import VueInstance from "vue";
|
2020-02-18 07:57:00 +00:00
|
|
|
import { ColorModifiers } from "buefy/types/helpers.d";
|
2021-11-18 08:49:00 +00:00
|
|
|
import { App } from "vue";
|
2019-06-17 15:15:27 +00:00
|
|
|
|
2021-11-18 08:49:00 +00:00
|
|
|
declare module "vue" {
|
2019-06-17 15:15:27 +00:00
|
|
|
interface Vue {
|
|
|
|
$notifier: {
|
|
|
|
success: (message: string) => void;
|
2019-09-11 07:59:01 +00:00
|
|
|
error: (message: string) => void;
|
2019-12-03 10:29:51 +00:00
|
|
|
info: (message: string) => void;
|
2019-06-17 15:15:27 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Notifier {
|
2020-10-13 18:39:59 +00:00
|
|
|
private readonly vue: typeof VueInstance;
|
2019-06-17 15:15:27 +00:00
|
|
|
|
2021-11-18 08:49:00 +00:00
|
|
|
constructor(vue: App) {
|
2019-06-17 15:15:27 +00:00
|
|
|
this.vue = vue;
|
|
|
|
}
|
|
|
|
|
2020-10-13 18:39:59 +00:00
|
|
|
success(message: string): void {
|
2020-02-18 07:57:00 +00:00
|
|
|
this.notification(message, "is-success");
|
2019-06-17 15:15:27 +00:00
|
|
|
}
|
2019-09-11 07:59:01 +00:00
|
|
|
|
2020-10-13 18:39:59 +00:00
|
|
|
error(message: string): void {
|
2020-02-18 07:57:00 +00:00
|
|
|
this.notification(message, "is-danger");
|
2019-12-03 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 18:39:59 +00:00
|
|
|
info(message: string): void {
|
2020-02-18 07:57:00 +00:00
|
|
|
this.notification(message, "is-info");
|
2019-12-03 10:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private notification(message: string, type: ColorModifiers) {
|
2021-11-18 08:49:00 +00:00
|
|
|
this.vue.config.globalProperties.$buefy.notification.open({
|
2019-09-11 07:59:01 +00:00
|
|
|
message,
|
|
|
|
duration: 5000,
|
2020-02-18 07:57:00 +00:00
|
|
|
position: "is-bottom-right",
|
2019-12-03 10:29:51 +00:00
|
|
|
type,
|
2019-09-11 07:59:01 +00:00
|
|
|
hasIcon: true,
|
|
|
|
});
|
|
|
|
}
|
2019-06-17 15:15:27 +00:00
|
|
|
}
|
|
|
|
|
2020-02-18 07:57:00 +00:00
|
|
|
/* eslint-disable */
|
2021-11-18 08:49:00 +00:00
|
|
|
export const NotifierPlugin = {
|
|
|
|
install(app: App) {
|
|
|
|
app.config.globalProperties.$notifier = new Notifier(app);
|
|
|
|
},
|
|
|
|
};
|