14 Commits
5 changed files with 27 additions and 20 deletions
+8 -8
View File
@@ -106,7 +106,7 @@ def alterLocation(locationID):
if locationID < 0: if locationID < 0:
# New entry # New entry
s = 'insert into locations (name, container_id) ' s = 'insert into locations (name, container_id) '
s += 'values (:name, :container, :userid);' s += 'values (:name, :container);'
s = text(s) s = text(s)
r = db_engine.execute(s,name=request.form['name'],container=request.form['container']); r = db_engine.execute(s,name=request.form['name'],container=request.form['container']);
r.close() r.close()
@@ -197,10 +197,10 @@ def getMap(containerID):
@app.route('/parts/getfile/<filename>') @app.route('/parts/getfile/<filename>')
def getfile(filename): def getfile(filename):
if(re.match('^[\w\-_]+$', filename) == None): if(re.match('^[\w\-_]+.[p|P][d|D][f|F]$', filename) == None):
return 'No injections pls.' return 'No injections pls.'
return send_from_directory('/srv/datasheets/', filename + '.pdf') return send_from_directory('/srv/datasheets/', filename)
@app.route('/parts/alter/<partID>', methods=['POST']) @app.route('/parts/alter/<partID>', methods=['POST'])
@requires_auth @requires_auth
@@ -254,9 +254,9 @@ def alter(partID):
datasheet_file.save('/srv/datasheets/' + datasheet_filename) datasheet_file.save('/srv/datasheets/' + datasheet_filename)
datasheet_filename = 'http://elab.kth.se/parts/getfile/' + 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']) whole_url = l[0]['datasheet']
# elif request.form.has_key('datasheet-url'): actual_filename = whole_url[whole_url.rfind('/') + 1:]
# datasheet_filename = request.form['datasheet-url'] os.remove('/srv/datasheets/' + actual_filename)
else: else:
try: try:
datasheet_filename = request.form['datasheet-url'] datasheet_filename = request.form['datasheet-url']
@@ -276,7 +276,7 @@ def alter(partID):
return '{"status":"ok", "part_id" : ' + str(new_id) + '}' return '{"status":"ok", "part_id" : ' + str(new_id) + '}'
@app.route('/parts/delete/<partID>') @app.route('/parts/delete/<partID>')
# @requires_auth @requires_auth
def delete(partID): def delete(partID):
if int(partID) < 0: if int(partID) < 0:
abort(400) abort(400)
@@ -285,7 +285,7 @@ def delete(partID):
return '{"status":"ok"}' return '{"status":"ok"}'
@app.route('/parts/deleteLocation/<locationID>') @app.route('/parts/deleteLocation/<locationID>')
# @requires_auth @requires_auth
def deleteLocation(locationID): def deleteLocation(locationID):
if int(locationID) < 0: if int(locationID) < 0:
abort(400) abort(400)
+4 -2
View File
@@ -55,11 +55,13 @@ function saveLocation(locationID) {
function deleteLocation(locationID) { function deleteLocation(locationID) {
if (locationID < 0) if (locationID < 0){
alert('Congratulations! You found the secret UI bug easter egg! This button should not be here, yet I left it specifically because I wanted an easter egg and not because of any other reasons! Good for you!') alert('Congratulations! You found the secret UI bug easter egg! This button should not be here, yet I left it specifically because I wanted an easter egg and not because of any other reasons! Good for you!')
return; return;
if (!confirm('Delete the selected location? If there are parts there, this will leave a mess in the database and Marek will be very sad.')) }
if (!confirm('Delete the selected location? If there are parts there, this will leave a mess in the database and Marek will be very sad.')){
return; return;
}
$.ajax({ $.ajax({
url: rootURL + 'deleteLocation/' + locationID, url: rootURL + 'deleteLocation/' + locationID,
type: 'GET', type: 'GET',
+8 -3
View File
@@ -1,3 +1,5 @@
var active_timer = 100;
function init_edit(partID) { function init_edit(partID) {
$('table#details tr#location td p').hide(); $('table#details tr#location td p').hide();
$('#location-dropdown').show(); $('#location-dropdown').show();
@@ -180,12 +182,14 @@ function show_part_info(partID) {
$('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>'));
$('input[name=datasheet-url-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: ');
$('input[name=datasheet-url-input]').val('');
}
$('#edit-button').click(function() { $('#edit-button').click(function() {
init_edit(partID); init_edit(partID);
}); });
$('#delete-button').click(function() { $('#delete-button').off('click').on('click', function() {
delete_entry(partID); delete_entry(partID);
}); });
overlay_in(); overlay_in();
@@ -254,7 +258,8 @@ function octopartFetch(){
$(document).ready(function() { $(document).ready(function() {
$.ajaxSetup({ cache: false }); $.ajaxSetup({ cache: false });
$('.search-bar').on('keyup', function() { $('.search-bar').on('keyup', function() {
perform_query(); clearTimeout(active_timer);
active_timer = setTimeout(perform_query, 100);
}); });
$('.checkbox').change( function() { $('.checkbox').change( function() {
if ( !$('#location').is(':checked') if ( !$('#location').is(':checked')
+3 -3
View File
@@ -8,10 +8,10 @@
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"> <link rel="stylesheet" type="text/css" href="/parts/static/style.css">
<script src="https://use.fontawesome.com/2fef7be393.js"></script> <script src="https://use.fontawesome.com/2fef7be393.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='common.js') }}"></script> <script type="text/javascript" src="/parts/static/common.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='locationEditorScript.js') }}"></script> <script type="text/javascript" src="/parts/static/locationEditorScript.js"></script>
</head> </head>
<body> <body>
<h1>LOCATION EDITOR</h1> <h1>LOCATION EDITOR</h1>
+4 -4
View File
@@ -8,12 +8,12 @@
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script> crossorigin="anonymous"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Roboto:300,400" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}"> <link rel="stylesheet" type="text/css" href="parts/static/style.css">
<link rel="apple-touch-icon-precomposed" href="{{ url_for('static', filename='apple-touch-icon.png') }}"> <link rel="apple-touch-icon-precomposed" href="parts/static/apple-touch-icon.png">
<script src="https://use.fontawesome.com/2fef7be393.js"></script> <script src="https://use.fontawesome.com/2fef7be393.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='common.js') }}"></script> <script type="text/javascript" src="parts/static/common.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='script.js') }}"></script> <script type="text/javascript" src="parts/static/script.js"></script>
</head> </head>
<body> <body>
<h1>ELAB Part Search Engine</h1> <h1>ELAB Part Search Engine</h1>