Browse Source

working configiration section, including read and save of dynamic values. Default values come from code.

new index page template including a statuspage showing up information of the system -> code extension
needed, to recognize status of devices and mainboard and filesystem status



git-svn-id: svn://svn.siningsoft.de/myCar@7 4258477e-9397-4ceb-bd8a-6305f6291781
devnull 7 years ago
parent
commit
f486a8d6a7

+ 5 - 0
lib/config.py

@@ -13,3 +13,8 @@ def myCar_read_config_defaults(config):
     # return a valid config object either 
     # with or without default values
     return config
+
+def myCar_save_config(config):
+    import configparser
+    with open('data/etc/myCar.conf', 'w') as configfile:
+        config.write(configfile)

+ 20 - 0
myCar.py

@@ -22,6 +22,7 @@ from flask import Flask
 from flask import url_for
 from flask import render_template
 from flask import request
+from flask import redirect
 app = Flask(__name__)
 
 
@@ -97,3 +98,22 @@ def myCar_conf():
     # !!! default vaules when the config file is not present
     return render_template('conf/main.html', config=myCar_config, sections=myCar_config.sections())
     
+    
+@app.route('/confsave', methods=['POST'])
+def myCar_conf_save():
+    # this method saves the configuration settings when posted, then redirects to context /conf
+
+    if request is not None and request.form['configsend'] == 'save':
+
+        myCar_config['paths'] = { 'app' : request.form['[paths][app]'],
+                                  'log' : request.form['[paths][log]'],
+                               'record' : request.form['[paths][record]'] }
+      
+        myCar_config['connections'] = { 'bt_dev' : request.form['[connections][bt_dev]'],
+                                        'gps_dev' : request.form['[connections][gps_dev]'],
+                                        'wifi_pwd' : request.form['[connections][wifi_pwd]'] }
+        lib.config.myCar_save_config(myCar_config)
+
+    return redirect(url_for('myCar_conf'), code=302)
+            
+

+ 12 - 0
static/css/myCar.css

@@ -0,0 +1,12 @@
+body {
+    margin: 2;
+    font-family: FreeSans, Arimo, "Droid Sans", Helvetica, Arial, sans-serif;
+}
+
+.myCar-text-green {
+    color: green;
+}
+
+.myCar-text-red {
+    color: red;
+}

BIN
static/img/location.png


BIN
static/img/location_green.png


BIN
static/img/location_red.png


BIN
static/img/wireless_2_green.png


BIN
static/img/wireless_2_red.png


BIN
static/img/wireless_green.png


BIN
static/img/wireless_red.png


+ 2 - 0
templates/VERSION

@@ -0,0 +1,2 @@
+Version: 0.1
+SVN-Commit: 

+ 10 - 6
templates/base.html

@@ -6,9 +6,10 @@
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     <title>myCar</title>
     <link rel="shortcut icon" href="{{ url_for('static', filename='img/favicon.ico') }}"/>
-    <link rel="stylesheet" href="{{ url_for('static', filename='css/pure/pure-min.css') }}" integrity="sha384-nn4HPE8lTHyVtfCBi5yW9d20FjT8BJwUXyWZT9InLYax14RDjBj46LmSztkmNP9w" crossorigin="anonymous">
+    <link rel="stylesheet" href="{{ url_for('static', filename='css/pure/pure.css') }}">
     <link rel="stylesheet" href="{{ url_for('static', filename='css/pure/side-menu.css') }}">
-    <link rel="stylesheet" href="{{ url_for('static', filename='static/css/pure/grids-responsive.css') }}">
+    <link rel="stylesheet" href="{{ url_for('static', filename='css/pure/grids-responsive.css') }}">
+    <link rel="stylesheet" href="{{ url_for('static', filename='css/myCar.css') }}">
     <meta name="viewport" content="width=device-width, initial-scale=1">
   </head>
   <body>
@@ -54,10 +55,10 @@
         </div>
 
         <div class="content" max-width="1700px">
-            <p>
+            
                 {% block content %}
                 {% endblock %}
-            </p>
+            
         </div>
 
          <div id="footer">
@@ -65,12 +66,15 @@
             {% block footer %}
 
              <table>
-                <tr><td width="5%">  </td>
+                <tr>
+                    <td width="5%">  </td>
                     <td>
                         This is free software.<br>
                         The license is yet undefined ...<br>
                         <a href="https://wiki.siningsoft.de/id=mycar:intro">myCar project Page at wiki.siningsoft.de</a>
-                    </td>
+                     </td>
+                    <td>{% include 'VERSION' %}</td>
+                    
                 </tr>
             </table>
                  

