4 Commits
Author SHA1 Message Date
davide 4429a2a4f6 Merge branch 'master' of git.elab.kth.se:davide/ELAB-partsearch
# Conflicts:
#	parts/server.py
2018-11-13 19:28:54 +01:00
davide 725d2b0cdd Deleted some old code 2018-11-13 19:24:45 +01:00
davide 3793f4a865 Added notes feature 2018-11-13 19:24:33 +01:00
davide d6f0421b9f Returning notes in query 2018-11-13 19:04:33 +01:00
4 changed files with 37 additions and 94 deletions
+7 -6
View File
@@ -123,7 +123,7 @@ def alterLocation(locationID):
@app.route('/parts/getpartinfo/<partID>') @app.route('/parts/getpartinfo/<partID>')
def get_part_info(partID): def get_part_info(partID):
s = 'select p.id,partno,description, c.name || l.name as location_descriptor, location_id, container_id, datasheet from parts as p inner join locations as l on p.location_id = l.id inner join containers as c on l.container_id = c.id where p.id = :id;' s = 'select p.id,partno,description,notes, c.name || l.name as location_descriptor, location_id, container_id, datasheet from parts as p inner join locations as l on p.location_id = l.id inner join containers as c on l.container_id = c.id where p.id = :id;'
r = db_engine.execute(text(s), id=partID) r = db_engine.execute(text(s), id=partID)
l = [] l = []
for row in r: for row in r:
@@ -210,8 +210,8 @@ def alter(partID):
r = {} r = {}
if partID < 0: if partID < 0:
# New entry # New entry
s = 'insert into parts (partno, description, datasheet, location_id, whoadded) ' s = 'insert into parts (partno, description, datasheet, location_id, whoadded, notes) '
s += 'values (:partno, :description, :datasheet, :location_id, :user_id) returning id;' s += 'values (:partno, :description, :datasheet, :location_id, :user_id, :notes) returning id;'
s = text(s) s = text(s)
if len(request.files) != 0: if len(request.files) != 0:
datasheet_file = request.files['datasheet-file'] datasheet_file = request.files['datasheet-file']
@@ -233,8 +233,8 @@ def alter(partID):
description=request.form['description'], description=request.form['description'],
datasheet=datasheet_filename, datasheet=datasheet_filename,
location_id=request.form['location_id'], location_id=request.form['location_id'],
notes=request.form['notes'])
user_id=session['uid'] user_id=session['uid']
)
else: else:
# Modify entry # Modify entry
r = db_engine.execute(text('select * from parts where id=:id;'), id=partID) r = db_engine.execute(text('select * from parts where id=:id;'), id=partID)
@@ -243,7 +243,7 @@ def alter(partID):
l.append(dict(row)) l.append(dict(row))
r.close() r.close()
s = 'update parts ' s = 'update parts '
s += 'set partno=:partno, description=:description, datasheet=:datasheet, location_id=:location_id ' s += 'set partno=:partno, description=:description, datasheet=:datasheet, location_id=:location_id, notes=:notes '
if len(request.files) != 0: if len(request.files) != 0:
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)
@@ -268,7 +268,8 @@ def alter(partID):
description=request.form['description'], description=request.form['description'],
datasheet=datasheet_filename, datasheet=datasheet_filename,
location_id=request.form['location_id'], location_id=request.form['location_id'],
id=partID) id=partID,
notes=request.form['notes'])
new_id = r.fetchone()[0] new_id = r.fetchone()[0]
r.close() r.close()
+15 -8
View File
@@ -12,13 +12,13 @@ function init_edit(partID) {
$('table#details tr#datasheet td input').closest().show(); $('table#details tr#datasheet td input').closest().show();
$('table#details tr#datasheet td input').show(); $('table#details tr#datasheet td input').show();
// $('input[name=datasheet-url-input]').closest().show();
$('#duplicate-button').closest('div').hide(); $('#duplicate-button').closest('div').hide();
$('tr#datasheet').show(); $('tr#datasheet').show();
// var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
// $('#datasheet-info').replaceWith(datasheet_input); $('input[name=notes-input]').show();
$('table#details tr#notes td p').hide();
var newButton = '<div class="round-button-left"><a href="#" onclick="save(' + partID + ')"><i class="fa fa-check" aria-hidden="true"></i></a></div>'; var newButton = '<div class="round-button-left"><a href="#" onclick="save(' + partID + ')"><i class="fa fa-check" aria-hidden="true"></i></a></div>';
$('.round-button-left').replaceWith(newButton); $('.round-button-left').replaceWith(newButton);
@@ -54,9 +54,9 @@ function end_edit() {
$('table#details tr#description td input').hide(); $('table#details tr#description td input').hide();
$('tr#datasheet').hide(); $('tr#datasheet').hide();
// $('table#details tr#datasheet td input').closest().hide();
// $('table#details tr#datasheet td input').hide(); $('input[name=notes-input]').hide();
// $('input[name=datasheet-url-input]').closest().hide(); $('table#details tr#notes td p').show();
$('#duplicate-button').closest('div').show(); $('#duplicate-button').closest('div').show();
@@ -74,6 +74,7 @@ function save(partID) {
var description_v = $('input[name=description-input]').val(); var description_v = $('input[name=description-input]').val();
var datasheet = $('table#details tr#datasheet td input')[0].files; var datasheet = $('table#details tr#datasheet td input')[0].files;
var datasheet_url_v = $('input[name=datasheet-url-input]').val(); var datasheet_url_v = $('input[name=datasheet-url-input]').val();
var notes_v = $('input[name=notes-input]').val();
if(partno_v.length == 0){ if(partno_v.length == 0){
alert('Please enter a part number.'); alert('Please enter a part number.');
return; return;
@@ -102,8 +103,9 @@ function save(partID) {
data.append('datasheet-url', datasheet_url_v); data.append('datasheet-url', datasheet_url_v);
} }
data.append('partno', partno_v); data.append('partno', partno_v);
data.append('location_id', location_id_v) data.append('location_id', location_id_v);
data.append('description', description_v); data.append('description', description_v);
data.append('notes', notes_v);
$.ajax({ $.ajax({
// Your server script to process the upload // Your server script to process the upload
@@ -171,6 +173,8 @@ function show_part_info(partID) {
$('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));
$('input[name=notes-input]').val(text_filter(data.notes));
container_onchange(); container_onchange();
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>'));
@@ -193,6 +197,7 @@ function show_part_info(partID) {
function perform_query() { function perform_query() {
$('#no-results').stop(); $('#no-results').stop();
$('#no-results').css("opacity", 0); $('#no-results').css("opacity", 0);
$('#no-results').hide();
var query = $('.search-bar').val(); var query = $('.search-bar').val();
var data = { var data = {
l:$('#location').is(':checked'), l:$('#location').is(':checked'),
@@ -211,9 +216,11 @@ function perform_query() {
$('#results').append(newRow); $('#results').append(newRow);
} }
if(data.length == 0) { if(data.length == 0) {
$('#no-results').animate({opacity:1},2000); $('#no-results').show();
$('#no-results').animate({opacity:1},2000);
} }
}).fail(function() { }).fail(function() {
$('#no-results').show();
$('#no-results').animate({opacity:1},2000); $('#no-results').animate({opacity:1},2000);
console.log( "Query failed" ); console.log( "Query failed" );
}); });
+4 -71
View File
@@ -176,25 +176,6 @@ div label input {
opacity: 0.0; opacity: 0.0;
} }
.details-item {
display: inline-block;
width: 25%;
padding: 12pt 10pt 12pt 0;
text-align: right;
text-transform: uppercase;
}
.details-content {
display: inline-block;
width: 65%;
padding-left: 20pt;
text-align: left;
}
.details-content p {
text-align: left;
}
.round-button { .round-button {
position: absolute; position: absolute;
bottom: 15pt; bottom: 15pt;
@@ -332,61 +313,13 @@ table#details {
margin-top: 0; margin-top: 0;
} }
table#details #location-head { .details-header {
height: 10%;
color: #013A3A; color: #013A3A;
} }
table#details #location { .details-content td{
height: 10%; padding-top:6pt;
} padding-bottom:16pt;
table#details #location td{
height: 10%;
}
table#details #partno-head {
height: 10%;
color: #013A3A;
}
table#details #partno-head td{
padding-top: 16pt;
}
table#details #partno{
height: 10%;
}
table#details #partno td{
height: 10%;
}
table#details #description-head {
height: 10%;
color: #013A3A;
}
table#details #description-head td {
padding-top: 16pt;
}
table#details #description {
height: 20%;
}
table#details #description td {
padding-left: 5%;
padding-right: 5%;
}
table#details #datasheet-head {
height: 10%;
color: #013A3A;
}
table#details #datasheet-head td {
padding-top: 16pt;
} }
td p { td p {
+11 -9
View File
@@ -44,8 +44,8 @@
<h2>Part Details</h2> <h2>Part Details</h2>
<div> <div>
<table id="details"> <table id="details">
<tr id="location-head"><td>LOCATION</td></tr> <tr id="location-head" class="details-header"><td>LOCATION</td></tr>
<tr id="location"><td><p></p> <tr id="location" class="details-content"><td><p></p>
<select class="pinfo-input" id="container-dropdown" onchange="container_onchange()"> <select class="pinfo-input" id="container-dropdown" onchange="container_onchange()">
{% for container in containers %} {% for container in containers %}
<option value="{{container['id']}}">{{container['name']}}</option> <option value="{{container['id']}}">{{container['name']}}</option>
@@ -55,14 +55,16 @@
<option value="-1" selected="true">-- Select a container --</option> <option value="-1" selected="true">-- Select a container --</option>
</select> </select>
</td></tr> </td></tr>
<tr id="partno-head"><td>PART NUMBER</td></tr> <tr id="partno-head" class="details-header"><td>PART NUMBER</td></tr>
<tr id="partno"><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"><td>DESCRIPTION</td></tr> <tr id="description-head" class="details-header"><td>DESCRIPTION</td></tr>
<tr id="description"><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" /></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="datasheet-head"><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%" 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>
<tr id="notes-head" class="details-header"><td>NOTES</td></tr>
<tr id="notes" class="details-content"><td><p></p><input type="text" name="notes-input" class="pinfo-input" placeholder="Notes"></td></tr>
</table> </table>
<img src="" id="map" class="map"/> <img src="" id="map" class="map"/>
</div> </div>