forked from p15670423/monkey
fix new monkeys settings bugs
This commit is contained in:
parent
4731df114c
commit
fe146c13cc
|
@ -136,16 +136,16 @@
|
|||
</div>
|
||||
<div id="config" class="panel-body panel-collapse collapse in">
|
||||
<span class="input-group-btn">
|
||||
<button id="btnGeneralConfigLoad" class="btn btn-default" type="button"
|
||||
onclick="loadGeneralConfig()" style="margin-top:-4px">
|
||||
<button id="btnNewConfigLoad" class="btn btn-default" type="button"
|
||||
onclick="loadNewMonkeysConfig()" style="margin-top:-4px">
|
||||
Load
|
||||
</button>
|
||||
<button id="btnGeneralConfigUpdate" class="btn btn-default" type="button"
|
||||
onclick="updateGeneralConfig()" style="margin-top:-4px">
|
||||
<button id="btnNewConfigUpdate" class="btn btn-default" type="button"
|
||||
onclick="updateNewMonkeysConfig()" style="margin-top:-4px">
|
||||
Update
|
||||
</button>
|
||||
</span>
|
||||
<div id="general-config">
|
||||
<div id="new-config">
|
||||
</div>
|
||||
<span class="input-group-btn">
|
||||
<button id="btnConfigLoad" style="display: none;" class="btn btn-default" type="button"
|
||||
|
|
|
@ -28,7 +28,7 @@ const ICONS_EXT = ".png";
|
|||
var focusedOnNode = false;
|
||||
|
||||
var monkeyCfg = undefined;
|
||||
var generalCfg = undefined;
|
||||
var newCfg = undefined;
|
||||
var telemTable = undefined;
|
||||
JSONEditor.defaults.theme = 'bootstrap3';
|
||||
|
||||
|
@ -74,7 +74,7 @@ function initAdmin() {
|
|||
disable_edit_json: false,
|
||||
});
|
||||
|
||||
generalCfg = new JSONEditor(document.getElementById('general-config'),{
|
||||
newCfg = new JSONEditor(document.getElementById('new-config'),{
|
||||
schema: {
|
||||
type: "object",
|
||||
title: "New Monkeys",
|
||||
|
@ -90,7 +90,7 @@ function initAdmin() {
|
|||
},
|
||||
disable_edit_json: false,
|
||||
});
|
||||
generalCfg.setValue({alive: true});
|
||||
newCfg.setValue({alive: true});
|
||||
|
||||
telemTable = $("#telemetris-table").DataTable({
|
||||
"ordering": false,
|
||||
|
@ -336,11 +336,11 @@ function toggleFocusOnNode() {
|
|||
}
|
||||
}
|
||||
|
||||
function loadGeneralConfig() {
|
||||
$.getJSON('/api/config/general', function(json) {
|
||||
function loadNewMonkeysConfig() {
|
||||
$.getJSON('/api/config/new', function(json) {
|
||||
if (jQuery.isEmptyObject(json))
|
||||
{
|
||||
generalCfg.setValue({alive: true});
|
||||
newCfg.setValue({alive: true});
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -349,31 +349,31 @@ function loadGeneralConfig() {
|
|||
json.alive = true;
|
||||
}
|
||||
delete json.id;
|
||||
generalCfg.setValue(json);
|
||||
newCfg.setValue(json);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function updateGeneralConfig() {
|
||||
var curr_config = generalCfg.getValue()
|
||||
function updateNewMonkeysConfig() {
|
||||
var curr_config = newCfg.getValue()
|
||||
|
||||
$.ajax({
|
||||
headers : {
|
||||
'Accept' : 'application/json',
|
||||
'Content-Type' : 'application/json'
|
||||
},
|
||||
url : '/api/config/general',
|
||||
url : '/api/config/new',
|
||||
type : 'POST',
|
||||
data : JSON.stringify(curr_config),
|
||||
success : function(response, textStatus, jqXhr) {
|
||||
console.log("General config successfully updated!");
|
||||
console.log("New monkeys config successfully updated!");
|
||||
},
|
||||
error : function(jqXHR, textStatus, errorThrown) {
|
||||
// log the error to the console
|
||||
console.log("The following error occured: " + textStatus, errorThrown);
|
||||
},
|
||||
complete : function() {
|
||||
console.log("Sending general config update...");
|
||||
console.log("Sending new monkeys config update...");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -90,12 +90,12 @@ class Monkey(restful.Resource):
|
|||
|
||||
monkey_json['modifytime'] = datetime.now()
|
||||
|
||||
# if new monkey, change config according to general config.
|
||||
# if new monkey, change config according to "new monkeys" config.
|
||||
db_monkey = mongo.db.monkey.find_one({"guid": monkey_json["guid"]})
|
||||
if not db_monkey:
|
||||
general_config = mongo.db.config.find_one({'name' : 'generalconfig'}) or {}
|
||||
new_config = mongo.db.config.find_one({'name' : 'newconfig'}) or {}
|
||||
monkey_json['config'] = monkey_json.get('config', {})
|
||||
monkey_json['config'].update(general_config)
|
||||
monkey_json['config'].update(new_config)
|
||||
else:
|
||||
db_config = db_monkey.get('config', {})
|
||||
if db_config.has_key('current_server'):
|
||||
|
@ -157,16 +157,16 @@ class Telemetry(restful.Resource):
|
|||
|
||||
return mongo.db.telemetry.find_one_or_404({"_id": telem_id})
|
||||
|
||||
class GeneralConfig(restful.Resource):
|
||||
class NewConfig(restful.Resource):
|
||||
def get(self):
|
||||
config = mongo.db.config.find_one({'name' : 'generalconfig'}) or {}
|
||||
config = mongo.db.config.find_one({'name' : 'newconfig'}) or {}
|
||||
if config.has_key('name'):
|
||||
del config['name']
|
||||
return config
|
||||
|
||||
def post(self):
|
||||
config_json = json.loads(request.data)
|
||||
return mongo.db.config.update({'name' : 'generalconfig'}, {"$set" : config_json}, upsert=True)
|
||||
return mongo.db.config.update({'name' : 'newconfig'}, {"$set" : config_json}, upsert=True)
|
||||
|
||||
|
||||
class MonkeyDownload(restful.Resource):
|
||||
|
@ -234,7 +234,7 @@ api.representations = DEFAULT_REPRESENTATIONS
|
|||
api.add_resource(Root, '/api')
|
||||
api.add_resource(Monkey, '/api/monkey', '/api/monkey/', '/api/monkey/<string:guid>')
|
||||
api.add_resource(Telemetry, '/api/telemetry', '/api/telemetry/', '/api/telemetry/<string:monkey_guid>')
|
||||
api.add_resource(GeneralConfig, '/api/config/general')
|
||||
api.add_resource(NewConfig, '/api/config/new')
|
||||
api.add_resource(MonkeyDownload, '/api/monkey/download', '/api/monkey/download/', '/api/monkey/download/<string:path>')
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue