Fix power button actions
This commit is contained in:
parent
8385ec7feb
commit
5cb57af193
2 changed files with 11 additions and 7 deletions
|
@ -1,12 +1,15 @@
|
|||
import Vue from 'vue';
|
||||
import { mapState } from 'vuex';
|
||||
import {mapState} from 'vuex';
|
||||
import Status from '../../../helpers/statuses';
|
||||
import {Socketio} from "@/mixins/socketio";
|
||||
|
||||
export default Vue.component('power-buttons', {
|
||||
computed: {
|
||||
...mapState('socket', ['connected', 'status']),
|
||||
},
|
||||
|
||||
mixins: [Socketio],
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
statuses: Status,
|
||||
|
@ -15,7 +18,7 @@ export default Vue.component('power-buttons', {
|
|||
|
||||
methods: {
|
||||
sendPowerAction: function (action: string) {
|
||||
// this.$socket().instance().emit('set status', action)
|
||||
this.$socket().instance().emit('set status', action)
|
||||
},
|
||||
},
|
||||
|
||||
|
@ -28,9 +31,9 @@ export default Vue.component('power-buttons', {
|
|||
v-on:click.prevent="sendPowerAction('start')"
|
||||
>Start</button>
|
||||
<div v-else>
|
||||
<button class="btn btn-red-500 uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('stop')">Stop</button>
|
||||
<button class="btn btn-red uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('stop')">Stop</button>
|
||||
<button class="btn btn-secondary uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('restart')">Restart</button>
|
||||
<button class="btn btn-secondary uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('kill')">Kill</button>
|
||||
<button class="btn btn-secondary btn-red uppercase text-xs px-4 py-2" v-on:click.prevent="sendPowerAction('kill')">Kill</button>
|
||||
</div>
|
||||
</transition>
|
||||
</div>
|
||||
|
|
|
@ -15,7 +15,7 @@ export default new class SocketEmitter {
|
|||
/**
|
||||
* Add an event listener for socket events.
|
||||
*/
|
||||
addListener(event: string | number, callback: (data: any) => void, vm: ComponentOptions<Vue>) {
|
||||
addListener(event: string | number, callback: (...data: any[]) => void, vm: ComponentOptions<Vue>) {
|
||||
if (!isFunction(callback)) {
|
||||
return;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ export default new class SocketEmitter {
|
|||
/**
|
||||
* Remove an event listener for socket events based on the context passed through.
|
||||
*/
|
||||
removeListener(event: string | number, callback: (data: any) => void, vm: ComponentOptions<Vue>) {
|
||||
removeListener(event: string | number, callback: (...data: any[]) => void, vm: ComponentOptions<Vue>) {
|
||||
if (!isFunction(callback) || !this.listeners.has(event)) {
|
||||
return;
|
||||
}
|
||||
|
@ -53,7 +53,8 @@ export default new class SocketEmitter {
|
|||
*/
|
||||
emit(event: string | number, ...args: any) {
|
||||
(this.listeners.get(event) || []).forEach((listener) => {
|
||||
listener.callback.call(listener.vm, args);
|
||||
// @ts-ignore
|
||||
listener.callback.call(listener.vm, ...args);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue