From d81ad6c988321c8ad6ff0b4bfaf2d3caa7e1af9e Mon Sep 17 00:00:00 2001 From: Taka Date: Wed, 11 Jul 2018 08:19:52 +0000 Subject: [PATCH] Added the ability to control snippet widths. --- .../webapp/data/default-templates/ob_setup.j2 | 2 +- .../webapp/data/default-templates/scenario.j2 | 1 + .../webapp/data/default-templates/ssr.j2 | 2 +- .../default-templates/victory_conditions.j2 | 2 +- vasl_templates/webapp/static/css/tabs-ob.css | 19 ++++++------- .../webapp/static/css/tabs-scenario.css | 14 +++++----- vasl_templates/webapp/static/generate.js | 2 ++ vasl_templates/webapp/templates/main.html | 26 +++++++++++++++--- vasl_templates/webapp/tests/test_generate.py | 27 ++++++++++++++++--- vasl_templates/webapp/tests/test_ob_setup.py | 12 +++++++++ vasl_templates/webapp/tests/test_ssr.py | 11 ++++++-- 11 files changed, 90 insertions(+), 28 deletions(-) diff --git a/vasl_templates/webapp/data/default-templates/ob_setup.j2 b/vasl_templates/webapp/data/default-templates/ob_setup.j2 index e9073a6..d83acf9 100644 --- a/vasl_templates/webapp/data/default-templates/ob_setup.j2 +++ b/vasl_templates/webapp/data/default-templates/ob_setup.j2 @@ -1 +1 @@ -[{{OB_SETUP}}] (col=[{{OB_SETUP_COLOR}}/{{OB_SETUP_COLOR_2}}]) +[{{OB_SETUP}}] (col=[{{OB_SETUP_COLOR}}/{{OB_SETUP_COLOR_2}}]){%if OB_SETUP_WIDTH%} (width=[{{OB_SETUP_WIDTH}}]){%endif%} diff --git a/vasl_templates/webapp/data/default-templates/scenario.j2 b/vasl_templates/webapp/data/default-templates/scenario.j2 index aefc950..9e81d82 100644 --- a/vasl_templates/webapp/data/default-templates/scenario.j2 +++ b/vasl_templates/webapp/data/default-templates/scenario.j2 @@ -1,3 +1,4 @@ name = [{{SCENARIO_NAME}}] loc = [{{SCENARIO_LOCATION}}] date = [{{SCENARIO_DATE}}]{%if SCENARIO_DATE%} aka "{{SCENARIO_DAY_OF_MONTH}} {{SCENARIO_MONTH_NAME}}, {{SCENARIO_YEAR}}"{%endif%} +{%if SCENARIO_WIDTH%}width = [{{SCENARIO_WIDTH}}]{%endif%} diff --git a/vasl_templates/webapp/data/default-templates/ssr.j2 b/vasl_templates/webapp/data/default-templates/ssr.j2 index 70397de..efa8e91 100644 --- a/vasl_templates/webapp/data/default-templates/ssr.j2 +++ b/vasl_templates/webapp/data/default-templates/ssr.j2 @@ -1,2 +1,2 @@ {% for ssr in SSR %}(*) [{{ssr}}] -{% endfor %} +{% endfor %}{%if SSR_WIDTH%}width = [{{SSR_WIDTH}}]{%endif%} diff --git a/vasl_templates/webapp/data/default-templates/victory_conditions.j2 b/vasl_templates/webapp/data/default-templates/victory_conditions.j2 index 03aa799..aa0f735 100644 --- a/vasl_templates/webapp/data/default-templates/victory_conditions.j2 +++ b/vasl_templates/webapp/data/default-templates/victory_conditions.j2 @@ -1 +1 @@ -VC: {{VICTORY_CONDITIONS}} +VC: [{{VICTORY_CONDITIONS}}]{%if VICTORY_CONDITIONS_WIDTH%} ; width=[{{VICTORY_CONDITIONS_WIDTH}}]{%endif%} diff --git a/vasl_templates/webapp/static/css/tabs-ob.css b/vasl_templates/webapp/static/css/tabs-ob.css index 54b4c95..e9c566c 100644 --- a/vasl_templates/webapp/static/css/tabs-ob.css +++ b/vasl_templates/webapp/static/css/tabs-ob.css @@ -8,12 +8,13 @@ .panel-obsetup .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; } .panel-obsetup textarea { width: 100% ; height: 100% ; resize: none ; } -.panel-obsetup input[type="button"][data-id='mol'] { float: left ; } -.panel-obsetup input[type="button"][data-id='mol-p'] { float: left ; } -.panel-obsetup input[type="button"][data-id='pf'] { float: left ; } -.panel-obsetup input[type="button"][data-id='psk'] { float: left ; } -.panel-obsetup input[type="button"][data-id='atmm'] { float: left ; } -.panel-obsetup input[type="button"][data-id='baz'] { float: left ; } -.panel-obsetup input[type="button"][data-id='piat'] { float: left ; } -.panel-obsetup input[type="button"][data-id='ob_setup_1'] { float: right ; } -.panel-obsetup input[type="button"][data-id='ob_setup_2'] { float: right ; } +.panel-obsetup input[data-id='mol'] { float: left ; } +.panel-obsetup input[data-id='mol-p'] { float: left ; } +.panel-obsetup input[data-id='pf'] { float: left ; } +.panel-obsetup input[data-id='psk'] { float: left ; } +.panel-obsetup input[data-id='atmm'] { float: left ; } +.panel-obsetup input[data-id='baz'] { float: left ; } +.panel-obsetup input[data-id='piat'] { float: left ; } +.panel-obsetup input[data-id='ob_setup_1'] { float: right ; } +.panel-obsetup input[data-id='ob_setup_2'] { float: right ; } +.panel-obsetup div.r { float: right ; font-size: 75% ; } diff --git a/vasl_templates/webapp/static/css/tabs-scenario.css b/vasl_templates/webapp/static/css/tabs-scenario.css index 3cea13f..4b4bd8f 100644 --- a/vasl_templates/webapp/static/css/tabs-scenario.css +++ b/vasl_templates/webapp/static/css/tabs-scenario.css @@ -10,9 +10,10 @@ #panel-scenario div[data-labelfor="scenario_location"] { -ms-grid-row: 2 ; -ms-grid-column: 1 ; } #panel-scenario input[name="scenario_location"] { -ms-grid-row: 2 ; -ms-grid-column: 2 ; } #panel-scenario div[data-labelfor="scenario_date"] { -ms-grid-row: 3 ; -ms-grid-column: 1 ; } -#panel-scenario div.scenario_date { -ms-grid-row: 3 ; -ms-grid-column: 2 ; } +#panel-scenario div.last_row { -ms-grid-row: 3 ; -ms-grid-column: 2 ; } -#panel-scenario input[type="button"] { float: right ; } +#panel-scenario .last_row .r { display: block-inline ; float: right ; font-size: 75% ; } +#panel-scenario input[data-id="scenario"] { height: 2em ; } /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ @@ -53,7 +54,8 @@ #panel-vc .footer { -ms-grid-row: 2 ; -ms-grid-column: 1 ; } #panel-vc textarea { width: 100% ; height: 100% ; resize: none ; } -#panel-vc input[type="button"] { height: 1.5em ; float: right ; } +#panel-vc .footer { text-align: right ; font-size: 75% ; } +#panel-vc input[data-id="victory_conditions"] { height: 2em ; } /* -------------------------------------------------------------------- */ @@ -75,9 +77,9 @@ #panel-ssr #ssr-sortable li.highlighted { background: #48c8ff ; } #panel-ssr #ssr-sortable li:hover { cursor: pointer ; } -#panel-ssr input#add-ssr { float: left ; } -#panel-ssr #ssr-trash { margin-left: 5px ; float: left ; height: 1.5em ; } -#panel-ssr input[data-id="ssr"] { float: right ; } +#panel-ssr .footer { text-align: right ; font-size: 75% ; } +#panel-ssr .footer .l { float: left ; } +#panel-ssr #ssr-trash { margin-left: 5px ; height: 2em ; } #ssr-hint { width:100% ; height: calc(100% - 1.5em) ; font-size: 80% ; font-style: italic ; } #ssr-hint p { margin-bottom: 1em ; } diff --git a/vasl_templates/webapp/static/generate.js b/vasl_templates/webapp/static/generate.js index 3496f4d..61515ab 100644 --- a/vasl_templates/webapp/static/generate.js +++ b/vasl_templates/webapp/static/generate.js @@ -32,12 +32,14 @@ function generate_snippet( $btn ) 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] ; + params.OB_SETUP_WIDTH = params.OB_SETUP_WIDTH_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] ; + params.OB_SETUP_WIDTH = params.OB_SETUP_WIDTH_2 ; } else if ( template_id === "ssr" ) { params.SSR = [] ; diff --git a/vasl_templates/webapp/templates/main.html b/vasl_templates/webapp/templates/main.html index c8c8f63..e99d2cf 100644 --- a/vasl_templates/webapp/templates/main.html +++ b/vasl_templates/webapp/templates/main.html @@ -28,9 +28,13 @@
Name:
Location:
Date:
-
+
- +
+ + + +
@@ -44,6 +48,8 @@
@@ -55,8 +61,12 @@
@@ -76,6 +86,10 @@ +
+ + +
@@ -102,6 +116,10 @@ +
+ + +
diff --git a/vasl_templates/webapp/tests/test_generate.py b/vasl_templates/webapp/tests/test_generate.py index 6f7b1f0..fbab3af 100644 --- a/vasl_templates/webapp/tests/test_generate.py +++ b/vasl_templates/webapp/tests/test_generate.py @@ -6,7 +6,6 @@ from vasl_templates.webapp.tests.utils import get_clipboard, get_stored_msg, fin # --------------------------------------------------------------------- -# initialize def _test_snippet( webdriver, template_id, params, expected, expected2 ): """Do a single test.""" @@ -87,6 +86,17 @@ def test_scenario_snippets( webapp, webdriver ): [ "scenario name", "scenario date" ], ) + # generate a SCENARIO snippet with a snippet width + _test_snippet( webdriver, "scenario", { + "scenario_name": "test", + "scenario_location": "here", + "scenario_date": "01/02/1942", + "scenario_width": "20em", + }, + 'name = [test] | loc = [here] | date = [01/02/1942] aka "2 January, 1942" | width = [20em]', + None + ) + # --------------------------------------------------------------------- def test_vc_snippets( webapp, webdriver ): @@ -99,15 +109,24 @@ def test_vc_snippets( webapp, webdriver ): _test_snippet( webdriver, "victory_conditions", { "victory_conditions": "Kill 'Em All!", }, - "VC: Kill 'Em All!", + "VC: [Kill 'Em All!]", None ) - # generate a VC snippet + # generate an empty VC snippet _test_snippet( webdriver, "victory_conditions", { "victory_conditions": "", }, - "VC:", + "VC: []", + None + ) + + # generate a VC snippet with a width + _test_snippet( webdriver, "victory_conditions", { + "victory_conditions": "Kill 'Em All!", + "victory_conditions_width": "100px", + }, + "VC: [Kill 'Em All!] ; width=[100px]", None ) diff --git a/vasl_templates/webapp/tests/test_ob_setup.py b/vasl_templates/webapp/tests/test_ob_setup.py index 58e1f33..27f2111 100644 --- a/vasl_templates/webapp/tests/test_ob_setup.py +++ b/vasl_templates/webapp/tests/test_ob_setup.py @@ -55,6 +55,18 @@ def test_ob_setup( webapp, webdriver ): btn2.click() assert get_clipboard() == "[setup there.] (col=[OBCOL:french/OBCOL2:french])" + # set the snippet widths and generate the snippets again + select_ob_tab( 1 ) + elem = find_child( webdriver, "input[name='ob_setup_width_1']" ) + elem.send_keys( "100px" ) + btn1.click() + assert get_clipboard() == "[setup here.] (col=[OBCOL:british/OBCOL2:british]) (width=[100px])" + select_ob_tab( 2 ) + elem = find_child( webdriver, "input[name='ob_setup_width_2']" ) + elem.send_keys( "200px" ) + btn2.click() + assert get_clipboard() == "[setup there.] (col=[OBCOL:french/OBCOL2:french]) (width=[200px])" + # --------------------------------------------------------------------- def test_nationality_specific( webapp, webdriver ): diff --git a/vasl_templates/webapp/tests/test_ssr.py b/vasl_templates/webapp/tests/test_ssr.py index a6db49c..9f31f53 100644 --- a/vasl_templates/webapp/tests/test_ssr.py +++ b/vasl_templates/webapp/tests/test_ssr.py @@ -36,12 +36,14 @@ def test_ssr( webapp, webdriver ): btn.click() # check the generated snippet check_snippet() - def check_snippet(): + def check_snippet( width=None ): """Check the generated SSR snippet.""" btn = find_child( webdriver, "input[type='button'][data-id='ssr']" ) btn.click() val = "\n".join( "(*) [{}]".format(e) for e in expected ) - assert html.unescape(get_clipboard()) == val + if width: + val += "\nwidth = [{}]".format( width ) + assert html.unescape( get_clipboard() ) == val # add an SSR and generate the SSR snippet add_ssr( "This is my first SSR." ) @@ -68,3 +70,8 @@ def test_ssr( webapp, webdriver ): ActionChains(webdriver).drag_and_drop( elem, trash ).perform() del expected[1] check_snippet() + + # set the snippet width + elem = find_child( webdriver, "input[name='ssr_width']" ) + elem.send_keys( "300px" ) + check_snippet( "300px" )