Skip to content

Preferences & coderbot.cfg

Matt Blickem edited this page Jul 13, 2015 · 7 revisions

A number of parameters that configure the coderbot are stored in coderbot.cfg. This file is generated from the data in an HTML form in config.html and therefore should not be edited manually (because the changes will be overridden).

Clientside (config.html)

The variables that get stored in coderbot.cfg can be identified in config.html as <input> elements inside the <form> that have the property name="" where the name is the variable name stored in coderbot.cfg. Example:

<form class="config" id="f_config">
    <...>
    <label for="i_ctrl_tr_speed">{% trans %}Turn speed{% endtrans %}</label>
    <input type="text" id="i_ctrl_tr_speed" name="ctrl_tr_speed" value="{{config.ctrl_tr_speed}}">
    <...>
 </form>

The label tags provide a text label for the input field for the user to read. Note that name between {% trans %} tags are replaced by Flask-Babel as a localised string (i.e. a natural language translation). (see Flask-Babel for more information)

The point at which all the forms data is written to coderbot.cfg is when the Save button is pressed.

<div class="ui-block-b"><button type="submit" id="b_config_save" data-rel="close" class="ui-btn ui-shadow ui-corner-all ui-btn-a ui-mini">{% trans %}Save{% endtrans %}</button></div>

In control.js (sidenote I think this JavaScript belongs in a new file called config.js) there is a function tied to the form (by the form id $('#f_config')) and Save button (by the button type .on("submit", function() )).

$('#f_config').on("submit", function (){	
	var form_data = $(this).serialize();
            $.post(url='/config', form_data, success=function(){
              alert(BotMessages.Saved);
              location.href="http://github.com/";
            });
            return false;
});

Serverside

This function serializes the form (converts the form data to text) and sends it back to the Flask server in main.py.

@app.route("/config", methods=["POST"])
def handle_config():
    Config.write(request.form)
    app.bot_config = Config.get()
    return "ok";

This remote function call passes parameters in a different way to ordinary function calls via the request object. The function handle_config() finally writes the form to coderbot.cfg using code from config.py.

Clone this wiki locally