From 13f6418fb9e84c0119b625c15c9e8e9bdb1eba74 Mon Sep 17 00:00:00 2001 From: Taka Date: Mon, 6 May 2019 08:58:31 +0000 Subject: [PATCH] Changed how where scenario images are loaded from is configured. --- .../static/css/user-settings-dialog.css | 1 + vasl_templates/webapp/static/snippets.js | 2 +- vasl_templates/webapp/static/user_settings.js | 31 ++++++++++++------- vasl_templates/webapp/static/utils.js | 2 +- vasl_templates/webapp/static/vo.js | 4 +-- .../templates/user-settings-dialog.html | 13 +++++--- .../webapp/tests/test_online_images.py | 12 ++++--- .../webapp/tests/test_user_settings.py | 24 +++++++------- 8 files changed, 52 insertions(+), 37 deletions(-) diff --git a/vasl_templates/webapp/static/css/user-settings-dialog.css b/vasl_templates/webapp/static/css/user-settings-dialog.css index b7f1e49..674e860 100644 --- a/vasl_templates/webapp/static/css/user-settings-dialog.css +++ b/vasl_templates/webapp/static/css/user-settings-dialog.css @@ -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 ; } diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 2157bd0..9484f9f 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -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"] ) diff --git a/vasl_templates/webapp/static/user_settings.js b/vasl_templates/webapp/static/user_settings.js index 2086bbf..a08f80a 100644 --- a/vasl_templates/webapp/static/user_settings.js +++ b/vasl_templates/webapp/static/user_settings.js @@ -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 = $( "" ) ; 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( $( "
" + - "This program must be running before
you load the scenario into VASSAL.
" + "This program must be running before
you load scenarios into VASSAL." ) ) ; // 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() { diff --git a/vasl_templates/webapp/static/utils.js b/vasl_templates/webapp/static/utils.js index 3e73efc..111ced8 100644 --- a/vasl_templates/webapp/static/utils.js +++ b/vasl_templates/webapp/static/utils.js @@ -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 ; diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js index 386095c..ed6cbcb 100644 --- a/vasl_templates/webapp/static/vo.js +++ b/vasl_templates/webapp/static/vo.js @@ -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" ; diff --git a/vasl_templates/webapp/templates/user-settings-dialog.html b/vasl_templates/webapp/templates/user-settings-dialog.html index c5681c9..845fdbc 100644 --- a/vasl_templates/webapp/templates/user-settings-dialog.html +++ b/vasl_templates/webapp/templates/user-settings-dialog.html @@ -1,7 +1,7 @@
Images in scenarios - Get images from the internet
-
+ Get images from: +
Include VASL counter images in snippets
- Include flags in snippets
+ Include player flags in snippets
Use custom list bullets
-
+
Show Chapter H vehicle/ordnance notes as images
diff --git a/vasl_templates/webapp/tests/test_online_images.py b/vasl_templates/webapp/tests/test_online_images.py index a4b8d03..510612f 100644 --- a/vasl_templates/webapp/tests/test_online_images.py +++ b/vasl_templates/webapp/tests/test_online_images.py @@ -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, } ) diff --git a/vasl_templates/webapp/tests/test_user_settings.py b/vasl_templates/webapp/tests/test_user_settings.py index 04dbba8..6473e20 100644 --- a/vasl_templates/webapp/tests/test_user_settings.py +++ b/vasl_templates/webapp/tests/test_user_settings.py @@ -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" ) # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -