web app, updated emane config api to be a general config api
This commit is contained in:
parent
a55cd6a524
commit
c90ee5fc84
3 changed files with 28 additions and 26 deletions
|
@ -226,23 +226,8 @@ def set_config(session_id):
|
||||||
return jsonify()
|
return jsonify()
|
||||||
|
|
||||||
|
|
||||||
@app.route("/sessions/<int:session_id>/emane/models")
|
@app.route("/sessions/<int:session_id>/config")
|
||||||
def get_emane_models(session_id):
|
def get_config(session_id):
|
||||||
session = coreemu.sessions.get(session_id)
|
|
||||||
if not session:
|
|
||||||
return jsonify(error="session does not exist"), 404
|
|
||||||
|
|
||||||
models = []
|
|
||||||
for model in session.emane._modelclsmap.keys():
|
|
||||||
if len(model.split("_")) != 2:
|
|
||||||
continue
|
|
||||||
models.append(model)
|
|
||||||
|
|
||||||
return jsonify(models=models)
|
|
||||||
|
|
||||||
|
|
||||||
@app.route("/sessions/<int:session_id>/emane/options")
|
|
||||||
def get_emane_options(session_id):
|
|
||||||
session = coreemu.sessions.get(session_id)
|
session = coreemu.sessions.get(session_id)
|
||||||
if not session:
|
if not session:
|
||||||
return jsonify(error="session does not exist"), 404
|
return jsonify(error="session does not exist"), 404
|
||||||
|
@ -251,14 +236,16 @@ def get_emane_options(session_id):
|
||||||
if node_id.isdigit():
|
if node_id.isdigit():
|
||||||
node_id = int(node_id)
|
node_id = int(node_id)
|
||||||
|
|
||||||
|
name = request.args["name"]
|
||||||
|
|
||||||
config_data = ConfigData(
|
config_data = ConfigData(
|
||||||
node=node_id,
|
node=node_id,
|
||||||
object="emane",
|
object=name,
|
||||||
type=ConfigFlags.REQUEST.value
|
type=ConfigFlags.REQUEST.value
|
||||||
)
|
)
|
||||||
replies = session.config_object(config_data)
|
replies = session.config_object(config_data)
|
||||||
if len(replies) != 1:
|
if len(replies) != 1:
|
||||||
return jsonify(error="failure getting emane options"), 404
|
return jsonify(error="failure getting config options"), 404
|
||||||
config_groups = replies[0]
|
config_groups = replies[0]
|
||||||
|
|
||||||
captions = config_groups.captions.split("|")
|
captions = config_groups.captions.split("|")
|
||||||
|
@ -266,7 +253,7 @@ def get_emane_options(session_id):
|
||||||
possible_values = config_groups.possible_values.split("|")
|
possible_values = config_groups.possible_values.split("|")
|
||||||
groups = config_groups.groups.split("|")
|
groups = config_groups.groups.split("|")
|
||||||
|
|
||||||
emane_options = []
|
config_options = []
|
||||||
for i, data_type in enumerate(config_groups.data_types):
|
for i, data_type in enumerate(config_groups.data_types):
|
||||||
data_value = data_values[i].split("=")
|
data_value = data_values[i].split("=")
|
||||||
value = None
|
value = None
|
||||||
|
@ -281,14 +268,14 @@ def get_emane_options(session_id):
|
||||||
|
|
||||||
label = captions[i]
|
label = captions[i]
|
||||||
|
|
||||||
emane_option = {
|
config_option = {
|
||||||
"label": label,
|
"label": label,
|
||||||
"name": name,
|
"name": name,
|
||||||
"value": value,
|
"value": value,
|
||||||
"type": data_type,
|
"type": data_type,
|
||||||
"select": select
|
"select": select
|
||||||
}
|
}
|
||||||
emane_options.append(emane_option)
|
config_options.append(config_option)
|
||||||
|
|
||||||
config_groups = []
|
config_groups = []
|
||||||
for group in groups:
|
for group in groups:
|
||||||
|
@ -298,12 +285,27 @@ def get_emane_options(session_id):
|
||||||
stop = indexes[1]
|
stop = indexes[1]
|
||||||
config_groups.append({
|
config_groups.append({
|
||||||
"name": name,
|
"name": name,
|
||||||
"options": emane_options[start: stop]
|
"options": config_options[start: stop]
|
||||||
})
|
})
|
||||||
|
|
||||||
return jsonify(groups=config_groups)
|
return jsonify(groups=config_groups)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/sessions/<int:session_id>/emane/models")
|
||||||
|
def get_emane_models(session_id):
|
||||||
|
session = coreemu.sessions.get(session_id)
|
||||||
|
if not session:
|
||||||
|
return jsonify(error="session does not exist"), 404
|
||||||
|
|
||||||
|
models = []
|
||||||
|
for model in session.emane._modelclsmap.keys():
|
||||||
|
if len(model.split("_")) != 2:
|
||||||
|
continue
|
||||||
|
models.append(model)
|
||||||
|
|
||||||
|
return jsonify(models=models)
|
||||||
|
|
||||||
|
|
||||||
@app.route("/sessions/<int:session_id>/nodes", methods=["POST"])
|
@app.route("/sessions/<int:session_id>/nodes", methods=["POST"])
|
||||||
@synchronized
|
@synchronized
|
||||||
def create_node(session_id):
|
def create_node(session_id):
|
||||||
|
|
|
@ -69,8 +69,8 @@ class CoreRest {
|
||||||
return await $.getJSON(`/sessions/${this.currentSession}/emane/models`);
|
return await $.getJSON(`/sessions/${this.currentSession}/emane/models`);
|
||||||
}
|
}
|
||||||
|
|
||||||
async getEmaneOptions(nodeId) {
|
async getConfig(config) {
|
||||||
return await $.getJSON(`/sessions/${this.currentSession}/emane/options`, {node: nodeId});
|
return await $.getJSON(`/sessions/${this.currentSession}/config`, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
async setConfig(config) {
|
async setConfig(config) {
|
||||||
|
|
|
@ -96,7 +96,7 @@ class ConfigModel {
|
||||||
const nodeId = this.$nodeEditModal.data('node');
|
const nodeId = this.$nodeEditModal.data('node');
|
||||||
this.$modal.data('type', 'emane');
|
this.$modal.data('type', 'emane');
|
||||||
this.$title.text('EMANE Options');
|
this.$title.text('EMANE Options');
|
||||||
const config = await this.coreRest.getEmaneOptions(nodeId);
|
const config = await this.coreRest.getConfig({node: nodeId, name: 'emane'});
|
||||||
console.log('emane options clicked: ', config);
|
console.log('emane options clicked: ', config);
|
||||||
this.$tabHeaders.html('');
|
this.$tabHeaders.html('');
|
||||||
this.$tabContent.html('');
|
this.$tabContent.html('');
|
||||||
|
|
Loading…
Reference in a new issue