Added the ability to control snippet widths.

master
Pacman Ghost 6 years ago
parent 26d376a2ab
commit d81ad6c988
  1. 2
      vasl_templates/webapp/data/default-templates/ob_setup.j2
  2. 1
      vasl_templates/webapp/data/default-templates/scenario.j2
  3. 2
      vasl_templates/webapp/data/default-templates/ssr.j2
  4. 2
      vasl_templates/webapp/data/default-templates/victory_conditions.j2
  5. 19
      vasl_templates/webapp/static/css/tabs-ob.css
  6. 14
      vasl_templates/webapp/static/css/tabs-scenario.css
  7. 2
      vasl_templates/webapp/static/generate.js
  8. 26
      vasl_templates/webapp/templates/main.html
  9. 27
      vasl_templates/webapp/tests/test_generate.py
  10. 12
      vasl_templates/webapp/tests/test_ob_setup.py
  11. 11
      vasl_templates/webapp/tests/test_ssr.py

@ -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%}

@ -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%}

@ -1,2 +1,2 @@
{% for ssr in SSR %}(*) [{{ssr}}]
{% endfor %}
{% endfor %}{%if SSR_WIDTH%}width = [{{SSR_WIDTH}}]{%endif%}

@ -1 +1 @@
VC: {{VICTORY_CONDITIONS}}
VC: [{{VICTORY_CONDITIONS}}]{%if VICTORY_CONDITIONS_WIDTH%} ; width=[{{VICTORY_CONDITIONS_WIDTH}}]{%endif%}

@ -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% ; }

@ -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 ; }

@ -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 = [] ;

@ -28,9 +28,13 @@
<div class="label" data-labelfor="scenario_name">Name:</div> <input name="scenario_name" type="text" class="param">
<div class="label" data-labelfor="scenario_location">Location:</div> <input name="scenario_location" type="text" class="param">
<div class="label" data-labelfor="scenario_date">Date:</div>
<div class="scenario_date">
<div class="last_row">
<input name="scenario_date" type="text" size="10" class="param">
<input type="button" class="generate" data-id="scenario" value="Go">
<div class="r">
<label for="scenario_width">Width:</label>
<input type="text" class="param" name="scenario_width" size="5">
<input type="button" class="generate" data-id="scenario" value="Go">
</div>
</div>
</div>
<div id="panel-players">
@ -44,6 +48,8 @@
<div id="panel-vc">
<textarea name="victory_conditions" type="text" class="param"></textarea>
<div class="footer">
<label for="victory_conditions_width">Width:</label>
<input type="text" class="param" name="victory_conditions_width" size="5">
<input type="button" class="generate" data-id="victory_conditions" value="Go">
</div>
</div>
@ -55,8 +61,12 @@
<ul id="ssr-sortable" style="display:none;"></ul>
</div>
<div class="footer">
<input type="button" id="add-ssr" value="+">
<img id="ssr-trash" src="{{url_for('static',filename='images/trash.png')}}">
<div class="l">
<input type="button" id="add-ssr" value="+">
<img id="ssr-trash" src="{{url_for('static',filename='images/trash.png')}}">
</div>
<label for="ssr_width">Width:</label>
<input type="text" class="param" name="ssr_width" size="5">
<input type="button" class="generate" data-id="ssr" value="Go">
</div>
</div>
@ -76,6 +86,10 @@
<input type="button" class="generate" data-id="baz" value="BAZ">
<input type="button" class="generate" data-id="piat" value="PIAT">
<input type="button" class="generate" data-id="ob_setup_1" value="Go">
<div class="r">
<label for="ob_setup_width_1">Width:</label>
<input type="text" class="param" name="ob_setup_width_1" size="5">
</div>
</div>
</div>
</fieldset>
@ -102,6 +116,10 @@
<input type="button" class="generate" data-id="baz" value="BAZ">
<input type="button" class="generate" data-id="ob_setup_2" value="Go">
<input type="button" class="generate" data-id="piat" value="PIAT">
<div class="r">
<label for="ob_setup_width_2">Width:</label>
<input type="text" class="param" name="ob_setup_width_2" size="5">
</div>
</div>
</div>
</fieldset>

@ -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
)

@ -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 ):

@ -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" )

Loading…
Cancel
Save