www: use vue.js-components to avoid duplicates
[ros_wild_thumper.git] / www / index.html
index a5509cb..97428fe 100644 (file)
 <!doctype html>
-<!--
-       Server: python -m SimpleHTTPServer
-       Bridge: roslaunch rosbridge_server rosbridge_websocket.launch
--->
 <html>
        <head>
                <meta charset="utf-8" />
 
-               <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
-               <link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
-
-               <script type="text/javascript">
-               function init() {
-                       var ros = new ROSLIB.Ros();
-                       ros.connect('ws://wildthumper:9090');
-                       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>
-                               `);
-                       });
-
-                       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>
-                               `);
-                       });
-
-                       ros.on('close', function() {
-                               $("#information").append(`
-                               <div class="alert alert-dismissible alert-info">
-                                       <span data-dismiss="alert">Connection to websocket server closed.</span>
-                               </div>
-                               `);
-                       });
-
-                       //tfClient.subscribe('base_link', function(tf) {
-                       //      var now = new Date();
-                       //      $("#pose").text(now.toLocaleTimeString() + ": (" + tf.translation.x + ", " + tf.translation.y + ")");
-
-                       //      robotMarker.x = tf.translation.x;
-                       //      robotMarker.y = -tf.translation.y;
-                       //      robotMarker.rotation = viewer2D.scene.rosQuaternionToGlobalTheta(tf.rotation);
-                       //});
-                       var poseTopic = new ROSLIB.Topic({ros: ros, name: '/robot_pose', messageType : 'geometry_msgs/Pose'});
-                       var sensorTopic = new ROSLIB.Topic({ros: ros, name: '/sensors', messageType : 'wild_thumper/Sensor'});
-                       var batteryTopic = new ROSLIB.Topic({ros: ros, name: '/battery', messageType : 'sensor_msgs/BatteryState'});
-
-                       poseTopic.subscribe(function(message) {
-                               var now = new Date();
-                               $("#pose").text(now.toLocaleTimeString() + ": (" + message.position.x + ", " + message.position.y + ")");
-                       });
-
-                       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);
-                       });
-
-                       itest = 123.4556;
-                       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));
-                       });
-
-                       viewer2D = new ROS2D.Viewer({
-                               divID: 'map',
-                               width: 640,
-                               height: 480,
-                               background: "#efefef"
-                       });
-                       $('#map')
-                       .bind('mousewheel', function(e) {
-                               if (e.originalEvent.wheelDelta/120 > 0) {
-                                       viewer2D.scaleToDimensions(10, 10)
-                               } else {
-                                       viewer2D.scaleToDimensions(5, 5)
-                               }
-                       })
-                       .mousedown(function() {
-                               isDragging = true;
-                               mousePreX = undefined;
-                               mousePreY = undefined;
-                       })
-                       .mouseup(function() {
-                               isDragging = false;
-                       })
-                       .mousemove(function(event) {
-                               if (isDragging) {
-                                       if (mousePreX != undefined && mousePreY != undefined) {
-                                               var diffX = event.pageX - mousePreX;
-                                               var diffY = event.pageY - mousePreY;
-                                               console.log("Moving viewer2D by " + diffX + ", " + diffY);
-                                               viewer2D.shift(diffX, diffY);
-                                       }
-                                       mousePreX = event.pageX;
-                                       mousePreY = event.pageY;
-                               }
-                       });
-
-                       // Setup the nav client.
-                       NAV2D.OccupancyGridClientNav({
-                               ros : ros,
-                               rootObject : viewer2D.scene,
-                               viewer : viewer2D,
-                               serverName : '/move_base'
-                       });
-
-                       // Initialize the teleop.
-                       var teleop = new KEYBOARDTELEOP.Teleop({
-                               ros : ros,
-                               topic : '/cmd_vel'
-                       });
-
-                       // Create a UI slider using JQuery UI.
-                       $('#speed-slider').slider({
-                               range : 'min',
-                               min : 0,
-                               max : 100,
-                               value : 50,
-                               slide : function(event, ui) {
-                                       // Change the speed label.
-                                       $('#speed-label').html('Speed: ' + ui.value + '%');
-                                       // Scale the speed.
-                                       teleop.scale = (ui.value / 100.0);
-                               }
-                       });
-
-                       // Set the initial speed.
-                       $('#speed-label').html('Speed: ' + ($('#speed-slider').slider('value')) + '%');
-                       teleop.scale = ($('#speed-slider').slider('value') / 100.0);
-               }
-               </script>
+               <link rel="stylesheet" href="assets/stylesheets/bootstrap.min.css">
+               <link rel="stylesheet" href="assets/stylesheets/jquery-ui.css">
+               <link rel="stylesheet" href="assets/stylesheets/jquery.minicolors.css">
+               <link rel="stylesheet" href="assets/stylesheets/application.css">
+
+               <script src="assets/javascripts/jquery-3.3.1.min.js"></script>
+               <script src="assets/javascripts/popper.min.js"></script>
+               <script src="assets/javascripts/bootstrap.min.js"></script>
+               <script src="assets/javascripts/jquery-ui.min.js"></script>
+               <script src="assets/javascripts/easeljs.min.js"></script>
+               <script src="assets/javascripts/eventemitter2.js"></script>
+               <script src="assets/javascripts/roslib.js"></script>
+               <script src="assets/javascripts/ros2d.js"></script>
+               <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>
+               <script src="assets/javascripts/application.js"></script>
+
+               <title>Wild Thumper control</title>
        </head>
        <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">
                                <a class="navbar-brand" href="#">Wild Thumper</a>
                                <ul class="nav nav-tabs" role="tablist">
                                        <li class="nav-item">
