diff --git a/vasl_templates/webapp/data/online-counter-images.json b/vasl_templates/webapp/data/online-counter-images.json new file mode 100644 index 0000000..0db92e5 --- /dev/null +++ b/vasl_templates/webapp/data/online-counter-images.json @@ -0,0 +1,30 @@ +{ + +"1413": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/br/vehicles/morris.gif", +"2241": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/al/veh/FT17C.gif", +"6849": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/veh/fiT-50r.png", +"7418": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/ru/veh/T28M34L.gif", +"7420": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/ru/veh/T28EM40L.gif", +"7423/0": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/ru/veh/Lee(a)RU.gif", +"7428/0": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/ru/veh/ruM3A1 SC UA.gif", +"7432/0": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/ru/veh/RU VALVnoaa.gif", +"7434/0": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/ru/veh/RU VALV.gif", + +"6765": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi81mmMTR.png", +"6782": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi81mmMTR Savu.png", +"6796": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi7.62AA.png", +"6797": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi20L4.png", +"6801": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi20L6.png", +"6806": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi120MTR.png", +"6808": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi20LAT.gif", +"6810": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi25LLAT.png", +"6811": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi37LAT.png", +"6812": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi37LAT H.png", +"6813": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi45LAT.png", +"6814": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi50LAT.png", +"6816": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi75LAT.png", +"6818": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi76INF.png", +"6820": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fi76ART.png", +"7409": "https://raw.githubusercontent.com/vasl-developers/vasl/develop/dist/images/fi/gun/fiAA76L.png" + +} diff --git a/vasl_templates/webapp/data/vehicles/german.json b/vasl_templates/webapp/data/vehicles/german.json index 81bc98f..b9c5658 100644 --- a/vasl_templates/webapp/data/vehicles/german.json +++ b/vasl_templates/webapp/data/vehicles/german.json @@ -937,7 +937,7 @@ "note_number": "88", "notes": [ "A\u2020", "D\u2020", "N" ], "id": "ge/v:105", - "gpid": [ 7146, 2772 ] + "gpid": 2772 }, { "name": "SdKfz 10/5", "type": "AAht", @@ -945,7 +945,7 @@ "note_number": "88.1\u2020", "notes": [ "A\u20202", "D\u20201" ], "id": "ge/v:106", - "gpid": [ 7140, 2775 ] + "gpid": 2775 }, { "name": "SdKfz 6/2", "type": "AAht", diff --git a/vasl_templates/webapp/static/main.js b/vasl_templates/webapp/static/main.js index fbfc693..af5c089 100644 --- a/vasl_templates/webapp/static/main.js +++ b/vasl_templates/webapp/static/main.js @@ -5,6 +5,7 @@ gValidTemplateIds = [] ; gVehicleOrdnanceListings = {} ; gVehicleOrdnanceNotes = {} ; gVaslPieceInfo = {} ; +gOnlineCounterImages = {} ; gWebChannelHandler = null ; gEmSize = null ; @@ -316,6 +317,15 @@ $(document).ready( function () { update_page_load_status( "vasl-piece-info" ) ; } ) ; + // get the online counter images data + $.getJSON( gGetOnlineCounterImagesUrl, function(data) { + gOnlineCounterImages = data ; + update_page_load_status( "online-counter-images" ) ; + } ).fail( function( xhr, status, errorMsg ) { + showErrorMsg( "Can't get the online counter images:
" + escapeHTML(errorMsg) + "
" ) ; + update_page_load_status( "online-counter-images" ) ; + } ) ; + // get the template pack $.getJSON( gGetTemplatePackUrl, function(data) { if ( "error" in data ) @@ -525,7 +535,7 @@ gPageLoadStatus = [ "main", "app-config", "vehicle-listings", "ordnance-listings", "reset-scenario", "vehicle-notes", "ordnance-notes", - "vasl-piece-info", "template-pack", "default-scenario" + "vasl-piece-info", "online-counter-images", "template-pack", "default-scenario" ] ; function update_page_load_status( id ) diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js index 8b19c86..72976b7 100644 --- a/vasl_templates/webapp/static/vo.js +++ b/vasl_templates/webapp/static/vo.js @@ -459,8 +459,21 @@ function make_local_counter_image_url( gpid, index, for_snippet ) function make_online_counter_image_url( gpid, index ) { + // check if a URL has been explicitly defined for this GPID + var key = gpid ; + if ( index !== null ) + key += "/" + index ; + var url = gOnlineCounterImages[ key ] ; + if ( url ) + return encodeURI( url ) ; + if ( index === 0 ) { + url = gOnlineCounterImages[ gpid ] ; + if ( url ) + return encodeURI( url ) ; + } + // check if we have a piece from the core VASL module or an extension - var url, extn_id ; + var extn_id ; var pos = gpid.toString().indexOf( ":" ) ; // FUDGE! K:FW was originally done as an extension, then moved into the main VASL module. // One of the consequences of this is that a lot of the new counters have a GPID that @@ -477,7 +490,10 @@ function make_online_counter_image_url( gpid, index ) if ( index === null ) index = 0 ; url = strReplaceAll( url, "{{INDEX}}", index ) ; - url = strReplaceAll( url, "{{PATH}}", gVaslPieceInfo[gpid].paths[index] ) ; + if ( gVaslPieceInfo[gpid] ) + url = strReplaceAll( url, "{{PATH}}", gVaslPieceInfo[gpid].paths[index] ) ; + else + console.log( "ERROR: Missing GPID:", gpid ) ; if ( extn_id ) url = strReplaceAll( url, "{{EXTN_ID}}", extn_id ) ; diff --git a/vasl_templates/webapp/templates/counter-image-urls.html b/vasl_templates/webapp/templates/counter-image-urls.html index 65e56c2..4ee1ce3 100644 --- a/vasl_templates/webapp/templates/counter-image-urls.html +++ b/vasl_templates/webapp/templates/counter-image-urls.html @@ -8,6 +8,8 @@ th, td { text-align: left ; vertical-align: top ; padding-right: 1em ; } th { background: #eee ; } td { border-bottom: 1px solid #eee ; font-size: 90% ; } +td.nationality { border: 1px solid black ; padding: 0.25em 0.5em ; background: #e8e8e8 ; font-size: 100% ; } +img.counter { float: left ; margin: 0 0.5em 0.5em 0 ; height: 3em ; } @@ -22,15 +24,19 @@ td { border-bottom: 1px solid #eee ; font-size: 90% ; } diff --git a/vasl_templates/webapp/templates/index.html b/vasl_templates/webapp/templates/index.html index 306e115..d0077e8 100644 --- a/vasl_templates/webapp/templates/index.html +++ b/vasl_templates/webapp/templates/index.html @@ -132,6 +132,7 @@ gOrdnanceListingsUrl = "{{url_for('get_ordnance_listings',merge_common=1)}}" ; gVehicleNotesUrl = "{{url_for('get_vehicle_notes')}}" ; gOrdnanceNotesUrl = "{{url_for('get_ordnance_notes')}}" ; gGetVaslPieceInfoUrl = "{{url_for('get_vasl_piece_info')}}" ; +gGetOnlineCounterImagesUrl = "{{url_for('get_online_counter_images')}}" ; gGetScenarioIndexUrl = "{{url_for('get_scenario_index')}}" ; gGetScenarioUrl = "{{url_for('get_scenario',scenario_id='ID')}}" ; gGetScenarioCardUrl = "{{url_for('get_scenario_card',scenario_id='ID')}}" ; diff --git a/vasl_templates/webapp/vasl_mod.py b/vasl_templates/webapp/vasl_mod.py index 8539358..1f84c9f 100644 --- a/vasl_templates/webapp/vasl_mod.py +++ b/vasl_templates/webapp/vasl_mod.py @@ -225,16 +225,20 @@ class VaslMod: """Return the piece's image paths.""" paths = piece[ "front_images" ] return paths if isinstance(paths,list) else [paths] - return { - get_reverse_remapped_gpid( self, p["gpid"] ): { - "name": p["name"], - "front_images": image_count( p, "front_images" ), - "back_images": image_count( p, "back_images" ), - "paths": get_image_paths( p ), - "is_small": p["is_small"], + piece_info_table = {} + for gpid, piece in self._pieces.items(): + piece_info = { + "name": piece["name"], + "front_images": image_count( piece, "front_images" ), + "back_images": image_count( piece, "back_images" ), + "paths": get_image_paths( piece ), + "is_small": piece["is_small"], } - for p in self._pieces.values() - } + piece_info_table[ gpid ] = piece_info + reverse_gpid = get_reverse_remapped_gpid( self, gpid ) + if reverse_gpid != gpid: + piece_info_table[ reverse_gpid ] = piece_info + return piece_info_table def get_extns( self ): """Return the loaded VASL extensions.""" diff --git a/vasl_templates/webapp/vo.py b/vasl_templates/webapp/vo.py index c8acc6e..a53486e 100644 --- a/vasl_templates/webapp/vo.py +++ b/vasl_templates/webapp/vo.py @@ -4,7 +4,7 @@ import os import json import copy -from flask import request, render_template, jsonify, abort +from flask import request, render_template, send_file, jsonify, abort from vasl_templates.webapp import app, globvars from vasl_templates.webapp.config.constants import DATA_DIR @@ -178,6 +178,19 @@ def _do_load_vo_listings( vasl_mod, vo_type, merge_common, real_data_dir, msg_st # --------------------------------------------------------------------- +@app.route( "/online-counter-images" ) +def get_online_counter_images(): + """Get the online counter images data.""" + # FUDGE! For some reason, some counters have a different path in the .vmod file to where they live + # in the source tree, which means that when we generate a URL for that counter image, it will 404. + # There doesn't seem to be any pattern to these counters, and since there aren't too many of them, + # the most robust solution is probably to fix them up manually :-/ + # NOTE: To check these: $/counter-image-urls.html?fetch-images=1 + fname = os.path.join( DATA_DIR, "online-counter-images.json" ) + return send_file( fname, "application/json" ) + +# --------------------------------------------------------------------- + @app.route( "////", defaults={"month":1} ) @app.route( "/////" ) def get_vo_report( vo_type, nat, theater, year, month ):