Pass some scenario parameters through to extras templates for their forms.

Updateed the "count remaining" extras template to reflect the scenario year.
master
Pacman Ghost 4 years ago
parent 86c2ff00df
commit 575e217c68
  1. 28
      vasl_templates/webapp/data/default-template-pack/extras/count-remaining.j2
  2. 23
      vasl_templates/webapp/static/extras.js
  3. 68
      vasl_templates/webapp/tests/test_extras_templates.py

@ -4,25 +4,33 @@
<!-- vasl-templates:description Add the snippet as the label of a counter (e.g. Panzerfaust or Tank-Hunter Hero), then press <i>Ctrl-L</i> when you need to update how many are left. -->
<!-- vasl-templates:comment The HTML is deliberately malformed, so that the number remaining is the last thing in snippet, which makes it easier to change during the course of a game. -->
<!-- vasl-templates:footer <table> <tr>
{% set HILITE_STYLE = 'style="background:#ffffe0;border-color:#888;"' %}
<td>
<h3>Panzerfaust</h3>
<table>
<tr> <td class="key"> before '44 <td class="val"> #squads
<tr> <td class="key"> '44 <td class="val"> #squads &times 1&half; (FRD)
<tr> <td class="key"> '45 <td class="val"> #squads &times 2
<table class="pf">
<tr> <td class="key"> before '44
<td class="val" {%if SCENARIO_YEAR and SCENARIO_YEAR < 1944%} {{HILITE_STYLE}} {%endif%} > #squads
<tr> <td class="key"> '44
<td class="val" {%if SCENARIO_YEAR and SCENARIO_YEAR == 1944%} {{HILITE_STYLE}} {%endif%}> #squads &times 1&half; (FRD)
<tr> <td class="key"> '45
<td class="val" {%if SCENARIO_YEAR and SCENARIO_YEAR == 1945%} {{HILITE_STYLE}} {%endif%}> #squads &times 2
</table>
<em> Squads or squad-equivalents. </em>
<td style="padding-left: 1em;">
<h3>Tank-Hunter Heroes</h3>
<table>
<tr> <td class="key"> before '43 <td class="val"> 10% of #squads (FRU) <br> <small><em>(20% vs. Russians)</em></small>
<tr> <td class="key"> '43 <td class="val"> 20% of #squads (FRU)
<tr> <td class="key"> '44 <td class="val"> 33% of #squads (FRU)
<tr> <td class="key"> '45 <td class="val"> 50% of #squads (FRU)
<table class="thh">
<tr> <td class="key"> before '43
<td class="val" {%if SCENARIO_YEAR and SCENARIO_YEAR < 1943%} {{HILITE_STYLE}} {%endif%}> 10% of #squads (FRU) <br> <small><em>(20% vs. Russians)</em></small>
<tr> <td class="key"> '43
<td class="val" {%if SCENARIO_YEAR and SCENARIO_YEAR == 1943%} {{HILITE_STYLE}} {%endif%}> 20% of #squads (FRU)
<tr> <td class="key"> '44
<td class="val" {%if SCENARIO_YEAR and SCENARIO_YEAR == 1944%} {{HILITE_STYLE}} {%endif%}> 33% of #squads (FRU)
<tr> <td class="key"> '45
<td class="val" {%if SCENARIO_YEAR and SCENARIO_YEAR == 1945%} {{HILITE_STYLE}} {%endif%}> 50% of #squads (FRU)
</table>
<em> Squads only, not squad-equivalents. </em>
</table> -->
</table> -->
<!-- vasl-templates:comment We don't include common.css because it's not necessary, and we want to keep the generated snippet short. -->
{# NOTE: We specify the font size in pixels, rather than as a percentage, since this label should be added to a counter. #}

@ -111,7 +111,28 @@ function _show_extra_template( template_id )
buf.push( "<div class='footer'>", template_info.footer, "</div>" ) ;
}
buf.push( "</div>" ) ;
var $form = $( buf.join("") ) ;
buf = buf.join( "" ) ;
// pass some basic parameters through to the form
// NOTE: We should really re-generate the form every time it gets focus (since the scenario parameters
// might have changed) but this would be horribly expensive (not to mention mostly un-necessary).
// The user can always click on the navbar to re-generate it.
try {
func = jinja.compile( buf ).render ;
} catch( ex ) {
showErrorMsg( "Can't compile template:<div class='pre'>" + escapeHTML(ex) + "</div>" ) ;
return ;
}
var params = unload_snippet_params( true, null ) ;
try {
buf = func( params, { autoEscape: false } ) ;
} catch( ex ) {
showErrorMsg( "Can't process template: <span class='pre'>" + template_id + "</span><div class='pre'>" + escapeHTML(ex) + "</div>" ) ;
return ;
}
// generate the form
var $form = $( buf ) ;
$form.find( "select" ).select2( {
minimumResultsForSearch: -1
} ).on( "select2:open", function() {

@ -3,7 +3,8 @@
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from vasl_templates.webapp.tests.utils import init_webapp, select_tab, get_droplist_vals, select_droplist_val, \
from vasl_templates.webapp.tests.utils import init_webapp, select_tab, \
set_template_params, get_droplist_vals, select_droplist_val, \
find_child, find_children, wait_for, wait_for_clipboard
from vasl_templates.webapp.tests.test_template_packs import make_zip_from_files, upload_template_pack_zip
@ -174,6 +175,71 @@ def test_edit_extras_template( webapp, webdriver ):
# ---------------------------------------------------------------------
def test_count_remaining_hilites( webapp, webdriver ):
"""Test highlighting in the "count remaining" extras template."""
# initialize
init_webapp( webapp, webdriver,
reset = lambda ct: ct.set_data_dir( dtype="real" )
)
def do_test( year, expected ): #pylint: disable=missing-docstring
# set the specified year
set_template_params( {
"SCENARIO_DATE": "01/01/{}".format( year ) if year else ""
} )
# select the "count remaining" template and check what's been highlighted
select_tab( "extras" )
_select_extras_template( webdriver, "extras/count-remaining" )
for count_type in expected:
table = find_child( "table.{}".format( count_type ) )
cells = []
for row in find_children( "tr", table ):
row = list( find_children( "td", row ) )
assert len(row) == 2
bgd_col = row[1].value_of_css_property( "background-color" )
assert bgd_col.startswith( ( "rgb(", "rgba(" ) )
cells.append( bgd_col != "rgba(0, 0, 0, 0)" )
assert cells == expected[count_type]
# do the tests
do_test( None, {
"pf": [ False, False, False ],
"thh": [ False, False, False, False ]
} )
do_test( 1940, {
"pf": [ True, False, False ],
"thh": [ True, False, False, False ]
} )
do_test( 1941, {
"pf": [ True, False, False ],
"thh": [ True, False, False, False ]
} )
do_test( 1942, {
"pf": [ True, False, False ],
"thh": [ True, False, False, False ]
} )
do_test( 1943, {
"pf": [ True, False, False ],
"thh": [ False, True, False, False ]
} )
do_test( 1944, {
"pf": [ False, True, False ],
"thh": [ False, False, True, False ]
} )
do_test( 1945, {
"pf": [ False, False, True ],
"thh": [ False, False, False, True ]
} )
do_test( 1946, {
"pf": [ False, False, False ],
"thh": [ False, False, False, False ]
} )
# ---------------------------------------------------------------------
def _get_extras_template_index():
"""Get the list of extras templates from the sidebar."""
def get_child_text( child_class, elem ): #pylint: disable=missing-docstring

Loading…
Cancel
Save