ソースを参照

first javascript

bscheibel 4 年 前
コミット
6575d374ea
共有3 個のファイルを変更した89 個の追加27 個の削除を含む
  1. 45 18
      app/templates/show_image.html
  2. 30 0
      app/test.html
  3. 14 9
      app/views.py

+ 45 - 18
app/templates/show_image.html

@@ -2,22 +2,7 @@
 <head>
   <title>Dimension Extraction</title>
   <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}"/>
-<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
-<script>
-
-$(document).ready(function(){
-
-    $("#myInput").on("input", function(){
-
-        // Print entered value in a div box
-
-        $("#result").text($(this).val());
-
-    });
-
-});
-
-</script>
+<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
 </head>
 
 <body>
@@ -36,10 +21,10 @@ $(document).ready(function(){
         {% endif %}
     </div>
 <!--<div class="split middle">-->
-    <div class="column column-two">
+    <div class="column column-two" id="measurements">
             <h1>Extracted Measurements</h1>
                 <font size="3" face="Courier New" >
-                <form method="post">
+                <form>
                 <table>
                     <tr>
                         <td style="text-align:center"><h3>Key Value</h3></td>
@@ -65,6 +50,7 @@ $(document).ready(function(){
                 </table>
                 </form>
                 </font>
+        <div id="result">Result</div>
     </div>
     <!--<div class="split right">-->
     <div class="column column-three">
@@ -78,4 +64,45 @@ $(document).ready(function(){
                 </table>
     </div>
 </div>
+
+<script>
+
+    $(document).ready(function(){
+
+        $("input[type=number]").on("change keyup input", function(){
+
+            // Print entered value in a div box
+            var coords = $(this).attr('data-coords');
+            var key = $(this).attr('name'));
+            $("#result").text($(this).val());
+            $("#result").append($(this).attr('name'));
+            $("#result").append(coords);
+
+        });
+
+         $("input[type=checkbox]").on("change keyup input", function(){
+
+            // Print entered value in a div box
+            $("#result").text($(this).attr('name'));
+
+        });
+    });
+
+   </script>
+    <script type="text/javascript">
+    var key = "blub";
+    $(document).ready(function(key) {
+        $.ajax({
+            url: "http://127.0.0.1:7379/GET/" + key,
+            data: "format=json",
+            dataType: "json",
+            success: function(data)
+            {
+                $("#result").text(data.GET);
+            }
+        });
+    });
+
+
+</script>
 </body>

+ 30 - 0
app/test.html

@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+</head>
+<body>
+        $("input#measurements").on("hover",function(){
+
+            // highlight values, does work so far
+
+            val number = $(this).attr('name');
+            $("#result").append(number));
+
+        });
+
+
+
+        $('#getPos').on('click', function(){
+
+            var xRes = $('#xRes span'),
+                yRes = $('#yRes span'),
+                image = $('img#myImg');
+
+            xRes.html(image.offset().top);
+            yRes.html(image.offset().left);
+
+        });
+</body>
+</html>

+ 14 - 9
app/views.py

@@ -5,6 +5,8 @@ import redis
 import random
 import json
 import os
+import json
+import re
 #https://medium.com/@emerico/convert-pdf-to-image-using-python-flask-2864fb655e01
 
 
@@ -25,7 +27,7 @@ def convert_pdf_img(filename):
 
 def extract_all(uuid, filename, db):
     #order_bounding_boxes_in_each_block.main(uuid, UPLOAD_FOLDER + "/" + filename)
-    subprocess.call(['python3','/home/bscheibel/PycharmProjects/dxf_reader/main.py', str(uuid),UPLOAD_FOLDER + "/" + filename,db])
+    subprocess.call(['python3','/home/bscheibel/PycharmProjects/dxf_reader/main.py', str(uuid),UPLOAD_FOLDER + "/" + filename, db, str(1)])
 
 @app.route('/', methods=['GET', 'POST'])
 def upload_file():
@@ -57,17 +59,20 @@ def uploaded_file(filename, uuid):
         db = redis.Redis("localhost")
         #isos = db.get(uuid+"dims")
         #print(iso)
-        isos = json.loads(db.get(uuid+"isos"))
-        dims = json.loads(db.get(uuid+"dims"))
+        isos = json.loads(db.get(str(uuid)+"isos"))
+        dims = json.loads(db.get(str(uuid)+"dims"))
         html_code = ""
-       # dims = eval(dims)
+        reg = r"(-?\d{1,}\.?\d*)"
         for dim in dims:
             html_code += '''<td><h4>''' + dim + '''</h4></td>'''
             for d in dims[dim]:
-                html_code += "<tr><td style='text-align:center'> <input type='checkbox' name='relevant." + d + "' value='checked'  onchange='submit()'> </td>" + \
+                number = re.search(reg, d)
+                number = number.group(1)
+                coords = ",".join(str(e) for e in dims[dim][d])
+                html_code += "<tr><td style='text-align:center'> <input type='checkbox' name='relevant." + d + "' value='checked'> </td>" + \
                              "<td style='text-align:center'>" + d + "</td>" + \
-                             "<td style='text-align:center'> <input type='number' name='" + d + "' value='" + d + "'  size='10'  onchange='submit()'> </td></tr>"
-                print(html_code)
+                             "<td style='text-align:center'> <input type='number' step=0.01 data-coords='" + coords + "' name='" + d + "' value='" + number + "'  size='10'> </td></tr>"
+                #print(html_code)
         return render_template('show_image.html', filename=file_out, isos=isos, dims=dims, text=html_code)
 
     else:
@@ -98,11 +103,11 @@ def generate(name):
     except:
         return"Sorry file not found"
 
-@app.route('/show_results')
+"""@app.route('/show_results')
 def form_post():
     text = []
     db = redis.Redis('localhost')
     for key in request.form:
         db.set(key, request.form[key])
-    return render_template('display_results.html')
+    return render_template('display_results.html'"""