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