From 1983a5076084e38a614dbccb5e45222c6417baf7 Mon Sep 17 00:00:00 2001 From: m1k1o Date: Mon, 8 Mar 2021 21:52:53 +0100 Subject: [PATCH] add actions. --- client/src/components/RoomsList.vue | 104 ++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/client/src/components/RoomsList.vue b/client/src/components/RoomsList.vue index 479662b..abd5072 100644 --- a/client/src/components/RoomsList.vue +++ b/client/src/components/RoomsList.vue @@ -5,6 +5,7 @@ class="elevation-1" :loading="loading" loading-text="Loading... Please wait" + hide-default-footer > @@ -30,6 +39,7 @@ import { Vue, Component, Prop } from 'vue-property-decorator' export default class RoomsList extends Vue { @Prop(Boolean) readonly loading: boolean = false + private deleteLoading = false private headers = [ { text: 'Name', value: 'name' }, { text: 'Link', value: 'url' }, @@ -38,10 +48,104 @@ export default class RoomsList extends Vue { { text: 'Running', value: 'running' }, { text: 'Status', value: 'status' }, { text: 'Created', value: 'created' }, + { + text: 'Actions', + value: 'actions', + align: 'end', + sortable: false, + }, + { + text: 'Destroy', + value: 'destroy', + align: 'end', + sortable: false, + }, ] get rooms() { return this.$store.state.rooms } + + async RoomStart(roomId: string) { + try { + await this.$store.dispatch('ROOMS_START', roomId) + await this.$swal({ + title: 'Room started!', + icon: 'success', + }) + } catch(e) { + this.handeErrors(e) + } + } + + async RoomStop(roomId: string) { + try { + await this.$store.dispatch('ROOMS_STOP', roomId) + await this.$swal({ + title: 'Room stopped!', + icon: 'success', + }) + } catch(e) { + this.handeErrors(e) + } + } + + async RoomRestart(roomId: string) { + try { + await this.$store.dispatch('ROOMS_RESTART', roomId) + await this.$swal({ + title: 'Room restarted!', + icon: 'success', + }) + } catch(e) { + this.handeErrors(e) + } + } + + async RoomRemove(roomId: string) { + const { value } = await this.$swal({ + title: "Remove room", + text: "Do you really want to remove this room?", + icon: 'warning', + showCancelButton: true, + confirmButtonText: "Yes", + cancelButtonText: "No", + }) + + if (!value) { + return + } + + this.deleteLoading = true + + try { + await this.$store.dispatch('ROOMS_REMOVE', roomId) + await this.$swal({ + title: 'Room removed!', + icon: 'success', + }) + } catch(e) { + this.handeErrors(e) + } finally { + this.deleteLoading = false + } + } + + // eslint-disable-next-line + handeErrors(e: any) { + if (e.response) { + this.$swal({ + title: 'Server error', + text: e.response.data, + icon: 'error', + }) + } else { + this.$swal({ + title: 'Network error', + text: String(e), + icon: 'error', + }) + } + } }