Compare commits
26
Commits
1.1-rc
...
4cf02f26c4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cf02f26c4 | ||
|
|
f4235556f7 | ||
|
|
dc880978ab | ||
|
|
582370a17d | ||
|
|
11b3ae1af5 | ||
|
|
82f1c364de | ||
|
|
38c22af31f | ||
|
|
112686b9c6 | ||
|
|
d64923ddad | ||
|
|
2a8b1f50f4 | ||
|
|
7e60da9362 | ||
|
|
227e725e95 | ||
|
|
a8496af806 | ||
|
|
cc6a1473cb | ||
|
|
b44d05aabd | ||
|
|
3cb81e9a79 | ||
|
|
b297462d3b | ||
|
|
40186ad08e | ||
|
|
a7751dc38b | ||
|
|
e2003e3562 | ||
|
|
7e1f59f781 | ||
|
|
4649723f87 | ||
|
|
0b64c50f36 | ||
|
|
597898885b | ||
|
|
55033f7295 | ||
|
|
8d1237011a |
+20
-19
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import re
|
||||
import json, urllib.parse, urllib.request
|
||||
import json
|
||||
import requests
|
||||
import sqlalchemy
|
||||
from functools import wraps
|
||||
from sqlalchemy.sql import select
|
||||
@@ -64,7 +65,7 @@ def serveImage(img):
|
||||
img_io.seek(0)
|
||||
return send_file(img_io, mimetype='image/png')
|
||||
|
||||
@app.route('/parts', strict_slashes=False)
|
||||
@app.route('/parts', strict_slashes=True)
|
||||
def index():
|
||||
return render_template('partsearch.html', containers=getContainers())
|
||||
|
||||
@@ -106,7 +107,7 @@ def alterLocation(locationID):
|
||||
if locationID < 0:
|
||||
# New entry
|
||||
s = 'insert into locations (name, container_id) '
|
||||
s += 'values (:name, :container, :userid);'
|
||||
s += 'values (:name, :container);'
|
||||
s = text(s)
|
||||
r = db_engine.execute(s,name=request.form['name'],container=request.form['container']);
|
||||
r.close()
|
||||
@@ -197,10 +198,10 @@ def getMap(containerID):
|
||||
|
||||
@app.route('/parts/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 send_from_directory('/srv/datasheets/', filename + '.pdf')
|
||||
return send_from_directory('/srv/datasheets/', filename)
|
||||
|
||||
@app.route('/parts/alter/<partID>', methods=['POST'])
|
||||
@requires_auth
|
||||
@@ -217,7 +218,7 @@ def alter(partID):
|
||||
datasheet_file = request.files['datasheet-file']
|
||||
datasheet_filename = secure_filename(datasheet_file.filename)
|
||||
i = 1
|
||||
while os.path.isfile('srv/datasheets/' + 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)
|
||||
@@ -248,15 +249,15 @@ def alter(partID):
|
||||
datasheet_file = request.files['datasheet-file']
|
||||
datasheet_filename = secure_filename(datasheet_file.filename)
|
||||
i = 1
|
||||
while os.path.isfile('srv/datasheets/' + 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']
|
||||
whole_url = l[0]['datasheet']
|
||||
actual_filename = whole_url[whole_url.rfind('/') + 1:]
|
||||
os.remove('/srv/datasheets/' + actual_filename)
|
||||
else:
|
||||
try:
|
||||
datasheet_filename = request.form['datasheet-url']
|
||||
@@ -276,7 +277,7 @@ def alter(partID):
|
||||
return '{"status":"ok", "part_id" : ' + str(new_id) + '}'
|
||||
|
||||
@app.route('/parts/delete/<partID>')
|
||||
# @requires_auth
|
||||
@requires_auth
|
||||
def delete(partID):
|
||||
if int(partID) < 0:
|
||||
abort(400)
|
||||
@@ -285,7 +286,7 @@ def delete(partID):
|
||||
return '{"status":"ok"}'
|
||||
|
||||
@app.route('/parts/deleteLocation/<locationID>')
|
||||
# @requires_auth
|
||||
@requires_auth
|
||||
def deleteLocation(locationID):
|
||||
if int(locationID) < 0:
|
||||
abort(400)
|
||||
@@ -297,13 +298,13 @@ def deleteLocation(locationID):
|
||||
def fetchOctopartSnippet(searchTerm):
|
||||
if octopartURL == '':
|
||||
return '{"result":"octopart integration not enabled"}'
|
||||
args = [
|
||||
('q', searchTerm),
|
||||
('start', 0),
|
||||
('limit', 1)
|
||||
]
|
||||
data = urllib.request.urlopen(octopartURL + '&' + urllib.parse.urlencode(args)).read()
|
||||
search_response = json.loads(data)
|
||||
args = {
|
||||
'q': searchTerm,
|
||||
'start': '0',
|
||||
'limit': 1
|
||||
}
|
||||
data = requests.get(octopartURL, params=args)
|
||||
search_response = json.loads(data.text)
|
||||
|
||||
result = '{"result":"no results. sorry :(("}'
|
||||
if search_response['hits']>0:
|
||||
|
||||
@@ -55,11 +55,13 @@ function saveLocation(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!')
|
||||
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;
|
||||
}
|
||||
$.ajax({
|
||||
url: rootURL + 'deleteLocation/' + locationID,
|
||||
type: 'GET',
|
||||
|
||||
+20
-4
@@ -1,3 +1,5 @@
|
||||
var active_timer = 100;
|
||||
|
||||
function init_edit(partID) {
|
||||
$('table#details tr#location td p').hide();
|
||||
$('#location-dropdown').show();
|
||||
@@ -175,17 +177,23 @@ function show_part_info(partID) {
|
||||
$('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));
|
||||
// Resetting file input. Super dirty hack. Disgusting
|
||||
var $el = $('#datasheet-finput');
|
||||
$el.wrap('<form>').closest('form').get(0).reset();
|
||||
$el.unwrap();
|
||||
container_onchange();
|
||||
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>'));
|
||||
$('input[name=datasheet-url-input]').val(data.datasheet);
|
||||
}
|
||||
else
|
||||
else {
|
||||
$('tr#datasheet-head td').text('DATASHEET: ');
|
||||
$('input[name=datasheet-url-input]').val('');
|
||||
}
|
||||
$('#edit-button').click(function() {
|
||||
init_edit(partID);
|
||||
});
|
||||
$('#delete-button').click(function() {
|
||||
$('#delete-button').off('click').on('click', function() {
|
||||
delete_entry(partID);
|
||||
});
|
||||
overlay_in();
|
||||
@@ -239,9 +247,10 @@ function container_onchange() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function octopartFetch(){
|
||||
$('#magic-autofill-button').attr('disabled', 'disabled');
|
||||
$.getJSON(rootURL + 'fetchOctopartSnippet/' + $('#partno-input').val()).done(function(json){
|
||||
$('#magic-autofill-button').removeAttr('disabled');
|
||||
if (json['result']=='ok'){
|
||||
$('#description-input').val(json['snippet']);
|
||||
}else{
|
||||
@@ -254,7 +263,8 @@ function octopartFetch(){
|
||||
$(document).ready(function() {
|
||||
$.ajaxSetup({ cache: false });
|
||||
$('.search-bar').on('keyup', function() {
|
||||
perform_query();
|
||||
clearTimeout(active_timer);
|
||||
active_timer = setTimeout(perform_query, 100);
|
||||
});
|
||||
$('.checkbox').change( function() {
|
||||
if ( !$('#location').is(':checked')
|
||||
@@ -265,4 +275,10 @@ $(document).ready(function() {
|
||||
else
|
||||
perform_query();
|
||||
});
|
||||
|
||||
// $('#partno-input').bind('blur',function() {
|
||||
// if($('#partno-input').val().length > 0){
|
||||
// octopartFetch();
|
||||
// }
|
||||
// });
|
||||
});
|
||||
@@ -313,6 +313,16 @@ table#details {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
#magical_autofill{
|
||||
font-size: small;
|
||||
}
|
||||
|
||||
a.small_link{
|
||||
text-decoration: none;
|
||||
color: #B0B0B0;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.details-header {
|
||||
color: #013A3A;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,10 @@
|
||||
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
|
||||
crossorigin="anonymous"></script>
|
||||
<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 type="text/javascript" src="{{ url_for('static', filename='common.js') }}"></script>
|
||||
<script type="text/javascript" src="{{ url_for('static', filename='locationEditorScript.js') }}"></script>
|
||||
<script type="text/javascript" src="/parts/static/common.js"></script>
|
||||
<script type="text/javascript" src="/parts/static/locationEditorScript.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>LOCATION EDITOR</h1>
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
|
||||
crossorigin="anonymous"></script>
|
||||
<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="apple-touch-icon-precomposed" href="{{ url_for('static', filename='apple-touch-icon.png') }}">
|
||||
<link rel="stylesheet" type="text/css" href="parts/static/style.css">
|
||||
<link rel="apple-touch-icon-precomposed" href="parts/static/apple-touch-icon.png">
|
||||
|
||||
<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="{{ url_for('static', filename='script.js') }}"></script>
|
||||
<script type="text/javascript" src="parts/static/common.js"></script>
|
||||
<script type="text/javascript" src="parts/static/script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>ELAB Part Search Engine</h1>
|
||||
@@ -59,7 +59,7 @@
|
||||
<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" class="details-header"><td>DESCRIPTION</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" style="margin-bottom:6pt"/></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"/> powered by <a href="http://octopart.com" class="small_link">OctoPart™</a></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>OR: <input type="text" class="pinfo-input" name="datasheet-url-input" style="width:80%; margin-bottom: 6pt;" placeholder="Datasheet URL"></td></tr>
|
||||
|
||||
Reference in New Issue
Block a user