فهرست منبع

added categories

Andrew Tridgell 4 سال پیش
والد
کامیت
bf517698d2
2فایلهای تغییر یافته به همراه36 افزوده شده و 20 حذف شده
  1. 15 7
      app.py
  2. 21 13
      templates/index.html

+ 15 - 7
app.py

@@ -350,15 +350,19 @@ def generate():
         feature_list = []
         selected_features = []
         app.logger.info('Fetching features from user input')
+
+        # add all undefs at the start
+        for f in BUILD_OPTIONS:
+            extra_hwdef.append('undef %s' % f.define)
+
         for f in BUILD_OPTIONS:
             if f.label not in request.form:
                 continue
-            extra_hwdef.append(request.form[f.label])
-            if request.form[f.label][-1] == '1':
+            if request.form[f.label] == '1':
+                extra_hwdef.append('define %s 1' % f.define)
                 feature_list.append(f.description)
                 selected_features.append(f.label)
-            undefine = 'undef ' + f.define
-            extra_hwdef.insert(0, undefine)
+
         extra_hwdef = '\n'.join(extra_hwdef)
         spaces = '\n'
         feature_list = spaces.join(feature_list)
@@ -464,8 +468,11 @@ def view():
     return render_template('generate.html', token=token)
 
     
-def get_build_options():
-    return BUILD_OPTIONS
+def get_build_options(category):
+    return [f for f in BUILD_OPTIONS if f.category == category]
+
+def get_build_categories():
+    return sorted(list(set([f.category for f in BUILD_OPTIONS])))
 
 def get_vehicles():
     return (VEHICLES, default_vehicle)
@@ -476,7 +483,8 @@ def home():
     return render_template('index.html',
                            get_boards=get_boards,
                            get_vehicles=get_vehicles,
-                           get_build_options=get_build_options)
+                           get_build_options=get_build_options,
+                           get_build_categories=get_build_categories)
 
 @app.route("/builds/<path:name>")
 def download_file(name):

+ 21 - 13
templates/index.html

@@ -31,7 +31,7 @@
                     {% endif %}
                 {% endfor %}
             </select>
-            <br><br>
+            <p/>
             <label for="board">Choose a board:</label>
             <select name="board">
                 {% for board in get_boards()[0] %}
@@ -42,17 +42,25 @@
                     {% endif %}
                 {% endfor %}
             </select>
-            <br><br>
-            {% for f in get_build_options() %}
-                {% if f.default == 0 %}
-                    <input type="checkbox" name="{{f.label}}" value="define {{f.define}} 1">
-                    <input type="hidden" name="{{f.label}}" value="define {{f.define}} 0"> {{f.description}}
-                {% else %}
-                    <input type="checkbox" name="{{f.label}}" value="define {{f.define}} 1" checked>
-                    <input type="hidden" name="{{f.label}}" value="define {{f.define}} 0"> {{f.description}}
-                {% endif %}
-            <br>
-            {% endfor %}
+            <p/>
+            <label for="board">Select Features:</label>
+            <ul>
+              {% for c in get_build_categories() %}
+              <li>{{c}}</li>
+                <ul>
+                  {% for f in get_build_options(c) %}
+                    <li>
+                    {% if f.default == 1 %}
+                    <input type="checkbox" name="{{f.label}}" value="1" checked>
+                    {% else %}
+                    <input type="checkbox" name="{{f.label}}" value="1">
+                    {% endif %}
+                    {{f.description}}
+                    </li>
+                  {% endfor %}
+                </ul>
+              {% endfor %}
+            </ul>
             <br>
             <input type="submit" value="Generate" method="post">
         </form>
@@ -60,7 +68,7 @@
 <hr>
     <div id="build_status"></div>
 <br />
-    <script>
+      <script>
       function reload() {
             var output = document.getElementById('build_status');
             var xhr = new XMLHttpRequest();