2019-06-17 17:15:27 +02:00
|
|
|
import Vue from 'vue';
|
2019-12-03 11:29:51 +01:00
|
|
|
import { ColorModifiers } from 'buefy/types/helpers';
|
2020-03-05 19:32:34 +01:00
|
|
|
import { Route, RawLocation } from 'vue-router';
|
2019-06-17 17:15:27 +02:00
|
|
|
|
|
|
|
declare module 'vue/types/vue' {
|
|
|
|
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?(
|
|
|
|
to: Route,
|
|
|
|
from: Route,
|
|
|
|
next: (to?: RawLocation | false | ((vm: Vue) => void)) => void,
|
|
|
|
): void;
|
|
|
|
|
|
|
|
beforeRouteLeave?(
|
|
|
|
to: Route,
|
|
|
|
from: Route,
|
|
|
|
next: (to?: RawLocation | false | ((vm: Vue) => void)) => void,
|
|
|
|
): void;
|
|
|
|
|
|
|
|
beforeRouteUpdate?(
|
|
|
|
to: Route,
|
|
|
|
from: Route,
|
|
|
|
next: (to?: RawLocation | false | ((vm: Vue) => void)) => void,
|
|
|
|
): void;
|
2019-06-17 17:15:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Notifier {
|
|
|
|
private readonly vue: typeof Vue;
|
|
|
|
|
|
|
|
constructor(vue: typeof Vue) {
|
|
|
|
this.vue = vue;
|
|
|
|
}
|
|
|
|
|
|
|
|
success(message: string) {
|
2019-12-03 11:29:51 +01:00
|
|
|
this.notification(message, 'is-success');
|
2019-06-17 17:15:27 +02:00
|
|
|
}
|
2019-09-11 09:59:01 +02:00
|
|
|
|
|
|
|
error(message: string) {
|
2019-12-03 11:29:51 +01:00
|
|
|
this.notification(message, 'is-danger');
|
|
|
|
}
|
|
|
|
|
|
|
|
info(message: string) {
|
|
|
|
this.notification(message, 'is-info');
|
|
|
|
}
|
|
|
|
|
|
|
|
private notification(message: string, type: ColorModifiers) {
|
2019-09-11 09:59:01 +02:00
|
|
|
this.vue.prototype.$buefy.notification.open({
|
|
|
|
message,
|
|
|
|
duration: 5000,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable
|
|
|
|
export function NotifierPlugin(vue: typeof Vue, options?: any): void {
|
|
|
|
vue.prototype.$notifier = new Notifier(vue);
|
|
|
|
}
|