Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0459cbdff0 | ||
|
|
cf97254ff0 | ||
|
|
bd3715888a | ||
|
|
bf37ea8c5c |
+8
-19
@@ -146,14 +146,14 @@ def getfile(filename):
|
|||||||
return send_from_directory('/srv/datasheets/', filename + '.pdf')
|
return send_from_directory('/srv/datasheets/', filename + '.pdf')
|
||||||
|
|
||||||
@app.route('/parts/alter/<partID>', methods=['POST'])
|
@app.route('/parts/alter/<partID>', methods=['POST'])
|
||||||
@requires_auth
|
# @requires_auth
|
||||||
def alter(partID):
|
def alter(partID):
|
||||||
partID = int(partID)
|
partID = int(partID)
|
||||||
s = ''
|
s = ''
|
||||||
if partID < 0:
|
if partID < 0:
|
||||||
# New entry
|
# New entry
|
||||||
s = 'insert into parts (block, type, partno, partnoalt, partnoalt2, description, quantity, datasheet, notes) '
|
s = 'insert into parts (partno, description, datasheet, location_id) '
|
||||||
s += 'values (:block, :type, :partno, :partnoalt, :partnoalt2, :description, :quantity, :datasheet, :notes);'
|
s += 'values (:partno, :description, :datasheet, :location_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']
|
||||||
@@ -165,15 +165,10 @@ def alter(partID):
|
|||||||
datasheet_file.save('/srv/datasheets/' + datasheet_filename)
|
datasheet_file.save('/srv/datasheets/' + datasheet_filename)
|
||||||
else:
|
else:
|
||||||
datasheet_filename = None
|
datasheet_filename = None
|
||||||
r = db_engine.execute(s, block=request.form['block'],
|
r = db_engine.execute(s, partno=request.form['partno'],
|
||||||
type=request.form['type'],
|
|
||||||
partno=request.form['partno'],
|
|
||||||
partnoalt=request.form['partnoalt'],
|
|
||||||
partnoalt2=request.form['partnoalt2'],
|
|
||||||
description=request.form['description'],
|
description=request.form['description'],
|
||||||
quantity=request.form['quantity'],
|
|
||||||
datasheet=datasheet_filename,
|
datasheet=datasheet_filename,
|
||||||
notes=request.form['notes'])
|
location_id=request.form['location_id'])
|
||||||
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)
|
||||||
@@ -182,7 +177,7 @@ def alter(partID):
|
|||||||
l.append(dict(row))
|
l.append(dict(row))
|
||||||
r.close()
|
r.close()
|
||||||
s = 'update parts '
|
s = 'update parts '
|
||||||
s += 'set block=:block, type=:type, partno=:partno, partnoalt=:partnoalt, partnoalt2=:partnoalt2, description=:description, quantity=:quantity, datasheet=:datasheet, notes=:notes '
|
s += 'set partno=:partno, description=:description, datasheet=:datasheet, location_id=:location_id '
|
||||||
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)
|
||||||
@@ -197,16 +192,10 @@ def alter(partID):
|
|||||||
datasheet_filename = l[0]['datasheet']
|
datasheet_filename = l[0]['datasheet']
|
||||||
s += 'where id=:id;'
|
s += 'where id=:id;'
|
||||||
s = text(s)
|
s = text(s)
|
||||||
r = db_engine.execute(s, location_id=request.form['block'],
|
r = db_engine.execute(s, partno=request.form['partno'],
|
||||||
type=request.form['type'],
|
|
||||||
partno=request.form['partno'],
|
|
||||||
partnoalt=request.form['partnoalt'],
|
|
||||||
partnoalt2=request.form['partnoalt2'],
|
|
||||||
description=request.form['description'],
|
description=request.form['description'],
|
||||||
quantity=request.form['quantity'],
|
|
||||||
datasheet=datasheet_filename,
|
datasheet=datasheet_filename,
|
||||||
notes=request.form['notes'],
|
location_id=request.form['location_id'])
|
||||||
id=partID)
|
|
||||||
|
|
||||||
|
|
||||||
return '{"status":"ok"}'
|
return '{"status":"ok"}'
|
||||||
|
|||||||
+56
-47
@@ -35,12 +35,12 @@ function init_edit(partID) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function new_entry() {
|
function new_entry() {
|
||||||
$('table#details tr#location td').text('');
|
$('table#details tr#location td p').text('');
|
||||||
$('table#details tr#partno td').text('');
|
$('table#details tr#partno td p').text('');
|
||||||
$('table#details tr#description td').text('');
|
$('table#details tr#description td p').text('');
|
||||||
// $('table#details tr#location select').text('');
|
// $('table#details tr#location select').text('');
|
||||||
$('table#details tr#partno input').text('');
|
$('table#details tr#partno td input').text('');
|
||||||
$('table#details tr#description input').text('');
|
$('table#details tr#description td input').text('');
|
||||||
init_edit(-1);
|
init_edit(-1);
|
||||||
overlay_in();
|
overlay_in();
|
||||||
}
|
}
|
||||||
@@ -62,39 +62,40 @@ function end_edit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function save(partID) {
|
function save(partID) {
|
||||||
var block_v = $('#block-input').val();
|
// var block_v = $('#block-input').val();
|
||||||
var type_v = $('#type-input').val();
|
// var type_v = $('#type-input').val();
|
||||||
var partno_v = $('#partno-input').val();
|
var location_id_v = $('table#details tr#location td select').val();
|
||||||
var description_v = $('#description-input').val();
|
var partno_v = $('table#details tr#partno td input').val();
|
||||||
var quantity_v = $('#quantity-input').val();
|
var description_v = $('table#details tr#description td input').val();
|
||||||
var notes_v = $('#notes-input').val();
|
// var quantity_v = $('#quantity-input').val();
|
||||||
var datasheet = $('#datasheet-input')[0].files;
|
// var notes_v = $('#notes-input').val();
|
||||||
if(! partno_v.match(/^([a-zA-Z0-9]{1,20}\s*){1,3}$/g)) {
|
var datasheet = $('table#details tr#datasheet td input')[0].files;
|
||||||
alert('Invalid part number format. Accepted: <Part-number-line-1(max 20 chars)> <Part-number-line-2(max 20 chars)> <Part-number-line-3(max 20 chars)>');
|
// if(! partno_v.match(/^([a-zA-Z0-9]{1,20}\s*){1,3}$/g)) {
|
||||||
return;
|
// alert('Invalid part number format. Accepted: <Part-number-line-1(max 20 chars)> <Part-number-line-2(max 20 chars)> <Part-number-line-3(max 20 chars)>');
|
||||||
}
|
// return;
|
||||||
if(! block_v.match(/^[0-9]+$/g)) {
|
// }
|
||||||
alert('Invalid location field. Only numbers accepted.');
|
// if(! block_v.match(/^[0-9]+$/g)) {
|
||||||
return;
|
// alert('Invalid location field. Only numbers accepted.');
|
||||||
}
|
// return;
|
||||||
if(type_v.length > 25) {
|
// }
|
||||||
alert('Manufacturer name too long (max 25 characters).')
|
// if(type_v.length > 25) {
|
||||||
return;
|
// alert('Manufacturer name too long (max 25 characters).')
|
||||||
}
|
// return;
|
||||||
|
// }
|
||||||
if(description_v.length > 200) {
|
if(description_v.length > 200) {
|
||||||
alert('Description too long (max 200 characters).')
|
alert('Description too long (max 200 characters).')
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(quantity_v.length > 10) {
|
// if(quantity_v.length > 10) {
|
||||||
alert('Quantity info too long (max 10 characters).')
|
// alert('Quantity info too long (max 10 characters).')
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
if(notes_v.length > 200) {
|
// if(notes_v.length > 200) {
|
||||||
alert('Notes too long (max 200 characters).')
|
// alert('Notes too long (max 200 characters).')
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
|
|
||||||
var partnos = partno_v.split(' ');
|
// var partnos = partno_v.split(' ');
|
||||||
|
|
||||||
var data = new FormData();
|
var data = new FormData();
|
||||||
|
|
||||||
@@ -104,20 +105,21 @@ function save(partID) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data.append('datasheet-file', datasheet[0]);
|
data.append('datasheet-file', datasheet[0]);
|
||||||
data.append('block', block_v);
|
// data.append('block', block_v);
|
||||||
data.append('type', type_v);
|
// data.append('type', type_v);
|
||||||
data.append('partno', partnos[0]);
|
data.append('partno', partno_v);
|
||||||
if (partnos.length > 1)
|
data.append('location_id', location_id_v)
|
||||||
data.append('partnoalt', partnos[1]);
|
// if (partnos.length > 1)
|
||||||
else
|
// data.append('partnoalt', partnos[1]);
|
||||||
data.append('partnoalt', '');
|
// else
|
||||||
if(partnos.length > 2)
|
// data.append('partnoalt', '');
|
||||||
data.append('partnoalt2', partnos[2]);
|
// if(partnos.length > 2)
|
||||||
else
|
// data.append('partnoalt2', partnos[2]);
|
||||||
data.append('partnoalt2', '');
|
// else
|
||||||
|
// data.append('partnoalt2', '');
|
||||||
data.append('description', description_v);
|
data.append('description', description_v);
|
||||||
data.append('quantity', quantity_v);
|
// data.append('quantity', quantity_v);
|
||||||
data.append('notes', notes_v);
|
// data.append('notes', notes_v);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
// Your server script to process the upload
|
// Your server script to process the upload
|
||||||
@@ -232,8 +234,15 @@ function perform_query() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function update_map() {
|
||||||
|
var selected_id = $('table#details tr#location td select').val();
|
||||||
|
$.ajax('parts/getlocationURL/' + selected_id).done( function(data) {
|
||||||
|
$('img#map').attr('src', 'parts/map/' + data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$.getJSON('http://127.0.0.1:5000/parts/getlocations', function(data){
|
$.getJSON('parts/getlocations', function(data){
|
||||||
$.each(data, function(i, val) {
|
$.each(data, function(i, val) {
|
||||||
$('table#details tr#location td select').append('<option value="' + i + '">' + val + '</option>');
|
$('table#details tr#location td select').append('<option value="' + i + '">' + val + '</option>');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
<h2>Part Details</h2>
|
<h2>Part Details</h2>
|
||||||
<table id="details">
|
<table id="details">
|
||||||
<tr id="location-head"><td>LOCATION</td></tr>
|
<tr id="location-head"><td>LOCATION</td></tr>
|
||||||
<tr id="location"><td><p></p><select class="pinfo-input"></select></td></tr>
|
<tr id="location"><td><p></p><select class="pinfo-input" onchange="update_map()"></select></td></tr>
|
||||||
<tr id="partno-head"><td>PART NUMBER</td></tr>
|
<tr id="partno-head"><td>PART NUMBER</td></tr>
|
||||||
<tr id="partno"><td><p></p><input type="text" name="partno-input" placeholder="Part Number" class="pinfo-input"/></td></tr>
|
<tr id="partno"><td><p></p><input type="text" name="partno-input" placeholder="Part Number" class="pinfo-input"/></td></tr>
|
||||||
<tr id="description-head"><td>DESCRIPTION</td></tr>
|
<tr id="description-head"><td>DESCRIPTION</td></tr>
|
||||||
|
|||||||
Reference in New Issue
Block a user