Simplified defaults data for maintainability
This commit is contained in:
@@ -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": ""
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
{
|
||||
|
||||
"motors": [
|
||||
{
|
||||
"travel-per-rev": 16,
|
||||
|
||||
Reference in New Issue
Block a user