diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index 62d7e2a..55729a6 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -225,6 +225,23 @@ function make_snippet( $btn, params, extra_params, show_date_warnings ) if ( data.vo_note.substr( 0, 7 ) === "http://" ) { // the vehicle/ordnance note is an image - just include it directly params.VO_NOTE_HTML = '' ; + // FUDGE! People are asking to be able to load Chapter H images from an online server. + // The code that figures out how to generate Chapter H content is horrendously complicated :-/, + // and letting the user point to the source content via a base URL or file system directory + // would make it even worse :-/ + // We could add a debug setting that specifies a base URL, and use it when we generate the image URL + // at the end of get_vo_note(), but that means that the location of the Chapter H content would be + // configurable in the UI, but ignored :-/ + // Parsing the generated image URL like this, and then getting the user to change their template + // to use this new parameter, is a bit hacky, but (1) it's more likely to get the path right, + // (2) is less likely to break existing functionality, and (3) we don't really want to be encouraging + // people to put their Chapter H content up online, anyway :-/ + var match = data.vo_note.match( /^https?:\/\/.*?\/(.*?)\/(.*?)\/note\/(.*)/ ) ; + if ( match ) { + params.VO_NOTE_IMAGE_URL_PATH = match[2] === "landing-craft" ? + match[2] + "/" + match[3] : + match[2] + "/" + match[1] + "/" + match[3] ; + } } else { // the vehicle/ordnance is HTML - check if we should show it as HTML or as an image if ( gUserSettings["vo-notes-as-images"] ) { diff --git a/vasl_templates/webapp/tests/fixtures/data/vehicles/landing-craft.json b/vasl_templates/webapp/tests/fixtures/data/vehicles/landing-craft.json index f042288..344d8ef 100644 --- a/vasl_templates/webapp/tests/fixtures/data/vehicles/landing-craft.json +++ b/vasl_templates/webapp/tests/fixtures/data/vehicles/landing-craft.json @@ -11,6 +11,11 @@ "notes": [ "B" ], "id": "sh/v:007", "gpid": 417 +}, +{ "name": "Shohatsu", + "note_number": "3", + "id": "sh/v:008", + "gpid": 419 } ] diff --git a/vasl_templates/webapp/tests/fixtures/template-packs/vo-note-image-url-path/ob_vo_note.j2 b/vasl_templates/webapp/tests/fixtures/template-packs/vo-note-image-url-path/ob_vo_note.j2 new file mode 100644 index 0000000..5c8d7ed --- /dev/null +++ b/vasl_templates/webapp/tests/fixtures/template-packs/vo-note-image-url-path/ob_vo_note.j2 @@ -0,0 +1 @@ +VO_NOTE_IMAGE_URL_PATH = {{VO_NOTE_IMAGE_URL_PATH}} diff --git a/vasl_templates/webapp/tests/fixtures/vo-notes/landing-craft/3.png b/vasl_templates/webapp/tests/fixtures/vo-notes/landing-craft/3.png new file mode 100644 index 0000000..62b2678 Binary files /dev/null and b/vasl_templates/webapp/tests/fixtures/vo-notes/landing-craft/3.png differ diff --git a/vasl_templates/webapp/tests/test_vo_notes.py b/vasl_templates/webapp/tests/test_vo_notes.py index 9a0d489..0317fc9 100644 --- a/vasl_templates/webapp/tests/test_vo_notes.py +++ b/vasl_templates/webapp/tests/test_vo_notes.py @@ -335,6 +335,55 @@ def test_landing_craft_notes( webapp, webdriver ): # --------------------------------------------------------------------- +def test_vo_note_image_url_path( webapp, webdriver ): + """Test generating the VO_NOTE_IMAGE_URL_PATH parameter.""" + + # initialize + webapp.control_tests \ + .set_data_dir( "{TEST}" ) \ + .set_vo_notes_dir( "{TEST}" ) \ + .set_default_template_pack( "vo-note-image-url-path/" ) + init_webapp( webapp, webdriver, scenario_persistence=1 ) + + def extract_url_path( clipboard ): + mo = re.search( r"^VO_NOTE_IMAGE_URL_PATH = (.+)", clipboard ) + return mo.group( 1 ) + def check_url_path( player_no, vo_type, entry_no, expected): + select_tab( "ob{}".format( player_no ) ) + sortable = find_child( "#ob_{}-sortable_{}".format( vo_type, player_no ) ) + elems = find_children( "li", sortable ) + elem = elems[ entry_no ] + btn = find_child( "img.snippet", elem ) + btn.click() + wait_for_clipboard( 2, expected, transform=extract_url_path ) + + # test normal vehicles/ordnance + load_scenario( { + "PLAYER_1": "german", "PLAYER_2": "russian", + "OB_VEHICLES_1": [ { "name": "a german vehicle" } ], + "OB_ORDNANCE_2": [ { "name": "a russian ordnance" } ], + } ) + check_url_path( 1, "vehicles", 0, "german/vehicles/1" ) + check_url_path( 2, "ordnance", 0, "russian/ordnance/1" ) + + # test Allied/Axis Minor common vehicles/ordnance + load_scenario( { + "PLAYER_1": "dutch", "PLAYER_2": "romanian", + "OB_ORDNANCE_1": [ { "name": "common allied minor ordnance" } ], + "OB_VEHICLES_2": [ { "name": "common axis minor vehicle" } ], + } ) + check_url_path( 1, "ordnance", 0, "allied-minor/ordnance/102" ) + check_url_path( 2, "vehicles", 0, "axis-minor/vehicles/103" ) + + # test landing craft + load_scenario( { + "PLAYER_1": "japanese", + "OB_VEHICLES_1": [ { "name": "Shohatsu" } ], + } ) + check_url_path( 1, "vehicles", 0, "landing-craft/3" ) + +# --------------------------------------------------------------------- + def test_vo_notes_image_cache( webapp, webdriver ): """Test the vehicle/ordnance notes image cache."""