diff --git a/parts/server.py b/parts/server.py index ac33284..89915ea 100644 --- a/parts/server.py +++ b/parts/server.py @@ -52,7 +52,7 @@ def get_part_info(partID): r.close() return json.dumps(l[0]) -@app.route('/parts/query//') +@app.route('/parts/query//') # TODO: maybe change AND to OR or maybe not def query(filter_dummy, query): filter = request.args.to_dict() keywords = query.split() # Default splits with spaces @@ -88,7 +88,6 @@ def query(filter_dummy, query): s = s[:-5] s += ') OR ' s = s[:-4] + ';' - print(s) s = text(s) r = db_engine.execute(s, kw_dict) l = [] diff --git a/parts/static/script.js b/parts/static/script.js index cbd7525..4dbde1b 100644 --- a/parts/static/script.js +++ b/parts/static/script.js @@ -144,7 +144,7 @@ function save(partID) { $.ajax({ // Your server script to process the upload - url: 'https://www.elab.kth.se/parts/alter/' + partID, + url: 'http://127.0.0.1:5000/parts/alter/' + partID, type: 'POST', data: data, @@ -183,7 +183,7 @@ function delete_entry(partID) { if (!confirm('Delete the selected entry?')) return; $.ajax({ - url: 'https://www.elab.kth.se/parts/delete/' + partID, + url: 'http://127.0.0.1:5000/parts/delete/' + partID, type: 'GET', cache: false, contentType: false, @@ -199,7 +199,7 @@ function delete_entry(partID) { } function show_part_info(partID) { - $.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) { + $.getJSON('http://127.0.0.1:5000/parts/getpartinfo/' + partID, function(data) { $('#block-info').text(text_filter(data.block)); $('#type-info').text(text_filter(data.type)); $('#partno-info').text(text_filter(data.partno) + ' ' + text_filter(data.partnoalt) + ' ' + text_filter(data.partnoalt2)); @@ -207,7 +207,7 @@ function show_part_info(partID) { $('#quantity-info').text(text_filter(data.quantity)); $('#notes-info').text(text_filter(data.notes)); if (data.datasheet != null) - $('#datasheet-info').html($('')); + $('#datasheet-info').html($('')); else $('#datasheet-info').text(' '); $('#edit-button').click(function() { @@ -223,51 +223,29 @@ function show_part_info(partID) { } function perform_query() { + $('#no-results').css("opacity", 0); var query = $('.search-bar').val(); - var filter = 0; - if($('#type').is(':checked')) - filter += 1; - if($('#partno').is(':checked')) - filter += 2 + 4 + 8; - if($('#description').is(':checked')) - filter += 16; - if($('#notes').is(':checked')) - filter += 32; - $.getJSON('https://www.elab.kth.se/parts/query/' + filter + '/' + query, function(data) { - var newResults = $('
'); - for(var i = 0; i < data.length; i++) { // Create new view for results - var newRow = $('
'); - var newClicker = $(''); - - newClicker.append($('
').text(text_filter(data[i].block))); - newClicker.append($('
').text(text_filter(data[i].type))); - newClicker.append($('
').text(text_filter(data[i].partno))); - newClicker.append($('
').text(text_filter(data[i].description))); - var notes = $('
'); - if (data[i].notes != null && data[i].notes.length > 0) { - var icon = $(''); - var tooltipText = $('
').text(data[i].notes); - var tooltip = $('
'); - tooltip.append(icon, tooltipText); - notes.append(tooltip); - } - newClicker.append(notes); - var datasheet = $('
'); - if (data[i].datasheet != null) - datasheet.html(''); - newClicker.append(datasheet); - - newRow.append(newClicker); - newResults.append(newRow); + var data = { + l:$('#type').is(':checked'), + p:$('#partno').is(':checked'), + d:$('#description').is(':checked'), + n:$('#notes').is(':checked') + }; + filter = '0'; + $.getJSON('http://127.0.0.1:5000/parts/query/' + filter + '/' + query, data, function(data) { + $("#results").find("tr:not(:first)").remove(); // Delete all table rows + for(var i = 0; i < data.length; i++) { + var newRow = $(''); + + newRow.append($('').text(text_filter(data[i].location_descriptor))); + newRow.append($('').text(text_filter(data[i].partno))); + newRow.append($('').text(text_filter(data[i].description))); + newRow.append($('').text(text_filter(data[i].docs))); + $('#results').append(newRow); } if(data.length == 0) { - newResults = '
'; - newResults += '

No results.

'; - newResults += '
'; + $('#no-results').animate({opacity:1},2000); } - $('.results').replaceWith(newResults); }).fail(function() { var newResults = '
'; newResults += '

No results.

'; diff --git a/parts/static/style.css b/parts/static/style.css index 5086b51..f5cc5f4 100644 --- a/parts/static/style.css +++ b/parts/static/style.css @@ -27,6 +27,7 @@ h3 { text-align: center; padding: 12pt; font-size: 20pt; + opacity: 0; } p { @@ -338,3 +339,41 @@ div label input { .bottom-spacer { height: 80pt; } + +table#results { + width: 100%; + border-collapse: collapse; +} + +table#results th { + background-color: #226666; + color: #D7E2E2; + padding: 4pt; + border-right: 2px solid #D7E2E2; + border-left: 2px solid #D7E2E2; +} + +table#results tr:nth-child(odd) { + background-color: #5E9292; +} + +table#results td { + padding: 4pt; + cursor: pointer; +} + +#location { + width: 15%; +} + +#partno { + /*width: 20%;*/ +} + +#description { + width: 65%; +} + +#docs { + width: 5%; +} \ No newline at end of file diff --git a/parts/templates/partsearch.html b/parts/templates/partsearch.html index da1b494..8f2262a 100644 --- a/parts/templates/partsearch.html +++ b/parts/templates/partsearch.html @@ -8,9 +8,9 @@ integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"> - + - +

ELAB Part Search Engine

@@ -21,20 +21,21 @@

Search in:

- +
-
Block
-
Manufacturer
-
Part Number
-
Description
-
Notes
-
Docs
-
-
+ + + + + + + +
LocationPart NumberDescriptionDocs
+

No results.