Webapp: make Tags view respond to SocketIO messages

Make the Tags view/tab respond to changes in worker tags. This way the
'Refresh' button is no longer necessary, as the information is always
up to date.
This commit is contained in:
Sybren A. Stüvel 2023-09-04 13:24:50 +02:00
parent d6ffb424eb
commit 0821df8f3a

View File

@ -4,7 +4,6 @@
<div class="action-buttons btn-bar-group"> <div class="action-buttons btn-bar-group">
<div class="btn-bar"> <div class="btn-bar">
<button @click="fetchTags">Refresh</button>
<button @click="deleteTag" :disabled="!selectedTag">Delete Tag</button> <button @click="deleteTag" :disabled="!selectedTag">Delete Tag</button>
</div> </div>
</div> </div>
@ -32,7 +31,14 @@
<div id="tag-table-container"></div> <div id="tag-table-container"></div>
</div> </div>
<footer class="app-footer"></footer> <footer class="app-footer">
<notification-bar />
<update-listener ref="updateListener"
mainSubscription="allWorkerTags"
@workerTagUpdate="onSIOWorkerTagsUpdate"
@sioReconnected="onSIOReconnected"
@sioDisconnected="onSIODisconnected" />
</footer>
</template> </template>
<style> <style>
@ -62,9 +68,13 @@ import { useNotifs } from "@/stores/notifications";
import { WorkerMgtApi } from "@/manager-api"; import { WorkerMgtApi } from "@/manager-api";
import { WorkerTag } from "@/manager-api"; import { WorkerTag } from "@/manager-api";
import { getAPIClient } from "@/api-client"; import { getAPIClient } from "@/api-client";
import NotificationBar from '@/components/footer/NotificationBar.vue'
import UpdateListener from '@/components/UpdateListener.vue'
export default { export default {
components: { components: {
NotificationBar,
UpdateListener,
}, },
data() { data() {
return { return {
@ -155,13 +165,6 @@ export default {
api api
.updateWorkerTag(tagId, updatedTagData) .updateWorkerTag(tagId, updatedTagData)
.then(() => { .then(() => {
// Update the local state with the edited data without requiring a page refresh
this.tags = this.tags.map((tag) => {
if (tag.id === tagId) {
return { ...tag, ...updatedTagData };
}
return tag;
});
console.log("Tag updated successfully"); console.log("Tag updated successfully");
}) })
.catch((error) => { .catch((error) => {
@ -181,8 +184,6 @@ export default {
.then(() => { .then(() => {
this.selectedTag = null; this.selectedTag = null;
this.tabulator.setData(this.tags); this.tabulator.setData(this.tags);
this.fetchTags();
}) })
.catch((error) => { .catch((error) => {
const errorMsg = JSON.stringify(error); const errorMsg = JSON.stringify(error);
@ -200,6 +201,17 @@ export default {
this.selectedTag = tag; this.selectedTag = tag;
this.activeRowIndex = rowIndex; this.activeRowIndex = rowIndex;
}, },
// SocketIO connection event handlers:
onSIOReconnected() {
this.fetchTags();
},
onSIODisconnected(reason) {
},
onSIOWorkerTagsUpdate(workerTagsUpdate) {
this.fetchTags();
},
}, },
}; };
</script> </script>