From 0382c5756bcecf23627c408d9d9f133ea24647ca Mon Sep 17 00:00:00 2001 From: Taka Date: Sat, 2 Feb 2019 13:39:20 +0000 Subject: [PATCH] Updated the tests to recognize extension and Allied/Axis Minor common mutli-applicable notes. --- .../webapp/data/extensions/bfp-cobra.json | 2 +- vasl_templates/webapp/static/snippets.js | 77 +++++++++++-------- .../webapp/templates/vo-notes-report.html | 32 +++++--- .../vo-reports/vehicles/american/1940.txt | 2 +- .../vo-reports/vehicles/american/1941.txt | 2 +- .../vo-reports/vehicles/american/1942.txt | 2 +- .../vo-reports/vehicles/american/1943.txt | 2 +- .../vo-reports/vehicles/american/1944.txt | 2 +- .../vo-reports/vehicles/american/1945.txt | 2 +- 9 files changed, 76 insertions(+), 47 deletions(-) diff --git a/vasl_templates/webapp/data/extensions/bfp-cobra.json b/vasl_templates/webapp/data/extensions/bfp-cobra.json index 6279fe9..9f178dc 100644 --- a/vasl_templates/webapp/data/extensions/bfp-cobra.json +++ b/vasl_templates/webapp/data/extensions/bfp-cobra.json @@ -169,7 +169,7 @@ "CS#": 6, "capabilities2": { "A": [ [4,"A4"], [5,5], "\u20202" ], "s": [ [5,5] ], "sM": 8 }, "note_number": "16\u2020", - "notes": [ "US A\u20202", "US F\u20201", "US G", "US P", "Y", "C" ], + "notes": [ "US A\u20202", "US F\u20201", "US G", "US P", "US Y", "C" ], "id": "am/v:876", "gpid": "adf:186" } diff --git a/vasl_templates/webapp/static/snippets.js b/vasl_templates/webapp/static/snippets.js index a33aeef..aaca571 100644 --- a/vasl_templates/webapp/static/snippets.js +++ b/vasl_templates/webapp/static/snippets.js @@ -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 diff --git a/vasl_templates/webapp/templates/vo-notes-report.html b/vasl_templates/webapp/templates/vo-notes-report.html index ff1e8a3..a680e7c 100644 --- a/vasl_templates/webapp/templates/vo-notes-report.html +++ b/vasl_templates/webapp/templates/vo-notes-report.html @@ -4,6 +4,7 @@ @@ -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( "", "", keys[i]+":", "", vo_notes[keys[i]] ) ; + buf.push( "", + "", keys[i]+":", + "", vo_notes[keys[i]] + ) ; } buf.push( "" ) ; } @@ -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( "", unrecognized ) ; - buf.push( "", find_missing_ma_notes(ma_notes,keys) ) ; + buf.push( "", find_missing_ma_notes(keys) ) ; } buf.push( "" ) ; $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 ; diff --git a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1940.txt b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1940.txt index af067fc..c0b12da 100644 --- a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1940.txt +++ b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1940.txt @@ -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†2 US G US R†1 US Y US BB†3 C M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†2 US G US R†1 US Y C M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†2 US F†1 US G US P US Y C -M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P Y C +M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P US Y C diff --git a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1941.txt b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1941.txt index 329a900..8f3e1d9 100644 --- a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1941.txt +++ b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1941.txt @@ -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†2 US G US R†1 US Y US BB†3 C M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†2 US G US R†1 US Y C M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†2 US F†1 US G US P US Y C -M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P Y C +M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P US Y C diff --git a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1942.txt b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1942.txt index be813c6..989581d 100644 --- a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1942.txt +++ b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1942.txt @@ -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†2 US G US R†1 US Y US BB†3 C M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†2 US G US R†1 US Y C M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†2 US F†1 US G US P US Y C -M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P Y C +M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P US Y C diff --git a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1943.txt b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1943.txt index 8844248..bf90629 100644 --- a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1943.txt +++ b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1943.txt @@ -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†2 US G US R†1 US Y US BB†3 C M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†2 US G US R†1 US Y C M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†2 US F†1 US G US P US Y C -M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P Y C +M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P US Y C diff --git a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1944.txt b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1944.txt index 75fe7bb..49f991e 100644 --- a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1944.txt +++ b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1944.txt @@ -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†2 US G US R†1 US Y US BB†3 C M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†2 US G US R†1 US Y C M4A1F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 15† US A†2 US F†1 US G US P US Y C -M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P Y C +M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 sM8 CS 6 16† US A†2 US F†1 US G US P US Y C diff --git a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1945.txt b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1945.txt index d22cab9..73bb4ba 100644 --- a/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1945.txt +++ b/vasl_templates/webapp/tests/fixtures/vo-reports/vehicles/american/1945.txt @@ -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†2 US G US R†1 US Y US BB†3 C M4A3F(75)W WP7 s5 sM8 CS 6 WP7 s5 sM8 CS 6 13† US F†2 US G US R†1 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†2 US F†1 US G US P 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†2 US F†1 US G US P Y C +M4A3F(76)W A4[A4]5[5]†[2] s5[5] sM8 CS 6 A5†[2] s5 sM8 CS 6 16† US A†2 US F†1 US G US P US Y C