Skip to content

Commit

Permalink
Beautified code
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikBoesen committed May 24, 2016
1 parent ff48336 commit 793de78
Showing 1 changed file with 54 additions and 54 deletions.
108 changes: 54 additions & 54 deletions tuning.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,62 +15,62 @@
var propName = key.substring(16, key.length);
// Check if value is new, starts with /SmartDashboard/, and doesn't have a spot on the list yet
if (isNew && value && document.getElementsByName(propName).length === 0) {
if (key.substring(0, 16) === '/SmartDashboard/') {
// Make a new div for this value
var div = document.createElement('div'); // Make div
ui.tuning.list.appendChild(div); // Add the div to the page
if (key.substring(0, 16) === '/SmartDashboard/') {
// Make a new div for this value
var div = document.createElement('div'); // Make div
ui.tuning.list.appendChild(div); // Add the div to the page

var p = document.createElement('p'); // Make a <p> to display the name of the property
p.innerHTML = propName; // Make content of <p> have the name of the NetworkTables value
div.appendChild(p); // Put <p> in div
var p = document.createElement('p'); // Make a <p> to display the name of the property
p.innerHTML = propName; // Make content of <p> have the name of the NetworkTables value
div.appendChild(p); // Put <p> in div

var input = document.createElement('input'); // Create input
input.name = propName; // Make its name property be the name of the NetworkTables value
input.value = value; // Set
// The following statement figures out which data type the variable is.
// If it's a boolean, it will make the input be a checkbox. If it's a number,
// it will make it a number chooser with up and down arrows in the box. Otherwise, it will make it a textbox.
if (value === true || value === false) { // Is it a boolean value?
input.type = 'checkbox';
input.checked = value; // value property doesn't work on checkboxes, we'll need to use the checked property instead
} else if (!isNaN(value)) { // Is the value not not a number? Great!
input.type = 'number';
} else { // Just use a text if there's no better manipulation method
input.type = 'text';
}
// Create listener for value of input being modified
input.onchange = function() {
switch (input.type) { // Figure out how to pass data based on data type
case 'checkbox':
// For booleans, send bool of whether or not checkbox is checked
NetworkTables.setValue(key, input.checked);
break;
case 'number':
// For number values, send value of input as an int.
NetworkTables.setValue(key, parseInt(input.value));
break;
case 'text':
// For normal text values, just send the value.
NetworkTables.setValue(key, input.value);
break;
}
};
// Put the input into the div.
div.appendChild(input);
}
} else { // If the value is new
// Find already-existing input for changing this variable
var oldInput = document.getElementsByName(propName)[0];
if (oldInput) { // If there is one (there should be, unless something is wrong)
if (oldInput.type === 'checkbox') { // Figure out what data type it is and update it in the list
oldInput.checked = value;
} else {
oldInput.value = value;
}
} else {
console.log('Error: Non-new variable ' + propName + ' not present in tuning list!');
}
}
var input = document.createElement('input'); // Create input
input.name = propName; // Make its name property be the name of the NetworkTables value
input.value = value; // Set
// The following statement figures out which data type the variable is.
// If it's a boolean, it will make the input be a checkbox. If it's a number,
// it will make it a number chooser with up and down arrows in the box. Otherwise, it will make it a textbox.
if (value === true || value === false) { // Is it a boolean value?
input.type = 'checkbox';
input.checked = value; // value property doesn't work on checkboxes, we'll need to use the checked property instead
} else if (!isNaN(value)) { // Is the value not not a number? Great!
input.type = 'number';
} else { // Just use a text if there's no better manipulation method
input.type = 'text';
}
// Create listener for value of input being modified
input.onchange = function() {
switch (input.type) { // Figure out how to pass data based on data type
case 'checkbox':
// For booleans, send bool of whether or not checkbox is checked
NetworkTables.setValue(key, input.checked);
break;
case 'number':
// For number values, send value of input as an int.
NetworkTables.setValue(key, parseInt(input.value));
break;
case 'text':
// For normal text values, just send the value.
NetworkTables.setValue(key, input.value);
break;
}
};
// Put the input into the div.
div.appendChild(input);
}
} else { // If the value is new
// Find already-existing input for changing this variable
var oldInput = document.getElementsByName(propName)[0];
if (oldInput) { // If there is one (there should be, unless something is wrong)
if (oldInput.type === 'checkbox') { // Figure out what data type it is and update it in the list
oldInput.checked = value;
} else {
oldInput.value = value;
}
} else {
console.log('Error: Non-new variable ' + propName + ' not present in tuning list!');
}
}

// End section

Expand Down

0 comments on commit 793de78

Please sign in to comment.