Merge branch 'master' of https://git.elab.kth.se/davide/ELAB-partsearch
This commit is contained in:
+32
-24
@@ -30,24 +30,24 @@ def getContainers():
|
|||||||
return containers
|
return containers
|
||||||
|
|
||||||
def check_auth(username, password):
|
def check_auth(username, password):
|
||||||
admin_list = []
|
admin_list = []
|
||||||
with open('edit_admin.json', 'r') as admin:
|
with open('edit_admin.json', 'r') as admin:
|
||||||
admin_list = json.load(admin)
|
admin_list = json.load(admin)
|
||||||
for user in admin_list:
|
for user in admin_list:
|
||||||
if username == user['username']:
|
if username == user['username']:
|
||||||
return password == user['password']
|
return password == user['password']
|
||||||
|
|
||||||
def authenticate():
|
def authenticate():
|
||||||
return Response('Could not verify access level. Please retry', 401, {'WWW-Authenticate' : 'Basic realm="Login Required"'})
|
return Response('Could not verify access level. Please retry', 401, {'WWW-Authenticate' : 'Basic realm="Login Required"'})
|
||||||
|
|
||||||
def requires_auth(f):
|
def requires_auth(f):
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
auth = request.authorization
|
auth = request.authorization
|
||||||
if not auth or not check_auth(auth.username, auth.password):
|
if not auth or not check_auth(auth.username, auth.password):
|
||||||
return authenticate()
|
return authenticate()
|
||||||
return f(*args, **kwargs)
|
return f(*args, **kwargs)
|
||||||
return decorated
|
return decorated
|
||||||
|
|
||||||
def serveImage(img):
|
def serveImage(img):
|
||||||
img_io = BytesIO()
|
img_io = BytesIO()
|
||||||
@@ -90,7 +90,7 @@ def locationEditor():
|
|||||||
return render_template('locationEditor.html', locations=locations, containers=getContainers())
|
return render_template('locationEditor.html', locations=locations, containers=getContainers())
|
||||||
|
|
||||||
@app.route('/parts/alterLocation/<locationID>', methods=['POST'])
|
@app.route('/parts/alterLocation/<locationID>', methods=['POST'])
|
||||||
# @requires_auth
|
@requires_auth
|
||||||
def alterLocation(locationID):
|
def alterLocation(locationID):
|
||||||
locationID = int(locationID)
|
locationID = int(locationID)
|
||||||
s = ''
|
s = ''
|
||||||
@@ -152,11 +152,7 @@ def query(filter_dummy, query):
|
|||||||
s += 'LOWER(description) like LOWER(:kw'+ str(i) +') AND '
|
s += 'LOWER(description) like LOWER(:kw'+ str(i) +') AND '
|
||||||
s = s[:-5]
|
s = s[:-5]
|
||||||
s += ') OR '
|
s += ') OR '
|
||||||
if filter['n'] == 'true':
|
|
||||||
s = s[:-4]
|
|
||||||
s += "AND (datasheet='' IS NOT FALSE) IS FALSE OR "
|
|
||||||
s = s[:-4] + ';'
|
s = s[:-4] + ';'
|
||||||
print(s)
|
|
||||||
s = text(s)
|
s = text(s)
|
||||||
r = db_engine.execute(s, kw_dict)
|
r = db_engine.execute(s, kw_dict)
|
||||||
l = []
|
l = []
|
||||||
@@ -198,7 +194,7 @@ 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 = ''
|
||||||
@@ -212,12 +208,18 @@ 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/datasheet/' + 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
|
||||||
|
# elif request.form.has_key('datasheet-url'):
|
||||||
|
# datasheet_filename = request.form['datasheet-url']
|
||||||
else:
|
else:
|
||||||
datasheet_filename = None
|
try:
|
||||||
|
datasheet_filename = request.form['datasheet-url']
|
||||||
|
except:
|
||||||
|
datasheet_filename = None
|
||||||
r = db_engine.execute(s, partno=request.form['partno'],
|
r = db_engine.execute(s, partno=request.form['partno'],
|
||||||
description=request.form['description'],
|
description=request.form['description'],
|
||||||
datasheet=datasheet_filename,
|
datasheet=datasheet_filename,
|
||||||
@@ -235,14 +237,20 @@ 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/datasheet/' + 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
|
||||||
if l[0]['datasheet'] != None:
|
if l[0]['datasheet'] != None:
|
||||||
os.remove('/srv/datasheets/' + l[0]['datasheet'])
|
os.remove('/srv/datasheets/' + l[0]['datasheet'])
|
||||||
|
# elif request.form.has_key('datasheet-url'):
|
||||||
|
# datasheet_filename = request.form['datasheet-url']
|
||||||
else:
|
else:
|
||||||
datasheet_filename = l[0]['datasheet']
|
try:
|
||||||
|
datasheet_filename = request.form['datasheet-url']
|
||||||
|
except:
|
||||||
|
datasheet_filename = l[0]['datasheet']
|
||||||
s += 'where id=:id returning id;'
|
s += 'where id=:id returning id;'
|
||||||
s = text(s)
|
s = text(s)
|
||||||
r = db_engine.execute(s, partno=request.form['partno'],
|
r = db_engine.execute(s, partno=request.form['partno'],
|
||||||
|
|||||||
+23
-10
@@ -4,18 +4,21 @@ function init_edit(partID) {
|
|||||||
$('#container-dropdown').show();
|
$('#container-dropdown').show();
|
||||||
|
|
||||||
$('table#details tr#partno td p').hide();
|
$('table#details tr#partno td p').hide();
|
||||||
$('table#details tr#partno td input').show();
|
$('input[name=partno-input]').show();
|
||||||
$('#magical_autofill').show();
|
$('#magical_autofill').show();
|
||||||
|
|
||||||
$('table#details tr#description td p').hide();
|
$('table#details tr#description td p').hide();
|
||||||
$('table#details tr#description td input').show();
|
$('input[name=description-input]').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();
|
||||||
|
|
||||||
var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
|
$('tr#datasheet').show();
|
||||||
$('#datasheet-info').replaceWith(datasheet_input);
|
// var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
|
||||||
|
// $('#datasheet-info').replaceWith(datasheet_input);
|
||||||
|
|
||||||
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);
|
||||||
@@ -27,6 +30,7 @@ function new_entry() {
|
|||||||
$('table#details tr#description td p').text('');
|
$('table#details tr#description td p').text('');
|
||||||
$('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('');
|
||||||
container_onchange();
|
container_onchange();
|
||||||
init_edit(-1);
|
init_edit(-1);
|
||||||
overlay_in();
|
overlay_in();
|
||||||
@@ -49,7 +53,10 @@ function end_edit() {
|
|||||||
$('table#details tr#description td p').show();
|
$('table#details tr#description td p').show();
|
||||||
$('table#details tr#description td input').hide();
|
$('table#details tr#description td input').hide();
|
||||||
|
|
||||||
$('table#details tr#datasheet td input').hide();
|
$('tr#datasheet').hide();
|
||||||
|
// $('table#details tr#datasheet td input').closest().hide();
|
||||||
|
// $('table#details tr#datasheet td input').hide();
|
||||||
|
// $('input[name=datasheet-url-input]').closest().hide();
|
||||||
|
|
||||||
$('#duplicate-button').closest('div').show();
|
$('#duplicate-button').closest('div').show();
|
||||||
|
|
||||||
@@ -58,10 +65,15 @@ function end_edit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function save(partID) {
|
function save(partID) {
|
||||||
|
if (!$('#location-dropdown').val()) {
|
||||||
|
alert('Please select a location.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
var location_id_v = $('#location-dropdown').val();
|
var location_id_v = $('#location-dropdown').val();
|
||||||
var partno_v = $('input[name=partno-input]').val();
|
var partno_v = $('input[name=partno-input]').val();
|
||||||
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();
|
||||||
if(partno_v.length == 0){
|
if(partno_v.length == 0){
|
||||||
alert('Please enter a part number.');
|
alert('Please enter a part number.');
|
||||||
return;
|
return;
|
||||||
@@ -86,6 +98,8 @@ function save(partID) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
data.append('datasheet-file', datasheet[0]);
|
data.append('datasheet-file', datasheet[0]);
|
||||||
|
} else if (datasheet_url_v.length > 0) {
|
||||||
|
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)
|
||||||
@@ -159,8 +173,8 @@ function show_part_info(partID) {
|
|||||||
$('table#details tr#description td input').val(text_filter(data.description));
|
$('table#details tr#description td input').val(text_filter(data.description));
|
||||||
container_onchange();
|
container_onchange();
|
||||||
if (data.datasheet != null) {
|
if (data.datasheet != null) {
|
||||||
$('tr#datasheet-head').html($('<td>DATASHEET: <a href="parts/getfile/' + data.datasheet + '"><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>'));
|
||||||
$('#datasheet-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: ');
|
||||||
@@ -183,8 +197,7 @@ function perform_query() {
|
|||||||
var data = {
|
var data = {
|
||||||
l:$('#location').is(':checked'),
|
l:$('#location').is(':checked'),
|
||||||
p:$('#partno').is(':checked'),
|
p:$('#partno').is(':checked'),
|
||||||
d:$('#description').is(':checked'),
|
d:$('#description').is(':checked')
|
||||||
n:$('#has-docs').is(':checked')
|
|
||||||
};
|
};
|
||||||
filter = '0';
|
filter = '0';
|
||||||
$("#results").find("tr:not(:first)").remove(); // Delete all table rows
|
$("#results").find("tr:not(:first)").remove(); // Delete all table rows
|
||||||
@@ -213,7 +226,7 @@ function container_onchange() {
|
|||||||
$('#location-dropdown').empty();
|
$('#location-dropdown').empty();
|
||||||
$.getJSON('parts/getlocationsInContainer/' + selected_container_id, function(data) {
|
$.getJSON('parts/getlocationsInContainer/' + selected_container_id, function(data) {
|
||||||
$.each(data, function(location_id, location_name) {
|
$.each(data, function(location_id, location_name) {
|
||||||
$('#location-dropdown').append('<option val="' + location_id + '">' + location_name + '</option>');
|
$('#location-dropdown').append('<option value="' + location_id + '">' + location_name + '</option>');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ input[type=text].search-bar {
|
|||||||
color: #D7E2E2;
|
color: #D7E2E2;
|
||||||
font-size: 10pt;
|
font-size: 10pt;
|
||||||
margin-top: 4pt;
|
margin-top: 4pt;
|
||||||
margin-left: 16pt;
|
margin-left: 3pt;
|
||||||
margin-bottom: 4pt;
|
margin-bottom: 4pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ div label input {
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
left: 0;
|
left: 0;
|
||||||
opacity: 0.0;
|
opacity: 0.0;
|
||||||
position: absolute;
|
position: fixed;
|
||||||
top: 0;
|
top: 0;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
z-index: 200;
|
z-index: 200;
|
||||||
@@ -172,7 +172,6 @@ div label input {
|
|||||||
min-width: 60%;
|
min-width: 60%;
|
||||||
width:900px;
|
width:900px;
|
||||||
z-index: 201;
|
z-index: 201;
|
||||||
border-radius: 2pt;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
opacity: 0.0;
|
opacity: 0.0;
|
||||||
}
|
}
|
||||||
@@ -308,7 +307,7 @@ table#results td {
|
|||||||
}
|
}
|
||||||
|
|
||||||
table#results #location {
|
table#results #location {
|
||||||
width: 15%;
|
width: 18%;
|
||||||
}
|
}
|
||||||
|
|
||||||
table#results #partno {
|
table#results #partno {
|
||||||
|
|||||||
@@ -23,11 +23,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="filter-concontainertainer">
|
<div class="filter-concontainertainer">
|
||||||
<div class="filter-container">
|
<div class="filter-container">
|
||||||
<p>Search in:</p>
|
<p>SEARCH IN</p>
|
||||||
<input type="checkbox" class="checkbox" id="location"></input><label class="toggle-btn" for="location">Locations<br/><i class="fa fa-map" style="font-size:28pt"></i></label>
|
<input type="checkbox" class="checkbox" id="location"></input><label class="toggle-btn" for="location">Locations<br/><i class="fa fa-map" style="font-size:28pt"></i></label>
|
||||||
<input type="checkbox" class="checkbox" id="partno" checked></input><label class="toggle-btn" for="partno">Part Number<br/><i class="fa fa-hashtag" style="font-size:28pt"></i></label>
|
<input type="checkbox" class="checkbox" id="partno" checked></input><label class="toggle-btn" for="partno">Part Number<br/><i class="fa fa-hashtag" style="font-size:28pt"></i></label>
|
||||||
<input type="checkbox" class="checkbox" id="description" checked></input><label class="toggle-btn" for="description">Description<br/><i class="fa fa-edit" style="font-size:28pt"></i></label>
|
<input type="checkbox" class="checkbox" id="description" checked></input><label class="toggle-btn" for="description">Description<br/><i class="fa fa-edit" style="font-size:28pt"></i></label>
|
||||||
<input type="checkbox" class="checkbox" id="has-docs"></input><label class="toggle-btn" for="has-docs">Has docs<br/><i class="fa fa-paperclip" style="font-size:28pt"></i></label>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<table id="results">
|
<table id="results">
|
||||||
@@ -62,7 +61,8 @@
|
|||||||
<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"><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" /></td></tr>
|
||||||
<tr id="datasheet-head"><td>DATASHEET: </td></tr>
|
<tr id="datasheet-head"><td>DATASHEET: </td></tr>
|
||||||
<tr id="datasheet"><td><input type="file" accept=".pdf" class="pinfo-input"></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>
|
||||||
</table>
|
</table>
|
||||||
<img src="" id="map" class="map"/>
|
<img src="" id="map" class="map"/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user