-                                               <a class="nav-link active" href="#data" data-toggle="tab" role="tab">Data</a>
+                                               <a class="nav-link" href="#data" data-toggle="tab" role="tab">Data</a>
                                        </li>
                                        <li class="nav-item">
                                                <a class="nav-link" href="#navigation" data-toggle="tab" role="tab">Navigation</a>
                                        </li>
+                                       <li class="nav-item">
+                                               <a class="nav-link active" href="#lights" data-toggle="tab" role="tab">Lights</a>
+                                       </li>
+                                       <li class="nav-item">
+                                               <a class="nav-link" href="#drive" data-toggle="tab" role="tab">Drive</a>
+                                       </li>
                                </ul>
                        </nav>
+
                        <div class="tab-content">
-                               <div id="data" class="tab-pane active" role="tabpanel">
+                               <div id="data" class="tab-pane" role="tabpanel">
                                        <div class="row">
                                                <div id="power" class="col-auto">
                                                        <h4>Power</h4>
-                                                       <label>Voltage:</label>
-                                                       <div class="input-group">
-                                                               <input type=text name="voltage" class="form-control" readonly>
-                                                               <div class="input-group-addon">V</div>
-                                                       </div>
-                                                       <label>Current:</label>
-                                                       <div class="input-group">
-                                                               <input type=text name="current" class="form-control" readonly>
-                                                               <div class="input-group-addon">A</div>
-                                                       </div>
+                                                       <input-value v-model="voltage" label="Voltage" unit="V"></input-value>
+                                                       <input-value v-model="current" label="Current" unit="A"></input-value>
                                                </div>
                                                <div id="sensors" class="col-auto">
                                                        <h4>Sensors</h4>
-                                                       <label>Light:</label>
-                                                       <div class="input-group">
-                                                               <input type=text name="light" class="form-control" readonly>
-                                                               <div class="input-group-addon">lx</div>
-                                                       </div>
-                                                       <label>Temperature:</label>
-                                                       <div class="input-group">
-                                                               <input type=text name="temp" class="form-control" readonly>
-                                                               <div class="input-group-addon">&#x2103</div>
-                                                       </div>
-                                                       <label>Humidity:</label>
-                                                       <div class="input-group">
-                                                               <input type=text name="humidity" class="form-control" readonly>
-                                                               <div class="input-group-addon">%</div>
-                                                       </div>
-                                                       <label>Pressure:</label>
-                                                       <div class="input-group">
-                                                               <input type=text name="pressure" class="form-control" readonly>
-                                                               <div class="input-group-addon">kPa</div>
-                                                       </div>
-                                                       <label>CO:</label>
-                                                       <input type=text name="co" class="form-control" readonly>
+                                                       <input-value v-model="light" label="Light" unit="lx"></input-value>
+                                                       <input-value v-model="temp" label="Temperature" unit="&#x2103"></input-value>
+                                                       <input-value v-model="humidity" label="Humidity" unit="%"></input-value>
+                                                       <input-value v-model="pressure" label="Pressure" unit="kPa"></input-value>
+                                                       <input-value v-model="co" label="CO"></input-value>
                                                </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 active" role="tabpanel">
