diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index f7ad595..0f9d037 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -194,6 +194,8 @@ function make_snippet( $btn, params, extra_params, show_date_warnings ) key = key.substring( pos+1 ) ; } } + if ( ! ma_note && gUserSettings["hide-unavailable-ma-notes"] ) + continue ; params[ param_name ].push( extn_marker + "" + key + ":" + " " + diff --git a/vasl_templates/webapp/static/user_settings.js b/vasl_templates/webapp/static/user_settings.js index e36a4e6..934f457 100644 --- a/vasl_templates/webapp/static/user_settings.js +++ b/vasl_templates/webapp/static/user_settings.js @@ -2,6 +2,7 @@ gUserSettings = Cookies.getJSON( "user-settings" ) || {} ; USER_SETTINGS = { "date-format": "droplist", + "hide-unavailable-ma-notes": "checkbox", "include-vasl-images-in-snippets": "checkbox", "include-flags-in-snippets": "checkbox", } ; @@ -43,7 +44,7 @@ function user_settings() dialogClass: "user-settings", modal: true, width: 440, - height: 250, + height: 270, resizable: false, create: function() { init_dialog( $(this), "OK", true ) ; diff --git a/vasl_templates/webapp/templates/user-settings-dialog.html b/vasl_templates/webapp/templates/user-settings-dialog.html index 3cf20d3..d660152 100644 --- a/vasl_templates/webapp/templates/user-settings-dialog.html +++ b/vasl_templates/webapp/templates/user-settings-dialog.html @@ -7,6 +7,10 @@ +
+  Hide unavailable multi-applicable notes
+
+
Provide services to VASL
diff --git a/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json b/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json index 0e81d8f..910a66c 100644 --- a/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json +++ b/vasl_templates/webapp/tests/fixtures/data/vehicles/german.json @@ -26,6 +26,10 @@ "comments": [ "a comment", "another comment" ], "id": "ge/v:993" }, +{ "name": "missing multi-applicable note", + "notes": [ "A", "Q" ], + "id": "ge/v:994" +}, { "name": "name only", "id": "ge/v:999" } diff --git a/vasl_templates/webapp/tests/test_user_settings.py b/vasl_templates/webapp/tests/test_user_settings.py index a72c874..316d67c 100644 --- a/vasl_templates/webapp/tests/test_user_settings.py +++ b/vasl_templates/webapp/tests/test_user_settings.py @@ -11,6 +11,7 @@ from vasl_templates.webapp.tests.utils import \ 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 +from vasl_templates.webapp.tests.test_vo_notes import extract_ma_notes # --------------------------------------------------------------------- @@ -178,6 +179,58 @@ def test_date_format( webapp, webdriver ): # --------------------------------------------------------------------- +def test_hide_unavailable_ma_notes( webapp, webdriver ): + """Test showing/hiding unavailable multi-applicable notes.""" + + # initialize + init_webapp( webapp, webdriver, scenario_persistence=1, + reset = lambda ct: ct.set_vo_notes_dir( dtype="test" ) + ) + + # load the test vehicle + load_scenario( { + "PLAYER_1": "german", + "OB_VEHICLES_1": [ + { "name": "missing multi-applicable note" } + ] + } ) + select_tab( "ob1" ) + + def test_ma_notes( ma_note_q_present ): #pylint: disable=missing-docstring + expected = [ ( "A", 'German Multi-Applicable Vehicle Note "A".' ) ] + if ma_note_q_present: + expected.append( ( "Q", "Unavailable." ) ) + btn = find_child( "button[data-id='ob_vehicles_ma_notes_1']" ) + btn.click() + wait_for_clipboard( 2, expected, transform=extract_ma_notes ) + + # generate the multi-applicable notes + test_ma_notes( True ) + + # enable "hide unavailable multi-applicable notes" + select_menu_option( "user_settings" ) + elem = find_child( ".ui-dialog.user-settings input[name='hide-unavailable-ma-notes']" ) + assert not elem.is_selected() + elem.click() + click_dialog_button( "OK" ) + _check_cookies( webdriver, "hide-unavailable-ma-notes", True ) + + # generate the multi-applicable notes + test_ma_notes( False ) + + # disable "hide unavailable multi-applicable notes" + select_menu_option( "user_settings" ) + elem = find_child( ".ui-dialog.user-settings input[name='hide-unavailable-ma-notes']" ) + assert elem.is_selected() + elem.click() + click_dialog_button( "OK" ) + _check_cookies( webdriver, "hide-unavailable-ma-notes", False ) + + # generate the multi-applicable notes + test_ma_notes( True ) + +# --------------------------------------------------------------------- + def _check_cookies( webdriver, name, expected ): """Check that a user setting was stored in the cookies correctly.""" cookies = [ c for c in webdriver.get_cookies() if c["name"] == "user-settings" ] diff --git a/vasl_templates/webapp/tests/test_vo_notes.py b/vasl_templates/webapp/tests/test_vo_notes.py index 6afef69..b25ba0e 100644 --- a/vasl_templates/webapp/tests/test_vo_notes.py +++ b/vasl_templates/webapp/tests/test_vo_notes.py @@ -74,7 +74,7 @@ def test_ma_notes( webapp, webdriver ): "button.generate[data-id='ob_{}_ma_notes_{}']".format( vo_type, player_no ) ) btn.click() - wait_for_clipboard( 2, expected, transform=_extract_ma_note_keys ) + wait_for_clipboard( 2, expected, transform=extract_ma_note_keys ) # test multi-applicable notes for German vehicles do_test( 1, "german", "vehicles", @@ -175,13 +175,13 @@ def test_extra_ma_notes( webapp, webdriver ): wait_for_clipboard( 2, [ ( "A", 'Dutch Multi-Applicable Vehicle Note "A".' ), ( "Du", 'Allied Minor Multi-Applicable Vehicle Note "Du".' ), - ], transform=_extract_ma_notes ) + ], transform=extract_ma_notes ) btn = find_child( "button.generate[data-id='ob_ordnance_ma_notes_1']" ) btn.click() wait_for_clipboard( 2, [ ( "A", 'Dutch Multi-Applicable Ordnance Note "A".' ), ( "Du", 'Allied Minor Multi-Applicable Ordnance Note "Du".' ), - ], transform=_extract_ma_notes ) + ], transform=extract_ma_notes ) # test Axis Minor vehicles/ordnance select_tab( "ob2" ) @@ -190,13 +190,13 @@ def test_extra_ma_notes( webapp, webdriver ): wait_for_clipboard( 2, [ ( "A", 'Romanian Multi-Applicable Vehicle Note "A".' ), ( "Ro", 'Axis Minor Multi-Applicable Vehicle Note "Ro".' ), - ], transform=_extract_ma_notes ) + ], transform=extract_ma_notes ) btn = find_child( "button.generate[data-id='ob_ordnance_ma_notes_2']" ) btn.click() wait_for_clipboard( 2, [ ( "A", 'Romanian Multi-Applicable Ordnance Note "A".' ), ( "Ro", 'Axis Minor Multi-Applicable Ordnance Note "Ro".' ), - ], transform=_extract_ma_notes ) + ], transform=extract_ma_notes ) # test Landing Craft load_scenario( { @@ -214,7 +214,7 @@ def test_extra_ma_notes( webapp, webdriver ): ( "Y", "Unavailable." ), "Landing Craft", ( "A", 'Landing Craft Multi-Applicable Note "A".' ), - ], transform=_extract_ma_notes ) + ], transform=extract_ma_notes ) select_tab( "ob2" ) btn = find_child( "button.generate[data-id='ob_vehicles_ma_notes_2']" ) btn.click() @@ -222,7 +222,7 @@ def test_extra_ma_notes( webapp, webdriver ): ( "A", 'Japanese Multi-Applicable Vehicle Note "A".' ), "Landing Craft", ( "B", 'Landing Craft Multi-Applicable Note "B".' ), - ], transform=_extract_ma_notes ) + ], transform=extract_ma_notes ) # --------------------------------------------------------------------- @@ -343,10 +343,10 @@ def test_special_cases( webapp, webdriver ): select_tab( "ob1" ) btn = find_child( "button.generate[data-id='ob_ordnance_ma_notes_1']" ) btn.click() - wait_for_clipboard( 2, ["N","R"], transform=_extract_ma_note_keys ) + wait_for_clipboard( 2, ["N","R"], transform=extract_ma_note_keys ) btn = find_child( "button.generate[data-id='ob_vehicles_ma_notes_1']" ) btn.click() - wait_for_clipboard( 2, ["N","R"], transform=_extract_ma_note_keys ) + wait_for_clipboard( 2, ["N","R"], transform=extract_ma_note_keys ) # --------------------------------------------------------------------- @@ -511,12 +511,12 @@ def _parse_report( buf ): # --------------------------------------------------------------------- -def _extract_ma_note_keys( snippet ): +def extract_ma_note_keys( snippet ): """Extract the multi-applicable note keys in a snippet.""" matches = re.finditer( r"(.+):", snippet ) return [ mo.group(1) for mo in matches ] -def _extract_ma_notes( snippet ): +def extract_ma_notes( snippet ): """Extract the multi-applicable notes in a snippet.""" mo = re.search( "=== ([^=]+) ===", snippet ) if mo: