diff --git a/src/js/control-view.js b/src/js/control-view.js index d69b793..629372f 100644 --- a/src/js/control-view.js +++ b/src/js/control-view.js @@ -493,18 +493,19 @@ module.exports = { const toolpath = await api.get(`path/${file}`); this.toolpath_progress = toolpath.progress; - if (typeof toolpath.progress == 'undefined') { + if (toolpath.progress === 1 || typeof toolpath.progress == 'undefined') { this.showGcodeMessage = false - toolpath.filename = file; - this.toolpath_progress = 1; - this.toolpath = toolpath; + if (toolpath.bounds) { + toolpath.filename = file; + this.toolpath_progress = 1; + this.toolpath = toolpath; - const state = this.$root.state; - const bounds = toolpath.bounds; - for (let axis of 'xyzabc') { - Vue.set(state, 'path_min_' + axis, bounds.min[axis]); - Vue.set(state, 'path_max_' + axis, bounds.max[axis]); + const state = this.$root.state; + for (let axis of 'xyzabc') { + Vue.set(state, 'path_min_' + axis, toolpath.bounds.min[axis]); + Vue.set(state, 'path_max_' + axis, toolpath.bounds.max[axis]); + } } } } @@ -540,29 +541,47 @@ module.exports = { }, - upload: function (e) { - var files = e.target.files || e.dataTransfer.files; - if (!files.length) return; + upload: async function (e) { + const files = e.target.files || e.dataTransfer.files; + if (!files.length) { + return; + } - var file = files[0]; - var fd = new FormData(); + 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; + } + + const fd = new FormData(); fd.append('gcode', file); - api.upload('file', fd) - .done(function () { - this.last_file_time = undefined; // Force reload - this.$broadcast('gcode-reload', file.name); + try { + await api.upload('file', fd); - }.bind(this)).fail(function (error) { - api.alert('Upload failed', error) - }.bind(this)); + this.last_file_time = undefined; // Force reload + this.$broadcast('gcode-reload', file.name); + } catch (err) { + api.alert('Upload failed', err) + } }, delete_current: function () { - if (this.state.selected) + if (this.state.selected) { api.delete('file/' + this.state.selected); + } + this.deleteGCode = false; }, diff --git a/src/pug/templates/console.pug b/src/pug/templates/console.pug index bc8df6c..0fe66f0 100644 --- a/src/pug/templates/console.pug +++ b/src/pug/templates/console.pug @@ -36,14 +36,8 @@ script#console-template(type="text/x-template") table tr th Level - th Source - th Location - th Repeat th Message tr(v-for="msg in messages", class="log-{{msg.level || 'info'}}") td {{msg.level || 'info'}} - td {{msg.source || ''}} - td {{msg.where || ''}} - td {{msg.repeat}} td.message {{msg.msg}} diff --git a/src/pug/templates/control-view.pug b/src/pug/templates/control-view.pug index 0765018..67c18bf 100644 --- a/src/pug/templates/control-view.pug +++ b/src/pug/templates/control-view.pug @@ -413,7 +413,7 @@ script#control-view-template(type="text/x-template") form.gcode-file-input.file-upload input(type="file", @change="upload", :disabled="!is_ready", - accept="text/*,.nc,.gcode,.gc,.ngc,.txt,.tap,.cnc") + accept=".nc,.ngc,.gcode,.gc") a(:disabled="!state.selected", download, :href="'/api/file/' + state.selected", diff --git a/src/py/bbctrl/AVREmu.py b/src/py/bbctrl/AVREmu.py index 7f6be71..05181af 100644 --- a/src/py/bbctrl/AVREmu.py +++ b/src/py/bbctrl/AVREmu.py @@ -128,7 +128,7 @@ class AVREmu(object): except Exception: self.close() - self.log.exception('Failed to start bbemu') + self.log.exception('Internal error: Failed to start bbemu') def set_handlers(self, read_cb, write_cb): diff --git a/src/py/bbctrl/Camera.py b/src/py/bbctrl/Camera.py index 17f1bb7..da42be1 100644 --- a/src/py/bbctrl/Camera.py +++ b/src/py/bbctrl/Camera.py @@ -429,7 +429,7 @@ class Camera(object): self._close_dev() self.log.info('Closed camera') - except: self.log.exception('Exception while closing camera') + except: self.log.exception('Internal error: Exception while closing camera') finally: self.dev = None diff --git a/src/py/bbctrl/CommandQueue.py b/src/py/bbctrl/CommandQueue.py index c167c57..a58eeb6 100644 --- a/src/py/bbctrl/CommandQueue.py +++ b/src/py/bbctrl/CommandQueue.py @@ -72,7 +72,7 @@ class CommandQueue(): try: if cb is not None: cb(*args, **kwargs) except Exception: - self.log.exception('During command queue callback') + self.log.exception('Internal error: Command queue callback error') diff --git a/src/py/bbctrl/Config.py b/src/py/bbctrl/Config.py index bdded41..370dddd 100644 --- a/src/py/bbctrl/Config.py +++ b/src/py/bbctrl/Config.py @@ -52,7 +52,7 @@ class Config(object): encoding = 'utf-8') as f: self.template = json.load(f) - except Exception: self.log.exception() + except Exception: self.log.exception('Internal error: Failed to load config template') def get(self, name, default = None): @@ -73,7 +73,7 @@ class Config(object): try: self.upgrade(config) - except Exception: self.log.exception() + except Exception: self.log.exception('Internal error: Failed to upgrade config') except Exception as e: self.log.warning('%s', e) diff --git a/src/py/bbctrl/Ctrl.py b/src/py/bbctrl/Ctrl.py index b3b443f..9a46323 100644 --- a/src/py/bbctrl/Ctrl.py +++ b/src/py/bbctrl/Ctrl.py @@ -67,7 +67,7 @@ class Ctrl(object): os.environ['GCODE_SCRIPT_PATH'] = self.get_upload() - except Exception: self.log.get('Ctrl').exception() + except Exception: self.log.get('Ctrl').exception('Internal error: Control initialization failed') def __del__(self): print('Ctrl deleted') diff --git a/src/py/bbctrl/FileHandler.py b/src/py/bbctrl/FileHandler.py index 8fb9d31..ad6a24e 100644 --- a/src/py/bbctrl/FileHandler.py +++ b/src/py/bbctrl/FileHandler.py @@ -79,7 +79,11 @@ class FileHandler(bbctrl.APIHandler): if not filename: raise HTTPError(400, 'Missing filename') filename = os.path.basename(filename) - with open(self.get_upload(filename).encode('utf8'), 'r') as f: - self.write(f.read()) + try: + with open(self.get_upload(filename).encode('utf8'), 'r') as f: + self.write(f.read()) + except Exception: + self.get_ctrl().state.select_file('') + raise HTTPError(400, "Unable to read file - doesn't appear to be GCode.") self.get_ctrl().state.select_file(filename) diff --git a/src/py/bbctrl/Log.py b/src/py/bbctrl/Log.py index 6e1226f..87f694f 100644 --- a/src/py/bbctrl/Log.py +++ b/src/py/bbctrl/Log.py @@ -101,8 +101,8 @@ class Logger(object): def exception(self, *args, **kwargs): msg = traceback.format_exc() if len(args): msg = args[0] % args[1:] + '\n' + msg - self._log(ERROR, msg, **kwargs) - + self._log(INFO, msg, **kwargs) + self._log(ERROR, *args, **kwargs) class Log(object): def __init__(self, args, ioloop, path): diff --git a/src/py/bbctrl/MonitorTemp.py b/src/py/bbctrl/MonitorTemp.py index 0d1501d..d208cd2 100644 --- a/src/py/bbctrl/MonitorTemp.py +++ b/src/py/bbctrl/MonitorTemp.py @@ -99,6 +99,6 @@ class MonitorTemp(object): self.update_camera(temp) self.log_warnings(temp) - except: self.log.exception() + except: self.log.exception('Internal error: Temperature status') self.ioloop.call_later(5, self.callback) diff --git a/src/py/bbctrl/Planner.py b/src/py/bbctrl/Planner.py index 2dda848..142d943 100644 --- a/src/py/bbctrl/Planner.py +++ b/src/py/bbctrl/Planner.py @@ -357,7 +357,7 @@ class Planner(): self.cmdq.clear() except: - self.log.exception() + self.log.exception('Internal error: Planner stop') self.reset() @@ -374,7 +374,7 @@ class Planner(): self.planner.restart(id, position) except: - self.log.exception() + self.log.exception('Internal error: Planner restart') self.stop() @@ -391,5 +391,5 @@ class Planner(): self.stop() except: - self.log.exception() + self.log.exception('Internal error: Planner next') self.stop() diff --git a/src/py/bbctrl/Preplanner.py b/src/py/bbctrl/Preplanner.py index d961d78..094fe9a 100644 --- a/src/py/bbctrl/Preplanner.py +++ b/src/py/bbctrl/Preplanner.py @@ -134,7 +134,7 @@ class Plan(object): return meta, positions, speeds except: - self.preplanner.log.exception() + self.preplanner.log.exception('Internal error: Preplanner read') # Clean for path in self.files: @@ -203,8 +203,7 @@ class Plan(object): self.future.set_result(self._read()) except: - self.preplanner.log.exception() - + self.preplanner.log.exception("Failed to load file - doesn't appear to be GCode.") class Preplanner(object):