diff --git a/vasl_templates/webapp/data/default-templates/ob_setup.j2 b/vasl_templates/webapp/data/default-templates/ob_setup.j2 new file mode 100644 index 0000000..e9073a6 --- /dev/null +++ b/vasl_templates/webapp/data/default-templates/ob_setup.j2 @@ -0,0 +1 @@ +[{{OB_SETUP}}] (col=[{{OB_SETUP_COLOR}}/{{OB_SETUP_COLOR_2}}]) diff --git a/vasl_templates/webapp/static/css/main.css b/vasl_templates/webapp/static/css/main.css index ee22fe8..d7c890f 100644 --- a/vasl_templates/webapp/static/css/main.css +++ b/vasl_templates/webapp/static/css/main.css @@ -108,6 +108,12 @@ input[type="text"] { margin-bottom: 0.25em ; } #panel-vc textarea[name="victory_conditions"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; } #panel-vc input[type="button"] { float: right ; } +#panel-obsetup1 textarea[name="ob_setup_1"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; } +#panel-obsetup1 input[type="button"] { float: right ; } + +#panel-obsetup2 textarea[name="ob_setup_2"] { width: calc(100% - 2px) ; height: calc(100% - 1.5em) ; resize: none ; } +#panel-obsetup2 input[type="button"] { float: right ; } + /* -------------------------------------------------------------------- */ .growl-title { display: none ; } diff --git a/vasl_templates/webapp/static/generate.js b/vasl_templates/webapp/static/generate.js index 3b5d6ab..41956a3 100644 --- a/vasl_templates/webapp/static/generate.js +++ b/vasl_templates/webapp/static/generate.js @@ -15,8 +15,22 @@ function generate_snippet( $btn ) $("textarea.param").each( function() { add_param($(this)) ; } ) ; $("select.param").each( function() { add_param($(this)) ; } ) ; - // check for mandatory parameters + // figore out which template to use var template_id = $btn.data( "id" ) ; + if ( template_id === "ob_setup_1" ) { + template_id = "ob_setup" ; + params.OB_SETUP = params.OB_SETUP_1 ; + params.OB_SETUP_COLOR = gNationalities[params.PLAYER_1].ob_colors[0] ; + params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_1].ob_colors[1] ; + } + else if ( template_id === "ob_setup_2" ) { + template_id = "ob_setup" ; + params.OB_SETUP = params.OB_SETUP_2 ; + params.OB_SETUP_COLOR = gNationalities[params.PLAYER_2].ob_colors[0] ; + params.OB_SETUP_COLOR_2 = gNationalities[params.PLAYER_2].ob_colors[1] ; + } + + // check for mandatory parameters if ( template_id in _MANDATORY_PARAMS ) { var missing_params = [] ; for ( var param_id in _MANDATORY_PARAMS[template_id] ) { diff --git a/vasl_templates/webapp/templates/main.html b/vasl_templates/webapp/templates/main.html index 1c4c93f..c99cb80 100644 --- a/vasl_templates/webapp/templates/main.html +++ b/vasl_templates/webapp/templates/main.html @@ -40,7 +40,7 @@
Victory Conditions - +
@@ -53,6 +53,8 @@
OB setup + +
@@ -68,6 +70,8 @@
OB setup + +
diff --git a/vasl_templates/webapp/tests/test_ob_setup.py b/vasl_templates/webapp/tests/test_ob_setup.py new file mode 100644 index 0000000..79dc69b --- /dev/null +++ b/vasl_templates/webapp/tests/test_ob_setup.py @@ -0,0 +1,54 @@ +""" Test generating OB SETUP snippets. """ + +from selenium.webdriver.support.ui import Select + +from vasl_templates.webapp.tests.utils import get_clipboard, find_child + +# --------------------------------------------------------------------- + +def test_ob_setup( webapp, webdriver ): + """Test generating OB SETUP snippets.""" + + # initialize + webdriver.get( webapp.url_for( "main" ) ) + + # initialize + def select_ob_tab( player_id ): + """Select the OB tab for the specified player.""" + elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-ob{}']".format( player_id ) ) + elem.click() + + # generate OB SETUP snippets for both players + select_ob_tab( 1 ) + textarea1 = find_child( webdriver, "textarea[name='ob_setup_1']" ) + textarea1.clear() + textarea1.send_keys( "setup here." ) + btn1 = find_child( webdriver, "input[type='button'][data-id='ob_setup_1']" ) + select_ob_tab( 2 ) + textarea2 = find_child( webdriver, "textarea[name='ob_setup_2']" ) + textarea2.clear() + textarea2.send_keys( "setup there." ) + btn2 = find_child( webdriver, "input[type='button'][data-id='ob_setup_2']" ) + btn2.click() + assert get_clipboard().strip() == "[setup there.] (col=[OBCOL:russian/OBCOL2:russian])" + select_ob_tab( 1 ) + btn1.click() + assert get_clipboard().strip() == "[setup here.] (col=[OBCOL:german/OBCOL2:german])" + + # change the player nationalities and generate the OB SETUP snippets again + elem = find_child( webdriver, "#tabs .ui-tabs-nav a[href='#tabs-scenario']" ) + elem.click() + sel = Select( + find_child( webdriver, "select[name='player_1']" ) + ) + sel.select_by_value( "british" ) + sel = Select( + find_child( webdriver, "select[name='player_2']" ) + ) + sel.select_by_value( "french" ) + select_ob_tab( 1 ) + btn1.click() + assert get_clipboard().strip() == "[setup here.] (col=[OBCOL:british/OBCOL2:british])" + select_ob_tab( 2 ) + btn2.click() + assert get_clipboard().strip() == "[setup there.] (col=[OBCOL:french/OBCOL2:french])"