From 09a46341eef4cc54aa815c39f98ff5b18f5d647d Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sat, 28 Oct 2023 21:39:35 +0200 Subject: [PATCH 01/18] style: move style block to the end Signed-off-by: Stefan Dej --- src/components/console/ConsoleTableEntry.vue | 50 ++++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/components/console/ConsoleTableEntry.vue b/src/components/console/ConsoleTableEntry.vue index 2ef07f65b..794701fbc 100644 --- a/src/components/console/ConsoleTableEntry.vue +++ b/src/components/console/ConsoleTableEntry.vue @@ -1,28 +1,3 @@ - - @@ -41,11 +42,13 @@ import TheManualProbeDialog from '@/components/dialogs/TheManualProbeDialog.vue' import TheBedScrewsDialog from '@/components/dialogs/TheBedScrewsDialog.vue' import TheScrewsTiltAdjustDialog from '@/components/dialogs/TheScrewsTiltAdjustDialog.vue' import { setAndLoadLocale } from './plugins/i18n' +import TheActionCommandPrompt from '@/components/dialogs/TheActionCommandPrompt.vue' Component.registerHooks(['metaInfo']) @Component({ components: { + TheActionCommandPrompt, TheTimelapseRenderingSnackbar, TheEditor, TheSelectPrinterDialog, diff --git a/src/components/dialogs/TheActionCommandPrompt.vue b/src/components/dialogs/TheActionCommandPrompt.vue new file mode 100644 index 000000000..f6ac113f9 --- /dev/null +++ b/src/components/dialogs/TheActionCommandPrompt.vue @@ -0,0 +1,111 @@ + + + + + From 1f17ba60c5e26f53c48a7bfe5354eda757c3f81f Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 00:25:39 +0200 Subject: [PATCH 04/18] feat: add action command prompt dialog and panel buttons Signed-off-by: Stefan Dej --- .../dialogs/TheActionCommandPrompt.vue | 104 +++++++++++------- .../TheActionCommandPromptActionButton.vue | 44 ++++++++ 2 files changed, 109 insertions(+), 39 deletions(-) create mode 100644 src/components/dialogs/TheActionCommandPromptActionButton.vue diff --git a/src/components/dialogs/TheActionCommandPrompt.vue b/src/components/dialogs/TheActionCommandPrompt.vue index f6ac113f9..8f0ee9b1f 100644 --- a/src/components/dialogs/TheActionCommandPrompt.vue +++ b/src/components/dialogs/TheActionCommandPrompt.vue @@ -2,8 +2,8 @@ @@ -13,21 +13,19 @@ - - {{ activePrompt.length }} - + - + - - {{ $t('BedScrews.Abort') }} - - - {{ $t('BedScrews.Adjusted') }} - - - {{ $t('BedScrews.Accept') }} - + + @@ -37,16 +35,14 @@ import { Component, Mixins } from 'vue-property-decorator' import BaseMixin from '@/components/mixins/base' import Panel from '@/components/ui/Panel.vue' -import Responsive from '@/components/ui/Responsive.vue' -import { mdiArrowCollapseDown, mdiInformation, mdiCloseThick } from '@mdi/js' -import ControlMixin from '@/components/mixins/control' +import { mdiCloseThick, mdiInformation } from '@mdi/js' import { ServerStateEvent } from '@/store/server/types' + @Component({ - components: { Panel, Responsive }, + components: { Panel }, }) -export default class TheActionCommandPrompt extends Mixins(BaseMixin, ControlMixin) { - mdiArrowCollapseDown = mdiArrowCollapseDown +export default class TheActionCommandPrompt extends Mixins(BaseMixin) { mdiInformation = mdiInformation mdiCloseThick = mdiCloseThick @@ -58,52 +54,82 @@ export default class TheActionCommandPrompt extends Mixins(BaseMixin, ControlMix return this.events.filter((event: ServerStateEvent) => event.type === 'action') } - get lastPromptStartPos() { + get lastPromptBeginPos() { if (this.lastPromptShowPos === -1) return -1 - return this.actions.lastIndexOf( - (event: ServerStateEvent) => event.message.startsWith('action:prompt_start'), + return this.actions.findLastIndex( + (event: ServerStateEvent) => event.message.startsWith('// action:prompt_begin'), this.lastPromptShowPos ) } get lastPromptShowPos() { - return this.actions.lastIndexOf((event: ServerStateEvent) => event.message.startsWith('action:prompt_show')) + return this.actions.findLastIndex((event: ServerStateEvent) => + event.message.startsWith('// action:prompt_show') + ) } get lastPromptClosePos() { - return this.actions.lastIndexOf((event: ServerStateEvent) => event.message.startsWith('action:prompt_close')) + return this.actions.findLastIndex((event: ServerStateEvent) => + event.message.startsWith('// action:prompt_close') + ) } get showDialog() { - if (this.lastPromptStartPos === -1) return false + if (this.lastPromptBeginPos === -1) return false - return this.lastPromptStartPos > this.lastPromptClosePos + return this.lastPromptBeginPos > this.lastPromptClosePos } get activePrompt() { if (this.lastPromptShowPos === -1) return [] - const events = this.actions.slice(this.lastPromptStartPos, this.lastPromptShowPos) - window.console.log(events) + return this.actions.slice(this.lastPromptBeginPos, this.lastPromptShowPos) + } + + get activePromptContent() { + const allowedTypes = ['button', 'text'] + + return this.activePrompt.filter((event: ServerStateEvent) => { + let type = event.message.replace('// action:prompt_', '').split(' ')[0].trim() - return events + return allowedTypes.includes(type) + }) } get headline() { - return 'Bla bla headline' + if (!this.showDialog || this.lastPromptBeginPos === -1) return '' + + return (this.actions[this.lastPromptBeginPos].message ?? '') + .replace('// action:prompt_begin', '') + .replace(/"/g, '') + .trim() } - closePrompt() { - const gcode = `RESPOND type="action" msg="action:prompt_close"` - this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' }) - this.$socket.emit('printer.gcode.script', { script: gcode }) + get buttonPrimary() { + const index = this.activePrompt.findLastIndex((event: ServerStateEvent) => + event.message.startsWith('// action:prompt_button_primary') + ) + + if (index === -1) return null + + return this.activePrompt[index] } - sendAdjusted() { - const gcode = `ADJUSTED` + get buttonSecondary() { + const index = this.activePrompt.findLastIndex((event: ServerStateEvent) => + event.message.startsWith('// action:prompt_button_secondary') + ) + + if (index === -1) return null + + return this.activePrompt[index] + } + + closePrompt() { + const gcode = `RESPOND type="command" msg="action:prompt_close"` this.$store.dispatch('server/addEvent', { message: gcode, type: 'command' }) - this.$socket.emit('printer.gcode.script', { script: gcode }, { loading: 'manualProbeAccept' }) + this.$socket.emit('printer.gcode.script', { script: gcode }) } } diff --git a/src/components/dialogs/TheActionCommandPromptActionButton.vue b/src/components/dialogs/TheActionCommandPromptActionButton.vue new file mode 100644 index 000000000..c8f0273f6 --- /dev/null +++ b/src/components/dialogs/TheActionCommandPromptActionButton.vue @@ -0,0 +1,44 @@ + + + + + From 45f2288ac5fecab5de029a2fe9254788af00fb8c Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 09:36:29 +0100 Subject: [PATCH 05/18] refactor: rename TheActionCommandPromptActionButton to ActionCommandPromptActionButton Signed-off-by: Stefan Dej --- ...nButton.vue => ActionCommandPromptActionButton.vue} | 2 +- src/components/dialogs/TheActionCommandPrompt.vue | 10 ++++------ src/sw.ts | 2 ++ 3 files changed, 7 insertions(+), 7 deletions(-) rename src/components/dialogs/{TheActionCommandPromptActionButton.vue => ActionCommandPromptActionButton.vue} (93%) diff --git a/src/components/dialogs/TheActionCommandPromptActionButton.vue b/src/components/dialogs/ActionCommandPromptActionButton.vue similarity index 93% rename from src/components/dialogs/TheActionCommandPromptActionButton.vue rename to src/components/dialogs/ActionCommandPromptActionButton.vue index c8f0273f6..7f1c1c398 100644 --- a/src/components/dialogs/TheActionCommandPromptActionButton.vue +++ b/src/components/dialogs/ActionCommandPromptActionButton.vue @@ -10,7 +10,7 @@ import BaseMixin from '@/components/mixins/base' import { ServerStateEvent } from '@/store/server/types' @Component({}) -export default class TheActionCommandPromptActionButton extends Mixins(BaseMixin) { +export default class ActionCommandPromptActionButton extends Mixins(BaseMixin) { @Prop({ type: Object, required: true }) readonly event!: ServerStateEvent @Prop({ type: String, required: true }) readonly type!: 'primary' | 'secondary' diff --git a/src/components/dialogs/TheActionCommandPrompt.vue b/src/components/dialogs/TheActionCommandPrompt.vue index 8f0ee9b1f..6a4c6aa30 100644 --- a/src/components/dialogs/TheActionCommandPrompt.vue +++ b/src/components/dialogs/TheActionCommandPrompt.vue @@ -21,11 +21,8 @@ - - + + @@ -38,9 +35,10 @@ import Panel from '@/components/ui/Panel.vue' import { mdiCloseThick, mdiInformation } from '@mdi/js' import { ServerStateEvent } from '@/store/server/types' +import ActionCommandPromptActionButton from '@/components/dialogs/ActionCommandPromptActionButton.vue' @Component({ - components: { Panel }, + components: { ActionCommandPromptActionButton, Panel }, }) export default class TheActionCommandPrompt extends Mixins(BaseMixin) { mdiInformation = mdiInformation diff --git a/src/sw.ts b/src/sw.ts index 811433b4c..4686000d3 100644 --- a/src/sw.ts +++ b/src/sw.ts @@ -6,6 +6,8 @@ declare let self: ServiceWorkerGlobalScope import { precacheAndRoute, cleanupOutdatedCaches } from 'workbox-precaching' import { clientsClaim } from 'workbox-core' +// disable workbox logs +self.__wb_disable_dev_logs = true cleanupOutdatedCaches() // cleanup everything that's not needed anymore precacheAndRoute(self.__WB_MANIFEST) //cache our new stuff From 056e370cbb2ebe52ac58e95860e6bf499b1c3b95 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 11:01:17 +0100 Subject: [PATCH 06/18] feat: add ActionCommandPromptButtons Signed-off-by: Stefan Dej --- .../dialogs/ActionCommandPromptButton.vue | 34 +++++++++++++++++ .../dialogs/ActionCommandPromptText.vue | 22 +++++++++++ .../dialogs/TheActionCommandPrompt.vue | 37 ++++++++++++++----- src/store/server/types.ts | 6 +++ 4 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 src/components/dialogs/ActionCommandPromptButton.vue create mode 100644 src/components/dialogs/ActionCommandPromptText.vue diff --git a/src/components/dialogs/ActionCommandPromptButton.vue b/src/components/dialogs/ActionCommandPromptButton.vue new file mode 100644 index 000000000..9bc1bc215 --- /dev/null +++ b/src/components/dialogs/ActionCommandPromptButton.vue @@ -0,0 +1,34 @@ + + + diff --git a/src/components/dialogs/ActionCommandPromptText.vue b/src/components/dialogs/ActionCommandPromptText.vue new file mode 100644 index 000000000..25b796293 --- /dev/null +++ b/src/components/dialogs/ActionCommandPromptText.vue @@ -0,0 +1,22 @@ + + + diff --git a/src/components/dialogs/TheActionCommandPrompt.vue b/src/components/dialogs/TheActionCommandPrompt.vue index 6a4c6aa30..f9b90e8e1 100644 --- a/src/components/dialogs/TheActionCommandPrompt.vue +++ b/src/components/dialogs/TheActionCommandPrompt.vue @@ -14,9 +14,8 @@ @@ -34,11 +33,13 @@ import BaseMixin from '@/components/mixins/base' import Panel from '@/components/ui/Panel.vue' import { mdiCloseThick, mdiInformation } from '@mdi/js' -import { ServerStateEvent } from '@/store/server/types' +import { ServerStateEvent, ServerStateEventPromptContent } from '@/store/server/types' import ActionCommandPromptActionButton from '@/components/dialogs/ActionCommandPromptActionButton.vue' +import ActionCommandPromptText from '@/components/dialogs/ActionCommandPromptText.vue' +import ActionCommandPromptButton from '@/components/dialogs/ActionCommandPromptButton.vue' @Component({ - components: { ActionCommandPromptActionButton, Panel }, + components: { ActionCommandPromptButton, ActionCommandPromptText, ActionCommandPromptActionButton, Panel }, }) export default class TheActionCommandPrompt extends Mixins(BaseMixin) { mdiInformation = mdiInformation @@ -87,12 +88,30 @@ export default class TheActionCommandPrompt extends Mixins(BaseMixin) { get activePromptContent() { const allowedTypes = ['button', 'text'] + const activePromptContent: ServerStateEventPromptContent[] = this.activePrompt.map( + (event: ServerStateEvent) => { + const type = event.message.replace('// action:prompt_', '').split(' ')[0].trim() + const message = (event.message ?? '').replace(`// action:prompt_${type}`, '').replace(/"/g, '').trim() + + const promptContent: ServerStateEventPromptContent = { + date: event.date, + type, + message, + } + + return promptContent + } + ) + + window.console.log(activePromptContent) + + const output = activePromptContent.filter((event: ServerStateEventPromptContent) => + allowedTypes.includes(event.type) + ) - return this.activePrompt.filter((event: ServerStateEvent) => { - let type = event.message.replace('// action:prompt_', '').split(' ')[0].trim() + window.console.log(output) - return allowedTypes.includes(type) - }) + return output } get headline() { diff --git a/src/store/server/types.ts b/src/store/server/types.ts index d11c23c88..d3683f092 100644 --- a/src/store/server/types.ts +++ b/src/store/server/types.ts @@ -71,6 +71,12 @@ export interface ServerStateEvent { formatMessage: string | string[] } +export interface ServerStateEventPromptContent { + date: Date + type: string + message: string +} + export interface ServerStateCpuInfo { bits: string cpu_count: number From aace58037c22b0c6fa2a5b09ed21177b0d542f38 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 11:05:20 +0100 Subject: [PATCH 07/18] refactor: rename action-command-prompt to macro-prompt Signed-off-by: Stefan Dej --- src/App.vue | 6 +++--- ...Button.vue => MacroPromptActionButton.vue} | 2 +- ...PromptButton.vue => MacroPromptButton.vue} | 2 +- ...mandPromptText.vue => MacroPromptText.vue} | 2 +- ...onCommandPrompt.vue => TheMacroPrompt.vue} | 20 +++++++++---------- 5 files changed, 16 insertions(+), 16 deletions(-) rename src/components/dialogs/{ActionCommandPromptActionButton.vue => MacroPromptActionButton.vue} (93%) rename src/components/dialogs/{ActionCommandPromptButton.vue => MacroPromptButton.vue} (90%) rename src/components/dialogs/{ActionCommandPromptText.vue => MacroPromptText.vue} (87%) rename src/components/dialogs/{TheActionCommandPrompt.vue => TheMacroPrompt.vue} (81%) diff --git a/src/App.vue b/src/App.vue index e21c5df23..315e6cfe5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -17,7 +17,7 @@ - + @@ -42,13 +42,13 @@ import TheManualProbeDialog from '@/components/dialogs/TheManualProbeDialog.vue' import TheBedScrewsDialog from '@/components/dialogs/TheBedScrewsDialog.vue' import TheScrewsTiltAdjustDialog from '@/components/dialogs/TheScrewsTiltAdjustDialog.vue' import { setAndLoadLocale } from './plugins/i18n' -import TheActionCommandPrompt from '@/components/dialogs/TheActionCommandPrompt.vue' +import TheMacroPrompt from '@/components/dialogs/TheMacroPrompt.vue' Component.registerHooks(['metaInfo']) @Component({ components: { - TheActionCommandPrompt, + TheMacroPrompt, TheTimelapseRenderingSnackbar, TheEditor, TheSelectPrinterDialog, diff --git a/src/components/dialogs/ActionCommandPromptActionButton.vue b/src/components/dialogs/MacroPromptActionButton.vue similarity index 93% rename from src/components/dialogs/ActionCommandPromptActionButton.vue rename to src/components/dialogs/MacroPromptActionButton.vue index 7f1c1c398..904578899 100644 --- a/src/components/dialogs/ActionCommandPromptActionButton.vue +++ b/src/components/dialogs/MacroPromptActionButton.vue @@ -10,7 +10,7 @@ import BaseMixin from '@/components/mixins/base' import { ServerStateEvent } from '@/store/server/types' @Component({}) -export default class ActionCommandPromptActionButton extends Mixins(BaseMixin) { +export default class MacroPromptActionButton extends Mixins(BaseMixin) { @Prop({ type: Object, required: true }) readonly event!: ServerStateEvent @Prop({ type: String, required: true }) readonly type!: 'primary' | 'secondary' diff --git a/src/components/dialogs/ActionCommandPromptButton.vue b/src/components/dialogs/MacroPromptButton.vue similarity index 90% rename from src/components/dialogs/ActionCommandPromptButton.vue rename to src/components/dialogs/MacroPromptButton.vue index 9bc1bc215..3b8cafc75 100644 --- a/src/components/dialogs/ActionCommandPromptButton.vue +++ b/src/components/dialogs/MacroPromptButton.vue @@ -12,7 +12,7 @@ import BaseMixin from '@/components/mixins/base' import { ServerStateEventPromptContent } from '@/store/server/types' @Component({}) -export default class ActionCommandPromptButton extends Mixins(BaseMixin) { +export default class MacroPromptButton extends Mixins(BaseMixin) { @Prop({ type: Object, required: true }) readonly event!: ServerStateEventPromptContent get splits() { diff --git a/src/components/dialogs/ActionCommandPromptText.vue b/src/components/dialogs/MacroPromptText.vue similarity index 87% rename from src/components/dialogs/ActionCommandPromptText.vue rename to src/components/dialogs/MacroPromptText.vue index 25b796293..858752c3b 100644 --- a/src/components/dialogs/ActionCommandPromptText.vue +++ b/src/components/dialogs/MacroPromptText.vue @@ -12,7 +12,7 @@ import BaseMixin from '@/components/mixins/base' import { ServerStateEventPromptContent } from '@/store/server/types' @Component({}) -export default class ActionCommandPromptText extends Mixins(BaseMixin) { +export default class MacroPromptText extends Mixins(BaseMixin) { @Prop({ type: Object, required: true }) readonly event!: ServerStateEventPromptContent get text() { diff --git a/src/components/dialogs/TheActionCommandPrompt.vue b/src/components/dialogs/TheMacroPrompt.vue similarity index 81% rename from src/components/dialogs/TheActionCommandPrompt.vue rename to src/components/dialogs/TheMacroPrompt.vue index f9b90e8e1..acfc82ff1 100644 --- a/src/components/dialogs/TheActionCommandPrompt.vue +++ b/src/components/dialogs/TheMacroPrompt.vue @@ -3,7 +3,7 @@ @@ -14,14 +14,14 @@ - - + + @@ -34,14 +34,14 @@ import Panel from '@/components/ui/Panel.vue' import { mdiCloseThick, mdiInformation } from '@mdi/js' import { ServerStateEvent, ServerStateEventPromptContent } from '@/store/server/types' -import ActionCommandPromptActionButton from '@/components/dialogs/ActionCommandPromptActionButton.vue' -import ActionCommandPromptText from '@/components/dialogs/ActionCommandPromptText.vue' -import ActionCommandPromptButton from '@/components/dialogs/ActionCommandPromptButton.vue' +import MacroPromptActionButton from '@/components/dialogs/MacroPromptActionButton.vue' +import MacroPromptText from '@/components/dialogs/MacroPromptText.vue' +import MacroPromptButton from '@/components/dialogs/MacroPromptButton.vue' @Component({ - components: { ActionCommandPromptButton, ActionCommandPromptText, ActionCommandPromptActionButton, Panel }, + components: { MacroPromptButton, MacroPromptText, MacroPromptActionButton, Panel }, }) -export default class TheActionCommandPrompt extends Mixins(BaseMixin) { +export default class TheMacroPrompt extends Mixins(BaseMixin) { mdiInformation = mdiInformation mdiCloseThick = mdiCloseThick From 646be2807080e0b2a9b6f9c75d15ca065c4cc2b1 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 11:10:25 +0100 Subject: [PATCH 08/18] fix: fix margin bottom of MacroPromptText Signed-off-by: Stefan Dej --- src/components/dialogs/MacroPromptText.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/dialogs/MacroPromptText.vue b/src/components/dialogs/MacroPromptText.vue index 858752c3b..08d7b6a83 100644 --- a/src/components/dialogs/MacroPromptText.vue +++ b/src/components/dialogs/MacroPromptText.vue @@ -1,7 +1,7 @@ From c1ec7598fb08b829cf96966a9023e167b3a575e1 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 12:16:10 +0100 Subject: [PATCH 09/18] refactor: remove debug output in store/server/action Signed-off-by: Stefan Dej --- src/store/server/actions.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/store/server/actions.ts b/src/store/server/actions.ts index d24f4c42c..b5a915735 100644 --- a/src/store/server/actions.ts +++ b/src/store/server/actions.ts @@ -247,8 +247,6 @@ export const actions: ActionTree = { let message = payload let type = 'response' - window.console.log(payload) - if (typeof payload === 'object' && 'type' in payload) type = payload.type if ('message' in payload) message = payload.message From 30a15c91fdc42d347c52ec2d1c43124e49a0eefc Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 12:16:34 +0100 Subject: [PATCH 10/18] feat: add macro-prompt button-group support Signed-off-by: Stefan Dej --- src/components/dialogs/MacroPromptButton.vue | 10 +++---- .../dialogs/MacroPromptButtonGroup.vue | 18 +++++++++++++ src/components/dialogs/TheMacroPrompt.vue | 26 +++++++++++++++---- src/store/server/types.ts | 1 + 4 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 src/components/dialogs/MacroPromptButtonGroup.vue diff --git a/src/components/dialogs/MacroPromptButton.vue b/src/components/dialogs/MacroPromptButton.vue index 3b8cafc75..23aad221d 100644 --- a/src/components/dialogs/MacroPromptButton.vue +++ b/src/components/dialogs/MacroPromptButton.vue @@ -1,9 +1,5 @@ diff --git a/src/components/dialogs/TheMacroPrompt.vue b/src/components/dialogs/TheMacroPrompt.vue index acfc82ff1..5a5400109 100644 --- a/src/components/dialogs/TheMacroPrompt.vue +++ b/src/components/dialogs/TheMacroPrompt.vue @@ -15,7 +15,11 @@ @@ -87,7 +91,7 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) { } get activePromptContent() { - const allowedTypes = ['button', 'text'] + const allowedTypes = ['button', 'text', 'button_group_start', 'button_group_end'] const activePromptContent: ServerStateEventPromptContent[] = this.activePrompt.map( (event: ServerStateEvent) => { const type = event.message.replace('// action:prompt_', '').split(' ')[0].trim() @@ -103,13 +107,25 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) { } ) - window.console.log(activePromptContent) - const output = activePromptContent.filter((event: ServerStateEventPromptContent) => allowedTypes.includes(event.type) ) - window.console.log(output) + while (output.findIndex((event) => event.type === 'button_group_start') !== -1) { + const start = output.findIndex((event) => event.type === 'button_group_start') + const end = output.findIndex((event) => event.type === 'button_group_end') + + const buttons = output.slice(start + 1, end) + + output[start] = { + date: buttons[0].date, + type: 'button_group', + message: '', + children: buttons, + } + + output.splice(start + 1, buttons.length + 1) + } return output } diff --git a/src/store/server/types.ts b/src/store/server/types.ts index d3683f092..620047219 100644 --- a/src/store/server/types.ts +++ b/src/store/server/types.ts @@ -75,6 +75,7 @@ export interface ServerStateEventPromptContent { date: Date type: string message: string + children?: ServerStateEventPromptContent[] } export interface ServerStateCpuInfo { From 3e2936877b9a0f8a433051667fdc8deb4893dfee Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 12:45:11 +0100 Subject: [PATCH 11/18] refactor: simplyfy filters Signed-off-by: Stefan Dej --- src/components/dialogs/MacroPromptButton.vue | 7 +- .../dialogs/MacroPromptButtonGroup.vue | 10 ++- src/components/dialogs/TheMacroPrompt.vue | 77 ++++++++++--------- src/store/server/types.ts | 4 +- 4 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/components/dialogs/MacroPromptButton.vue b/src/components/dialogs/MacroPromptButton.vue index 23aad221d..e3959c151 100644 --- a/src/components/dialogs/MacroPromptButton.vue +++ b/src/components/dialogs/MacroPromptButton.vue @@ -5,11 +5,11 @@ diff --git a/src/components/dialogs/MacroPromptButtonGroup.vue b/src/components/dialogs/MacroPromptButtonGroup.vue index aa99b9cbc..d4206460a 100644 --- a/src/components/dialogs/MacroPromptButtonGroup.vue +++ b/src/components/dialogs/MacroPromptButtonGroup.vue @@ -1,7 +1,10 @@ @@ -9,10 +12,11 @@ diff --git a/src/components/dialogs/TheMacroPrompt.vue b/src/components/dialogs/TheMacroPrompt.vue index 5a5400109..aa279877a 100644 --- a/src/components/dialogs/TheMacroPrompt.vue +++ b/src/components/dialogs/TheMacroPrompt.vue @@ -14,12 +14,17 @@ @@ -39,6 +44,7 @@ import Panel from '@/components/ui/Panel.vue' import { mdiCloseThick, mdiInformation } from '@mdi/js' import { ServerStateEvent, ServerStateEventPromptContent } from '@/store/server/types' import MacroPromptActionButton from '@/components/dialogs/MacroPromptActionButton.vue' +import { ServerStateEvent, ServerStateEventPrompt } from '@/store/server/types' import MacroPromptText from '@/components/dialogs/MacroPromptText.vue' import MacroPromptButton from '@/components/dialogs/MacroPromptButton.vue' @@ -57,25 +63,38 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) { return this.events.filter((event: ServerStateEvent) => event.type === 'action') } + get macroPromptEvents() { + return this.actions + .filter((event: ServerStateEvent) => event.message.startsWith('// action:prompt_')) + .map((event: ServerStateEvent) => { + const type = event.message.replace('// action:prompt_', '').split(' ')[0].trim() + const message = (event.message ?? '').replace(`// action:prompt_${type}`, '').replace(/"/g, '').trim() + + const promptContent: ServerStateEventPromptContent = { + date: event.date, + type, + message, + } + + return promptContent + }) + } + get lastPromptBeginPos() { if (this.lastPromptShowPos === -1) return -1 - return this.actions.findLastIndex( - (event: ServerStateEvent) => event.message.startsWith('// action:prompt_begin'), + return this.macroPromptEvents.findLastIndex( + (event: ServerStateEventPrompt) => event.type === 'begin', this.lastPromptShowPos ) } get lastPromptShowPos() { - return this.actions.findLastIndex((event: ServerStateEvent) => - event.message.startsWith('// action:prompt_show') - ) + return this.macroPromptEvents.findLastIndex((event: ServerStateEventPrompt) => event.type === 'show') } get lastPromptClosePos() { - return this.actions.findLastIndex((event: ServerStateEvent) => - event.message.startsWith('// action:prompt_close') - ) + return this.macroPromptEvents.findLastIndex((event: ServerStateEventPrompt) => event.type === 'close') } get showDialog() { @@ -87,33 +106,20 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) { get activePrompt() { if (this.lastPromptShowPos === -1) return [] - return this.actions.slice(this.lastPromptBeginPos, this.lastPromptShowPos) + return this.macroPromptEvents.slice(this.lastPromptBeginPos, this.lastPromptShowPos) } - get activePromptContent() { + get activePromptContent(): ServerStateEventPrompt[] { const allowedTypes = ['button', 'text', 'button_group_start', 'button_group_end'] - const activePromptContent: ServerStateEventPromptContent[] = this.activePrompt.map( - (event: ServerStateEvent) => { - const type = event.message.replace('// action:prompt_', '').split(' ')[0].trim() - const message = (event.message ?? '').replace(`// action:prompt_${type}`, '').replace(/"/g, '').trim() - - const promptContent: ServerStateEventPromptContent = { - date: event.date, - type, - message, - } - return promptContent - } - ) - - const output = activePromptContent.filter((event: ServerStateEventPromptContent) => - allowedTypes.includes(event.type) - ) + const output = this.activePrompt.filter((event: ServerStateEventPrompt) => allowedTypes.includes(event.type)) - while (output.findIndex((event) => event.type === 'button_group_start') !== -1) { - const start = output.findIndex((event) => event.type === 'button_group_start') - const end = output.findIndex((event) => event.type === 'button_group_end') + while ( + output.findIndex((event: ServerStateEventPrompt) => event.type === 'button_group_start') !== -1 && + output.findIndex((event: ServerStateEventPrompt) => event.type === 'button_group_end') !== -1 + ) { + const start = output.findIndex((event: ServerStateEventPrompt) => event.type === 'button_group_start') + const end = output.findIndex((event: ServerStateEventPrompt) => event.type === 'button_group_end') const buttons = output.slice(start + 1, end) @@ -133,10 +139,7 @@ export default class TheMacroPrompt extends Mixins(BaseMixin) { get headline() { if (!this.showDialog || this.lastPromptBeginPos === -1) return '' - return (this.actions[this.lastPromptBeginPos].message ?? '') - .replace('// action:prompt_begin', '') - .replace(/"/g, '') - .trim() + return this.activePrompt[this.lastPromptBeginPos].message ?? '' } get buttonPrimary() { diff --git a/src/store/server/types.ts b/src/store/server/types.ts index 620047219..03c5f0c11 100644 --- a/src/store/server/types.ts +++ b/src/store/server/types.ts @@ -71,11 +71,11 @@ export interface ServerStateEvent { formatMessage: string | string[] } -export interface ServerStateEventPromptContent { +export interface ServerStateEventPrompt { date: Date type: string message: string - children?: ServerStateEventPromptContent[] + children?: ServerStateEventPrompt[] } export interface ServerStateCpuInfo { From 563711a318e90155e284acaac6faa16d2f13cef4 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Sun, 29 Oct 2023 12:45:40 +0100 Subject: [PATCH 12/18] refactor: convert primary/secondary buttons to footer_button Signed-off-by: Stefan Dej --- ...Button.vue => MacroPromptFooterButton.vue} | 21 +++++------- src/components/dialogs/TheMacroPrompt.vue | 33 ++++++------------- 2 files changed, 18 insertions(+), 36 deletions(-) rename src/components/dialogs/{MacroPromptActionButton.vue => MacroPromptFooterButton.vue} (57%) diff --git a/src/components/dialogs/MacroPromptActionButton.vue b/src/components/dialogs/MacroPromptFooterButton.vue similarity index 57% rename from src/components/dialogs/MacroPromptActionButton.vue rename to src/components/dialogs/MacroPromptFooterButton.vue index 904578899..83a0d9b06 100644 --- a/src/components/dialogs/MacroPromptActionButton.vue +++ b/src/components/dialogs/MacroPromptFooterButton.vue @@ -7,31 +7,26 @@