Fixed handling of Boolean values in wizard and CtrlBoolean, fixed handling of Enums for wizardEnd

This commit is contained in:
PAJohnson
2020-10-05 20:25:12 -04:00
parent f260ffeba8
commit f5a2c2e149
4 changed files with 42 additions and 29 deletions
+11 -3
View File
@@ -10,8 +10,16 @@ import time
import argparse
# interface for odrive GUI to get data from odrivetool
#better handling of websockets
# eventlet.monkey_patch()
# Flush stdout by default
# Source:
# https://stackoverflow.com/questions/230751/how-to-flush-output-of-python-print
old_print = print
def print(*args, **kwargs):
kwargs.pop('flush', False)
old_print(*args, **kwargs)
file = kwargs.get('file', sys.stdout)
file.flush() if file is not None else sys.stdout.flush()
app = flask.Flask(__name__)
app.config['SECRET_KEY'] = 'secret'
@@ -178,7 +186,7 @@ def postVal(odrives, keyList, value, argType):
if argType == "number":
RO.set_value(float(value))
elif argType == "boolean":
RO.set_value(value == "true")
RO.set_value(value)
else:
pass # dont support that type yet
except fibre.protocol.ChannelBrokenException:
+2 -5
View File
@@ -3,13 +3,13 @@
<button class="close-button" @click=deleteCtrl>X</button>
<span class="ctrlName">{{name}}:</span>
<div class="right">
<span class="ctrlVal" v-if="!writeAccess">{{value}}</span>
<span class="ctrlVal" v-if="writeAccess">{{fakeValue}}</span>
<span class="ctrlVal">{{value}}</span>
<input
class="ctrlInput"
v-if="writeAccess"
type="checkbox"
:value="value"
:checked="value"
@click="putVal"
/>
</div>
@@ -29,7 +29,6 @@ export default {
},
data() {
return {
fakeValue: undefined,
}
},
computed: {
@@ -55,7 +54,6 @@ export default {
keys.shift();
putVal(keys.join('.'), e.target.checked);
fetchParam(keys.join('.'));
this.fakeValue = e.target.checked;
},
deleteCtrl: function() {
// commit a mutation in the store with the relevant information
@@ -67,7 +65,6 @@ export default {
let keys = this.path.split('.');
keys.shift();
fetchParam(keys.join('.'));
this.fakeValue = getVal(keys.join('.'));
}
};
</script>
+28 -21
View File
@@ -2,9 +2,9 @@
<div class="card" :class="{'choice-inactive': !allowed}">
<div class="diff" v-for="diff in configDiffs" :key="diff.path">
<span class="diff-path">{{diff.path}}: </span>
<span class="diff-old">{{diff.oldVal}}</span>
<span class="diff-old">{{diffRepresentation(diff.path,diff.oldVal)}}</span>
<span class="diff-seperator"> </span>
<span :class="{'diff-new': diff.oldVal != diff.newVal, 'diff-same': diff.oldVal == diff.newVal}">{{diff.newVal}}</span>
<span :class="{'diff-new': diff.oldVal != diff.newVal, 'diff-same': diff.oldVal == diff.newVal}">{{diffRepresentation(diff.path,diff.newVal)}}</span>
</div>
<button class="wizard-button card" @click="applyConfig">Apply</button>
</div>
@@ -32,9 +32,9 @@ export default {
created() {
// flatten config tree into array of full variable paths
this.pathFromTree(this.config);
for (const path of this.flatpaths){
console.log(path);
}
//for (const path of this.flatpaths){
// console.log(path);
//}
for (const path of this.flatpaths) {
let odrvObj = this.$store.state.odrives.odrive0;
let configObj = this.config;
@@ -43,24 +43,15 @@ export default {
configObj = configObj[key];
}
if (configObj != null) {
let keys = path.split('.');
if (Object.keys(enumVars).includes(keys[keys.length - 1])){
// print old enum and new enum strings
console.log(enumVars[keys[keys.length-1]]);
this.configDiffs.push({path: path, oldVal: enumVars[keys[keys.length-1]][odrvObj["val"]], newVal: enumVars[keys[keys.length-1]][configObj]})
console.log("oldVal is " + odrvObj["val"] + " path is " + path);
if (Number.isInteger(parseFloat(odrvObj["val"]))){
this.configDiffs.push({path: path, oldVal: parseFloat(odrvObj["val"]), newVal: configObj});
}
else if (typeof configObj == 'boolean'){
this.configDiffs.push({path: path, oldVal: odrvObj["val"] == "True", newVal: configObj});
}
else {
// display numeric or boolean value
console.log("oldVal is " + parseFloat(odrvObj["val"]) + " path is " + path);
if (Number.isInteger(parseFloat(odrvObj["val"]))){
this.configDiffs.push({path: path, oldVal: parseFloat(odrvObj["val"]), newVal: configObj});
}
else if (typeof configObj == 'boolean'){
this.configDiffs.push({path: path, oldVal: odrvObj["val"] == true, newVal: configObj == true});
}
else {
this.configDiffs.push({path: path, oldVal: parseFloat(odrvObj["val"]).toExponential(3), newVal: configObj.toExponential(3)});
}
this.configDiffs.push({path: path, oldVal: parseFloat(odrvObj["val"]), newVal: configObj});
}
}
}
@@ -86,6 +77,22 @@ export default {
console.log("applying " + diff.newVal + " to " + diff.path);
}
},
diffRepresentation(path, val) {
// for the diff view, check if the path indicates that a value is an Enum and return enum string
// otherwise, just the numeric value
let keys = path.split('.');
let retval;
if (Object.keys(enumVars).includes(keys[keys.length - 1])) {
retval = enumVars[keys[keys.length-1]][val];
}
else if (!Number.isInteger(val) && typeof val != 'boolean') {
retval = parseFloat(val).toExponential(3);
}
else {
retval = val;
}
return retval;
}
}
}
</script>
+1
View File
@@ -33,6 +33,7 @@ export function fetchParam(path) {
}
export function putVal(path, value) {
console.log("path: " + path + ", val: " + value + ", type: " + typeof value);
socketio.sendEvent({
type: "setProperty",
data: {path: path, val: value, type: typeof value}