]> defiant.homedns.org Git - ros_wild_thumper.git/commitdiff
www: use vue.js-components to avoid duplicates
authorErik Andresen <erik@vontaene.de>
Sat, 29 Sep 2018 09:10:03 +0000 (11:10 +0200)
committerErik Andresen <erik@vontaene.de>
Sat, 29 Sep 2018 09:10:03 +0000 (11:10 +0200)
www/assets/javascripts/application.js
www/index.html

index eed4a38f4a565d1d3a121920a3bd1d5254751ef5..3f85f00359078679d2be5b09d15aa8acb4c06d94 100644 (file)
@@ -114,6 +114,16 @@ function init() {
        // Set the initial speed.
        teleop.scale = ($('#speed-slider').slider('value') * 2);
 
+       new Vue({
+               el: '#lights',
+               data: {
+                       front_row: ["[0]", "[1]", "[2]", "[3]"],
+                       top_row: ["[7]", "[6]", "[5]", "[4]"],
+                       aft_row: ["[8]", "[9]", "[10]", "[11]"],
+                       bottom_left_row: ["[14]", "[15]"],
+                       bottom_right_row: ["[13]", "[12]"],
+               }
+       })
        $('.led_color').minicolors({
                control: 'wheel',
                format: 'rgb',
@@ -216,4 +226,15 @@ function init() {
                        speed: $('#speed-slider').slider('value'),
                }
        })
+
 }
+
+Vue.component('input-value', {
+       template: '#input-value-template',
+       props: ['value', 'label', 'unit']
+})
+
+Vue.component('input-led', {
+       template: '#input-led-template',
+       props: ['name', 'label']
+})
index e9e23f672d195fb4fd94cc798953fd7a760a3143..97428fe915329182ea9e77e270e2c5f7f64e0b60 100644 (file)
                                <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" href="#lights" data-toggle="tab" role="tab">Lights</a>
+                                               <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" 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" v-model="current" readonly>
-                                                               <div class="input-group-append">
-                                                                       <span class="input-group-text">A</span>
-                                                               </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" 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" 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" 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" 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" v-model="co" 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="speed-label">Speed: {{speed}} m/s</div>
                                        <div id="speed-slider"></div>
                                </div>
-                               <div id="lights" class="tab-pane" role="tabpanel">
+                               <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="[0]" readonly="true"/>
-                                                               <input class="led_color" type="hidden" name="[1]" readonly="true"/>
-                                                               <input class="led_color" type="hidden" name="[2]" readonly="true"/>
-                                                               <input class="led_color" type="hidden" name="[3]" readonly="true"/>
+                                                               <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="[14]" readonly="true"/>
-                                                                               <input class="led_color" type="hidden" name="[15]" readonly="true"/>
+                                                                               <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="[7]" readonly="true"/>
-                                                                                       <input class="led_color" type="hidden" name="[6]" readonly="true"/>
-                                                                                       <input class="led_color" type="hidden" name="[5]" readonly="true"/>
-                                                                                       <input class="led_color" type="hidden" name="[4]" readonly="true"/>
+                                                                                       <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="[13]" readonly="true"/>
-                                                                               <input class="led_color" type="hidden" name="[12]" readonly="true"/>
+                                                                               <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="[8]" readonly="true"/>
-                                                               <input class="led_color" type="hidden" name="[9]" readonly="true"/>
-                                                               <input class="led_color" type="hidden" name="[10]" readonly="true"/>
-                                                               <input class="led_color" type="hidden" name="[11]" readonly="true"/>
+                                                               <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">
-                                                       <div class="form-group row">
-                                                               <label class="col-sm-2 col-form-label">Alle</label>
-                                                               <div class="col-sm-10">
-                                                                       <input class="led_color" type="text" name="[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]" class="form-control" readonly="true"/>
-                                                               </div>
-                                                       </div>
-                                                       <div class="form-group row">
-                                                               <label class="col-sm-2 col-form-label">Front</label>
-                                                               <div class="col-sm-10">
-                                                                       <input class="led_color" type="text" name="[0, 1, 2, 3]" class="form-control" readonly="true"/>
-                                                               </div>
-                                                       </div>
-                                                       <div class="form-group row">
-                                                               <label class="col-sm-2 col-form-label">Aft</label>
-                                                               <div class="col-sm-10">
-                                                                       <input class="led_color" type="text" name="[8, 9, 10, 11]" class="form-control" readonly="true"/>
-                                                               </div>
-                                                       </div>
-                                                       <div class="form-group row">
-                                                               <label class="col-sm-2 col-form-label">Top</label>
-                                                               <div class="col-sm-10">
-                                                                       <input class="led_color" type="text" name="[4, 5, 6, 7]" class="form-control" readonly="true"/>
-                                                               </div>
-                                                       </div>
-                                                       <div class="form-group row">
-                                                               <label class="col-sm-2 col-form-label">Bottom</label>
-                                                               <div class="col-sm-10">
-                                                                       <input class="led_color" type="text" name="[12, 13, 14, 15]" class="form-control" readonly="true"/>
-                                                               </div>
-                                                       </div>
+                                                       <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>
                </div>
        </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>