diff --git a/src/components/panels/MiniconsolePanel.vue b/src/components/panels/MiniconsolePanel.vue index 1533576f..dcb5088e 100644 --- a/src/components/panels/MiniconsolePanel.vue +++ b/src/components/panels/MiniconsolePanel.vue @@ -25,7 +25,32 @@ mdi-console-lineConsole + + + + + + + + mdi-send send + + + + + import { mapState } from 'vuex' + import Vue from "vue"; export default { components: { @@ -83,15 +109,65 @@ options: { }, + gcode: "", + lastCommands: [ + + ], + lastCommandNumber: null, + items: [], } }, computed: { ...mapState({ events: state => state.server.events, + helplist: state => state.printer.helplist, + loadings: state => state.socket.loadings, }) }, methods: { + doSend() { + this.$store.commit('socket/addLoading', { name: 'sendGcode' }); + this.$store.commit('server/addEvent', this.gcode); + Vue.prototype.$socket.sendObj('printer.gcode.script', { script: this.gcode }, "socket/removeLoading", { name: 'sendGcode' }); + this.lastCommands.push(this.gcode); + this.gcode = ""; + this.lastCommandNumber = null; + }, + onKeyUp() { + if (this.lastCommandNumber === null && this.lastCommands.length) { + this.lastCommandNumber = this.lastCommands.length - 1; + this.gcode = this.lastCommands[this.lastCommandNumber]; + } else if (this.lastCommandNumber > 0) { + this.lastCommandNumber--; + this.gcode = this.lastCommands[this.lastCommandNumber]; + } + }, + onKeyDown() { + if (this.lastCommandNumber !== null && this.lastCommandNumber < (this.lastCommands.length - 1)) { + this.lastCommandNumber++; + this.gcode = this.lastCommands[this.lastCommandNumber]; + } else if (this.lastCommandNumber !== null && this.lastCommandNumber === (this.lastCommands.length - 1)) { + this.lastCommandNumber = null; + this.gcode = ""; + } + }, + getAutocomplete(e) { + e.preventDefault(); + if (this.gcode.length) { + let commands = this.helplist.filter((element) => element.commandLow.indexOf(this.gcode.toLowerCase()) === 0); + if (commands && commands.length === 1) this.gcode = commands[0].command; + else { + let commands = this.helplist.filter((element) => element.commandLow.includes(this.gcode.toLowerCase())); + if (commands && commands.length) { + let output = ""; + commands.forEach(command => output += ""+command.command+": "+command.description+"
"); + this.$store.commit('server/addEvent', output); + } + } + } + this.$refs.gcodeCommandField.focus(); + }, formatTime(date) { let hours = date.getHours(); if (hours < 10) hours = "0"+hours.toString(); diff --git a/src/pages/Console.vue b/src/pages/Console.vue index 559c1e61..74b27b66 100644 --- a/src/pages/Console.vue +++ b/src/pages/Console.vue @@ -32,22 +32,22 @@ - + mdi-send send @@ -115,7 +115,6 @@ ], lastCommandNumber: null, items: [], - loadingSendGcode: false, } }, computed: { @@ -130,9 +129,9 @@ }, methods: { doSend() { - //this.$store.commit('setLoading', { name: 'loadingSendGcode' }); + this.$store.commit('socket/addLoading', { name: 'sendGcode' }); this.$store.commit('server/addEvent', this.gcode); - Vue.prototype.$socket.sendObj('printer.gcode.script', { script: this.gcode }, "server/getGcodeRespond"); + Vue.prototype.$socket.sendObj('printer.gcode.script', { script: this.gcode }, "socket/removeLoading", { name: 'sendGcode' }); this.lastCommands.push(this.gcode); this.gcode = ""; this.lastCommandNumber = null; @@ -193,12 +192,5 @@ return items; } }, - watch: { - loadings: { - handler: function(newVal) { - this.loadingSendGcode = newVal.includes('loadingSendGcode'); - } - } - } } \ No newline at end of file