From c568635f60aefe754d646aabd94bff34a1bfdcef Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 13:36:21 +0100 Subject: [PATCH 01/13] Removed has docs filter --- parts/server.py | 4 ---- parts/templates/partsearch.html | 1 - 2 files changed, 5 deletions(-) diff --git a/parts/server.py b/parts/server.py index 068803f..b1df0e0 100644 --- a/parts/server.py +++ b/parts/server.py @@ -151,11 +151,7 @@ def query(filter_dummy, query): s += 'LOWER(description) like LOWER(:kw'+ str(i) +') AND ' s = s[:-5] s += ') OR ' - if filter['n'] == 'true': - s = s[:-4] - s += "AND (datasheet='' IS NOT FALSE) IS FALSE OR " s = s[:-4] + ';' - print(s) s = text(s) r = db_engine.execute(s, kw_dict) l = [] diff --git a/parts/templates/partsearch.html b/parts/templates/partsearch.html index cd3801a..8342413 100644 --- a/parts/templates/partsearch.html +++ b/parts/templates/partsearch.html @@ -27,7 +27,6 @@ - From a222906fe2239eb0cb2d94d0e298029267904df9 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 13:36:57 +0100 Subject: [PATCH 02/13] Added datasheet URL possiblity --- parts/static/script.js | 19 ++++++++++++------- parts/templates/partsearch.html | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/parts/static/script.js b/parts/static/script.js index d58adf6..202b4c5 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -4,17 +4,20 @@ function init_edit(partID) { $('#container-dropdown').show(); $('table#details tr#partno td p').hide(); - $('table#details tr#partno td input').show(); + $('input[name=partno-input]').show(); $('table#details tr#description td p').hide(); - $('table#details tr#description td input').show(); + $('input[name=description-input]').show(); + $('table#details tr#datasheet td input').closest().show(); $('table#details tr#datasheet td input').show(); + // $('input[name=datasheet-url-input]').closest().show(); $('#duplicate-button').closest('div').hide(); - var datasheet_input = $('') - $('#datasheet-info').replaceWith(datasheet_input); + $('tr#datasheet').show(); + // var datasheet_input = $('') + // $('#datasheet-info').replaceWith(datasheet_input); var newButton = '
'; $('.round-button-left').replaceWith(newButton); @@ -46,7 +49,10 @@ function end_edit() { $('table#details tr#description td p').show(); $('table#details tr#description td input').hide(); - $('table#details tr#datasheet td input').hide(); + $('tr#datasheet').hide(); + // $('table#details tr#datasheet td input').closest().hide(); + // $('table#details tr#datasheet td input').hide(); + // $('input[name=datasheet-url-input]').closest().hide(); $('#duplicate-button').closest('div').show(); @@ -180,8 +186,7 @@ function perform_query() { var data = { l:$('#location').is(':checked'), p:$('#partno').is(':checked'), - d:$('#description').is(':checked'), - n:$('#has-docs').is(':checked') + d:$('#description').is(':checked') }; filter = '0'; $("#results").find("tr:not(:first)").remove(); // Delete all table rows diff --git a/parts/templates/partsearch.html b/parts/templates/partsearch.html index 8342413..8fcf1d3 100644 --- a/parts/templates/partsearch.html +++ b/parts/templates/partsearch.html @@ -60,7 +60,8 @@
- + +
DESCRIPTION

DATASHEET:
From caf1efce0c5259349157c8a7245594c92ba34655 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 13:37:06 +0100 Subject: [PATCH 03/13] Fixed shadow position --- parts/static/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parts/static/style.css b/parts/static/style.css index 77b4320..2e1ee69 100644 --- a/parts/static/style.css +++ b/parts/static/style.css @@ -152,7 +152,7 @@ div label input { height: 100%; left: 0; opacity: 0.0; - position: absolute; + position: fixed; top: 0; width: 100%; z-index: 200; From da5339a473f06b125f65d37fd38782b1a3bfeb78 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 13:50:18 +0100 Subject: [PATCH 04/13] Handling datasheet URLs --- parts/server.py | 6 ++++++ parts/static/script.js | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/parts/server.py b/parts/server.py index b1df0e0..0e8da1d 100644 --- a/parts/server.py +++ b/parts/server.py @@ -211,6 +211,9 @@ def alter(partID): datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) + datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename + elif request.form.has_key('datasheet-url'): + datasheet_filename = request.form['datasheet-url'] else: datasheet_filename = None r = db_engine.execute(s, partno=request.form['partno'], @@ -234,8 +237,11 @@ def alter(partID): datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) + datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename if l[0]['datasheet'] != None: os.remove('/srv/datasheets/' + l[0]['datasheet']) + elif request.form.has_key('datasheet-url'): + datasheet_filename = request.form['datasheet-url'] else: datasheet_filename = l[0]['datasheet'] s += 'where id=:id returning id;' diff --git a/parts/static/script.js b/parts/static/script.js index 202b4c5..d67b31c 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -65,6 +65,7 @@ function save(partID) { var partno_v = $('input[name=partno-input]').val(); var description_v = $('input[name=description-input]').val(); var datasheet = $('table#details tr#datasheet td input')[0].files; + var datasheet_url_v = $('input[name=datasheet-url-input]').val(); if(partno_v.length == 0){ alert('Please enter a part number.'); return; @@ -89,6 +90,8 @@ function save(partID) { return; } data.append('datasheet-file', datasheet[0]); + } else if (datasheet_url_v.length > 0) { + data.append('datasheet-url', datasheet_url_v); } data.append('partno', partno_v); data.append('location_id', location_id_v) @@ -162,8 +165,8 @@ function show_part_info(partID) { $('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); + $('tr#datasheet-head').html($('DATASHEET: ')); + $('input[name=datasheet-url-input]').val(data.datasheet); } else $('tr#datasheet-head td').text('DATASHEET: '); From 590701fe22bcefef9df2eb843aacfa2708ac4f7f Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 13:51:33 +0100 Subject: [PATCH 05/13] Typo --- parts/server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parts/server.py b/parts/server.py index 0e8da1d..06399fd 100644 --- a/parts/server.py +++ b/parts/server.py @@ -207,7 +207,7 @@ def alter(partID): datasheet_file = request.files['datasheet-file'] datasheet_filename = secure_filename(datasheet_file.filename) i = 1 - while os.path.isfile('srv/datasheet/' + datasheet_filename): + while os.path.isfile('srv/datasheets/' + datasheet_filename): datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) @@ -233,7 +233,7 @@ def alter(partID): datasheet_file = request.files['datasheet-file'] datasheet_filename = secure_filename(datasheet_file.filename) i = 1 - while os.path.isfile('srv/datasheet/' + datasheet_filename): + while os.path.isfile('srv/datasheets/' + datasheet_filename): datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) From 08b864637422f29ff507e4a0b3aada714646f9d9 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 14:48:03 +0100 Subject: [PATCH 06/13] Minor style adjustments --- parts/static/style.css | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/parts/static/style.css b/parts/static/style.css index 2e1ee69..af5887c 100644 --- a/parts/static/style.css +++ b/parts/static/style.css @@ -172,7 +172,6 @@ div label input { min-width: 60%; width:900px; z-index: 201; - border-radius: 2pt; text-align: center; opacity: 0.0; } @@ -308,7 +307,7 @@ table#results td { } table#results #location { - width: 15%; + width: 18%; } table#results #partno { From 7098d192250204395bfa0d6cbc85cf958d634052 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 14:49:35 +0100 Subject: [PATCH 07/13] Fixed datsheet info upload check. NOW WITH TRY-CATCH! --- parts/server.py | 52 ++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/parts/server.py b/parts/server.py index 06399fd..bdf2db0 100644 --- a/parts/server.py +++ b/parts/server.py @@ -29,24 +29,24 @@ def getContainers(): return containers def check_auth(username, password): - admin_list = [] - with open('edit_admin.json', 'r') as admin: - admin_list = json.load(admin) - for user in admin_list: - if username == user['username']: - return password == user['password'] + admin_list = [] + with open('edit_admin.json', 'r') as admin: + admin_list = json.load(admin) + for user in admin_list: + if username == user['username']: + return password == user['password'] def authenticate(): - return Response('Could not verify access level. Please retry', 401, {'WWW-Authenticate' : 'Basic realm="Login Required"'}) + return Response('Could not verify access level. Please retry', 401, {'WWW-Authenticate' : 'Basic realm="Login Required"'}) def requires_auth(f): - @wraps(f) - def decorated(*args, **kwargs): - auth = request.authorization - if not auth or not check_auth(auth.username, auth.password): - return authenticate() - return f(*args, **kwargs) - return decorated + @wraps(f) + def decorated(*args, **kwargs): + auth = request.authorization + if not auth or not check_auth(auth.username, auth.password): + return authenticate() + return f(*args, **kwargs) + return decorated def serveImage(img): img_io = BytesIO() @@ -89,7 +89,7 @@ def locationEditor(): return render_template('locationEditor.html', locations=locations, containers=getContainers()) @app.route('/parts/alterLocation/', methods=['POST']) -# @requires_auth +@requires_auth def alterLocation(locationID): locationID = int(locationID) s = '' @@ -193,7 +193,7 @@ def getfile(filename): return send_from_directory('/srv/datasheets/', filename + '.pdf') @app.route('/parts/alter/', methods=['POST']) -# @requires_auth +@requires_auth def alter(partID): partID = int(partID) s = '' @@ -212,10 +212,14 @@ def alter(partID): i += 1 datasheet_file.save('/srv/datasheets/' + datasheet_filename) datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename - elif request.form.has_key('datasheet-url'): - datasheet_filename = request.form['datasheet-url'] + # elif request.form.has_key('datasheet-url'): + # datasheet_filename = request.form['datasheet-url'] else: - datasheet_filename = None + try: + datasheet_filename = request.form['datasheet-url'] + except: + print('No docs provided') + datasheet_filename = None r = db_engine.execute(s, partno=request.form['partno'], description=request.form['description'], datasheet=datasheet_filename, @@ -240,10 +244,14 @@ def alter(partID): datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename if l[0]['datasheet'] != None: os.remove('/srv/datasheets/' + l[0]['datasheet']) - elif request.form.has_key('datasheet-url'): - datasheet_filename = request.form['datasheet-url'] + # elif request.form.has_key('datasheet-url'): + # datasheet_filename = request.form['datasheet-url'] else: - datasheet_filename = l[0]['datasheet'] + try: + datasheet_filename = request.form['datasheet-url'] + except: + print('No docs provided') + datasheet_filename = l[0]['datasheet'] s += 'where id=:id returning id;' s = text(s) r = db_engine.execute(s, partno=request.form['partno'], From 623770091bd943e40db69f53230e42782725879a Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 14:50:10 +0100 Subject: [PATCH 08/13] Fixed not retrieving correctly the location_id --- parts/static/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parts/static/script.js b/parts/static/script.js index d67b31c..f3917c3 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -218,7 +218,7 @@ function container_onchange() { $('#location-dropdown').empty(); $.getJSON('parts/getlocationsInContainer/' + selected_container_id, function(data) { $.each(data, function(location_id, location_name) { - $('#location-dropdown').append(''); + $('#location-dropdown').append(''); }); }); } From afecca71721118ff84ca7fc646dd6fa21000e576 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 14:50:24 +0100 Subject: [PATCH 09/13] Appending datasheet url to form data --- parts/static/script.js | 1 + 1 file changed, 1 insertion(+) diff --git a/parts/static/script.js b/parts/static/script.js index f3917c3..f88feff 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -29,6 +29,7 @@ function new_entry() { $('table#details tr#description td p').text(''); $('table#details tr#partno td input').val(''); $('table#details tr#description td input').val(''); + $('input[name=datasheet-url-input]').val(''); container_onchange(); init_edit(-1); overlay_in(); From d65de687d8cd0f5f336a77c8f1b8802efb721fee Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 14:58:07 +0100 Subject: [PATCH 10/13] Opening datasheet in new tab --- parts/static/script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parts/static/script.js b/parts/static/script.js index f88feff..841c558 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -166,7 +166,7 @@ function show_part_info(partID) { $('table#details tr#description td input').val(text_filter(data.description)); container_onchange(); if (data.datasheet != null) { - $('tr#datasheet-head').html($('DATASHEET: ')); + $('tr#datasheet-head').html($('DATASHEET: ')); $('input[name=datasheet-url-input]').val(data.datasheet); } else From 50e4903a302d0270aa97987873091a41c89af6a7 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 14:58:20 +0100 Subject: [PATCH 11/13] Check if user has selected a location --- parts/static/script.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/parts/static/script.js b/parts/static/script.js index 841c558..02bd755 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -62,6 +62,10 @@ function end_edit() { } function save(partID) { + if (!$('#location-dropdown').val()) { + alert('Please select a location.'); + return; + } var location_id_v = $('#location-dropdown').val(); var partno_v = $('input[name=partno-input]').val(); var description_v = $('input[name=description-input]').val(); From 4541fab34e93b5a111ea13a2017124a04d337595 Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 14:58:31 +0100 Subject: [PATCH 12/13] Removed debug prints --- parts/server.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/parts/server.py b/parts/server.py index bdf2db0..1108b5e 100644 --- a/parts/server.py +++ b/parts/server.py @@ -218,7 +218,6 @@ def alter(partID): try: datasheet_filename = request.form['datasheet-url'] except: - print('No docs provided') datasheet_filename = None r = db_engine.execute(s, partno=request.form['partno'], description=request.form['description'], @@ -250,7 +249,6 @@ def alter(partID): try: datasheet_filename = request.form['datasheet-url'] except: - print('No docs provided') datasheet_filename = l[0]['datasheet'] s += 'where id=:id returning id;' s = text(s) From 0e949dff50bf1987f849088baaefc725bd8ee08c Mon Sep 17 00:00:00 2001 From: Davide Bongiovanni Date: Tue, 13 Nov 2018 17:16:33 +0100 Subject: [PATCH 13/13] Minor style adjustments --- parts/static/style.css | 2 +- parts/templates/partsearch.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/parts/static/style.css b/parts/static/style.css index af5887c..ff0aa90 100644 --- a/parts/static/style.css +++ b/parts/static/style.css @@ -68,7 +68,7 @@ input[type=text].search-bar { color: #D7E2E2; font-size: 10pt; margin-top: 4pt; - margin-left: 16pt; + margin-left: 3pt; margin-bottom: 4pt; } diff --git a/parts/templates/partsearch.html b/parts/templates/partsearch.html index 8fcf1d3..7165845 100644 --- a/parts/templates/partsearch.html +++ b/parts/templates/partsearch.html @@ -23,7 +23,7 @@
-

Search in:

+

SEARCH IN