From d77e81aafb997667ed36cb15736fab6ff03dc452 Mon Sep 17 00:00:00 2001 From: sanjayk03-dev Date: Sun, 21 Jan 2024 22:52:49 +0530 Subject: [PATCH] changed gcode viewer in macros --- src/js/macros.js | 27 +++++++++++++-------------- src/pug/templates/macros.pug | 35 +++++++++++++++++++---------------- src/py/bbctrl/State.py | 4 ++++ src/stylus/style.styl | 3 +++ 4 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/js/macros.js b/src/js/macros.js index 14b3a6b..4ceffcb 100644 --- a/src/js/macros.js +++ b/src/js/macros.js @@ -15,11 +15,6 @@ module.exports = { newGcode: ["", "", "", "", "", "", "", ""], }; }, - components: { - "axis-control": require("./axis-control"), - "path-viewer": require("./path-viewer"), - "gcode-viewer": require("./gcode-viewer"), - }, computed: { mach_state: function () { const cycle = this.state.cycle; @@ -42,11 +37,15 @@ module.exports = { open: function () { utils.clickFileInput("gcode-file-input"); }, - load: function () { + load: async function () { const file = this.state.selected; - this.$broadcast("gcode-load", file); - this.$broadcast("gcode-line", this.state.line); - this.newGcode[this.tab - 1] = ""; + const response = await fetch(`/api/file/${file}`, { cache: "no-cache" }); + const text = await response.text(); + if (text.length > 20e6) { + this.newGcode[this.tab - 1] = "File is large - gcode view disabled"; + } else { + this.newGcode[this.tab - 1] = text; + } }, upload: function (e) { const files = e.target.files || e.dataTransfer.files; @@ -72,11 +71,10 @@ module.exports = { file, onComplete: () => { this.last_file_time = undefined; // Force reload - this.$broadcast("gcode-reload", file.name); }, }); }, - uploadGCode: function (filename,file) { + uploadGCode: function (filename, file) { const xhr = new XMLHttpRequest(); xhr.onload = function () { @@ -112,12 +110,13 @@ module.exports = { if (this.state.selected == "default") { var file = this.newGcode[this.tab - 1]; - this.uploadGCode(macrosName,file); + this.uploadGCode(macrosName, file); } this.config.macros[this.tab - 1].name = macrosName; this.config.macros[this.tab - 1].color = macrosColor; - this.config.macros[this.tab - 1].gcode_file_name = this.state.selected == 'default' ? macrosName : this.state.selected; + this.config.macros[this.tab - 1].gcode_file_name = + this.state.selected == "default" ? macrosName : this.state.selected; this.config.macros[this.tab - 1].gcode_file_time = this.state.selected_time; this.cancelMacros(this.tab - 1); @@ -135,7 +134,7 @@ module.exports = { document.getElementById(`macros-name-${this.tab - 1}`).value = ""; document.getElementById(`macros-color-${this.tab - 1}`).value = "#ffffff"; document.getElementById(`gcodeSelect-${this.tab - 1}`).value = "default"; - this.$broadcast("gcode-clear"); + this.newGcode[this.tab-1] = ''; }, resetConfig: async function () { this.config.macros = [ diff --git a/src/pug/templates/macros.pug b/src/pug/templates/macros.pug index b9c70aa..a1e8f44 100644 --- a/src/pug/templates/macros.pug +++ b/src/pug/templates/macros.pug @@ -75,8 +75,8 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", @@ -105,8 +105,8 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", @@ -135,8 +135,8 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", @@ -165,8 +165,8 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", @@ -195,8 +195,8 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", @@ -225,8 +225,8 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", @@ -255,8 +255,8 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", @@ -285,9 +285,12 @@ script#macros-template(type="text/x-template") accept=".nc,.ngc,.gcode,.gc") br .gcodeContainer - textarea.new-gcode( v-if="state.selected=='default'",:value='newGcode[tab-1]' @input="updateNewGcode") - gcode-viewer(v-if="state.selected !== 'default'") + textarea.new-gcode( :value='newGcode[tab-1]' @input="updateNewGcode") + //- gcode-viewer(v-if="state.selected !== 'default'") button.submit-macros(title="Save Macros",@click="confirmSave=true", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border:0;margin-top:30px") Save button.submit-macros(title="Cancel Macros",@click="cancelMacros", style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Cancel + + button.submit-macros(title="Cancel Macros",@click="printState", + style="height:50px;width:140px;font-weight:normal;margin-left:5px;background-color:#f6f6f6;color:#000;border:0;margin-top:30px") Print State diff --git a/src/py/bbctrl/State.py b/src/py/bbctrl/State.py index e4e3b94..e9cd638 100644 --- a/src/py/bbctrl/State.py +++ b/src/py/bbctrl/State.py @@ -146,6 +146,10 @@ class State(object): files.append(filename) files.sort() self.set('files', files) + self.log.info('===================') + for i in files: + self.log.info(i) + self.log.info('===================') self.select_file(filename) diff --git a/src/stylus/style.styl b/src/stylus/style.styl index 2632059..3a9767f 100644 --- a/src/stylus/style.styl +++ b/src/stylus/style.styl @@ -628,8 +628,11 @@ span.unit width 140px font-weight normal border-radius 10px + margin-left 1rem border 0 color #fff + box-shadow rgba(0, 0, 0, 0.3) 0px 0px 5px + text-shadow: rgba(0, 0, 0, 0.8) 0px 0px 3px #macros width 104%