diff --git a/src/js/control-view.js b/src/js/control-view.js index 464bdd7..c48b0b2 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -203,7 +203,7 @@ module.exports = { return Math.min(1, p); }, isMacrosPresent: function(){ - return this.config.macros!=undefined; + return this.config.macros==undefined; }, }, diff --git a/src/js/macros.js b/src/js/macros.js index 6f84bac..2b050c6 100644 --- a/src/js/macros.js +++ b/src/js/macros.js @@ -53,6 +53,34 @@ module.exports = { this.toolpath_progress = 0; this.load_toolpath(file, file_time); }, + upload: function(e) { + const files = e.target.files || e.dataTransfer.files; + if (!files.length) { + return; + } + + const file = files[0]; + const extension = file.name.split(".").pop(); + switch (extension.toLowerCase()) { + case "nc": + case "ngc": + case "gcode": + case "gc": + break; + + default: + alert(`Unsupported file type: ${extension}`); + return; + } + + SvelteComponents.showDialog("Upload", { + file, + onComplete: () => { + this.last_file_time = undefined; // Force reload + this.$broadcast("gcode-reload", file.name); + } + }); + }, saveMacros: function(){ var macrosName = document.getElementById("macros-name").value; var macrosColor = document.getElementById("macros-color").value; diff --git a/src/pug/templates/macros.pug b/src/pug/templates/macros.pug index b8dcf2f..51918e3 100644 --- a/src/pug/templates/macros.pug +++ b/src/pug/templates/macros.pug @@ -11,8 +11,13 @@ script#macros-template(type="text/x-template") v-model="state.selected", @change="load", :disabled="!is_ready", style="max-width:100%;height:40px;border-radius:5px") option(v-for="file in state.files", :value="file") {{file}} + button.pure-button(title="Upload a new GCode program.", @click="open", - :disabled="!is_ready",style="height:40px;width:130px;font-weight:normal;border-radius:5px") Upload + :disabled="!is_ready",style="height:40px;width:130px;font-weight:normal;border-radius:5px;margin-left:4px") Upload + + form.gcode-file-input.file-upload + input(type="file", @change="upload", :disabled="!is_ready", + accept=".nc,.ngc,.gcode,.gc") br button.submit-macros(title="Save Macros",@click="saveMacros", style="height:50px;width:140px;font-weight:normal;background-color:#add1ad;color:#fff;border-color:#add1ad;margin-top:15px") Save Macros