Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev/bool dropdown #38

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions src/main/kotlin/org/team5499/dashboard/Dashboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.json.JSONObject
*
* Handles starting the server
*/
@Suppress("TooManyFunctions")
object Dashboard {

private var config: Config = Config()
Expand Down Expand Up @@ -122,17 +123,59 @@ object Dashboard {
SocketHandler.startBroadcastThread() // start broadcasting data
}

fun setVariable(key: String, value: Any) {
fun setString(key: String, value: String) {
variableUpdates.put(key, value)
}

fun <T> getVariable(key: String): T {
fun setInt(key: String, value: Int) {
variableUpdates.put(key, value)
}

fun setBool(key: String, value: Boolean) {
variableUpdates.put(key, value)
}

fun setDouble(key: String, value: Double) {
variableUpdates.put(key, value)
}

fun getString(key: String): String {
if ((!variables.has(key)) && (!variableUpdates.has(key))) {
throw DashboardException("The variable with name " + key + " was not found.")
} else if (variableUpdates.has(key)) {
return variableUpdates.getString(key)
} else {
return variables.getString(key)
}
}

fun getInt(key: String): Int {
if ((!variables.has(key)) && (!variableUpdates.has(key))) {
throw DashboardException("The variable with name " + key + " was not found.")
} else if (variableUpdates.has(key)) {
return variableUpdates.getInt(key)
} else {
return variables.getInt(key)
}
}

fun getBool(key: String): Boolean {
if ((!variables.has(key)) && (!variableUpdates.has(key))) {
throw DashboardException("The variable with name " + key + " was not found.")
} else if (variableUpdates.has(key)) {
return variableUpdates.getBoolean(key)
} else {
return variables.getBoolean(key)
}
}

fun getDouble(key: String): Double {
if ((!variables.has(key)) && (!variableUpdates.has(key))) {
throw DashboardException("The variable with name " + key + " was not found.")
} else if (variableUpdates.has(key)) {
return variableUpdates.get(key) as T
return variableUpdates.getDouble(key)
} else {
return variables.get(key) as T
return variables.getDouble(key)
}
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

{% block beforeScripts %}{% endblock %}
<script src="/javascript/libs/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script src="/javascript/libs/popper.min.js"></script>
<script src="/javascript/libs/tooltip.min.js"></script>
<script src="/javascript/libs/bootstrap.min.js"></script>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{% block beforeScripts %}{% endblock %}
{% block afterJSLibs %}
<script src="/javascript/libs/babel.min.js"></script>

{% if developmentEnvironment %}
<script src="/javascript/libs/react.development.js"></script>
<script src="/javascript/libs/react-dom.development.js"></script>
Expand Down
12 changes: 11 additions & 1 deletion src/main/resources/static/javascript/widgets/rawvareditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class RawVarEditor extends React.Component {
onVarSave() {
let newVal = $('#' + this.props.id + '_var_display').val();
SocketHandler.setVariable(this.state.targetName, newVal);

}

onFieldEdit(e) {
Expand All @@ -42,10 +43,19 @@ class RawVarEditor extends React.Component {
}

render() {
let input;
if(typeof $('#' + this.props.id + '_var_display').val() != "boolean"){
input = <input className='form-control mb-2' type='text' id={this.props.id + '_var_display'} placeholder="value" value={this.state.targetValue} onChange={(e) => this.onFieldEdit(e)} />;
}else{
input = <div id={this.props.id + '_var_display'} class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<a class="dropdown-item" href="#">True</a>
<a class="dropdown-item" href="#">False</a>
</div>;
}
return (
<WidgetContainer title={this.props.title} width={this.props.width} height={this.props.height} id={this.props.id}>
<WidgetBody title={this.props.title} id={this.props.id}>
<input className='form-control mb-2' type='text' id={this.props.id + '_var_display'} placeholder="value" value={this.state.targetValue} onChange={(e) => this.onFieldEdit(e)} />
{input}
<button className='btn btn-primary' id={this.props.id + '_body_submit'} onClick={() => this.onVarSave()} >Submit</button>
</WidgetBody>
<WidgetSettings title={this.props.title} id={this.props.id} onSave={() => this.onSettingsSave()}>
Expand Down