From 5a8916f2ce7089d493addd270bb5b3c22cdbd043 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sun, 29 Aug 2021 14:08:32 +0200 Subject: [PATCH] Show online status for all bots --- src/components/BotList.vue | 3 +++ src/components/layout/NavBar.vue | 6 +++--- src/store/modules/botStoreWrapper.ts | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/components/BotList.vue b/src/components/BotList.vue index 17e96220..06505510 100644 --- a/src/components/BotList.vue +++ b/src/components/BotList.vue @@ -17,6 +17,7 @@ + {{ allIsBotOnline[bot.botId] ? 'Online' : 'Offline' }} @@ -38,6 +39,8 @@ const ftbot = namespace('ftbot'); export default class BotList extends Vue { @ftbot.Getter [MultiBotStoreGetters.selectedBot]: string; + @ftbot.Getter [MultiBotStoreGetters.allIsBotOnline]; + @ftbot.Getter [MultiBotStoreGetters.allAvailableBots]: BotDescriptors; @ftbot.Action removeBot; diff --git a/src/components/layout/NavBar.vue b/src/components/layout/NavBar.vue index 1cc093f9..7c3e9265 100644 --- a/src/components/layout/NavBar.vue +++ b/src/components/layout/NavBar.vue @@ -87,7 +87,7 @@ export default class NavBar extends Vue { @Getter getUiVersion!: string; - @ftbot.Action ping; + @ftbot.Action pingAll; @ftbot.Action getState; @@ -116,9 +116,9 @@ export default class NavBar extends Vue { favicon: Favico | undefined = undefined; mounted() { - this.ping(); + this.pingAll(); this.loadUIVersion(); - this.pingInterval = window.setInterval(this.ping, 60000); + this.pingInterval = window.setInterval(this.pingAll, 60000); if (this.hasBots) { // Query botstate - this will enable / disable certain modes diff --git a/src/store/modules/botStoreWrapper.ts b/src/store/modules/botStoreWrapper.ts index a5e835a6..8f64b653 100644 --- a/src/store/modules/botStoreWrapper.ts +++ b/src/store/modules/botStoreWrapper.ts @@ -10,6 +10,8 @@ export enum MultiBotStoreGetters { hasBots = 'hasBots', selectedBot = 'selectedBot', allAvailableBots = 'allAvailableBots', + allAvailableBotsList = 'allAvailableBotsList', + allIsBotOnline = 'allIsBotOnline', nextBotId = 'nextBotId', } @@ -30,6 +32,16 @@ export default function createBotStore(store) { [MultiBotStoreGetters.allAvailableBots](state: FTMultiBotState): BotDescriptors { return state.availableBots; }, + [MultiBotStoreGetters.allAvailableBotsList](state: FTMultiBotState): string[] { + return Object.keys(state.availableBots); + }, + [MultiBotStoreGetters.allIsBotOnline](state: FTMultiBotState, getters): {} { + const result = {}; + getters.allAvailableBotsList.forEach((e) => { + result[e] = getters[`${e}/isBotOnline`]; + }); + return result; + }, [MultiBotStoreGetters.nextBotId](state: FTMultiBotState): string { let botCount = Object.keys(state.availableBots).length; @@ -96,6 +108,11 @@ export default function createBotStore(store) { selectBot({ commit }, botId: string) { commit('selectBot', botId); }, + pingAll({ getters, dispatch }) { + getters.allAvailableBotsList.forEach((e) => { + dispatch(`${e}/ping`); + }); + }, }; // Autocreate Actions from botstores Object.keys(BotStoreActions).forEach((e) => {