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 @@ + + + + +