39 Commits
Author SHA1 Message Date
davide d7e9615453 Always show scrollbar 2018-11-19 09:35:08 +01:00
davide f2ddbd6fdf Changed inactive filter button color 2018-11-19 09:32:00 +01:00
davide d70c5dbde3 ... and height 2018-11-16 17:26:32 +01:00
davide f1c32251f7 Corrected css property name 2018-11-16 17:25:39 +01:00
davide 71ed8a60f4 Fixed floating button style to more consistently center the plus sign. 2018-11-16 08:12:52 +01:00
davide ae96e7457c Re-activating button in case of failure 2018-11-15 16:37:55 +01:00
davide 5da9712276 Location should now stay the same on creation of new part 2018-11-15 16:33:47 +01:00
davide ff55c778ef Added background shadow 2018-11-15 16:31:24 +01:00
davide bcbdc6b52a Whoops. Fixed for real now 2018-11-15 15:42:36 +01:00
davide dac5d96f03 Fixed setting location in dropdown on show_part_info 2018-11-15 15:37:17 +01:00
davide 97a208f48c Fixed dropdown population order 2018-11-15 13:10:56 +01:00
davide 6e13be37e6 Merge branch 'master' of git.elab.kth.se:davide/ELAB-partsearch 2018-11-14 18:41:10 +01:00
davide 0789b3a0d8 Fixed location search 2018-11-14 18:40:39 +01:00
marek 4cf02f26c4 octopart link pretty 2018-11-14 16:40:40 +01:00
marek f4235556f7 octopart-fetch button is mash-like-an-idiot proof 2018-11-14 16:40:28 +01:00
davide dc880978ab Updated dependencies in readme 2018-11-14 14:09:06 +01:00
davide 582370a17d Merge branch 'master' of git.elab.kth.se:davide/ELAB-partsearch 2018-11-13 22:50:59 +01:00
davide 11b3ae1af5 Reset file input when opening new part info. 2018-11-13 22:50:54 +01:00
marek 82f1c364de Merge branch 'master' of https://git.elab.kth.se/davide/ELAB-partsearch 2018-11-13 22:50:41 +01:00
marek 38c22af31f fixed octopart fetch for server encoding issues 2018-11-13 22:50:29 +01:00
davide 112686b9c6 Merge branch 'master' of git.elab.kth.se:davide/ELAB-partsearch 2018-11-13 22:38:55 +01:00
davide d64923ddad Added missing leading slash 2018-11-13 22:38:40 +01:00
marek 2a8b1f50f4 Merge branch 'master' of https://git.elab.kth.se/davide/ELAB-partsearch 2018-11-13 22:10:44 +01:00
marek 7e60da9362 octopart button now with more sponsor product placement! 2018-11-13 22:10:26 +01:00
marek 227e725e95 more magical octopart button prototype (temporarily disabled) 2018-11-13 22:09:34 +01:00
davide a8496af806 Merge branch 'master' of git.elab.kth.se:davide/ELAB-partsearch 2018-11-13 22:07:32 +01:00
davide cc6a1473cb Correctly deleting existing datasheet 2018-11-13 22:07:19 +01:00
davide b44d05aabd Resetting url input on new part if datasheet is empty 2018-11-13 22:07:02 +01:00
marek 3cb81e9a79 Merge branch 'master' of https://git.elab.kth.se/davide/ELAB-partsearch 2018-11-13 21:58:49 +01:00
marek b297462d3b fixed location editor 2018-11-13 21:58:38 +01:00
davide 40186ad08e Fixed getfile 2018-11-13 21:51:56 +01:00
davide a7751dc38b Added query timer 2018-11-13 21:35:37 +01:00
davide e2003e3562 Merge branch 'master' of git.elab.kth.se:davide/ELAB-partsearch 2018-11-13 21:09:31 +01:00
davide 7e1f59f781 Delete button now deletes only once. 2018-11-13 21:09:17 +01:00
marek 4649723f87 Merge branch 'master' of https://git.elab.kth.se/davide/ELAB-partsearch 2018-11-13 20:56:51 +01:00
marek 0b64c50f36 fixed links for the locationEditor 2018-11-13 20:56:44 +01:00
davide 597898885b Re-inserted auth requirements 2018-11-13 20:49:10 +01:00
davide 55033f7295 Fixed static files paths. 4real 2018-11-13 20:38:48 +01:00
davide 8d1237011a Corrected static folder location 2018-11-13 20:18:21 +01:00
7 changed files with 85 additions and 44 deletions
+21 -20
View File
@@ -1,6 +1,7 @@
import os import os
import re import re
import json, urllib.parse, urllib.request import json
import requests
import sqlalchemy import sqlalchemy
from functools import wraps from functools import wraps
from sqlalchemy.sql import select from sqlalchemy.sql import select
@@ -64,7 +65,7 @@ def serveImage(img):
img_io.seek(0) img_io.seek(0)
return send_file(img_io, mimetype='image/png') return send_file(img_io, mimetype='image/png')
@app.route('/parts', strict_slashes=False) @app.route('/parts', strict_slashes=True)
def index(): def index():
return render_template('partsearch.html', containers=getContainers()) return render_template('partsearch.html', containers=getContainers())
@@ -106,7 +107,7 @@ def alterLocation(locationID):
if locationID < 0: if locationID < 0:
# New entry # New entry
s = 'insert into locations (name, container_id) ' s = 'insert into locations (name, container_id) '
s += 'values (:name, :container, :userid);' s += 'values (:name, :container);'
s = text(s) s = text(s)
r = db_engine.execute(s,name=request.form['name'],container=request.form['container']); r = db_engine.execute(s,name=request.form['name'],container=request.form['container']);
r.close() r.close()
@@ -146,7 +147,7 @@ def query(filter_dummy, query):
if filter['l'] == 'true': if filter['l'] == 'true':
s += '(' s += '('
for i in range(len(keywords)): for i in range(len(keywords)):
s += 'LOWER(l.name) like LOWER(:kw'+ str(i) +') AND ' s += 'LOWER(c.name||l.name) like LOWER(:kw'+ str(i) +') AND '
s = s[:-5] s = s[:-5]
s += ') OR ' s += ') OR '
if filter['p'] == 'true': if filter['p'] == 'true':
@@ -197,10 +198,10 @@ def getMap(containerID):
@app.route('/parts/getfile/<filename>') @app.route('/parts/getfile/<filename>')
def getfile(filename): def getfile(filename):
if(re.match('^[\w\-_]+$', filename) == None): if(re.match('^[\w\-_]+.[p|P][d|D][f|F]$', filename) == None):
return 'No injections pls.' return 'No injections pls.'
return send_from_directory('/srv/datasheets/', filename + '.pdf') return send_from_directory('/srv/datasheets/', filename)
@app.route('/parts/alter/<partID>', methods=['POST']) @app.route('/parts/alter/<partID>', methods=['POST'])
@requires_auth @requires_auth
@@ -217,7 +218,7 @@ def alter(partID):
datasheet_file = request.files['datasheet-file'] datasheet_file = request.files['datasheet-file']
datasheet_filename = secure_filename(datasheet_file.filename) datasheet_filename = secure_filename(datasheet_file.filename)
i = 1 i = 1
while os.path.isfile('srv/datasheets/' + datasheet_filename): while os.path.isfile('/srv/datasheets/' + datasheet_filename):
datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf'
i += 1 i += 1
datasheet_file.save('/srv/datasheets/' + datasheet_filename) datasheet_file.save('/srv/datasheets/' + datasheet_filename)
@@ -248,15 +249,15 @@ def alter(partID):
datasheet_file = request.files['datasheet-file'] datasheet_file = request.files['datasheet-file']
datasheet_filename = secure_filename(datasheet_file.filename) datasheet_filename = secure_filename(datasheet_file.filename)
i = 1 i = 1
while os.path.isfile('srv/datasheets/' + datasheet_filename): while os.path.isfile('/srv/datasheets/' + datasheet_filename):
datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf' datasheet_filename = datasheet_filename[:-4] + str(i) + '.pdf'
i += 1 i += 1
datasheet_file.save('/srv/datasheets/' + datasheet_filename) datasheet_file.save('/srv/datasheets/' + datasheet_filename)
datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename
if l[0]['datasheet'] != None: if l[0]['datasheet'] != None:
os.remove('/srv/datasheets/' + l[0]['datasheet']) whole_url = l[0]['datasheet']
# elif request.form.has_key('datasheet-url'): actual_filename = whole_url[whole_url.rfind('/') + 1:]
# datasheet_filename = request.form['datasheet-url'] os.remove('/srv/datasheets/' + actual_filename)
else: else:
try: try:
datasheet_filename = request.form['datasheet-url'] datasheet_filename = request.form['datasheet-url']
@@ -276,7 +277,7 @@ def alter(partID):
return '{"status":"ok", "part_id" : ' + str(new_id) + '}' return '{"status":"ok", "part_id" : ' + str(new_id) + '}'
@app.route('/parts/delete/<partID>') @app.route('/parts/delete/<partID>')
# @requires_auth @requires_auth
def delete(partID): def delete(partID):
if int(partID) < 0: if int(partID) < 0:
abort(400) abort(400)
@@ -285,7 +286,7 @@ def delete(partID):
return '{"status":"ok"}' return '{"status":"ok"}'
@app.route('/parts/deleteLocation/<locationID>') @app.route('/parts/deleteLocation/<locationID>')
# @requires_auth @requires_auth
def deleteLocation(locationID): def deleteLocation(locationID):
if int(locationID) < 0: if int(locationID) < 0:
abort(400) abort(400)
@@ -297,13 +298,13 @@ def deleteLocation(locationID):
def fetchOctopartSnippet(searchTerm): def fetchOctopartSnippet(searchTerm):
if octopartURL == '': if octopartURL == '':
return '{"result":"octopart integration not enabled"}' return '{"result":"octopart integration not enabled"}'
args = [ args = {
('q', searchTerm), 'q': searchTerm,
('start', 0), 'start': '0',
('limit', 1) 'limit': 1
] }
data = urllib.request.urlopen(octopartURL + '&' + urllib.parse.urlencode(args)).read() data = requests.get(octopartURL, params=args)
search_response = json.loads(data) search_response = json.loads(data.text)
result = '{"result":"no results. sorry :(("}' result = '{"result":"no results. sorry :(("}'
if search_response['hits']>0: if search_response['hits']>0:
+4 -2
View File
@@ -55,11 +55,13 @@ function saveLocation(locationID) {
function deleteLocation(locationID) { function deleteLocation(locationID) {
if (locationID < 0) if (locationID < 0){
alert('Congratulations! You found the secret UI bug easter egg! This button should not be here, yet I left it specifically because I wanted an easter egg and not because of any other reasons! Good for you!') alert('Congratulations! You found the secret UI bug easter egg! This button should not be here, yet I left it specifically because I wanted an easter egg and not because of any other reasons! Good for you!')
return; return;
if (!confirm('Delete the selected location? If there are parts there, this will leave a mess in the database and Marek will be very sad.')) }
if (!confirm('Delete the selected location? If there are parts there, this will leave a mess in the database and Marek will be very sad.')){
return; return;
}
$.ajax({ $.ajax({
url: rootURL + 'deleteLocation/' + locationID, url: rootURL + 'deleteLocation/' + locationID,
type: 'GET', type: 'GET',
+32 -8
View File
@@ -1,3 +1,5 @@
var active_timer = 100;
function init_edit(partID) { function init_edit(partID) {
$('table#details tr#location td p').hide(); $('table#details tr#location td p').hide();
$('#location-dropdown').show(); $('#location-dropdown').show();
@@ -31,7 +33,7 @@ function new_entry() {
$('table#details tr#partno td input').val(''); $('table#details tr#partno td input').val('');
$('table#details tr#description td input').val(''); $('table#details tr#description td input').val('');
$('input[name=datasheet-url-input]').val(''); $('input[name=datasheet-url-input]').val('');
container_onchange(); // container_onchange();
init_edit(-1); init_edit(-1);
overlay_in(); overlay_in();
} }
@@ -167,25 +169,37 @@ function delete_entry(partID) {
function show_part_info(partID) { function show_part_info(partID) {
$.getJSON(rootURL + 'getpartinfo/' + partID, function(data) { $.getJSON(rootURL + 'getpartinfo/' + partID, function(data) {
$('table#details tr#location td p').text(text_filter(data.location_descriptor)); // name is the location friendly name $('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); $('#container-dropdown').val(data.container_id);
$('img#map').attr('src', 'parts/map/' + data.container_id);
$('#location-dropdown').empty();
$.getJSON('parts/getlocationsInContainer/' + data.container_id, function(json) {
$.each(json, function(loc_id, loc_name) {
$('#location-dropdown').append('<option value="' + loc_id + '">' + loc_name + '</option>');
});
$('#location-dropdown').val(data.location_id);
});
$('table#details tr#partno td p').text(text_filter(data.partno)); $('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#partno td input').val(text_filter(data.partno));
$('table#details tr#description td p').text(text_filter(data.description)); $('table#details tr#description td p').text(text_filter(data.description));
$('table#details tr#description td input').val(text_filter(data.description)); $('table#details tr#description td input').val(text_filter(data.description));
$('table#details tr#notes td p').text(text_filter(data.notes)); $('table#details tr#notes td p').text(text_filter(data.notes));
$('input[name=notes-input]').val(text_filter(data.notes)); $('input[name=notes-input]').val(text_filter(data.notes));
container_onchange(); // Resetting file input. Super dirty hack. Disgusting
var $el = $('#datasheet-finput');
$el.wrap('<form>').closest('form').get(0).reset();
$el.unwrap();
if (data.datasheet != null) { if (data.datasheet != null) {
$('tr#datasheet-head').html($('<td>DATASHEET: <a href="' + data.datasheet + '" target="_blank"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>')); $('tr#datasheet-head').html($('<td>DATASHEET: <a href="' + data.datasheet + '" target="_blank"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>'));
$('input[name=datasheet-url-input]').val(data.datasheet); $('input[name=datasheet-url-input]').val(data.datasheet);
} }
else else {
$('tr#datasheet-head td').text('DATASHEET: '); $('tr#datasheet-head td').text('DATASHEET: ');
$('input[name=datasheet-url-input]').val('');
}
$('#edit-button').click(function() { $('#edit-button').click(function() {
init_edit(partID); init_edit(partID);
}); });
$('#delete-button').click(function() { $('#delete-button').off('click').on('click', function() {
delete_entry(partID); delete_entry(partID);
}); });
overlay_in(); overlay_in();
@@ -239,22 +253,26 @@ function container_onchange() {
} }
} }
function octopartFetch(){ function octopartFetch(){
$('#magic-autofill-button').attr('disabled', 'disabled');
$.getJSON(rootURL + 'fetchOctopartSnippet/' + $('#partno-input').val()).done(function(json){ $.getJSON(rootURL + 'fetchOctopartSnippet/' + $('#partno-input').val()).done(function(json){
$('#magic-autofill-button').removeAttr('disabled');
if (json['result']=='ok'){ if (json['result']=='ok'){
$('#description-input').val(json['snippet']); $('#description-input').val(json['snippet']);
}else{ }else{
$('#description-input').val(''); $('#description-input').val('');
$('#description-input').attr('placeholder', json['result']); $('#description-input').attr('placeholder', json['result']);
} }
}); }).fail(function() {
$('#magic-autofill-button').removeAttr('disabled');
});
} }
$(document).ready(function() { $(document).ready(function() {
$.ajaxSetup({ cache: false }); $.ajaxSetup({ cache: false });
$('.search-bar').on('keyup', function() { $('.search-bar').on('keyup', function() {
perform_query(); clearTimeout(active_timer);
active_timer = setTimeout(perform_query, 100);
}); });
$('.checkbox').change( function() { $('.checkbox').change( function() {
if ( !$('#location').is(':checked') if ( !$('#location').is(':checked')
@@ -265,4 +283,10 @@ $(document).ready(function() {
else else
perform_query(); perform_query();
}); });
// $('#partno-input').bind('blur',function() {
// if($('#partno-input').val().length > 0){
// octopartFetch();
// }
// });
}); });
+18 -5
View File
@@ -3,6 +3,7 @@ html {
color: #000F0F; color: #000F0F;
font-family: 'Roboto', sans-serif; font-family: 'Roboto', sans-serif;
font-size:large; font-size:large;
overflow-y: scroll;
} }
body { body {
@@ -83,7 +84,7 @@ input[type=checkbox]{
input[type=checkbox] + label.toggle-btn { input[type=checkbox] + label.toggle-btn {
display: inline-block; display: inline-block;
padding: 5pt; padding: 5pt;
color: #D7E2E2; color: #013A3A;
margin-top: 6pt; margin-top: 6pt;
margin-bottom: 6pt; margin-bottom: 6pt;
margin-left: 3pt; margin-left: 3pt;
@@ -91,13 +92,14 @@ input[type=checkbox] + label.toggle-btn {
width: 80pt; width: 80pt;
line-height: 300%; line-height: 300%;
text-align: center; text-align: center;
border: 1pt solid #D7E2E2; border: 1pt solid #013A3A;
transition: 0.2s; transition: 0.2s;
-webkit-transition: 0.2s; -webkit-transition: 0.2s;
} }
input[type=checkbox]:checked + label.toggle-btn { input[type=checkbox]:checked + label.toggle-btn {
background-color: #D7E2E2; background-color: #D7E2E2;
border: 1pt solid #D7E2E2;
color: #000F0F; color: #000F0F;
} }
@@ -240,17 +242,18 @@ div label input {
} }
.round-floating-button { .round-floating-button {
display: flex;
align-items: center;
justify-content: center;
position: fixed; position: fixed;
bottom: 15pt; bottom: 15pt;
right: 15pt; right: 15pt;
width: 40pt; width: 40pt;
height: 32pt; height: 40pt;
border-radius: 20pt; border-radius: 20pt;
background-color: #5E9292; background-color: #5E9292;
font-size: 22pt; font-size: 22pt;
padding-top: 8pt;
box-shadow: 2pt 1pt 8pt black; box-shadow: 2pt 1pt 8pt black;
text-align: center;
} }
.round-floating-button a{ .round-floating-button a{
@@ -313,6 +316,16 @@ table#details {
margin-top: 0; margin-top: 0;
} }
#magical_autofill{
font-size: small;
}
a.small_link{
text-decoration: none;
color: #B0B0B0;
font-weight: 600;
}
.details-header { .details-header {
color: #013A3A; color: #013A3A;
} }
+4 -3
View File
@@ -8,10 +8,10 @@
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"> <link rel="stylesheet" type="text/css" href="/parts/static/style.css">
<script src="https://use.fontawesome.com/2fef7be393.js"></script> <script src="https://use.fontawesome.com/2fef7be393.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='common.js') }}"></script> <script type="text/javascript" src="/parts/static/common.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='locationEditorScript.js') }}"></script> <script type="text/javascript" src="/parts/static/locationEditorScript.js"></script>
</head> </head>
<body> <body>
<h1>LOCATION EDITOR</h1> <h1>LOCATION EDITOR</h1>
@@ -34,6 +34,7 @@
</table> </table>
<div class="bottom-spacer"></div> <div class="bottom-spacer"></div>
<div class="shadow" onclick="overlay_out()"></div>
<div class="overlay"> <div class="overlay">
<h2>Part Details</h2> <h2>Part Details</h2>
<table id="details"> <table id="details">
+5 -5
View File
@@ -8,12 +8,12 @@
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"> <link rel="stylesheet" type="text/css" href="parts/static/style.css">
<link rel="apple-touch-icon-precomposed" href="{{ url_for('static', filename='apple-touch-icon.png') }}"> <link rel="apple-touch-icon-precomposed" href="parts/static/apple-touch-icon.png">
<script src="https://use.fontawesome.com/2fef7be393.js"></script> <script src="https://use.fontawesome.com/2fef7be393.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='common.js') }}"></script> <script type="text/javascript" src="parts/static/common.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script> <script type="text/javascript" src="parts/static/script.js"></script>
</head> </head>
<body> <body>
<h1>ELAB Part Search Engine</h1> <h1>ELAB Part Search Engine</h1>
@@ -59,7 +59,7 @@
<tr id="partno" class="details-content"><td><p></p><input type="text" name="partno-input" placeholder="Part Number" class="pinfo-input" id="partno-input"/></td></tr> <tr id="partno" class="details-content"><td><p></p><input type="text" name="partno-input" placeholder="Part Number" class="pinfo-input" id="partno-input"/></td></tr>
<tr id="description-head" class="details-header"><td>DESCRIPTION</td></tr> <tr id="description-head" class="details-header"><td>DESCRIPTION</td></tr>
<tr id="description" class="details-content"><td><p></p><input type="text" name="description-input" placeholder="Description" class="pinfo-input" id="description-input"/></td></tr> <tr id="description" class="details-content"><td><p></p><input type="text" name="description-input" placeholder="Description" class="pinfo-input" id="description-input"/></td></tr>
<tr id="magical_autofill" style="display:none"><td><input type="button" id="magic-autofill-button" onclick="octopartFetch()" value="magical auto-fill" style="margin-bottom:6pt"/></td></tr> <tr id="magical_autofill" style="display:none"><td><input type="button" id="magic-autofill-button" onclick="octopartFetch()" value="magical auto-fill" style="margin-bottom:6pt"/> powered by <a href="http://octopart.com" class="small_link">OctoPart™</a></td></tr>
<tr id="datasheet-head" class="details-header"><td>DATASHEET: </td></tr> <tr id="datasheet-head" class="details-header"><td>DATASHEET: </td></tr>
<tr id="datasheet" style="display: none"><td><input type="file" accept=".pdf" class="pinfo-input" id="datasheet-finput"></td></tr> <tr id="datasheet" style="display: none"><td><input type="file" accept=".pdf" class="pinfo-input" id="datasheet-finput"></td></tr>
<tr id="datasheet" style="display: none"><td>OR: <input type="text" class="pinfo-input" name="datasheet-url-input" style="width:80%; margin-bottom: 6pt;" placeholder="Datasheet URL"></td></tr> <tr id="datasheet" style="display: none"><td>OR: <input type="text" class="pinfo-input" name="datasheet-url-input" style="width:80%; margin-bottom: 6pt;" placeholder="Datasheet URL"></td></tr>
+1 -1
View File
@@ -9,7 +9,7 @@ The system allows searching for parts in ELAB by part name or a description text
Python, and the following packages: Python, and the following packages:
* flask * flask
* flask-login * requests
* sqlalchemy * sqlalchemy
* werkzeug * werkzeug
* pillow * pillow