Просмотр исходного кода

Accounted for multiple dependencies

willpiper 4 лет назад
Родитель
Сommit
7a5a372a11
2 измененных файлов с 16 добавлено и 7 удалено
  1. 3 2
      app.py
  2. 13 5
      templates/index.html

+ 3 - 2
app.py

@@ -13,7 +13,8 @@ import fnmatch
 from distutils.dir_util import copy_tree
 from flask import Flask, render_template, request, send_from_directory, render_template_string
 from threading import Thread, Lock
-from dataclasses import dataclass
+from dataclasses import dataclass, field
+from typing import List
 
 # run at lower priority
 os.nice(20)
@@ -59,8 +60,8 @@ class Feature:
     default: int
     dependency: str
 
-
 # list of build options to offer
+# NOTE: the dependencies must be written as a single string with commas and no spaces, eg. 'dependency1,dependency2'
 BUILD_OPTIONS = [
     Feature('AHRS', 'EKF3', 'HAL_NAVEKF3_AVAILABLE', 'Enable EKF3', 1, None),
     Feature('AHRS', 'EKF2', 'HAL_NAVEKF2_AVAILABLE', 'Enable EKF2', 0, None),

+ 13 - 5
templates/index.html

@@ -21,6 +21,8 @@
 
         <p>Please select the required options for the custom firmware build.</p>
 
+        <textarea style="float:right" readonly>hello</textarea>
+
         <form action="/generate" method="post">
             <label for="vehicle">Choose a vehicle:</label>
             <select name="vehicle">
@@ -52,9 +54,9 @@
                   {% for f in get_build_options(c) %}
                     <li>
                     {% if f.default == 1 %}
-                    <input onclick='handleClick(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox" name="{{f.label}}" id="{{f.label}}" value="1" checked>
+                    <input onclick='dependencies(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox" name="{{f.label}}" id="{{f.label}}" value="1" checked>
                     {% else %}
-                    <input onclick='handleClick(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox" name="{{f.label}}" id="{{f.label}}" value="1">
+                    <input onclick='dependencies(this, "{{f.label}}", "{{f.dependency}}");' type="checkbox" name="{{f.label}}" id="{{f.label}}" value="1">
                     {% endif %}
                     {{f.description}}
                     </li>
@@ -70,6 +72,8 @@
 <hr>
     <div id="build_status"></div>
 <br />
+<p id="demo"></p>
+<p id="demo2"></p>
     <script>
         CollapsibleLists.apply();
         function reload() {
@@ -91,11 +95,15 @@
             xhr.send();
             }
         
-        function handleClick(cb, f_label, f_dependency) {
+        function dependencies(cb, f_label, f_dependency1) {
             switch (cb.name) {
             case f_label:
-                if (document.getElementById(f_dependency).checked == false){
-                    document.getElementById(f_dependency).checked = cb.checked;
+                const f_dependency = f_dependency1.split(",")
+                var arrayLength = f_dependency.length;
+                for (var i = 0; i < arrayLength; i++) {
+                    if (document.getElementById(f_dependency[i]).checked == false){
+                        document.getElementById(f_dependency[i]).checked = cb.checked;
+                }
                 }
             break;
             }