-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
217 lines (187 loc) · 7.46 KB
/
index.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
</div>
<script src="js/rSlider.min.js"></script>
<script src="src/js/rSlider.js"></script>
<script src="src/js/restClient.js"></script>
<script>
(function() {
'use strict';
var init = function() {
function getArrayValues(values) {
if (values.indexOf(',') > 0) {
var stringValues = values.split(',');
var intValues = [];
var slider2 = new rSlider({
for (var i = 0; i < stringValues.length; i++) {
intValues.push(parseInt(stringValues[i]));
}
return intValues;
}
return [parseInt(values)];
}
function run(config) {
console.log('config', config);
const mode = config.modes[config.active];
var simv = new rSlider({
target: '#slider2',
values: {
min: 0,
max: 30
min: mode.simv.min,
max: mode.simv.max
},
range: true,
step: 1,
set: [5, 12],
set: mode.simv.value,
tooltip: true,
labels: false,
onChange: function(vals) {
console.log(vals);
console.log(getArrayValues(vals));
var newConfig = Object.assign({}, config);
newConfig.modes[newConfig.active].simv.value = getArrayValues(vals);
RestClient.postConfig(newConfig, function (response) {
console.log('new config saved', response);
})
}
});
var slider3 = new rSlider({
var tidal_volume = new rSlider({
target: '#slider3',
values: {
min: 0,
max: 500
min: mode.tidal_volume.min,
max: mode.tidal_volume.max
},
step: 10,
range: false,
set: [250],
set: mode.tidal_volume.value,
scale: true,
labels: false,
onChange: function(vals) {
console.log(vals);
console.log(getArrayValues(vals));
var newConfig = Object.assign({}, config);
newConfig.modes[newConfig.active].tidal_volume.value = getArrayValues(vals);
RestClient.postConfig(newConfig, function (response) {
console.log('new config saved', response);
})
}
});
var slider = new rSlider({
var peep = new rSlider({
target: '#slider',
values: {
min: 0,
max: 30
min: mode.peep.min,
max: mode.peep.max
},
step: 1,
range: true,
set: [6, 20],
set: mode.peep.value,
scale: false,
labels: false,
onChange: function(vals) {
console.log(vals);
console.log(getArrayValues(vals));
var newConfig = Object.assign({}, config);
newConfig.modes[newConfig.active].peep.value = getArrayValues(vals);
RestClient.postConfig(newConfig, function (response) {
console.log('new config saved', response);
})
}
});
var slider4 = new rSlider({
var i_ratio = new rSlider({
target: '#slider4',
values: {
min: 0,
max: 4
min: mode.i_ratio.min,
max: mode.i_ratio.max
},
step: 1,
range: false,
set: [1],
set: mode.i_ratio.value,
scale: true,
labels: false,
onChange: function(vals) {
console.log(vals);
console.log(getArrayValues(vals));
var newConfig = Object.assign({}, config);
newConfig.modes[newConfig.active].i_ratio.value = getArrayValues(vals);
RestClient.postConfig(newConfig, function (response) {
console.log('new config saved', response);
})
}
});
var slider5 = new rSlider({
var e_ratio = new rSlider({
target: '#slider5',
values: {
min: 0,
max: 4
min: mode.e_ratio.min,
max: mode.e_ratio.max
},
step: 1,
range: false,
set: [1],
set: mode.e_ratio.value,
scale: true,
labels: true,
onChange: function(vals) {
console.log(vals);
console.log(getArrayValues(vals));
var newConfig = Object.assign({}, config);
newConfig.modes[newConfig.active].e_ratio.value = getArrayValues(vals);
RestClient.postConfig(newConfig, function (response) {
console.log('new config saved', response);
})
}
});
};
function init() {
RestClient.getConfig(run);
}
if (document.readyState != 'loading'){
init();
if (document.readyState != 'loading') {
RestClient.getConfig(init);
} else {
document.addEventListener('DOMContentLoaded', init);
}
32 src/js/restClient.js
@@ -0,0 +1,32 @@
(function () {
var host = "http://192.168.1.6:5000";
var configUrl = host + '/config';
window.RestClient = {
getConfig: function (cb) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
cb(JSON.parse(this.responseText))
}
};
xhr.open("GET", configUrl, true);
xhr.send();
},
postConfig: function (data, cb) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
cb(JSON.parse(this.responseText))
}
};
xhr.open("POST", configUrl, true);
xhr.setRequestHeader("Content-type", "application/json");
xhr.send(JSON.stringify(data));
}
};
})();