This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpreference-editor.html
162 lines (142 loc) · 4.83 KB
/
preference-editor.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>SmartDashboard.js - Properties</title>
<link rel="stylesheet" href="index.css" />
<script>
document.write('<link rel="stylesheet" id="theme-css" href="' + global.FileUtils.getThemeLocation() + '"/>');
</script>
<link rel="stylesheet" href="assets/font-awesome.min.css" />
<style>
form {
height: 100%;
width: 100%;
display: flex;
flex-direction: column;
}
.form-items {
flex: 1 1 auto;
overflow-y: auto;
min-height: 0px;
padding: 1em;
border-collapse: collapse;
border-spacing: 0;
}
.form-table {
width: 100%;
height: 100%;
display: table;
}
.button-pane {
border-top: 1px solid black;
width: 100%;
text-align: right;
-webkit-app-region: drag;
}
.button-pane button {
-webkit-app-region: no-drag;
}
.form-items label {
display: table-row;
border-collapse: collapse;
border-spacing: 0;
}
.form-items label span {
text-align: right;
vertical-align: top;
display: table-cell;
padding-right: 0.2em;
white-space: nowrap;
}
.form-items .input-container {
display: table-cell;
border-collapse: collapse;
border-spacing: 0;
width: 100%;
}
input, textarea {
box-sizing: border-box;
width: 100%;
resize: vertical;
}
.dialog-header {
margin: 0;
padding-left: 0.2em;
-webkit-app-region: drag;
}
</style>
</head>
<body class="properties">
<form action="javascript:void(0)">
<h3 class="dialog-header"><i class="fa fa-sliders" aria-hidden="true"></i> Robot Preferences Editor</h3>
<div class="form-items">
<div class="form-table">
</div>
</div>
<div class="align-bottom text-right button-pane">
Click out or [F10] to update
<button type="button" id="close">Close</button>
</div>
</form>
<script>
var gui = require("nw.gui");
if(location.hash == "#in-frame") {
document.querySelector(".dialog-header").style.display = "none";
document.querySelector(".button-pane").style.display = "none";
}
document.querySelector("#close").onclick = function(){
window.close();
}
document.onkeyup = function(e){
if(e.which == 121){ // F10
try {
document.querySelector(":focus").blur();
} catch(e) {} // querySelector() returns null
}
};
function update(key, value){
global.SmartDashboard.setPreference(key, value);
}
function addPreference(name, type, def){
var label = document.createElement("label");
var text = document.createElement("span");
text.textContent = name + ": ";
label.appendChild(text);
var inp = document.createElement("input");
var cont = document.createElement("div");
cont.classList.add("input-container");
if(type == "textarea"){
inp = document.createElement("textarea");
}
cont.appendChild(inp);
inp.setAttribute("type", type);
if(type == "checkbox"){
inp.checked = def;
} else {
inp.setAttribute("value", def);
}
inp.onchange = (function(name){
return function(e){
var val =
(type == "checkbox") ? e.target.checked :
(type == "number") ? parseFloat(e.target.value) : e.target.value;
update(name, val);
};
})(name);
label.appendChild(cont);
document.querySelector(".form-table").appendChild(label);
}
global.SmartDashboard.getPreferenceKeys().forEach(function(key){
var rawType = global.WidgetUtils.getTypeForEntry("Preferences/" + key);
var type = "text";
if(rawType == "number"){
type = "number";
} else if(rawType == "boolean"){
type = "checkbox";
}
addPreference(key, type, global.SmartDashboard.getPreference(key));
});
</script>
</body>
</html>