From 04d10120da319b839d0ac160e4f2b4669181dfd4 Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Fri, 9 Nov 2018 23:28:55 +0100 Subject: [PATCH 1/2] map X Y coordinate generator for making new locations --- parts/static/script.js | 20 ++++++++++++++++++++ parts/test.html | 20 ++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 parts/test.html diff --git a/parts/static/script.js b/parts/static/script.js index 94da536..f120cbd 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -270,3 +270,23 @@ $(document).ready(function() { perform_query(); }); }); + +$(document).ready(function() { + $("#clickablemap").on("click", function(event) { + var $img = $(this); + var currentClickPosX = event.pageX - $img.offset().left; + var currentClickPosY = event.pageY - $img.offset().top; + + var currentWidth = $img.width(); + var currentHeight = $img.height(); + + var naturalWidth = this.naturalWidth; + var naturalHeight = this.naturalHeight; + + var correctX = ((naturalWidth / currentWidth) * currentClickPosX).toFixed(0); + var correctY = ((naturalHeight / currentHeight) * currentClickPosY).toFixed(0); + + $("#mapURL").html("elab.png?x=" + correctX + "&y=" + correctY); + $("#clickablemap").attr("src", "http://127.0.0.1:5000/parts/map/elab.png?x=" + correctX + "&y=" + correctY); + }); +}); \ No newline at end of file diff --git a/parts/test.html b/parts/test.html new file mode 100644 index 0000000..d185757 --- /dev/null +++ b/parts/test.html @@ -0,0 +1,20 @@ + + + + + ELAB Part Search Engine + + + + + + + +
unknown.png
+
+ + + \ No newline at end of file From dadab62e9ea11a6094b9e172198e20ee6e4dc4fa Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Sat, 10 Nov 2018 00:15:00 +0100 Subject: [PATCH 2/2] endpoint for listing locations --- parts/server.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parts/server.py b/parts/server.py index f4ae96a..92710ee 100644 --- a/parts/server.py +++ b/parts/server.py @@ -47,6 +47,16 @@ def serveImage(img): def index(): return render_template('partsearch.html') +@app.route('/parts/getlocations/') +def get_locations(): + s = 'select id, map from locations' + r = db_engine.execute(text(s)) + l = {} + for row in r: + l[row[0]]=row[1] + r.close() + return json.dumps(l) + @app.route('/parts/getpartinfo/') def get_part_info(partID): s = 'select * from parts as p inner join locations as l on p.location_id=l.id where p.id = :id;'