www: use vue.js
[ros_wild_thumper.git] / www / index.html
index 4e6b565..4be3d5e 100644 (file)
                        var isDragging = false;
 
                        ros.on('connection', function() {
-                               $("#information").append(`
-                               <div class="alert alert-dismissible alert-success">
-                                       <span data-dismiss="alert">Connected to websocket server.</span>
-                               </div>
-                               `);
+                               information.alerts.push({message: "Connected to websocket server.", success: true});
                        });
 
                        ros.on('error', function(error) {
-                               $("#information").append(`
-                               <div class="alert alert-dismissible alert-danger">
-                                       <span data-dismiss="alert">Error connecting to websocket server.</span>
-                               </div>
-                               `);
+                               information.alerts.push({message: "Error connecting to websocket server.", danger: true});
                        });
 
                        ros.on('close', function() {
-                               $("#information").append(`
-                               <div class="alert alert-dismissible alert-info">
-                                       <span data-dismiss="alert">Connection to websocket server closed.</span>
-                               </div>
-                               `);
+                               information.alerts.push({message: "Connection to websocket server closed.", info: true});
                        });
 
                        //tfClient.subscribe('base_link', function(tf) {
                        });
 
                        sensorTopic.subscribe(function(message) {
-                               sensordiv = $("#sensors")
-                               sensordiv.find("input[name=light]").val(message.light);
-                               sensordiv.find("input[name=temp]").val(message.temp.toFixed(1));
-                               sensordiv.find("input[name=humidity]").val(message.humidity);
-                               sensordiv.find("input[name=pressure]").val(message.pressure.toFixed(1));
-                               sensordiv.find("input[name=co]").val(message.co);
+                               sensors.light = message.light;
+                               sensors.temp = message.temp.toFixed(1);
+                               sensors.humidity = message.humidity;
+                               sensors.pressure = message.pressure.toFixed(1);
+                               sensors.co = message.co;
                        });
 
                        batteryTopic.subscribe(function(message) {
-                               powerdiv = $("#power");
-                               powerdiv.find("input[name=voltage]").val(message.voltage.toFixed(1));
-                               powerdiv.find("input[name=current]").val(message.current.toFixed(1));
+                               power.voltage = message.voltage.toFixed(1);
+                               power.current = message.current.toFixed(1);
                        });
 
                        viewer2D = new ROS2D.Viewer({
                                value : 0.5,
                                slide : function(event, ui) {
                                        // Change the speed label.
-                                       $('#speed-label').html('Speed: ' + ui.value + ' m/s');
+                                       speed_label.speed = ui.value;
                                        // Scale the speed.
                                        teleop.scale = (ui.value * 2);
                                }
                        });
 
                        // Set the initial speed.
-                       $('#speed-label').html('Speed: ' + ($('#speed-slider').slider('value')) + ' m/s');
                        teleop.scale = ($('#speed-slider').slider('value') * 2);
 
                        $('.led_color').minicolors({
                                        setSpeed(trans, rot*3);
                                }
                        });
+
+                       information = new Vue({
+                               el: '#information',
+                               data: {
+                                       alerts: [],
+                               },
+                               methods: {
+                                       classObject: function(id) {
+                                               return {
+                                                       "alert-success": this.alerts[id].success,
+                                                       "alert-danger": this.alerts[id].danger,
+                                                       "alert-info": this.alerts[id].info
+                                               }
+                                       }
+                               }
+                       })
+
+                       sensors = new Vue({
+                               el: '#sensors',
+                               data: {light: '', temp: '', humidity: '', pressure: '', co: ''}
+                       })
+
+                       power = new Vue({
+                               el: '#power',
+                               data: {
+                                       voltage: '',
+                                       current: '',
+                               }
+                       })
+
+                       speed_label = new Vue({
+                               el: '#speed-label',
+                               data: {
+                                       speed: $('#speed-slider').slider('value'),
+                               }
+                       })
                }
                </script>
                <title>Wild Thumper control</title>
        <body onload="init()">
                <div class="container-fluid">
                        <div id="information">
+                               <div v-for="(alert, id) in alerts" class="alert alert-dismissible}" v-bind:class="classObject(id)">
+                                       <span data-dismiss="alert">{{alert.message}}</span>
+                               </div>
                        </div>
 
                        <nav class="navbar navbar-expand-lg navbar-light bg-light">
                                                        <h4>Power</h4>
                                                        <label>Voltage:</label>
                                                        <div class="input-group">
-                                                               <input type=text name="voltage" class="form-control" readonly>
+                                                               <input type=text name="voltage" class="form-control" v-model="voltage" readonly>
                                                                <div class="input-group-append">
                                                                        <span class="input-group-text">V</span>
                                                                </div>
                                                        </div>
                                                        <label>Current:</label>
                                                        <div class="input-group">
-                                                               <input type=text name="current" class="form-control" readonly>
+                                                               <input type=text name="current" class="form-control" v-model="current" readonly>
                                                                <div class="input-group-append">
                                                                        <span class="input-group-text">A</span>
                                                                </div>
                                                        <h4>Sensors</h4>
                                                        <label>Light:</label>
                                                        <div class="input-group">
-                                                               <input type=text name="light" class="form-control" readonly>
+                                                               <input type=text name="light" class="form-control" v-model="light" readonly>
                                                                <div class="input-group-append">
                                                                        <span class="input-group-text">lx</span>
                                                                </div>
                                                        </div>
                                                        <label>Temperature:</label>
                                                        <div class="input-group">
-                                                               <input type=text name="temp" class="form-control" readonly>
+                                                               <input type=text name="temp" class="form-control" v-model="temp" readonly>
                                                                <div class="input-group-append">
                                                                        <span class="input-group-text">&#x2103</span>
                                                                </div>
                                                        </div>
                                                        <label>Humidity:</label>
                                                        <div class="input-group">
-                                                               <input type=text name="humidity" class="form-control" readonly>
+                                                               <input type=text name="humidity" class="form-control" v-model="humidity" readonly>
                                                                <div class="input-group-append">
                                                                        <span class="input-group-text">%</span>
                                                                </div>
                                                        </div>
                                                        <label>Pressure:</label>
                                                        <div class="input-group">
-                                                               <input type=text name="pressure" class="form-control" readonly>
+                                                               <input type=text name="pressure" class="form-control" v-model="pressure" readonly>
                                                                <div class="input-group-append">
                                                                        <span class="input-group-text">kPa</span>
                                                                </div>
                                                        </div>
                                                        <label>CO:</label>
-                                                       <input type=text name="co" class="form-control" readonly>
+                                                       <input type=text name="co" class="form-control" v-model="co" readonly>
                                                </div>
                                        </div>
                                </div>
                                <div id="navigation" class="tab-pane" role="tabpanel">
                                        <div id="pose"></div>
                                        <div id="map"></div>
-                                       <div id="speed-label"></div>
+                                       <div id="speed-label">Speed: {{speed}} m/s</div>
                                        <div id="speed-slider"></div>
                                </div>
                                <div id="lights" class="tab-pane" role="tabpanel">
                <script src="assets/javascripts/nav2d.js"></script>
                <script src="assets/javascripts/keyboardteleop.js"></script>
                <script src="assets/javascripts/jquery.minicolors.js"></script>
+               <script src="assets/javascripts/vue.js"></script>
        </body>
 </html>