Added the SCENARIO_THEATER field.

master
Pacman Ghost 6 years ago
parent 673877bc5b
commit 4693a7531f
  1. 2
      vasl_templates/webapp/data/default-scenario.json
  2. 3
      vasl_templates/webapp/static/css/tabs-scenario.css
  3. 9
      vasl_templates/webapp/static/main.js
  4. 72
      vasl_templates/webapp/static/snippets.js
  5. 5
      vasl_templates/webapp/templates/index.html
  6. 5
      vasl_templates/webapp/templates/vo-report.html
  7. 2
      vasl_templates/webapp/tests/fixtures/data/default-scenario.json
  8. 6
      vasl_templates/webapp/tests/test_scenario_persistence.py

@ -1,5 +1,7 @@
{
"SCENARIO_THEATER": "ETO",
"PLAYER_1": "german",
"PLAYER_1_ELR": "5",
"PLAYER_1_SAN": "2",

@ -4,7 +4,8 @@
#panel-scenario .row { display: flex ; align-items: center ; }
#panel-scenario input { flex-grow: 1 ; }
#panel-scenario input[name='SCENARIO_ID'] { margin-left: 0.25em ; width: 4em ; flex-grow: 0 ; }
#panel-scenario input[name='SCENARIO_ID'] { margin-left: 0.25em ; width: 70px ; flex-grow: 0 ; }
#panel-scenario .ui-selectmenu-button.scenario_theater { margin: -3px 0 0 0.25em ; width: 60px ; flex-grow: 0 ; }
#panel-scenario input[name='SCENARIO_DATE'] { width: 6em ; flex-grow: 0 ; }
#panel-scenario label { font-weight: bold ; width: 5em ; }

@ -30,7 +30,7 @@ $(document).ready( function () {
// initialize the menu
var $menu = $("#menu input") ;
$menu.popmenu( {
new_scenario: { label: "New scenario", action: function() { on_new_scenario(true) ; } },
new_scenario: { label: "New scenario", action: function() { on_new_scenario() ; } },
load_scenario: { label: "Load scenario", action: on_load_scenario },
save_scenario: { label: "Save scenario", action: on_save_scenario },
separator: { type: "separator" },
@ -91,6 +91,11 @@ $(document).ready( function () {
var navHeight = $("#tabs .ui-tabs-nav").height() ;
$("#tabs .ui-tabs-nav a").click( function() { $(this).blur() ; } ) ;
// initialize the scenario theater
$( "select[name='SCENARIO_THEATER']" ).selectmenu( {
classes: { "ui-selectmenu-button": "scenario_theater" },
} ) ;
// initialize the scenario date picker
$("input[name='SCENARIO_DATE']").datepicker( {
showAnim: "slideDown",
@ -220,7 +225,7 @@ $(document).ready( function () {
}
}
install_template_pack( data ) ;
on_new_scenario( false ) ;
do_on_new_scenario() ;
gDefaultNationalities = $.extend( true, {}, data.nationalities ) ;
// NOTE: If we are loading a user-defined template pack, then what we think
// is the set of valid template ID's will depend on what's in it :-/

@ -228,10 +228,20 @@ function unload_snippet_params( params, check_date_capabilities )
// but by the time the filter gets called, it's too late :-( Instead, we provide a "raw_capabilities"
// parameter that people can use in their templates - ugly, but probably not something that will
// get a lot of use :-/
var capabilities = make_capabilities( entry, params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities, false ) ;
var capabilities = make_capabilities(
entry,
params.SCENARIO_THEATER,
params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities,
false
) ;
if ( capabilities )
obj.capabilities = capabilities ;
capabilities = make_capabilities( entry, params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities, true ) ;
capabilities = make_capabilities(
entry,
params.SCENARIO_THEATER,
params.SCENARIO_YEAR, params.SCENARIO_MONTH, check_date_capabilities,
true
) ;
if ( capabilities )
obj.raw_capabilities = capabilities ;
var crew_survival = make_crew_survival( entry ) ;
@ -252,7 +262,7 @@ function unload_snippet_params( params, check_date_capabilities )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function make_capabilities( entry, scenario_year, scenario_month, check_date_capabilities, raw )
function make_capabilities( entry, scenario_theater, scenario_year, scenario_month, check_date_capabilities, raw )
{
var capabilities = [] ;
@ -523,6 +533,10 @@ function on_load_scenario_file_selected()
function do_load_scenario( data, fname )
{
// NOTE: We reset the scenario first, in case the loaded scenario is missing fields,
// so that those fields will be reset to their default values (instead of just staying unchanged).
do_on_new_scenario() ;
// load the scenario
try {
data = JSON.parse( data ) ;
@ -742,43 +756,45 @@ function unload_params_for_save()
// --------------------------------------------------------------------
function on_new_scenario( verbose )
function on_new_scenario()
{
// check if the scenario is dirty
if ( ! is_scenario_dirty() )
do_on_new_scenario() ;
do_on_new_scenario( true ) ;
else {
// yup - confirm the operation
ask( "New scenario", "<p>This scenario has been changed.<p>Do you want to reset it, and lose your changes?", {
ok: do_on_new_scenario,
ok: function() { do_on_new_scenario( true ) ; },
cancel: function() {},
} ) ;
}
}
function do_on_new_scenario() {
// load the default scenario
if ( gDefaultScenario )
do_load_scenario_data( gDefaultScenario ) ;
else {
$.getJSON( gGetDefaultScenarioUrl, function(data) {
gDefaultScenario = data ;
do_load_scenario_data( data ) ;
update_page_load_status( "default-scenario" ) ;
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the default scenario:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
return ;
} ) ;
}
// flag that we have a new scenario
gLastSavedScenarioFilename = null ;
if ( gWebChannelHandler )
gWebChannelHandler.on_new_scenario() ;
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// provide some feedback to the user
if ( verbose )
showInfoMsg( "The scenario was reset." ) ;
function do_on_new_scenario( verbose ) {
// load the default scenario
if ( gDefaultScenario )
do_load_scenario_data( gDefaultScenario ) ;
else {
$.getJSON( gGetDefaultScenarioUrl, function(data) {
gDefaultScenario = data ;
do_load_scenario_data( data ) ;
update_page_load_status( "default-scenario" ) ;
} ).fail( function( xhr, status, errorMsg ) {
showErrorMsg( "Can't get the default scenario:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
return ;
} ) ;
}
// flag that we have a new scenario
gLastSavedScenarioFilename = null ;
if ( gWebChannelHandler )
gWebChannelHandler.on_new_scenario() ;
// provide some feedback to the user
if ( verbose )
showInfoMsg( "The scenario was reset." ) ;
}
function reset_scenario()

@ -59,6 +59,11 @@
<div class='row'>
<label for="SCENARIO_LOCATION">Location:</label>
<input name="SCENARIO_LOCATION" type="text" class="param">
<select name="SCENARIO_THEATER" class="param" title="Scenario theater">
<option value="ETO">ETO</option>
<option value="PTO">PTO</option>
<option value="">other</option>
</select>
</div>
<div class='row'>
<label for="SCENARIO_DATE">Date:</label>

@ -68,9 +68,10 @@ function load_vo_listings( objs )
buf.push( "<td>", fmtval( obj.no_if ? "" : "&#10003;" ) ) ;
buf.push( "<td>", fmtval(make_crew_survival(obj)) ) ;
}
var capabilities = make_capabilities( obj, year, month, true, true ) ;
var theater = "ETO" ;
var capabilities = make_capabilities( obj, theater, year, month, true, true ) ;
buf.push( "<td>", listval(capabilities) ) ;
var capabilities = make_capabilities( obj, year, month, true, false ) ;
var capabilities = make_capabilities( obj, theater, year, month, true, false ) ;
buf.push( "<td>", listval(capabilities) ) ;
buf.push( "<td>", "<span class='val'>" + fmtval(obj.note_number) + "</span>" ) ;
buf.push( "<td>", listval(obj.notes) ) ;

@ -1,5 +1,7 @@
{
"SCENARIO_THEATER": "ETO",
"PLAYER_1": "german",
"PLAYER_1_ELR": "5",
"PLAYER_1_SAN": "2",

@ -14,7 +14,9 @@ from vasl_templates.webapp.tests.utils import \
# this table lists all parameters stored in a scenario
ALL_SCENARIO_PARAMS = {
"scenario": [
"SCENARIO_NAME", "SCENARIO_ID", "SCENARIO_LOCATION", "SCENARIO_DATE", "SCENARIO_WIDTH",
"SCENARIO_NAME", "SCENARIO_ID",
"SCENARIO_LOCATION", "SCENARIO_THEATER",
"SCENARIO_DATE", "SCENARIO_WIDTH",
"PLAYER_1", "PLAYER_1_ELR", "PLAYER_1_SAN",
"PLAYER_2", "PLAYER_2_ELR", "PLAYER_2_SAN",
"VICTORY_CONDITIONS", "VICTORY_CONDITIONS_WIDTH",
@ -62,6 +64,7 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-st
"SCENARIO_NAME": "my test scenario",
"SCENARIO_ID": "xyz123",
"SCENARIO_LOCATION": "right here",
"SCENARIO_THEATER": "PTO",
"SCENARIO_DATE": "12/31/1945",
"SCENARIO_WIDTH": "101",
"PLAYER_1": "russian", "PLAYER_1_ELR": "1", "PLAYER_1_SAN": "2",
@ -132,6 +135,7 @@ def test_scenario_persistence( webapp, webdriver ): #pylint: disable=too-many-st
data = _save_scenario()
data2 = { k: v for k,v in data.items() if v }
assert data2 == {
"SCENARIO_THEATER": "ETO",
"PLAYER_1": "german", "PLAYER_1_ELR": "5", "PLAYER_1_SAN": "2",
"PLAYER_2": "russian", "PLAYER_2_ELR": "5", "PLAYER_2_SAN": "2",
}

Loading…
Cancel
Save