Marek Baczynski 6 years ago
commit c0f0fd732f

@ -30,24 +30,24 @@ def getContainers():
return containers
def check_auth(username, password):
admin_list = []
with open('edit_admin.json', 'r') as admin:
admin_list = json.load(admin)
for user in admin_list:
if username == user['username']:
return password == user['password']
admin_list = []
with open('edit_admin.json', 'r') as admin:
admin_list = json.load(admin)
for user in admin_list:
if username == user['username']:
return password == user['password']
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):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
def serveImage(img):
img_io = BytesIO()
@ -90,7 +90,7 @@ def locationEditor():
return render_template('locationEditor.html', locations=locations, containers=getContainers())
@app.route('/parts/alterLocation/<locationID>', methods=['POST'])
# @requires_auth
@requires_auth
def alterLocation(locationID):
locationID = int(locationID)
s = ''
@ -152,11 +152,7 @@ def query(filter_dummy, query):
s += 'LOWER(description) like LOWER(:kw'+ str(i) +') AND '
s = s[:-5]
s += ') OR '
if filter['n'] == 'true':
s = s[:-4]
s += "AND (datasheet='' IS NOT FALSE) IS FALSE OR "
s = s[:-4] + ';'
print(s)
s = text(s)
r = db_engine.execute(s, kw_dict)
l = []
@ -198,7 +194,7 @@ def getfile(filename):
return send_from_directory('/srv/datasheets/', filename + '.pdf')
@app.route('/parts/alter/<partID>', methods=['POST'])
# @requires_auth
@requires_auth
def alter(partID):
partID = int(partID)
s = ''
@ -212,12 +208,18 @@ def alter(partID):
datasheet_file = request.files['datasheet-file']
datasheet_filename = secure_filename(datasheet_file.filename)
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'
i += 1
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:
datasheet_filename = None
try:
datasheet_filename = request.form['datasheet-url']
except:
datasheet_filename = None
r = db_engine.execute(s, partno=request.form['partno'],
description=request.form['description'],
datasheet=datasheet_filename,
@ -235,14 +237,20 @@ def alter(partID):
datasheet_file = request.files['datasheet-file']
datasheet_filename = secure_filename(datasheet_file.filename)
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'
i += 1
datasheet_file.save('/srv/datasheets/' + datasheet_filename)
datasheet_filename = 'http://elab.kth.se/parts/getfile/' + datasheet_filename
if l[0]['datasheet'] != None:
os.remove('/srv/datasheets/' + l[0]['datasheet'])
# elif request.form.has_key('datasheet-url'):
# datasheet_filename = request.form['datasheet-url']
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 = text(s)
r = db_engine.execute(s, partno=request.form['partno'],

@ -4,18 +4,21 @@ function init_edit(partID) {
$('#container-dropdown').show();
$('table#details tr#partno td p').hide();
$('table#details tr#partno td input').show();
$('input[name=partno-input]').show();
$('#magical_autofill').show();
$('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();
// $('input[name=datasheet-url-input]').closest().show();
$('#duplicate-button').closest('div').hide();
var datasheet_input = $('<input type="file" class="part-edit-file" id="datasheet-input" accept=".pdf">')
$('#datasheet-info').replaceWith(datasheet_input);
$('tr#datasheet').show();
// 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>';
$('.round-button-left').replaceWith(newButton);
@ -27,6 +30,7 @@ function new_entry() {
$('table#details tr#description td p').text('');
$('table#details tr#partno td input').val('');
$('table#details tr#description td input').val('');
$('input[name=datasheet-url-input]').val('');
container_onchange();
init_edit(-1);
overlay_in();
@ -49,7 +53,10 @@ function end_edit() {
$('table#details tr#description td p').show();
$('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();
@ -58,10 +65,15 @@ function end_edit() {
}
function save(partID) {
if (!$('#location-dropdown').val()) {
alert('Please select a location.');
return;
}
var location_id_v = $('#location-dropdown').val();
var partno_v = $('input[name=partno-input]').val();
var description_v = $('input[name=description-input]').val();
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){
alert('Please enter a part number.');
return;
@ -86,6 +98,8 @@ function save(partID) {
return;
}
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('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));
container_onchange();
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>'));
$('#datasheet-input').val(data.datasheet);
$('tr#datasheet-head').html($('<td>DATASHEET: <a href="' + data.datasheet + '" target="_blank"><i class="fa fa-file-text" aria-hidden="true"></i></a></td>'));
$('input[name=datasheet-url-input]').val(data.datasheet);
}
else
$('tr#datasheet-head td').text('DATASHEET: ');
@ -183,8 +197,7 @@ function perform_query() {
var data = {
l:$('#location').is(':checked'),
p:$('#partno').is(':checked'),
d:$('#description').is(':checked'),
n:$('#has-docs').is(':checked')
d:$('#description').is(':checked')
};
filter = '0';
$("#results").find("tr:not(:first)").remove(); // Delete all table rows
@ -213,7 +226,7 @@ function container_onchange() {
$('#location-dropdown').empty();
$.getJSON('parts/getlocationsInContainer/' + selected_container_id, function(data) {
$.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;
font-size: 10pt;
margin-top: 4pt;
margin-left: 16pt;
margin-left: 3pt;
margin-bottom: 4pt;
}
@ -152,7 +152,7 @@ div label input {
height: 100%;
left: 0;
opacity: 0.0;
position: absolute;
position: fixed;
top: 0;
width: 100%;
z-index: 200;
@ -172,7 +172,6 @@ div label input {
min-width: 60%;
width:900px;
z-index: 201;
border-radius: 2pt;
text-align: center;
opacity: 0.0;
}
@ -308,7 +307,7 @@ table#results td {
}
table#results #location {
width: 15%;
width: 18%;
}
table#results #partno {

@ -23,11 +23,10 @@
</div>
<div class="filter-concontainertainer">
<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="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="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>
<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="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"><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>
<img src="" id="map" class="map"/>
</div>

Loading…
Cancel
Save