Made a new VO_NOTE_IMAGE_URL_PATH parameter available to templates.

master
Pacman Ghost 2 years ago
parent 114db959bd
commit dad7dab770
  1. 17
      vasl_templates/webapp/static/snippets.js
  2. 5
      vasl_templates/webapp/tests/fixtures/data/vehicles/landing-craft.json
  3. 1
      vasl_templates/webapp/tests/fixtures/template-packs/vo-note-image-url-path/ob_vo_note.j2
  4. BIN
      vasl_templates/webapp/tests/fixtures/vo-notes/landing-craft/3.png
  5. 49
      vasl_templates/webapp/tests/test_vo_notes.py

@ -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 = '<img src="' + data.vo_note + '">' ;
// 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"] ) {

@ -11,6 +11,11 @@
"notes": [ "B" ],
"id": "sh/v:007",
"gpid": 417
},
{ "name": "Shohatsu",
"note_number": "3",
"id": "sh/v:008",
"gpid": 419
}
]

@ -0,0 +1 @@
VO_NOTE_IMAGE_URL_PATH = {{VO_NOTE_IMAGE_URL_PATH}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -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."""

Loading…
Cancel
Save