ソースを参照

enabled download and info update.

Signed-off-by: root <root@ipekatrinadei.ipe.kit.edu>
root 6 年 前
コミット
ca853e6e8d
4 ファイル変更64 行追加12 行削除
  1. 25 6
      main.py
  2. 4 0
      static/fossil/css/style.css
  3. 30 1
      static/fossil/js/script.js
  4. 5 5
      templates/index.html

+ 25 - 6
main.py

@@ -40,6 +40,7 @@ class Application(tornado.web.Application):
     def __init__(self):
         handlers = [
             (r"/", MainHandler),
+            (r"/update", UpdateHandler),
             (r"/img", ImageHandler),
             (r"/download", GenFileStreamerHandler),
         ]
@@ -136,6 +137,20 @@ class DATA:
         return self.data_list
 
 
+class UpdateHandler(tornado.web.RequestHandler):
+
+    def get(self):
+        index = self.get_argument("index", None)
+        name = self.get_argument("name", None)
+        print index, name
+        selected_data = DATA(index)
+
+        self.write({
+            "data_size": selected_data.get_size(),
+            "desc": selected_data.get_desc()
+        })
+
+
 class MainHandler(tornado.web.RequestHandler):
 
     def get(self):
@@ -165,16 +180,20 @@ class GenFileStreamerHandler(tornado.web.RequestHandler):
     @tornado.web.asynchronous
     @tornado.gen.engine
     def get(self):
-        cdid = self.get_arguments("did")
+        cdid = self.get_argument("did")
+        print cdid
         con = lite.connect('fossil.db')
         with con:
             cur = con.cursor()
-            cur.execute("SELECT name FROM Fossil WHERE name = ?", (cdid))
+            cur.execute("SELECT name FROM Fossil WHERE name = ?", [cdid])
             data_key = cur.fetchall()
             
         if len(data_key) > 0:
-            file_name = str(cdid[0]) + ".zip"
-            self.path = self.DATA_PATH + str(cdid[0]) + "/" + file_name
+            file_name = str(cdid) + ".zip"
+            self.path = os.path.join(
+                self.DATA_PATH,
+                str(cdid),
+                file_name)
             self.set_header('Content-Type',
                             'application/octet-stream')
             self.set_header('Content-Disposition',
@@ -224,8 +243,8 @@ class ImageHandler(tornado.web.RequestHandler):
                 dtype,
                 prefix+str(dcounter)+".png")
 
-        print did, dname, dtype, dcounter
-        print self.path
+        #print did, dname, dtype, dcounter
+        #print self.path
 
         self.set_header('Content-Type', 'image/png')
         self.set_header("Content-Length",

+ 4 - 0
static/fossil/css/style.css

@@ -327,3 +327,7 @@ hr {
 #download:hover {
     background-color: #ddd;
 }
+
+.target {
+    width: auto;
+}

+ 30 - 1
static/fossil/js/script.js

@@ -35,4 +35,33 @@ $(function() {
         e.preventDefault();  //stop the browser from following
         window.location.href = 'download?did=' + did;
     });
-});
+
+    $('.target').change(function() {
+        var name = $(this).find("option:selected").text();
+        var index = $(this).find("option:selected").val();
+        $.ajax({
+            url: 'update?index=' + index + '&name=' + name,
+            type: 'GET',
+            success: function (response) {
+                console.log("Success.");
+                console.log(response);
+                $("#size").text("("+response.data_size+" GB)");
+
+                var html = "<span>Description</span>";
+                for (i = 0; i < response["desc"].length; i++) { 
+                    if (response["desc"][i]["type"] == "i") {
+                        tmp = "<i>" + response["desc"][i]["text"] + "</i>";
+                    } else if (response["desc"][i]["type"] == "p") {
+                        tmp = "<p>" + response["desc"][i]["text"] + "</p>";
+                    }
+                    html += tmp;
+                }
+                $("#description").empty().append(html);
+            },
+            error: function () {
+                console.log("Error.")
+            }
+        });
+        $("#img-preview").attr("src", "img?id="+index+"&name="+name+"&type=preview&counter=0");
+    });
+});

+ 5 - 5
templates/index.html

@@ -59,7 +59,7 @@
     
     <div id="subheader">
         <span>Sample:</span> 
-        <select style="width: auto;">
+        <select class="target">
             {% for sample in data_list %}
             {% if sample[1]  == name %}
             <option value={{ sample[0] }} selected>{{ sample[1] }}</option> 
@@ -69,7 +69,7 @@
             {% end %}
         </select>
         <img class="icon" id="download" src="{{ static_url("img/icon/download.svg") }}"/>
-        <span>({{ data_size }} GB)</span>
+        <span id="size">({{ data_size }} GB)</span>
     </div>
 
     <div id="image-container" class="clearfix">
@@ -78,9 +78,9 @@
 	            <span id="image-text">Overview (Volume Rendering)</span>
             </div>
 	        <div class="photowrapper">
-                <img src="img?id={{ index }}&name={{ name }}&type=preview&counter=0"/>
+                <img id="img-preview" src="img?id={{ index }}&name={{ name }}&type=preview&counter=0"/>
             <div id="text-desc">
-            <p><span>Description</span>
+            <p id="description"><span>Description</span>
                 {% for text_desc in desc %}
                     {% if text_desc['type'] == "i" %}
                         <i>{{ text_desc['text'] }}</i>
@@ -129,7 +129,7 @@
     </div>
     <hr>
 
-    <div id="footer">&copy;2017 A service provided by Ultra-fast Online Processing for Data-intensive Sciences group (UFO)</div>
+    <div id="footer">&copy;2017 A service provided by Ultra-fast Online Processing for Data-intensive Sciences group (UFO), https://ufo.kit.edu/</div>
 <script src="{{ static_url("js/jquery-1.12.4.min.js") }}"></script>
 <script src="{{ static_url("js/jquery-ui.min.js") }}"></script>
 <script src="{{ static_url("js/script.js") }}"></script>