From 954b4497576dc42afd874fc149bbab62aec913e8 Mon Sep 17 00:00:00 2001 From: Marek Baczynski Date: Mon, 12 Nov 2018 20:56:12 +0100 Subject: [PATCH] location editor can now be used to edit locations. And add them! --- parts/server.py | 12 +++--- parts/static/locationEditorScript.js | 62 +++++++++++++++++++++------- parts/static/style.css | 10 +++++ parts/templates/locationEditor.html | 40 ++++++++++-------- 4 files changed, 85 insertions(+), 39 deletions(-) diff --git a/parts/server.py b/parts/server.py index 56e105c..be123c5 100644 --- a/parts/server.py +++ b/parts/server.py @@ -80,7 +80,7 @@ def get_locationURL(locationID): @app.route('/parts/locationEditor') def locationEditor(): - query = 'select c.name as container, l.name as name, l.id from locations as l inner join containers as c on l.container_id = c.id order by container, name;' + query = 'select c.name as container, l.name as name, l.id, c.id as container_id from locations as l inner join containers as c on l.container_id = c.id order by container, name;' r = db_engine.execute(text(query)) locations = [] for row in r: @@ -95,19 +95,19 @@ def alterLocation(locationID): s = '' if locationID < 0: # New entry - s = 'insert into locations (name, map) ' - s += 'values (:name, :map);' + s = 'insert into locations (name, container_id) ' + s += 'values (:name, :container);' s = text(s) - r = db_engine.execute(s,name=request.form['name'],map=request.form['map']); + r = db_engine.execute(s,name=request.form['name'],container=request.form['container']); r.close() return '{"status":"ok"}' else: # Modify entry s = 'update locations ' - s += 'set name=:name, map=:map, ' + s += 'set name=:name, container_id=:container ' s += 'where id=:locationID;' s = text(s) - r = db_engine.execute(s, name=request.form['name'],map=request.form['map'],locationID=locationID); + r = db_engine.execute(s, name=request.form['name'],container=request.form['container'],locationID=locationID); r.close() return '{"status":"ok"}' diff --git a/parts/static/locationEditorScript.js b/parts/static/locationEditorScript.js index 8511890..4c4bd4e 100644 --- a/parts/static/locationEditorScript.js +++ b/parts/static/locationEditorScript.js @@ -1,27 +1,25 @@ function new_location_entry() { - $('#location-name-input').text(''); - $('#location-name-input').show(); - $('#mapfile-input').show(); - init_Location_edit(-1); - overlay_in(); + } -function init_Location_edit(locationID) { - - $('table#details tr#datasheet td input').show(); - +function init_Location_edit(locationID, name, containerID) { var newButton = '
'; - $('.round-button-left').replaceWith(newButton); + $('#save-button').attr("onclick", "saveLocation(" + locationID + ")"); + $('#location-name-input').val(name); + if(containerID > 0){ + $("#container-input").val(containerID); + } + overlay_in(); } -function update_clickable_map() { - var selected_map_file = $('#mapfile-input').val(); - $('#clickablemap').attr('src', 'map/' + selected_map_file); +function update_map() { + var selected_map_file = $('#container-input').val(); + $('#map').attr('src', 'map/' + selected_map_file); } function saveLocation(locationID) { - var map_v = $('#clickablemap').attr('src').substring(4); + var container_v = $('#container-input').val(); var name_v = $('#location-name-input').val(); if(name_v.length > 100) { @@ -30,7 +28,7 @@ function saveLocation(locationID) { } var data = new FormData(); - data.append('map', map_v); + data.append('container', container_v); data.append('name', name_v) $.ajax({ @@ -54,7 +52,41 @@ function saveLocation(locationID) { }); } +function end_edit(){ + //intentionally left blank +} + + +function show_location_info(locationID) { + $.getJSON(rootURL + 'getpartinfo/' + partID, function(data) { + $('table#details tr#location td p').text(text_filter(data.location_descriptor)); // name is the location friendly name + $('#location-dropdown').val(data.location_id); + $('#container-dropdown').val(data.container_id); + $('table#details tr#partno td p').text(text_filter(data.partno)); + $('table#details tr#partno td input').val(text_filter(data.partno)); + $('table#details tr#description td p').text(text_filter(data.description)); + $('table#details tr#description td input').val(text_filter(data.description)); + container_onchange(); + if (data.datasheet != null) { + $('tr#datasheet-head').html($('DATASHEET: ')); + $('#datasheet-input').val(data.datasheet); + } + else + $('tr#datasheet-head td').text('DATASHEET: '); + $('#edit-button').click(function() { + init_edit(partID); + }); + $('#delete-button').click(function() { + delete_entry(partID); + }); + overlay_in(); + }).fail(function() { + console.log( "Fetching part info failed" ); + }); +} + function placeMarker(locationID){ + //temporarily not used var $img = $('#clickablemap'); var currentClickPosX = event.pageX - $img.offset().left; var currentClickPosY = event.pageY - $img.offset().top; diff --git a/parts/static/style.css b/parts/static/style.css index ef11f39..949739f 100644 --- a/parts/static/style.css +++ b/parts/static/style.css @@ -399,4 +399,14 @@ td p { .pinfo-input { display: none; width: 90%; +} + +.nothidden{ + display: initial !important; +} + +.results-locations{ + max-width: 1000px; + margin-left: auto; + margin-right: auto; } \ No newline at end of file diff --git a/parts/templates/locationEditor.html b/parts/templates/locationEditor.html index fbdd1ed..1bd48a9 100644 --- a/parts/templates/locationEditor.html +++ b/parts/templates/locationEditor.html @@ -2,7 +2,7 @@ - ELAB Part Search Engine + ELAB Part Search Engine - Location editor -

ELAB Part Search Engine - LOCATION EDITOR

-

Looking for a place to store your obsolete ICs discontinued years ago? Just toss them anywhere and mark that location here!

- +

LOCATION EDITOR

+

Looking for a place to store your obsolete ICs discontinued years ago? Just toss them anywhere and mark that location here! back to parts

+
- - - + + + + {% for location in locations %} - + + + - {% endfor %}
ContainerLocation nameIDIDc.IDContainer nameLocation name
{{location['id']}}{{location['container_id']}} {{location['container']}} {{location['name']}}{{location['id']}}
@@ -35,26 +37,28 @@

Part Details

- - - - + - + + + + + +
Name

MAP
Adding a new LOCATION inside a given CONTAINER
- {% for container in containers %} {% endfor %}
And click on the map to place the marker
Location name (obs! If a drawer has an identification sticker, start the name with it.
Example: ".2 - Power resistors"

Note: adding custom "containers" is currently insupported and unpossible.
- -
+ +
-
+