Change flash mixin

This commit is contained in:
Dane Everitt 2018-12-29 19:24:09 -08:00
parent 96468ab4b3
commit f7ba30fbbe
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
4 changed files with 59 additions and 64 deletions

View File

@ -9,7 +9,7 @@ import {Ziggy} from './helpers/ziggy';
// @ts-ignore // @ts-ignore
import Locales from './../../../resources/lang/locales'; import Locales from './../../../resources/lang/locales';
import {flash} from './mixins/flash'; import {FlashMixin} from './mixins/flash';
import store from './store/index'; import store from './store/index';
import router from './router'; import router from './router';
@ -30,7 +30,7 @@ Vue.use(VueI18n);
const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default; const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default;
Vue.mixin({methods: {route}}); Vue.mixin({methods: {route}});
Vue.mixin(flash); Vue.mixin(FlashMixin);
const i18n = new VueI18n({ const i18n = new VueI18n({
locale: 'en', locale: 'en',

View File

@ -1,9 +1,22 @@
export const flash = { import {ComponentOptions} from "vue";
methods: { import {Vue} from "vue/types/vue";
/**
* Flash a message to the event stream in the browser. export interface FlashInterface {
*/ flash(message: string, title: string, severity: string): void;
flash: function (message: string, title: string, severity: string = 'info'): void {
clear(): void,
success(message: string): void,
info(message: string): void,
warning(message: string): void,
error(message: string): void,
}
class Flash implements FlashInterface {
flash(message: string, title: string, severity: string = 'info'): void {
severity = severity || 'info'; severity = severity || 'info';
if (['danger', 'fatal', 'error'].includes(severity)) { if (['danger', 'fatal', 'error'].includes(severity)) {
severity = 'error'; severity = 'error';
@ -11,42 +24,34 @@ export const flash = {
// @ts-ignore // @ts-ignore
window.events.$emit('flash', {message, title, severity}); window.events.$emit('flash', {message, title, severity});
}, }
/** clear(): void {
* Clear all of the flash messages from the screen.
*/
clearFlashes: function (): void {
// @ts-ignore // @ts-ignore
window.events.$emit('clear-flashes'); window.events.$emit('clear-flashes');
},
/**
* Helper function to flash a normal success message to the user.
*/
success: function (message: string): void {
this.flash(message, 'Success', 'success');
},
/**
* Helper function to flash a normal info message to the user.
*/
info: function (message: string): void {
this.flash(message, 'Info', 'info');
},
/**
* Helper function to flash a normal warning message to the user.
*/
warning: function (message: string): void {
this.flash(message, 'Warning', 'warning');
},
/**
* Helper function to flash a normal error message to the user.
*/
error: function (message: string): void {
this.flash(message, 'Error', 'danger');
},
} }
success(message: string): void {
this.flash(message, 'Success', 'success');
}
info(message: string): void {
this.flash(message, 'Info', 'info');
}
warning(message: string): void {
this.flash(message, 'Warning', 'warning');
}
error(message: string): void {
this.flash(message, 'Error', 'error');
}
}
export const FlashMixin: ComponentOptions<Vue> = {
methods: {
'$flash': function () {
return new Flash();
}
},
}; };

View File

@ -1,5 +1,6 @@
import Vue from "vue"; import Vue from "vue";
import {Store} from "vuex"; import {Store} from "vuex";
import {FlashInterface} from "./mixins/flash";
declare module 'vue/types/options' { declare module 'vue/types/options' {
interface ComponentOptions<V extends Vue> { interface ComponentOptions<V extends Vue> {
@ -15,5 +16,6 @@ declare module 'vue/types/options' {
declare module 'vue/types/vue' { declare module 'vue/types/vue' {
interface Vue { interface Vue {
$store: Store<any>, $store: Store<any>,
$flash: FlashInterface
} }
} }

View File

@ -1,27 +1,15 @@
{ {
"compilerOptions": { "compilerOptions": {
"target": "esnext", "target": "es6",
"module": "esnext",
"strict": true, "strict": true,
"noImplicitReturns": true,
"moduleResolution": "node", "moduleResolution": "node",
"lib": [ "lib": [
"esnext", "es2016",
"dom", "dom"
"dom.iterable",
"scripthost"
],
"baseUrl": ".",
"paths": {
"@/*": [
"resources/*"
] ]
}
}, },
"include": [ "include": [
"./resources/assets/**/*.ts", "./resources/assets/scripts/**/*"
"./resources/assets/**/*.vue"
],
"exclude": [
"node_modules"
] ]
} }