+ 11 - 7
templates/conf/main.html

@@ -11,9 +11,8 @@
     </table>
 {% endif %}
 
-<br>
-    <center>
-        <form class="pure-form pure-form-aligned">
+
+        <form class="pure-form pure-form-aligned" action='{{url_for('myCar_conf_save')}}' method='post'>
             <fieldset>
             {% for section in sections %}
                 <h1>Configuration Section <i>{{ section }}</i></h1>
@@ -23,16 +22,21 @@
 
                     <div class="pure-control-group">
                                 <label for="[{{ section }}][{{ confval }}]">{{ confval }}</label>
-                                <input id="[{{ section }}][{{ confval }}]" value="{{ config[section][confval] }}" placeholder="{{ confval }}">
+                                <input name="[{{ section }}][{{ confval }}]" id="[{{ section }}][{{ confval }}]" value="{{ config[section][confval] }}" placeholder="{{ confval }}">
                     </div>
               
                 {% endfor %}
             
             {% endfor %}
 
+                <input type="hidden" name="testval" value="testA">
+                <input type="hidden" name="[A][B]" value="testB">
+                <button name='configsend' value='nosave' class="pure-button"><img src='{{ url_for('static', filename='img/nosave.png') }}' width='30px' height='30px'></button>
+                <button name='configsend' value='save' class="pure-button"><img src='{{ url_for('static', filename='img/save.png') }}' width='30px' height='30px'></button>
+
             </fieldset>
+        
         </form>
-        <button formmethod='post' name='configsend' value='nosave' class="pure-button"><img src='{{ url_for('static', filename='img/nosave.png') }}' width='30px' height='30px'></button>
-        <button formmethod='post' name='configsend' value='save' class="pure-button"><img src='{{ url_for('static', filename='img/save.png') }}' width='30px' height='30px'></button>
-    </center>
+        
+
 {% endblock %}

+ 40 - 3
templates/index.html

@@ -5,9 +5,46 @@
 <h1>Statuspage</h1>
 
 <div class="pure-g">
-    <div class="pure-u-1-3"><img src="{{ url_for('static', filename='img/wireless_2.png') }}" class="pure-img"><p>Bluetooth Controller</p></div>
-    <div class="pure-u-1-3"><img src="{{ url_for('static', filename='img/wireless.png') }}" class="pure-img"><p>Wireless Network</p></div>
-    <div class="pure-u-1-3"><img src="{{ url_for('static', filename='img/location.png') }}" class="pure-img"><p>GPS Receiver</p></div>
+    <div class="pure-u-1-3">
+        {% if bt_ctrl_isactive == True %}
+            <div class="pure-g">
+                <div class="pure-u-1-2"><img src="{{ url_for('static', filename='img/wireless_2_green.png') }}" class="pure-img"></div>
+                <div class="pure-u-1-2 myCar-text-green">Bluetooth Controller</div>
+            </div>
+        {% else %}
+            <div class="pure-g">
+                <div class="pure-u-1-2"><img src="{{ url_for('static', filename='img/wireless_2_red.png') }}" class="pure-img"></div>
+                <div class="pure-u-1-2 myCar-text-red">Bluetooth Controller</div>
+            </div>
+        {% endif %}
+    </div>
+
+    <div class="pure-u-1-3">
+        {% if wlan_ctrl_isactive == True %}
+            <div class="pure-g">
+                <div class="pure-u-1-2"><img src="{{ url_for('static', filename='img/wireless_green.png') }}" class="pure-img"></div>
+                <div class="pure-u-1-2 myCar_text_green">Wireless Network</div>
+            </div>
+        {% else %}
+            <div class="pure-g">
+                <div class="pure-u-1-2"><img src="{{ url_for('static', filename='img/wireless_red.png') }}" class="pure-img"></div>
+                <div class="pure-u-1-2 myCar-text-red">Wireless Network</div>
+            </div>
+        {% endif %}
+    </div>
+    <div class="pure-u-1-3">
+        {% if gps_ctrl_isactive == True %}
+            <div class="pure-g">
+                <div class="pure-u-1-2"><img src="{{ url_for('static', filename='img/location_green.png') }}" class="pure-img"></div>
+                <div class="pure-u-1-2 myCar-text-green">GPS Receiver</div>
+            </div>
+        {% else %}
+            <div class="pure-g">
+                <div class="pure-u-1-2"><img src="{{ url_for('static', filename='img/location_red.png') }}" class="pure-img"></div>
+                <div class="pure-u-1-2 myCar-text-red">GPS Receiver</div>
+            </div>
+         {% endif %}
+    </div>
 </div>
 
 {% endblock %}