Skip to content

Commit

Permalink
[WebInterface] add save and restart on tentacles config
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeDSM committed Jul 10, 2024
1 parent 34c877c commit cdbd4b0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ def config_tentacle():
tentacle_name = flask.request.args.get("name")
action = flask.request.args.get("action")
profile_id = flask.request.args.get("profile_id")
restart = flask.request.args.get("restart", "false") == "true"
tentacles_setup_config = models.get_tentacles_setup_config_from_profile_id(profile_id) if profile_id else None
success = True
response = ""
Expand Down Expand Up @@ -311,6 +312,8 @@ def config_tentacle():
success = False
response = f"Error when reloading configuration {e}"
if success:
if restart:
models.schedule_delayed_command(models.restart_bot)
return util.get_rest_reply(flask.jsonify(response))
else:
return util.get_rest_reply(response, 500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ $(document).ready(function() {
}
};
const onEditorChange = (newValue) => {
updateTentacleConfig(newValue);
const update_url = $("button[data-role='saveConfig']").attr(update_url_attr);
updateTentacleConfig(newValue, update_url);
};
const startAutomations = () => {
const successCallback = (updated_data, update_url, dom_root_element, msg, status) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ function handle_apply_evaluator_default_config_success_callback(updated_data, up
location.reload();
}

function updateTentacleConfig(updatedConfig){
const update_url = $("button[data-role='saveConfig']").attr(update_url_attr);
function updateTentacleConfig(updatedConfig, update_url){
send_and_interpret_bot_update(updatedConfig, update_url, null, handle_tentacle_config_update_success_callback, handle_tentacle_config_update_error_callback);
}

Expand Down Expand Up @@ -67,13 +66,15 @@ function handleConfigDisplay(success){
$("#configErrorDetails").hide();
if(canEditConfig()) {
$("#saveConfigFooter").show();
$("button[data-role='saveConfig']").removeClass(hidden_class).unbind("click").click(function () {
$("button[data-role='saveConfig']").removeClass(hidden_class).unbind("click").click(function (event) {
const errorsDesc = validateJSONEditor(configEditor);
if (errorsDesc.length) {
create_alert("error", "Error when saving configuration",
`Invalid configuration data: ${errorsDesc}.`);
} else
updateTentacleConfig(configEditor.getValue());
} else{
const url = $(event.currentTarget).attr(update_url_attr)
updateTentacleConfig(configEditor.getValue(), url);
}
});
}else{
$("#noConfigMessage").show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ <h2><i class="fa fa-spinner fa-spin"></i></h2>
</div>
</div>
<div class="card-footer" id='saveConfigFooter' style='display: none;'>
<button class="btn btn-outline-success waves-effect" data-role='saveConfig' update-url="{{ url_for('config_tentacle', name=name, action='update') }}">Save configuration and restart later</button>
<button class="btn btn-primary waves-effect" data-role='saveConfig' update-url="{{ url_for('config_tentacle', name=name, action='update', restart='false') }}"><i class="fas fa-save"></i> Save configuration and restart later</button>
<button class="btn btn-outline-primary waves-effect mx-5" data-role='saveConfig' update-url="{{ url_for('config_tentacle', name=name, action='update', restart='true') }}">Save and restart</button>
<button class="btn btn-outline-warning waves-effect float-right" data-role='factoryResetConfig'
update-url="{{ url_for('config_tentacle', name=name, action='factory_reset') }}"><i class="fas fa-recycle"></i> Reset configuration to default values</button>
</div>
Expand All @@ -79,7 +80,7 @@ <h2>Commands</h2>
<div class="card-body">
{% for command_action, command_params in user_commands.items() %}
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary waves-effect"
<button type="button" class="btn btn-outline-primary waves-effect"
data-toggle="modal" data-target="#{{ command_action | replace (' ', '') }}Modal">
{{ command_action }}
</button>
Expand Down

0 comments on commit cdbd4b0

Please sign in to comment.