From bcc08c09d94fc3467e373ac6b84146ec6301d8ff Mon Sep 17 00:00:00 2001 From: David Carley Date: Sun, 10 Oct 2021 15:35:43 -0700 Subject: [PATCH] Simplified defaults data for maintainability --- package.json | 5 +-- src/js/admin-general-view.js | 33 +++++++++---------- src/py/bbctrl/Web.py | 9 ----- src/resources/onefinity_defaults.json | 3 +- .../onefinity_woodworker_x50_defaults.json | 1 - src/stylus/style.styl | 12 +++---- 6 files changed, 27 insertions(+), 36 deletions(-) diff --git a/package.json b/package.json index f837bd1..af22757 100644 --- a/package.json +++ b/package.json @@ -5,10 +5,11 @@ "repository": "https://github.com/OneFinityCNC/onefinity", "license": "GPL-3.0+", "dependencies": { - "jshint": "", "browserify": "", - "jstransformer-stylus": "", + "jshint": "", "jstransformer-escape-html": "", + "jstransformer-stylus": "", + "lodash.merge": "4.6.2", "pug-cli": "" } } diff --git a/src/js/admin-general-view.js b/src/js/admin-general-view.js index 891c77c..2db7e1e 100644 --- a/src/js/admin-general-view.js +++ b/src/js/admin-general-view.js @@ -27,14 +27,19 @@ 'use strict' +const merge = require("lodash.merge"); + +const config_defaults = require("../resources/onefinity_defaults.json"); + +const variant_defaults = { + machinist_x35: require("../resources/onefinity_machinist_x35_defaults.json"), + woodworker_x35: require("../resources/onefinity_woodworker_x35_defaults.json"), + woodworker_x50: require("../resources/onefinity_woodworker_x50_defaults.json"), + journeyman_x50: require("../resources/onefinity_journeyman_x50_defaults.json") +}; + const api = require('./api'); -async function fetchJSON(url, options) { - const response = await fetch(url, options); - - return response.json(); -} - module.exports = { template: '#admin-general-view-template', props: ['config', 'state'], @@ -99,17 +104,11 @@ module.exports = { }, reset: async function () { - const fetchConfig = async () => { - try { - return await fetchJSON(`/api/config/${this.reset_variant}`); - } catch (err) { - api.alert("Invalid default config file"); - console.error('Invalid default config file', err); - return undefined; - } - } - - const config = await fetchConfig(); + const config = merge( + {}, + config_defaults, + variant_defaults[this.reset_variant] + ); try { await api.put('config/save', config) diff --git a/src/py/bbctrl/Web.py b/src/py/bbctrl/Web.py index 951c7f7..266cf50 100644 --- a/src/py/bbctrl/Web.py +++ b/src/py/bbctrl/Web.py @@ -34,7 +34,6 @@ import subprocess import socket from tornado.web import HTTPError from tornado import gen -from pkg_resources import Requirement, resource_filename import bbctrl @@ -225,13 +224,6 @@ class PasswordHandler(bbctrl.APIHandler): raise HTTPError(401, 'Failed to set password') -class ConfigDefaultsHandler(bbctrl.APIHandler): - def get(self): - # defaults_path = bbctrl.get_resource("") - # defaults_path = resource_filename(Requirement.parse('bbctrl'), 'bbctrl/' + path) - # self.write_json(self.get_ctrl().config.load()) - pass - class ConfigLoadHandler(bbctrl.APIHandler): def get(self): self.write_json(self.get_ctrl().config.load()) @@ -529,7 +521,6 @@ class Web(tornado.web.Application): (r'/api/wifi', WifiHandler), (r'/api/remote/username', UsernameHandler), (r'/api/remote/password', PasswordHandler), - (r'/api/config/defaults/(.*)', ConfigDefaultsHandler), (r'/api/config/load', ConfigLoadHandler), (r'/api/config/download', ConfigDownloadHandler), (r'/api/config/save', ConfigSaveHandler), diff --git a/src/resources/onefinity_defaults.json b/src/resources/onefinity_defaults.json index f4f861b..76883f3 100644 --- a/src/resources/onefinity_defaults.json +++ b/src/resources/onefinity_defaults.json @@ -14,13 +14,14 @@ "probe": "normally-open" }, "probe": { + "probe-diameter": 6.35, "probe-ydim": 53.975, "probe-slow-seek": 25, "probe-fast-seek": 75, "probe-zdim": 15.4, "probe-xdim": 53.975 }, - "version": "1.0.4", + "version": "1.0.9", "outputs": { "load-1": "disabled", "fault": "disabled", diff --git a/src/resources/onefinity_woodworker_x50_defaults.json b/src/resources/onefinity_woodworker_x50_defaults.json index 48a29f4..99d70a9 100644 --- a/src/resources/onefinity_woodworker_x50_defaults.json +++ b/src/resources/onefinity_woodworker_x50_defaults.json @@ -1,5 +1,4 @@ { - "motors": [ { "travel-per-rev": 16, diff --git a/src/stylus/style.styl b/src/stylus/style.styl index 31808b7..7acd5e1 100644 --- a/src/stylus/style.styl +++ b/src/stylus/style.styl @@ -995,12 +995,12 @@ tt.save width 98% .reset-variants - padding-left 40px - padding-bottom 20px - display grid - grid-template-rows repeat(4, auto) - grid-template-columns min-content auto - grid-gap 20px 10px + padding-left 40px + padding-bottom 20px + display grid + grid-template-rows repeat(4, auto) + grid-template-columns min-content auto + grid-gap 20px 10px input[type="radio"] width 30px