+                                       <div class="row">
+                                               <div class="col-md-2 offset-md-1" >
+                                                       <div class="d-flex justify-content-center">
+                                                               <input class="led_color" type="hidden" :name="led" readonly="true" v-for="led in front_row" />
+                                                       </div>
+                                                       <div>
+                                                               <div class="row wt-icon">
+                                                                       <div class="col-md-2 align-self-center bottom-leds">
+                                                                               <input class="led_color" type="hidden" :name="led" readonly="true" v-for="led in bottom_left_row" />
+                                                                       </div>
+                                                                       <div class="col-md-8">
+                                                                               <div class="d-flex justify-content-center top-leds">
+                                                                                       <input class="led_color" type="hidden" :name="led" readonly="true" v-for="led in top_row" />
+                                                                               </div>
+                                                                       </div>
+                                                                       <div class="col-md-2 align-self-center bottom-leds">
+                                                                               <input class="led_color" type="hidden" :name="led" readonly="true" v-for="led in bottom_right_row" />
+                                                                       </div>
+                                                               </div>
+                                                       </div>
+                                                       <div class="d-flex justify-content-center">
+                                                               <input class="led_color" type="hidden" :name="led" readonly="true" v-for="led in aft_row" />
+                                                       </div>
+                                               </div>
+                                               <div class="col-md-3 offset-md-1">
+                                                       <input-led label="All" name="[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]"></input-led>
+                                                       <input-led label="Front" name="[0, 1, 2, 3]"></input-led>
+                                                       <input-led label="Aft" name="[8, 9, 10, 11]"></input-led>
+                                                       <input-led label="Top" name="[4, 5, 6, 7]"></input-led>
+                                                       <input-led label="Bottom" name="[12, 13, 14, 15]"></input-led>
+                                               </div>
+                                       </div>
+                               </div>
+                               <div id="drive" class="tab-pane" role="tabpanel">
+                                       <div class="cmd_vel_circle"></div>
+                               </div>
                        </div>
                </div>
-               <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
-               <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js" integrity="sha384-vFJXuSJphROIrBnz7yo7oB41mKfc8JzQZiCq4NCceLEaO4IHwicKwpJf9c9IpFgh" crossorigin="anonymous"></script>
-               <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js" integrity="sha384-alpBpkh1PFOepccYVYDB4do5UnbKysX5WZXm3XxPqe5iKTfUKjNkCk9SaVuEZflJ" crossorigin="anonymous"></script>
-               <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
-               <script src="http://static.robotwebtools.org/EaselJS/current/easeljs.min.js"></script>
-               <script src="http://static.robotwebtools.org/EventEmitter2/current/eventemitter2.js"></script>
-               <script src="http://static.robotwebtools.org/roslibjs/current/roslib.js"></script>
-               <script src="http://static.robotwebtools.org/ros2djs/current/ros2d.js"></script>
-               <script src="http://static.robotwebtools.org/nav2djs/current/nav2d.js"></script>
-               <script src="http://static.robotwebtools.org/keyboardteleopjs/current/keyboardteleop.js"></script>
        </body>
+       <script type="text/x-template" id="input-value-template">
+               <div class="input-value">
+                       <label>{{label}}:</label>
+                       <div class="input-group">
+                               <input type=text class="form-control" :value="value" readonly>
+                               <div class="input-group-append" v-if="unit">
+                                       <span class="input-group-text">{{unit}}</span>
+                               </div>
+                       </div>
+               </div>
+       </script>
+       <script type="text/x-template" id="input-led-template">
+               <div class="form-group row">
+                       <label class="col-sm-2 col-form-label">{{label}}</label>
+                       <div class="col-sm-10">
+                               <input type="text" :name="name" class="led_color" readonly="true"/>
+                       </div>
+               </div>
+       </script>
 </html>