Author SHA1 Message Date
marek e21ec9065d bug fixes 2022-11-29 00:26:48 +01:00
marek 4988f0eebd fixed path added javascript 2022-11-29 00:15:26 +01:00
marek aca7505ae9 added backed of missing part reporting 2022-11-28 22:24:24 +01:00
3 changed files with 49 additions and 18 deletions
+17 -2
View File
@@ -149,7 +149,7 @@ def alterUser(userID):
s = 'insert into users (username, password) ' s = 'insert into users (username, password) '
s += 'values (:name, :password);' s += 'values (:name, :password);'
s = text(s) s = text(s)
r = db_engine.execute(s,name=request.form['name'],password=request.form['password']); r = db_engine.execute(s,username=request.form['name'],password=request.form['password']);
r.close() r.close()
return '{"status":"ok"}' return '{"status":"ok"}'
else: else:
@@ -164,7 +164,7 @@ def alterUser(userID):
@app.route(baseURL+'/getpartinfo/<partID>') @app.route(baseURL+'/getpartinfo/<partID>')
def get_part_info(partID): def get_part_info(partID):
s = 'select p.id,partno,description,notes, c.name || l.name as location_descriptor, location_id, container_id, datasheet from parts as p inner join locations as l on p.location_id = l.id inner join containers as c on l.container_id = c.id where p.id = :id;' s = 'select p.id,partno,description,notes,EXTRACT(EPOCH from now()-reported_missing) as missing_for, c.name || l.name as location_descriptor, location_id, container_id, datasheet from parts as p inner join locations as l on p.location_id = l.id inner join containers as c on l.container_id = c.id where p.id = :id;'
r = db_engine.execute(text(s), id=partID) r = db_engine.execute(text(s), id=partID)
l = [] l = []
for row in r: for row in r:
@@ -316,6 +316,21 @@ def alter(partID):
r.close() r.close()
return '{"status":"ok", "part_id" : ' + str(new_id) + '}' return '{"status":"ok", "part_id" : ' + str(new_id) + '}'
@app.route(baseURL+'/report_missing', methods=['POST'])
def report_missing():
if 'partID' not in request.form:
return '{"status":"fail"}'
partID = request.form['partID']
missing = True if request.form['missing']=='missing' else False #must be "missing" or "found"
if missing:
r = db_engine.execute(text('update parts set reported_missing = now() where id=:id;'), id=partID)
r.close()
return '{"status":"ok"}'
else:
r = db_engine.execute(text('update parts set reported_missing = NULL where id=:id;'), id=partID)
r.close()
return '{"status":"ok"}'
@app.route(baseURL+'/delete/<partID>') @app.route(baseURL+'/delete/<partID>')
@requires_auth @requires_auth
def delete(partID): def delete(partID):
+30 -14
View File
@@ -145,6 +145,32 @@ function save(partID) {
perform_query(); perform_query();
} }
function report_missing(partID, missing){
var data = new FormData();
data.append('partID', partID);
if(missing){
missing = 'missing'
}else{
missing = 'found'
}
data.append('missing', missing)
$.ajax({
url: rootURL + 'report_missing',
type: 'POST',
data: data,
cache: false,
contentType: false,
processData: false,
success: function(data) {
alert("Thank you for reporting part as " + missing + ".");
},
error: function() {
alert("Couldn't update the part information. Please retry.");
}
});
}
function text_filter(string) { function text_filter(string) {
if (string != null) if (string != null)
return string; return string;
@@ -215,19 +241,8 @@ function show_part_info(partID) {
}); });
// update URL and history // update URL and history
update_url(partID); var query = $('.search-bar').val();
} window.history.pushState('searching', '', 'parts?q=' + query + '&p=' + partID)
function update_url(partID){
params = {}
// If there is a seach bar, take its content
if($('.search-bar').length){
params['q'] = $('.search-bar').val();
}
if(partID != 0){
params['p'] = partID
}
window.history.pushState('searching', '', 'parts?' + jQuery.param(params));
} }
function perform_query() { function perform_query() {
@@ -261,7 +276,8 @@ function perform_query() {
console.log( "Query failed" ); console.log( "Query failed" );
}); });
update_url(0); // update URL and history
window.history.pushState('searching', '', 'parts?q=' + query)
} }
function container_onchange() { function container_onchange() {
+2 -2
View File
@@ -37,7 +37,7 @@
</tr> </tr>
</table> </table>
<h3 id="no-results">No results.</h3> <h3 id="no-results">No results.</h3>
<div class="shadow" onclick="overlay_out();update_url(0);"></div> <div class="shadow" onclick="overlay_out()"></div>
<div class="overlay"> <div class="overlay">
<h2>Part Details</h2> <h2>Part Details</h2>
<div id="info-container"> <div id="info-container">
@@ -73,7 +73,7 @@
</div> </div>
</div> </div>
<div> <div>
<div class="small-square-button"><a href="#" onclick="overlay_out();update_url(0);"><i class="fa fa-times" aria-hidden="true"></i></a></div> <div class="small-square-button"><a href="#" onclick="overlay_out()"><i class="fa fa-times" aria-hidden="true"></i></a></div>
</div> </div>
</div> </div>
<div class="round-floating-button"><a href="#" onclick="new_entry()"><i class="fa fa-plus" aria-hidden="true"></i></a></div> <div class="round-floating-button"><a href="#" onclick="new_entry()"><i class="fa fa-plus" aria-hidden="true"></i></a></div>