implemented reset DB from UI

This commit is contained in:
itsikkes 2016-07-24 16:27:56 +03:00
parent 97cf9031c4
commit 4ed667d805
2 changed files with 31 additions and 12 deletions

View File

@ -77,10 +77,7 @@ function initAdmin() {
var options = {
layout: {
improvedLayout: false
}/*,
physics: {
enabled: true
}*/
}
};
// Using jQuery to get the element does not work with vis.js library
@ -213,7 +210,6 @@ function updateMonkeys() {
else {
convertScanNodeToMonkey(exiting_scan, new_monkeys[i]);
}
updateCounters();
}
}
@ -224,6 +220,7 @@ function updateMonkeys() {
refreshDrawing();
}
createScanned();
updateCounters();
});
}
@ -803,8 +800,17 @@ function resetDB() {
url : '/api?action=reset',
type : 'GET',
success : function(response, textStatus, jqXhr) {
console.log(response);
if (response.status != 'OK') {
BootstrapDialog.show({
title: "Reset DB",
message: "The following error occured: " + response.reason
});
}
else {
console.log("DB was successfully reset!");
location.reload();
}
},
error : function(jqXHR, textStatus, errorThrown) {
// log the error to the console

View File

@ -223,11 +223,24 @@ class MonkeyDownload(restful.Resource):
class Root(restful.Resource):
def get(self):
def get(self, action=None):
if not action:
action = request.args.get('action')
if not action:
return {
'status': 'OK',
'mongo': str(mongo.db),
}
elif action=="reset":
mongo.db.config.drop()
mongo.db.monkey.drop()
mongo.db.telemetry.drop()
return {
'status': 'OK',
}
else:
return {'status': 'BAD',
'reason': 'unknown action'}
def normalize_obj(obj):