2020-10-13 20:39:59 +02:00
|
|
|
/* eslint-disable no-shadow */
|
|
|
|
import VueInstance from "vue";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { ColorModifiers } from "buefy/types/helpers.d";
|
|
|
|
import { Route, RawLocation } from "vue-router";
|
2019-06-17 17:15:27 +02:00
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
declare module "vue/types/vue" {
|
2019-06-17 17:15:27 +02:00
|
|
|
interface Vue {
|
|
|
|
$notifier: {
|
|
|
|
success: (message: string) => void;
|
2019-09-11 09:59:01 +02:00
|
|
|
error: (message: string) => void;
|
2019-12-03 11:29:51 +01:00
|
|
|
info: (message: string) => void;
|
2019-06-17 17:15:27 +02:00
|
|
|
};
|
2020-03-05 19:32:34 +01:00
|
|
|
beforeRouteEnter?(
|
2020-02-18 08:57:00 +01:00
|
|
|
to: Route,
|
|
|
|
from: Route,
|
2020-10-13 20:39:59 +02:00
|
|
|
next: (to?: RawLocation | false | ((vm: VueInstance) => void)) => void
|
2020-03-05 19:32:34 +01:00
|
|
|
): void;
|
|
|
|
|
|
|
|
beforeRouteLeave?(
|
2020-02-18 08:57:00 +01:00
|
|
|
to: Route,
|
|
|
|
from: Route,
|
2020-10-13 20:39:59 +02:00
|
|
|
next: (to?: RawLocation | false | ((vm: VueInstance) => void)) => void
|
2020-03-05 19:32:34 +01:00
|
|
|
): void;
|
|
|
|
|
|
|
|
beforeRouteUpdate?(
|
2020-02-18 08:57:00 +01:00
|
|
|
to: Route,
|
|
|
|
from: Route,
|
2020-10-13 20:39:59 +02:00
|
|
|
next: (to?: RawLocation | false | ((vm: VueInstance) => void)) => void
|
2020-03-05 19:32:34 +01:00
|
|
|
): void;
|
2019-06-17 17:15:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Notifier {
|
2020-10-13 20:39:59 +02:00
|
|
|
private readonly vue: typeof VueInstance;
|
2019-06-17 17:15:27 +02:00
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
constructor(vue: typeof VueInstance) {
|
2019-06-17 17:15:27 +02:00
|
|
|
this.vue = vue;
|
|
|
|
}
|
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
success(message: string): void {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.notification(message, "is-success");
|
2019-06-17 17:15:27 +02:00
|
|
|
}
|
2019-09-11 09:59:01 +02:00
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
error(message: string): void {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.notification(message, "is-danger");
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|
|
|
|
|
2020-10-13 20:39:59 +02:00
|
|
|
info(message: string): void {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.notification(message, "is-info");
|
2019-12-03 11:29:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private notification(message: string, type: ColorModifiers) {
|
2019-09-11 09:59:01 +02:00
|
|
|
this.vue.prototype.$buefy.notification.open({
|
|
|
|
message,
|
|
|
|
duration: 5000,
|
2020-02-18 08:57:00 +01:00
|
|
|
position: "is-bottom-right",
|
2019-12-03 11:29:51 +01:00
|
|
|
type,
|
2019-09-11 09:59:01 +02:00
|
|
|
hasIcon: true,
|
|
|
|
});
|
|
|
|
}
|
2019-06-17 17:15:27 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
/* eslint-disable */
|
2020-10-13 20:39:59 +02:00
|
|
|
export function NotifierPlugin(vue: typeof VueInstance): void {
|
2019-06-17 17:15:27 +02:00
|
|
|
vue.prototype.$notifier = new Notifier(vue);
|
|
|
|
}
|