Skip to content

Commit f7ba30f

Browse files
committed
Change flash mixin
1 parent 96468ab commit f7ba30f

File tree

4 files changed

+65
-70
lines changed

4 files changed

+65
-70
lines changed

resources/assets/scripts/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {Ziggy} from './helpers/ziggy';
99
// @ts-ignore
1010
import Locales from './../../../resources/lang/locales';
1111

12-
import {flash} from './mixins/flash';
12+
import {FlashMixin} from './mixins/flash';
1313
import store from './store/index';
1414
import router from './router';
1515

@@ -30,7 +30,7 @@ Vue.use(VueI18n);
3030
const route = require('./../../../vendor/tightenco/ziggy/src/js/route').default;
3131

3232
Vue.mixin({methods: {route}});
33-
Vue.mixin(flash);
33+
Vue.mixin(FlashMixin);
3434

3535
const i18n = new VueI18n({
3636
locale: 'en',
Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,57 @@
1-
export const flash = {
2-
methods: {
3-
/**
4-
* Flash a message to the event stream in the browser.
5-
*/
6-
flash: function (message: string, title: string, severity: string = 'info'): void {
7-
severity = severity || 'info';
8-
if (['danger', 'fatal', 'error'].includes(severity)) {
9-
severity = 'error';
10-
}
11-
12-
// @ts-ignore
13-
window.events.$emit('flash', { message, title, severity });
14-
},
15-
16-
/**
17-
* Clear all of the flash messages from the screen.
18-
*/
19-
clearFlashes: function (): void {
20-
// @ts-ignore
21-
window.events.$emit('clear-flashes');
22-
},
23-
24-
/**
25-
* Helper function to flash a normal success message to the user.
26-
*/
27-
success: function (message: string): void {
28-
this.flash(message, 'Success', 'success');
29-
},
30-
31-
/**
32-
* Helper function to flash a normal info message to the user.
33-
*/
34-
info: function (message: string): void {
35-
this.flash(message, 'Info', 'info');
36-
},
37-
38-
/**
39-
* Helper function to flash a normal warning message to the user.
40-
*/
41-
warning: function (message: string): void {
42-
this.flash(message, 'Warning', 'warning');
43-
},
44-
45-
/**
46-
* Helper function to flash a normal error message to the user.
47-
*/
48-
error: function (message: string): void {
49-
this.flash(message, 'Error', 'danger');
50-
},
1+
import {ComponentOptions} from "vue";
2+
import {Vue} from "vue/types/vue";
3+
4+
export interface FlashInterface {
5+
flash(message: string, title: string, severity: string): void;
6+
7+
clear(): void,
8+
9+
success(message: string): void,
10+
11+
info(message: string): void,
12+
13+
warning(message: string): void,
14+
15+
error(message: string): void,
16+
}
17+
18+
class Flash implements FlashInterface {
19+
flash(message: string, title: string, severity: string = 'info'): void {
20+
severity = severity || 'info';
21+
if (['danger', 'fatal', 'error'].includes(severity)) {
22+
severity = 'error';
23+
}
24+
25+
// @ts-ignore
26+
window.events.$emit('flash', {message, title, severity});
27+
}
28+
29+
clear(): void {
30+
// @ts-ignore
31+
window.events.$emit('clear-flashes');
5132
}
33+
34+
success(message: string): void {
35+
this.flash(message, 'Success', 'success');
36+
}
37+
38+
info(message: string): void {
39+
this.flash(message, 'Info', 'info');
40+
}
41+
42+
warning(message: string): void {
43+
this.flash(message, 'Warning', 'warning');
44+
}
45+
46+
error(message: string): void {
47+
this.flash(message, 'Error', 'error');
48+
}
49+
}
50+
51+
export const FlashMixin: ComponentOptions<Vue> = {
52+
methods: {
53+
'$flash': function () {
54+
return new Flash();
55+
}
56+
},
5257
};

resources/assets/scripts/pterodactyl-shims.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Vue from "vue";
22
import {Store} from "vuex";
3+
import {FlashInterface} from "./mixins/flash";
34

45
declare module 'vue/types/options' {
56
interface ComponentOptions<V extends Vue> {
@@ -15,5 +16,6 @@ declare module 'vue/types/options' {
1516
declare module 'vue/types/vue' {
1617
interface Vue {
1718
$store: Store<any>,
19+
$flash: FlashInterface
1820
}
1921
}

tsconfig.json

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,15 @@
11
{
22
"compilerOptions": {
3-
"target": "esnext",
4-
"module": "esnext",
3+
"target": "es6",
54
"strict": true,
5+
"noImplicitReturns": true,
66
"moduleResolution": "node",
77
"lib": [
8-
"esnext",
9-
"dom",
10-
"dom.iterable",
11-
"scripthost"
12-
],
13-
"baseUrl": ".",
14-
"paths": {
15-
"@/*": [
16-
"resources/*"
17-
]
18-
}
8+
"es2016",
9+
"dom"
10+
]
1911
},
2012
"include": [
21-
"./resources/assets/**/*.ts",
22-
"./resources/assets/**/*.vue"
23-
],
24-
"exclude": [
25-
"node_modules"
13+
"./resources/assets/scripts/**/*"
2614
]
2715
}

0 commit comments

Comments
 (0)