Updated the tests to recognize extension and Allied/Axis Minor common mutli-applicable notes.

master
Pacman Ghost 5 years ago
parent 5c8b077142
commit 0382c5756b
  1. 2
      vasl_templates/webapp/data/extensions/bfp-cobra.json
  2. 77
      vasl_templates/webapp/static/snippets.js
  3. 32
      vasl_templates/webapp/templates/vo-notes-report.html
  4. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1940.txt
  5. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1941.txt
  6. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1942.txt
  7. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1943.txt
  8. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1944.txt
  9. 2
      vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1945.txt

@ -169,7 +169,7 @@
"CS#": 6,
"capabilities2": { "A": [ [4,"A4"], [5,5], "\u2020<sup>2</sup>" ], "s": [ [5,5] ], "sM": 8 },
"note_number": "16\u2020",
"notes": [ "US A\u2020<sup>2</sup>", "US F\u2020<sup>1</sup>", "US G", "US <s>P</s>", "Y", "C" ],
"notes": [ "US A\u2020<sup>2</sup>", "US F\u2020<sup>1</sup>", "US G", "US <s>P</s>", "US Y", "C" ],
"id": "am/v:876",
"gpid": "adf:186"
}

@ -177,34 +177,12 @@ function make_snippet( $btn, params, extra_params, show_date_warnings )
// generate snippets for multi-applicable vehicle/ordnance notes
var pos ;
function redirect_ma_note( target, vo_type ) {
pos = target.indexOf( " " ) ;
var nat_redirect = BFP_MA_NOTE_REDIRECTS[ target.substring( 0, pos ) ] ;
if ( nat_redirect )
return get_ma_notes_for_nat( nat_redirect, vo_type )[ target.substring(pos+1 ) ] ;
return null ;
}
function add_ma_notes( ma_notes, keys, param_name, nat, vo_type ) {
if ( ! keys )
return ;
params[ param_name ] = [] ;
for ( var i=0 ; i < keys.length ; ++i ) {
var ma_note = null ;
if ( keys[i].substring( 0, 4 ) == "adf:" )
ma_note = redirect_ma_note( keys[i].substring(4), vo_type ) ;
else if ( keys[i].substring( 0, 6 ) == "cobra:" )
ma_note = redirect_ma_note( keys[i].substring(6), vo_type ) ;
else if ( keys[i].substring( 0, 4 ) == "pif:" )
ma_note = redirect_ma_note( keys[i].substring(4), vo_type ) ;
if ( ! ma_note )
ma_note = ma_notes[ keys[i] ] ;
if ( ! ma_note ) {
// couldn't find anything - if we're allied/axis minor, try the common notes
if ( gTemplatePack.nationalities[ nat ].type === "allied-minor" )
ma_note = get_ma_notes_for_nat( "allied-minor", vo_type )[ keys[i] ] ;
else if ( gTemplatePack.nationalities[ nat ].type === "axis-minor" )
ma_note = get_ma_notes_for_nat( "axis-minor", vo_type )[ keys[i] ] ;
}
var ma_note = get_ma_note( nat, vo_type, keys[i] ) ;
var key = keys[i] ;
var extn_marker = "" ;
if ( nat === "italian" && vo_type === "ordnance" && keys[i] === "R" )
@ -243,13 +221,6 @@ function make_snippet( $btn, params, extra_params, show_date_warnings )
}
}
}
function get_ma_notes_for_nat( nat, vo_type ) {
if ( nat === "landing-craft" && nat in gVehicleOrdnanceNotes.vehicles )
return gVehicleOrdnanceNotes.vehicles[ nat ][ "multi-applicable" ] ;
if ( vo_type in gVehicleOrdnanceNotes && nat in gVehicleOrdnanceNotes[vo_type] )
return gVehicleOrdnanceNotes[ vo_type ][ nat ][ "multi-applicable" ] ;
return {} ;
}
get_ma_notes( "vehicles", 1, "OB_VEHICLES_MA_NOTES_1" ) ;
get_ma_notes( "ordnance", 1, "OB_ORDNANCE_MA_NOTES_1" ) ;
get_ma_notes( "vehicles", 2, "OB_VEHICLES_MA_NOTES_2" ) ;
@ -568,6 +539,52 @@ function sort_ma_notes_keys( nat, keys )
return keys ;
}
function get_ma_note( nat, vo_type, key )
{
var ma_notes ;
function redirect_ma_note( target, vo_type ) {
pos = target.indexOf( " " ) ;
var nat_redirect = BFP_MA_NOTE_REDIRECTS[ target.substring( 0, pos ) ] ;
if ( nat_redirect ) {
ma_notes = get_ma_notes_for_nat( nat_redirect, vo_type ) ;
return ma_notes[ target.substring( pos+1 ) ] ;
}
return null ;
}
// check for redirected notes
var ma_note = null ;
var pos = key.indexOf( ":" ) ;
if ( pos !== -1 )
ma_note = redirect_ma_note( key.substring(pos+1), vo_type ) ;
if ( ! ma_note ) {
// look for a normal note
ma_notes = get_ma_notes_for_nat( nat, vo_type ) ;
ma_note = ma_notes[ key ] ;
}
if ( ! ma_note ) {
// still couldn't find anything - if we're Allied/Axis Minor, try the common notes
if ( gTemplatePack.nationalities[ nat ].type === "allied-minor" )
ma_note = get_ma_notes_for_nat( "allied-minor", vo_type )[ key ] ;
else if ( gTemplatePack.nationalities[ nat ].type === "axis-minor" )
ma_note = get_ma_notes_for_nat( "axis-minor", vo_type )[ key ] ;
}
return ma_note ;
}
function get_ma_notes_for_nat( nat, vo_type )
{
// get the multi-applicable vehicle/ordnance notes for the specified nationality
if ( nat === "landing-craft" && nat in gVehicleOrdnanceNotes.vehicles )
return gVehicleOrdnanceNotes.vehicles[ "landing-craft" ][ "multi-applicable" ] ;
if ( vo_type in gVehicleOrdnanceNotes && nat in gVehicleOrdnanceNotes[vo_type] )
return gVehicleOrdnanceNotes[ vo_type ][ nat ][ "multi-applicable" ] ;
return {} ;
}
function _make_snippet_image_filename( snippet )
{
// generate the save filename for a generated snippet image

@ -4,6 +4,7 @@
<script>
var nat = "{{NATIONALITY}}" ;
var vo_type = "{{VO_TYPE}}" ;
var gTemplatePack = {} ;
var gVehicleOrdnanceNotes = {} ;
</script>
@ -30,15 +31,23 @@ td { padding: 0.2em 0.5em ; }
$(document).ready( function () {
// initialize
var vo_notes, vo_entries ;
var on_load_counter = 2 ;
var vo_entries ;
var on_load_counter = 3 ;
function on_data_loaded() {
if ( --on_load_counter == 0 ) {
// everything's loaded - generate the report
load_vo_notes( vo_notes, vo_entries ) ;
load_vo_notes( vo_entries ) ;
}
}
// get the template pack
$.getJSON( "{{url_for('get_template_pack')}}", function(data) {
gTemplatePack = data ;
on_data_loaded() ;
} ).fail( function( xhr, status, errorMsg ) {
alert( "Can't get the template pack:\n\n" + errorMsg ) ;
} ) ;
// get the vehicle/ordnance listings
var url ;
if ( vo_type === "vehicles" )
@ -58,17 +67,17 @@ $(document).ready( function () {
else
url = "{{url_for('get_ordnance_notes')}}" ;
$.getJSON( url, function( data ) {
gVehicleOrdnanceNotes[vo_type] = data ;
vo_notes = data[ nat ] ;
gVehicleOrdnanceNotes[ vo_type ] = data ;
on_data_loaded() ;
} ).fail( function( xhr, status, errorMsg ) {
alert( "Can't get the vehicle/ordnance notes:\n\n" + errorMsg ) ;
} ) ;
} ) ;
function load_vo_notes( vo_notes, vo_entries )
function load_vo_notes( vo_entries )
{
var $results = $("#results") ;
var vo_notes = gVehicleOrdnanceNotes[ vo_type ][ nat ] ;
if ( !vo_notes && !vo_entries ) {
$results.html( "No results." ).show() ;
return ;
@ -136,7 +145,10 @@ function load_vo_notes( vo_notes, vo_entries )
for ( var i=0 ; i < keys.length ; ++i ) {
if ( keys[i] === "multi-applicable" )
continue ;
buf.push( "<tr>", "<td class='key'>", keys[i]+":", "<td>", vo_notes[keys[i]] ) ;
buf.push( "<tr>",
"<td class='key'>", keys[i]+":",
"<td>", vo_notes[keys[i]]
) ;
}
buf.push( "</table>" ) ;
}
@ -182,21 +194,21 @@ function load_vo_notes( vo_notes, vo_entries )
for ( var j=0 ; j < result[4].length ; ++j )
unrecognized.push( result[4][j][1] ) ;
buf.push( "<td class='unrecognized'>", unrecognized ) ;
buf.push( "<td class='missing'>", find_missing_ma_notes(ma_notes,keys) ) ;
buf.push( "<td class='missing'>", find_missing_ma_notes(keys) ) ;
}
buf.push( "</table>" ) ;
$results.html( buf.join("") ).show() ;
}
function find_missing_ma_notes( ma_notes, keys )
function find_missing_ma_notes( keys )
{
// find Multi-Applicable Notes that are referenced but not defined
if ( ! keys )
return null ;
var missing_keys = [] ;
for ( var i=0 ; i < keys.length ; ++i ) {
if ( !ma_notes || !( keys[i] in ma_notes ) )
if ( ! get_ma_note( nat, vo_type, keys[i] ) )
missing_keys.push( keys[i] ) ;
}
return missing_keys ;

@ -93,4 +93,4 @@ M4A1F WP7[J4+]†[3] s5[J4+] sM5[4+] CS 5[brewup] CS 5[brewup]
M4A3F WP7[J4+]†[3] s5[J4+] sM4[4+] CS 5[brewup] CS 5[brewup] 12† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y US BB†<sup>3</sup> C
M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y C
M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C

@ -93,4 +93,4 @@ M4A1F WP7[J4+]†[3] s5[J4+] sM5[4+] CS 5[brewup] CS 5[brewup]
M4A3F WP7[J4+]†[3] s5[J4+] sM4[4+] CS 5[brewup] CS 5[brewup] 12† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y US BB†<sup>3</sup> C
M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y C
M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C

@ -93,4 +93,4 @@ M4A1F WP7[J4+]†[3] s5[J4+] sM5[4+] CS 5[brewup] CS 5[brewup]
M4A3F WP7[J4+]†[3] s5[J4+] sM4[4+] CS 5[brewup] CS 5[brewup] 12† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y US BB†<sup>3</sup> C
M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y C
M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C

@ -93,4 +93,4 @@ M4A1F WP7[J4+]†[3] s5[J4+] sM5[4+] CS 5[brewup] CS 5[brewup]
M4A3F WP7[J4+]†[3] s5[J4+] sM4[4+] CS 5[brewup] CS 5[brewup] 12† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y US BB†<sup>3</sup> C
M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y C
M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C

@ -93,4 +93,4 @@ M4A1F WP7[J4+]†[3] s5[J4+] sM5[4+] CS 5[brewup] sM5 CS 5[brewu
M4A3F WP7[J4+]†[3] s5[J4+] sM4[4+] CS 5[brewup] sM4 CS 5[brewup] 12† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y US BB†<sup>3</sup> C
M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y C
M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C

@ -93,4 +93,4 @@ M4A1F WP7[J4+]†[3] s5[J4+] sM5[4+] CS 5[brewup] WP7†[3] s5 s
M4A3F WP7[J4+]†[3] s5[J4+] sM4[4+] CS 5[brewup] WP7†[3] s5 sM4 CS 5[brewup] 12† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y US BB†<sup>3</sup> C
M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†<sup>2</sup> US G US R†<sup>1</sup> US Y C
M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 A5†[2] s5 sM8 CS 6 15† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 A5†[2] s5 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> Y C
M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 A5†[2] s5 sM8 CS 6 16† US A†<sup>2</sup> US F†<sup>1</sup> US G US <s>P</s> US Y C

Loading…
Cancel
Save