Commits

Chris Mutel committed 95b9bb5

Change windows drives with web UI for all actions

Comments (0)

Files changed (4)

 ### Getting started ###
 #######################
 
+def get_windows_drives():
+    if not config._windows:
+        return {'windows': False}
+    else:
+        return {
+            'windows': True,
+            'drive_letters': get_windows_drive_letters(),
+            'current_drive': os.path.splitdrive(os.getcwd())[0]
+        }
 
 @app.route('/start/path', methods=["POST"])
 def set_path():
 
 @app.route('/start')
 def start():
-    if config._windows:
-        windows, drive_letters = True, get_windows_drive_letters()
-    else:
-        windows, drive_letters = False, []
     return render_template(
         "start.html",
         root_path=json.dumps(os.path.abspath("/")),
-        windows=windows,
-        drive_letters=drive_letters
+        **get_windows_drives()
     )
 
 #################
 @app.route("/import/database", methods=["GET", "POST"])
 def import_database():
     if request.method == "GET":
-        return render_template("import-database.html")
+        return render_template("import-database.html", **get_windows_drives())
     else:
         path = urllib2.unquote(request.form["path"])
         name = urllib2.unquote(request.form["name"])
 @app.route("/import/method", methods=["GET", "POST"])
 def import_method():
     if request.method == "GET":
-        return render_template("import-method.html")
+        return render_template("import-method.html", **get_windows_drives())
     else:
         path = urllib2.unquote(request.form["path"])
         EcospoldImpactAssessmentImporter().importer(path)

bw2ui/web/templates/import-database.html

   <div class="span-15 colborder">
     <h3 id="fp-selected">1. Click to select the directory that the XML files are in, or a single XML file.</h3>
     <p>Note: Not all files are shown...</p>
+    {% if windows %}
+      <h3>Change the drive (Windows only)</h3>
+      <select id="driveletter">
+      {% for letter in drive_letters %}
+        <option value="{{ letter }}" {% if letter[:2] == current_drive %}selected{% endif %}>{{ letter }}</option>
+      {% endfor %}
+      </select>
+    {% endif %}
     <div id="fp"></div>
   </div>
   <div class="span-8 last">
 };
 </script>
 <script src="{{ url_for('static', filename="jqueryFileTree/jqueryFileTree.js") }}"></script>
-<script type="text/javascript">      
-$(document).ready( function() {        
+<script type="text/javascript">
+$(document).ready( function() {
   $("#success").hide();
 
   $('#fp').fileTree({
-    root: '/', 
-    script: '{{ url_for('fp_api') }}', 
-    folderEvent: 'click', 
-    multiFolder: false 
-    }, 
-    function(file) { 
+    root: '/',
+    script: '{{ url_for('fp_api') }}',
+    folderEvent: 'click',
+    multiFolder: false
+    },
+    function(file) {
       $("#fp-selected").text("Currently selected: " + file);
       $("#hidden-path").val(file);
     }
     }
   });
 });
+
+$(function() {
+  $("#driveletter").change(function() {
+      var letter = $(this).val();
+      $('#fp').html("");
+      $('#fp').fileTree({
+        root: letter,
+        script: '/fp-api',
+        folderEvent: 'click',
+        multiFolder: false
+        },
+        function(file) { console.log(file); }
+      );
+  })
+});
 </script>
-{% endblock %}
+{% endblock %}

bw2ui/web/templates/import-method.html

   <h1>Import an LCIA method</h1>
   <div class="span-15 colborder">
     <h3 id="fp-selected">Click to select the directory that the XML files are in, or a single XML file.</h3>
+    {% if windows %}
+      <h3>Change the drive (Windows only)</h3>
+      <select id="driveletter">
+      {% for letter in drive_letters %}
+        <option value="{{ letter }}" {% if letter[:2] == current_drive %}selected{% endif %}>{{ letter }}</option>
+      {% endfor %}
+      </select>
+    {% endif %}
     <div id="fp"></div>
   </div>
   <div class="span-8 last">
 };
 </script>
 <script src="{{ url_for('static', filename="jqueryFileTree/jqueryFileTree.js") }}"></script>
-<script type="text/javascript">      
-$(document).ready( function() {        
+<script type="text/javascript">
+$(document).ready( function() {
   $("#in-submission").hide();
 
   $('#fp').fileTree({
-    root: '/', 
-    script: '{{ url_for('fp_api') }}?full=1', 
-    folderEvent: 'click', 
-    multiFolder: false 
-    }, 
-    function(file) { 
+    root: '/',
+    script: '{{ url_for('fp_api') }}?full=1',
+    folderEvent: 'click',
+    multiFolder: false
+    },
+    function(file) {
       $("#fp-selected").text("Currently selected: " + file);
       $("#hidden-path").val(file);
     }
     }
   });
 });
+
+$(function() {
+  $("#driveletter").change(function() {
+      var letter = $(this).val();
+      $('#fp').html("");
+      $('#fp').fileTree({
+        root: letter,
+        script: '/fp-api',
+        folderEvent: 'click',
+        multiFolder: false
+        },
+        function(file) { console.log(file); }
+      );
+  })
+});
 </script>
-{% endblock %}
+{% endblock %}

bw2ui/web/templates/start.html

       <h3>Change the drive (Windows only)</h3>
       <select id="driveletter">
       {% for letter in drive_letters %}
-        <option value="{{ letter }}">{{ letter }}</option>
+        <option value="{{ letter }}" {% if letter[:2] == current_drive %}selected{% endif %}>{{ letter }}</option>
       {% endfor %}
       </select>
     {% endif %}