Merge branch 'master' of gits-15.sys.kth.se:ELAB/ELAB-partsearch

pull/3/head
Davide Bongiovanni 8 years ago
commit 0c4cb3aeba

@ -11,11 +11,11 @@ db_engine = {}
db_metadata = {} db_metadata = {}
parts = {} parts = {}
@app.route('/') @app.route('/parts')
def index(): def index():
return render_template('partsearch.html') return render_template('partsearch.html')
@app.route('/getpartinfo/<partID>') @app.route('/parts/getpartinfo/<partID>')
def get_part_info(partID): def get_part_info(partID):
s = 'select * from parts where id = :id;' s = 'select * from parts where id = :id;'
r = db_engine.execute(text(s), id=partID) r = db_engine.execute(text(s), id=partID)
@ -25,9 +25,10 @@ def get_part_info(partID):
r.close() r.close()
return json.dumps(l[0]) return json.dumps(l[0])
@app.route('/query/<filter>/<query>') @app.route('/parts/query/<filter>/<query>')
def query(filter, query): def query(filter, query):
query = '%' + query + '%' query = '%' + query + '%'
filter = int(filter)
s = 'select * from parts where ' s = 'select * from parts where '
if filter & (1 << 0) != 0: if filter & (1 << 0) != 0:
s += 'LOWER(type) like LOWER(:name) or ' s += 'LOWER(type) like LOWER(:name) or '

@ -61,7 +61,7 @@ $(document).ready(function() {
filter += 16; filter += 16;
if($('#notes').is(':checked')) if($('#notes').is(':checked'))
filter += 32; filter += 32;
$.getJSON('http://127.0.0.1:5000/query/' + filter + '/' + query, function(data) { $.getJSON('https://www.elab.kth.se/parts/query/' + filter + '/' + query, function(data) {
var newResults = '<div class="results">'; var newResults = '<div class="results">';
for(var i = 0; i < data.length; i++) { // Create new view for results for(var i = 0; i < data.length; i++) { // Create new view for results
newResults += '<div class="results-row" part-id="' + data[i].id + '">'; newResults += '<div class="results-row" part-id="' + data[i].id + '">';
@ -95,7 +95,7 @@ $(document).ready(function() {
newResults += '<div class="results-datasheet">'; newResults += '<div class="results-datasheet">';
if (data[i].datasheet != null) if (data[i].datasheet != null)
newResults += '<a href="http://127.0.0.1:5000/getfile/' + data[i].datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>'; newResults += '<a href="https://www.elab.kth.se/parts/getfile/' + data[i].datasheet + '"><i class="fa fa-file-text" aria-hidden="true"></i></a>';
newResults += '</div>'; newResults += '</div>';
newResults += '</a>' newResults += '</a>'
newResults += '</div>'; newResults += '</div>';
@ -109,7 +109,7 @@ $(document).ready(function() {
$('.results-row').on('click', function() { $('.results-row').on('click', function() {
var partID = $(this).attr('part-id'); var partID = $(this).attr('part-id');
$.getJSON('http://127.0.0.1:5000/getpartinfo/' + partID, function(data) { $.getJSON('https://www.elab.kth.se/parts/getpartinfo/' + partID, function(data) {
// TODO: Fill stuff with the fetched info // TODO: Fill stuff with the fetched info
}).fail(function() { }).fail(function() {
console.log( "Fetching part info failed" ); console.log( "Fetching part info failed" );

Loading…
Cancel
Save