Skip to content

Commit

Permalink
Fix scalar input forms (#141)
Browse files Browse the repository at this point in the history
* Fix scalar input forms

* Fix to support hexadecimal, binary and octal

* Fixing the arguments to use full type names

* Fixing boolean handling into drop downs

---------

Co-authored-by: M Starch <[email protected]>
  • Loading branch information
SMorettini and LeStarch authored Oct 16, 2023
1 parent 6a545e0 commit 8c0d105
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ export let command_enum_argument_template = `
</v-select>
`;

/**
* Enum argument uses the v-select dropdown to render the various choices while providing search and match capabilities.
*/
export let command_bool_argument_template = `
<v-select :id="argument.name" style="flex: 1 1 auto; background-color: white;"
:clearable="false" :searchable="true" @input="validateTrigger"
:filterable="true" label="full_name" :options="['True', 'False']"
v-model="argument.value" class="fprime-input" :class="argument.error == '' ? '' : 'is-invalid'" required>
</v-select>
`;

/**
* Serializable arguments "flatten" the structure into a list of fields.
*/
Expand Down Expand Up @@ -64,8 +75,8 @@ export let command_scalar_argument_template = `
<label :for="argument.name" class="control-label font-weight-bold">
{{ argument.name + ((argument.description != null) ? ": " + argument.description : "") }}
</label>
<command-enum-argument v-if="argument.type.ENUM_DICT" :argument="argument"></command-enum-argument>
<command-bool-argument v-if="argument.type.name == 'BoolType'" :argument="argument"></command-bool-argument>
<command-enum-argument v-else-if="argument.type.ENUM_DICT" :argument="argument"></command-enum-argument>
<input v-else :type="inputType[0]" v-bind:id="argument.name" class="form-control fprime-input"
:placeholder="argument.name" :pattern="inputType[1]" :step="inputType[2]" v-on:input="validateTrigger"
v-model="argument.value" :class="argument.error == '' ? '' : 'is-invalid'" required>
Expand Down
44 changes: 41 additions & 3 deletions src/fprime_gds/flask/static/addons/commanding/arguments.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
import "../../third-party/js/vue-select.js"
import {
command_bool_argument_template,
command_enum_argument_template,
command_array_argument_template,
command_serializable_argument_template,
Expand Down Expand Up @@ -118,6 +119,35 @@ export function squashify_argument(argument) {
let field = argument.type.MEMBER_LIST[i][0];
value[field] = squashify_argument(argument.value[field]);
}
} else if (["U64Type", "U32Type", "U16Type", "U8Type"].indexOf(argument.type.name) != -1) {
if (argument.value.startsWith("0x")) {
// Hexadecimal
value = parseInt(argument.value, 16);
} else if (argument.value.startsWith("0b")) {
// Binary
value = parseInt(argument.value.slice(2), 2);
} else if (argument.value.startsWith("0o")) {
// Octal
value = parseInt(argument.value.slice(2), 8);
} else {
// Decimal
value = parseInt(argument.value, 10);
}
}
else if (["I64Type", "I32Type", "I16Type", "I8Type"].indexOf(argument.type.name) != -1) {
value = parseInt(argument.value, 10);
}
else if (["F64Type", "F32Type"].indexOf(argument.type.name) != -1) {
value = parseFloat(argument.value);
}
else if (argument.type.name == "BoolType") {
if ((typeof(value) === "string") && (["true", "yes"].indexOf(value.toLowerCase()) !== -1)) {
value = true;
} else if ((typeof(value) === "string") && (["false", "no"].indexOf(value.toLowerCase()) !== -1)) {
value = false;
} else {
console.assert(typeof(value) !== "boolean", "Cannot process boolean, invalid input type")
}
}
return value;
}
Expand Down Expand Up @@ -225,6 +255,14 @@ Vue.component("command-enum-argument", {
template: command_enum_argument_template,
});

/**
* Special boolean processing component to render as a drop-down.
*/
Vue.component("command-bool-argument", {
...base_argument_component_properties,
template: command_bool_argument_template,
});

/**
* Scalar argument processing. Sets up the input type such that numbers can be input with the correct formatting.
*/
Expand All @@ -239,14 +277,14 @@ Vue.component("command-scalar-argument", {
*/
inputType() {
// Unsigned integer
if (this.argument.type.name[0] == 'U') {
if (["U64Type", "U32Type", "U16Type", "U8Type"].indexOf(this.argument.type.name) != -1) {
// Supports binary, hex, octal, and digital
return ["text", "0[bB][01]+|0[oO][0-7]+|0[xX][0-9a-fA-F]+|[1-9]\\d*|0", ""];
}
else if (this.argument.type.name[0] == 'I') {
else if (["I64Type", "I32Type", "I16Type", "I8Type"].indexOf(this.argument.type.name) != -1) {
return ["number", null, "1"];
}
else if (this.argument.type.name[0] == 'F') {
else if (["F64Type", "F32Type"].indexOf(this.argument.type.name) != -1) {
return ["number", null, "any"];
}
return ["text", ".*", null];
Expand Down
4 changes: 4 additions & 0 deletions src/fprime_gds/flask/static/js/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ class DataStore {
if (argument.type.ENUM_DICT) {
argument.value = Object.keys(argument.type.ENUM_DICT)[0];
}
// Booleans are initialized to True
else if (argument.type.name === "BoolType") {
argument.value = "True";
}
// Arrays expand to a set length of N pseudo-arguments
else if (argument.type.LENGTH) {
let array_length = argument.type.LENGTH;
Expand Down
5 changes: 5 additions & 0 deletions src/fprime_gds/flask/static/js/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ export function validate_scalar_input(argument) {
argument.error = "";
return true;
}
// Boolean type handling
else if (argument.type.name === "BoolType") {
return (argument.value == null) ? null :
["yes", "no", "true", "false"].indexOf(argument.value.toString().toLowerCase()) >= 0;
}
console.assert(false, "Unknown scalar type: " + argument.type.name);
argument.error = "";
return true;
Expand Down

0 comments on commit 8c0d105

Please sign in to comment.