From dad7dab770500011002e73498f99a3a0b81f2045 Mon Sep 17 00:00:00 2001 From: Taka Date: Thu, 17 Mar 2022 18:57:06 +1100 Subject: [PATCH] Made a new VO_NOTE_IMAGE_URL_PATH parameter available to templates. --- vasl_templates/webapp/static/snippets.js | 17 ++++++ .../fixtures/data/vehicles/landing-craft.json | 5 ++ .../vo-note-image-url-path/ob_vo_note.j2 | 1 + .../fixtures/vo-notes/landing-craft/3.png | Bin 0 -> 1339 bytes vasl_templates/webapp/tests/test_vo_notes.py | 49 ++++++++++++++++++ 5 files changed, 72 insertions(+) create mode 100644 vasl_templates/webapp/tests/fixtures/template-packs/vo-note-image-url-path/ob_vo_note.j2 create mode 100644 vasl_templates/webapp/tests/fixtures/vo-notes/landing-craft/3.png 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 0000000000000000000000000000000000000000..62b26786bb3c169f871ad6e5fa6f6712e0ee5a5f GIT binary patch literal 1339 zcmXxkeN>WH90%}6NRUTB)TfC;_T)=Fvm$V~sWiuHVlIR7nC#J_fLAldhyTX}>WmD9N(a2|-D5`$=ZYmNb=wrc(I;0I z0KhCwWKE24-9rO(4m)_f-w6iPc}M3NPeF_&SaP)_k~9^~#P zUqlgI=%mtwQVnxH$}?17BVyi2TmqZNy*g>)E7BZUmiwn+=9R>!ut@NHmmaeUf`~+R zS=)gWnZ+#t}>q1QNq3Pmo0F zL3o`MVRiGGYbEjqV9e0rW+Zt;fPTazI1#B~4(juljTK(-34y>^Vk10=tYak`Q))FA zQ@qA$1)M?;%0|S8>B#%q9ON#5x|@-5rbAzB4k8Icx*HH5mc!6i7&KeJ?#@KYS%C)O zj<7xvj3}$GH#Ihrud+`rS-g0sEve34T2c~I(Q~h-y}f;^r>AGZwTO~(#7qbBk|}wd z3Y)U}oI9|0-@fUycDp@{gdGiZNc_U%CMPFz7cW}$j-GS5uP^4!9_lIBn7z8ItLy3V zL#wvr=Ei)<;cT6h-L7h0@%|X8M!*^DI?NzX9Qw0j6SN!dq-Pwmny~)&ex2tng1RHC zVw6ZKcYcdLp6~58em6=8f$N zz|^KOz7@!@{Gt1I^E)v4f?JiIV3Y@*n1CFFYnaWJGQGwzn#ad<_!|R4BTci2%PTB! zIrFH*pcgwVTmmM@KbQ?hivyW_D|&^5UZyOo-S1RD_?r2Dgrqq0%KPY5% z)V6_Es!Y0JmbCa8a@m03NSA(s&Ag%)b4{uJ)}iaoim0+^#K|F}|tc)zF9oojHca