Skip to content

Commit

Permalink
web: refresh leds status
Browse files Browse the repository at this point in the history
  • Loading branch information
SpComb committed Dec 26, 2024
1 parent ec68713 commit 77d7f66
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
1 change: 0 additions & 1 deletion web/src/components/ArtNetView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
</table>
</template>


<template v-if="outputs">
<table class="outputs">
<caption>
Expand Down
28 changes: 22 additions & 6 deletions web/src/components/LedsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
<table class="limits">
<caption>
Limits
<button @click="loadStatus"><span :class="{spin: true, active: loadingStatus}">&#10227;</span></button>
</caption>
<thead>
<tr>
Expand Down Expand Up @@ -146,6 +147,7 @@
export default {
data: () => ({
loading: true,
loadingStatus: false,
activeID: "leds1",
}),
created() {
Expand All @@ -157,19 +159,24 @@ data: () => ({
return [...this.$store.state.leds.keys()];
}
},
activeLeds() {
if (this.$store.state.leds) {
return this.$store.state.leds.get(this.activeID);
}
},
options() {
if (this.$store.state.leds && this.activeID) {
return this.$store.state.leds.get(this.activeID).options;
if (this.activeLeds) {
return this.activeLeds.options;
}
},
artnet() {
if (this.$store.state.leds && this.activeID) {
return this.$store.state.leds.get(this.activeID).artnet;
if (this.activeLeds) {
return this.activeLeds.artnet;
}
},
status() {
if (this.$store.state.leds && this.activeID) {
return this.$store.state.leds.get(this.activeID).status;
if (this.activeLeds) {
return this.activeLeds.status;
}
},
},
Expand Down Expand Up @@ -220,6 +227,15 @@ data: () => ({
this.loading = false;
}
},
async loadStatus() {
this.loadingStatus = true;
try {
await this.$store.dispatch('loadLedsStatus', this.activeID);
} finally {
this.loadingStatus = false;
}
},
switchActive(id) {
this.activeID = id;
},
Expand Down
4 changes: 2 additions & 2 deletions web/src/services/api.service.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import axios from 'axios'

export default class APIService {
get(url) {
return axios.get(url);
get(url, params = {}) {
return axios.get(url, {params});
}

post(url, data) {
Expand Down
5 changes: 5 additions & 0 deletions web/src/services/leds.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ export default class LedsService {

return new Map(Object.entries(response.data));
}
async getStatus(leds) {
const response = await this.apiService.get('/api/leds/status', { leds: leds });

return response.data;
}
}

11 changes: 11 additions & 0 deletions web/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ export default new Vuex.Store({

commit('updateLeds', data);
},
async loadLedsStatus({ commit }, id) {
const status = await ledsService.getStatus(id);

commit('updateLedsStatus', {id, status});
},

/* VFS */
async loadVFS({ commit }) {
Expand Down Expand Up @@ -180,6 +185,12 @@ export default new Vuex.Store({
updateLeds(state, leds) {
state.leds = leds;
},
updateLedsStatus(state, {id, status}) {
// no reactive map support
let leds = new Map(state.leds);
leds.get(id).status = status;
state.leds = leds;
},

updateArtNet(state, artnet) {
state.artnet = artnet;
Expand Down

0 comments on commit 77d7f66

Please sign in to comment.