Changed how where scenario images are loaded from is configured.

master
Pacman Ghost 5 years ago
parent 5d2e01ec2e
commit 13f6418fb9
  1. 1
      vasl_templates/webapp/static/css/user-settings-dialog.css
  2. 2
      vasl_templates/webapp/static/snippets.js
  3. 31
      vasl_templates/webapp/static/user_settings.js
  4. 2
      vasl_templates/webapp/static/utils.js
  5. 4
      vasl_templates/webapp/static/vo.js
  6. 13
      vasl_templates/webapp/templates/user-settings-dialog.html
  7. 12
      vasl_templates/webapp/tests/test_online_images.py
  8. 24
      vasl_templates/webapp/tests/test_user_settings.py

@ -2,6 +2,7 @@
.ui-dialog.user-settings .ui-dialog-buttonpane { border: none ; margin-top: 0 !important ; padding-top: 0 !important ; }
.ui-dialog.user-settings fieldset { margin: 0.5em 0 0 0 ; padding-top: 0.5em ; border-radius: 0 ; }
.ui-dialog.user-settings .select2 { margin-top: -4px ; }
.ui-dialog.user-settings img.need-localhost { display: inline-block ; height: 0.75em ; }
.ui-dialog.user-settings div.need-localhost { float: left ; width: 290px ; font-size: 80% ; font-style: italic ; color: #c02020 ; }

@ -125,7 +125,7 @@ function make_snippet( $btn, params, extra_params, show_date_warnings )
var snippet_save_name = null ;
// add simple parameters
params.IMAGES_BASE_URL = gUserSettings["use-online-images"] ?
params.IMAGES_BASE_URL = gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET ?
gAppConfig.ONLINE_IMAGES_URL_BASE :
APP_URL_BASE + gImagesBaseUrl ;
if ( gUserSettings["custom-list-bullets"] )

@ -1,8 +1,11 @@
gUserSettings = Cookies.getJSON( "user-settings" ) || {} ;
SCENARIO_IMAGES_SOURCE_THIS_PROGRAM = 1 ;
SCENARIO_IMAGES_SOURCE_INTERNET = 2 ;
gUserSettings = Cookies.getJSON( "user-settings" ) || { "scenario-images-source": SCENARIO_IMAGES_SOURCE_THIS_PROGRAM } ;
USER_SETTINGS = {
"date-format": "droplist",
"use-online-images": "checkbox",
"scenario-images-source": "droplist",
"hide-unavailable-ma-notes": "checkbox",
"include-vasl-images-in-snippets": "checkbox",
"include-flags-in-snippets": "checkbox",
@ -37,15 +40,15 @@ function user_settings()
function update_ui() {
// update the UI
var use_online_images = $( ".ui-dialog.user-settings input[name='use-online-images']" ).prop( "checked" ) ;
var images_source = $( ".ui-dialog.user-settings select[name='scenario-images-source']" ).val() ;
$( ".ui-dialog.user-settings img.need-localhost.sometimes" ).css(
"display", use_online_images ? "none" : "inline-block"
"display", (images_source == SCENARIO_IMAGES_SOURCE_THIS_PROGRAM) ? "inline-block" : "none"
) ;
// update the UI
var rc = false ;
$( ".ui-dialog.user-settings input.need-localhost:checked" ).each( function() {
if ( $(this).hasClass( "sometimes" ) ) {
if ( ! use_online_images )
if ( images_source == SCENARIO_IMAGES_SOURCE_THIS_PROGRAM )
rc = true ;
}
else
@ -68,8 +71,8 @@ function user_settings()
title: "User settings",
dialogClass: "user-settings",
modal: true,
width: 440,
height: 305,
width: 450,
height: 290,
resizable: false,
create: function() {
init_dialog( $(this), "OK", true ) ;
@ -78,26 +81,30 @@ function user_settings()
var $img = $( "<img src='" + gImagesBaseUrl+"/warning.gif" + "'class='need-localhost'>" ) ;
if ( $(this).hasClass( "sometimes" ) )
$img.addClass( "sometimes" ) ;
$img.attr( "title", "If you turn this option on, this program must be running\nbefore you load the scenario into VASSAL." ) ;
$img.attr( "title", "If you turn this option on, this program must be running\nbefore you load scenarios into VASSAL." ) ;
$(this).next().before( $img ) ;
} ) ;
var $btn_pane = $(".ui-dialog.user-settings .ui-dialog-buttonpane") ;
$btn_pane.prepend( $(
"<div class='need-localhost'><img src='" + gImagesBaseUrl+"/warning.gif" + "'>" +
"This program must be running before<br>you load the scenario into VASSAL.</div>"
"This program must be running before<br>you load scenarios into VASSAL.</div>"
) ) ;
// install handlers to keep the UI updated
for ( var name in USER_SETTINGS ) {
if ( USER_SETTINGS[name] === "checkbox" ) {
var $elem = $( ".ui-dialog.user-settings [name='" + name + "']" ) ;
var $elem = $( ".ui-dialog.user-settings [name='" + name + "']" ) ;
if ( USER_SETTINGS[name] === "checkbox" )
$elem.click( update_ui ) ;
}
else if ( USER_SETTINGS[name] === "droplist" )
$elem.change( update_ui ) ;
}
},
open: function() {
on_dialog_open( $(this) ) ;
// load the current user settings
load_settings( $(this) ) ;
// FUDGE! Doing this in the "open" handler breaks loading the scenario-images-source droplist :shrug:
// FIXME! Using select2 breaks Ctrl-Enter handling :-(
$(this).find( "select" ).select2( { minimumResultsForSearch: -1 } ) ;
},
buttons: {
OK: function() {

@ -34,7 +34,7 @@ function get_player_colors_for_element( $elem )
}
function make_player_flag_url( nat, for_snippet ) {
if ( for_snippet && gUserSettings["use-online-images"] )
if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET )
return gAppConfig.ONLINE_IMAGES_URL_BASE + "/flags/" + nat + ".png" ;
else
return APP_URL_BASE + "/flags/" + nat ;

@ -391,7 +391,7 @@ function get_vo_image_url( vo_entry, vo_image_id, allow_missing_image, for_snipp
gpid = $.isArray( vo_entry.gpid ) ? vo_entry.gpid[0] : vo_entry.gpid ;
}
if ( gpid ) {
if ( for_snippet && gUserSettings["use-online-images"] )
if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET )
return make_online_counter_image_url( gpid, index ) ;
else
return make_local_counter_image_url( gpid, index ) ;
@ -399,7 +399,7 @@ function get_vo_image_url( vo_entry, vo_image_id, allow_missing_image, for_snipp
// couldn't find an image
if ( allow_missing_image ) {
if ( for_snippet && gUserSettings["use-online-images"] )
if ( for_snippet && gUserSettings["scenario-images-source"] == SCENARIO_IMAGES_SOURCE_INTERNET )
return gAppConfig.ONLINE_IMAGES_URL_BASE + "/missing-image.png" ;
else
return gImagesBaseUrl + "/missing-image.png" ;

@ -1,7 +1,7 @@
<div id="user-settings" style="display:none;">
<label for="">Date format:</label>
<select name="date-format">
<select name="date-format" style="width:9em;">
<option value="mm/dd/yy">MM/DD/YYYY</option>
<option value="dd/mm/yy">DD/MM/YYYY</option>
<option value="yy-mm-dd">YYYY-MM-DD</option>
@ -11,12 +11,15 @@
</div>
<fieldset> <legend> Images in scenarios </legend>
<input type="checkbox" name="use-online-images"> Get images from the internet <br>
<div style="height:0.25em;"></div>
Get images from:
<select name="scenario-images-source" style="width:8em;">
<option value="1">this program</option>
<option value="2">the internet</option>
</select> <br>
<input type="checkbox" name="include-vasl-images-in-snippets" class="need-localhost sometimes"> Include VASL counter images in snippets <br>
<input type="checkbox" name="include-flags-in-snippets" class="need-localhost sometimes"> Include flags in snippets <br>
<input type="checkbox" name="include-flags-in-snippets" class="need-localhost sometimes"> Include player flags in snippets <br>
<input type="checkbox" name="custom-list-bullets" class="need-localhost sometimes"> Use custom list bullets <br>
<div style="height:0.25em;"></div>
<div style="height:0.5em;"></div>
<input type="checkbox" name="vo-notes-as-images" class="need-localhost"> Show Chapter H vehicle/ordnance notes as images <br>
</fieldset>

@ -9,6 +9,10 @@ from vasl_templates.webapp.tests.utils import init_webapp, select_tab, \
from vasl_templates.webapp.tests.test_user_settings import set_user_settings
from vasl_templates.webapp.tests.test_scenario_persistence import load_scenario
# nb: these are taken from user_settings.js
SCENARIO_IMAGES_SOURCE_THIS_PROGRAM = 1
SCENARIO_IMAGES_SOURCE_INTERNET = 2
# ---------------------------------------------------------------------
def test_online_images( webapp, webdriver ):
@ -37,12 +41,12 @@ def test_online_images( webapp, webdriver ):
def do_test( snippet_id, expected1, expected2 ): #pylint: disable=missing-docstring
# generate the snippet with online images enabled
set_user_settings( { "use-online-images": True } )
set_user_settings( { "scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET } )
btn = find_child( "button[data-id='{}']".format( snippet_id ) )
btn.click()
wait_for_clipboard( 2, expected1 )
# generate the snippet with online images disabled
set_user_settings( { "use-online-images": False } )
set_user_settings( { "scenario-images-source": SCENARIO_IMAGES_SOURCE_THIS_PROGRAM } )
btn.click()
wait_for_clipboard( 2, expected2 )
@ -86,7 +90,7 @@ def test_multiple_images( webapp, webdriver ):
# configure the user settings
set_user_settings( {
"use-online-images": True,
"scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET,
"include-vasl-images-in-snippets": True,
} )
@ -143,7 +147,7 @@ def test_extensions( webapp, webdriver ):
# configure the user settings
set_user_settings( {
"use-online-images": True,
"scenario-images-source": SCENARIO_IMAGES_SOURCE_INTERNET,
"include-vasl-images-in-snippets": True,
} )

@ -8,7 +8,7 @@ from selenium.webdriver.common.keys import Keys
from vasl_templates.webapp.tests.utils import \
init_webapp, find_child, find_children, wait_for_clipboard, \
select_tab, select_menu_option, set_player, click_dialog_button, add_simple_note
select_tab, select_menu_option, select_droplist_val, set_player, click_dialog_button, add_simple_note
from vasl_templates.webapp.tests.test_vehicles_ordnance import add_vo
from vasl_templates.webapp.tests.test_scenario_persistence import save_scenario, load_scenario
from vasl_templates.webapp.tests.test_template_packs import upload_template_pack_file
@ -149,7 +149,7 @@ def test_date_format( webapp, webdriver ):
# change the date format to YYYY-MM-DD
select_menu_option( "user_settings" )
date_format_sel = Select( find_child( ".ui-dialog.user-settings select[name='date-format']" ) )
date_format_sel.select_by_visible_text( "YYYY-MM-DD" )
select_droplist_val( date_format_sel, "yy-mm-dd" )
click_dialog_button( "OK" )
_check_cookies( webdriver, "date-format", "yy-mm-dd" )
@ -160,7 +160,7 @@ def test_date_format( webapp, webdriver ):
# clear the scenario date, set the date format to DD-MM-YYY
set_scenario_date( "" )
select_menu_option( "user_settings" )
date_format_sel.select_by_visible_text( "DD/MM/YYYY" )
select_droplist_val( date_format_sel, "dd/mm/yy" )
click_dialog_button( "OK" )
_check_cookies( webdriver, "date-format", "dd/mm/yy" )
@ -173,11 +173,6 @@ def test_date_format( webapp, webdriver ):
check_scenario_date( (1,2,1940) )
assert scenario_date.get_attribute( "value" ) == "02/01/1940"
# restore the date format back to default (for the rest of the tests :-/)
select_menu_option( "user_settings" )
date_format_sel.select_by_visible_text( "MM/DD/YYYY" )
click_dialog_button( "OK" )
# ---------------------------------------------------------------------
def test_hide_unavailable_ma_notes( webapp, webdriver ):
@ -288,10 +283,15 @@ def set_user_settings( opts ):
"""Configure the user settings."""
select_menu_option( "user_settings" )
for key,val in opts.items():
assert isinstance( val, bool ) # nb: we currently only support checkboxes
elem = find_child( ".ui-dialog.user-settings input[name='{}']".format( key ) )
if (val and not elem.is_selected()) or (not val and elem.is_selected()):
elem.click()
if isinstance( val, bool ):
elem = find_child( ".ui-dialog.user-settings input[name='{}']".format( key ) )
if (val and not elem.is_selected()) or (not val and elem.is_selected()):
elem.click()
elif isinstance( val, int ):
elem = find_child( ".ui-dialog.user-settings select[name='{}']".format( key ) )
select_droplist_val( Select(elem), val )
else:
assert False
click_dialog_button( "OK" )
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Loading…
Cancel
Save