Fixed some incorrect online counter image URL's.

master
Pacman Ghost 3 years ago
parent 189293add5
commit 2cc5b3cad4
  1. 30
      vasl_templates/webapp/data/online-counter-images.json
  2. 4
      vasl_templates/webapp/data/vehicles/german.json
  3. 12
      vasl_templates/webapp/static/main.js
  4. 20
      vasl_templates/webapp/static/vo.js
  5. 158
      vasl_templates/webapp/templates/counter-image-urls.html
  6. 1
      vasl_templates/webapp/templates/index.html
  7. 22
      vasl_templates/webapp/vasl_mod.py
  8. 15
      vasl_templates/webapp/vo.py

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

@ -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\u2020<sup>2</sup>", "D\u2020<sup>1</sup>" ],
"id": "ge/v:106",
"gpid": [ 7140, 2775 ]
"gpid": 2775
},
{ "name": "SdKfz 6/2",
"type": "AAht",

@ -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:<div class='pre'>" + escapeHTML(errorMsg) + "</div>" ) ;
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 )

@ -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 ) ;

@ -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 ; }
</style>
</head>
@ -22,15 +24,19 @@ td { border-bottom: 1px solid #eee ; font-size: 90% ; }
<script>
gAppConfig = null ;
gVaslPieceInfo = null ;
gOnlineCounterImages = null ;
$(document).ready( function () {
// parse URL arguments
var fetch_images = getUrlParam( "fetch-images" ) ;
// initialize
var counter_image_urls ;
var on_load_counter = 3 ;
var on_load_counter = 4 ;
function on_data_loaded() {
if ( --on_load_counter == 0 )
show_counter_image_urls( counter_image_urls ) ;
show_counter_image_urls( counter_image_urls, fetch_images ) ;
}
// get the app config
@ -39,6 +45,7 @@ $(document).ready( function () {
on_data_loaded() ;
} ).fail( function( xhr, status, errorMsg ) {
alert( "Can't get the application config:\n\n" + errorMsg ) ;
return ;
} ) ;
// get the VASL piece info
@ -47,72 +54,153 @@ $(document).ready( function () {
on_data_loaded() ;
} ).fail( function( xhr, status, errorMsg ) {
alert( "Can't get the VASL piece info:\n\n" + errorMsg ) ;
return ;
} ) ;
// get the online counter images
$.getJSON( "{{url_for('get_online_counter_images')}}", function(data) {
gOnlineCounterImages = data ;
on_data_loaded() ;
} ).fail( function( xhr, status, errorMsg ) {
alert( "Can't get the online counter images:\n\n" + errorMsg ) ;
return ;
} ) ;
// get the vehicle/ordnance listings
var url ;
if ( "{{VO_TYPE}}" == "ordnance" )
url = "{{url_for( 'get_ordnance_listings', report=1 )}}" ;
else
else if ( "{{VO_TYPE}}" == "vehicles" )
url = "{{url_for( 'get_vehicle_listings', report=1 )}}" ; // nb: includes landing craft
else {
alert( "Invelid vo/type: {{VO_TYPE}}" ) ;
return ;
}
url += "&merge_common=1" ;
$.getJSON( url, function(data) {
counter_image_urls = data[ "{{NATIONALITY}}" ] ;
counter_image_urls = data ;
if ( "{{NATIONALITY}}" != "*" )
counter_image_urls = { "{{NATIONALITY}}": data[ "{{NATIONALITY}}" ] } ;
on_data_loaded() ;
} ).fail( function( xhr, status, errorMsg ) {
alert( "Can't get the {{VO_TYPE0}} listings:\n\n" + errorMsg ) ;
return ;
} ) ;
} ) ;
function show_counter_image_urls( counters )
function show_counter_image_urls( counters, fetch_images )
{
// initialize
if ( ! counters )
counters = [] ;
var buf = [] ;
buf.push( "<table>" ) ;
buf.push( "<tr>", "<th>ID", "<th>Name", "<th>GPID", "<th>Local URL's", "<th>Online URL's" ) ;
// process each counter
for ( var i=0 ; i < counters.length ; ++i ) {
// process each nationality
for ( var nat in counters ) {
var counter = counters[i] ;
buf.push( "<tr>",
"<td>", counter.id,
"<td>", counter.name,
) ;
if ( Object.keys( counters ).length > 1 )
buf.push( "<tr>", "<td class='nationality' colspan=5>", nat ) ;
// process each counter variant
var gpids = $.isArray( counter.gpid ) ? counter.gpid : [ counter.gpid ] ;
var gpids2=[] , local_urls=[] , online_urls=[] ;
for ( var j=0 ; j < gpids.length ; ++j ) {
buf.push( "<tr>", "<th>ID", "<th>Name", "<th>GPID", "<th>Local URL's", "<th>Online URL's" ) ;
if ( gpids[j] === null || [7140,7146].indexOf( gpids[j] ) !== -1 ) {
buf.push( "<td>", "<td>", "<td>" ) ;
continue ;
function add_image( urls, online, caption, url ) {
var buf2 = [ "<div>" ] ;
if ( fetch_images ) {
buf2.push( "<img" ) ;
if ( online )
buf2.push( " data-url='" + url + "'" ) ;
else
buf2.push( " src='" + url + "'" ) ;
buf2.push( " class='counter' data-caption='" + caption + "'>" ) ;
}
gpids2.push( gpids[j] ) ;
buf2.push( "<a href='" + url + "' target='_blank'>" + url + "</a>" ) ;
buf2.push( "</div>" ) ;
urls.push( buf2.join("") ) ;
}
function check_image( evt ) {
// check if the counter image loaded OK
var img = evt.target ;
if ( img.complete && img.naturalWidth !== 0 )
return ;
var $img = $( img ) ;
console.log( "COUNTER ERROR: " + $img.data("caption") + "\n-", $img.prop("src") ) ;
}
// NOTE: We don't handle the case where there are multiple images available for a GPID,
// but this happens so infrequently, we can live with it (see expected-multiple-images.json).
var index = 0 ;
// process each counter
for ( var i=0 ; i < counters[nat].length ; ++i ) {
var counter = counters[nat][i] ;
buf.push( "<tr>",
"<td>", counter.id,
"<td>", counter.name,
) ;
// process each counter variant
var gpids = $.isArray( counter.gpid ) ? counter.gpid : [ counter.gpid ] ;
var gpids2=[] , local_urls=[] , online_urls=[] ;
for ( var j=0 ; j < gpids.length ; ++j ) {
if ( gpids[j] === null )
continue ;
gpids2.push( gpids[j] ) ;
// NOTE: We don't handle the case where there are multiple images available for a GPID,
// but this happens so infrequently, we can live with it (see expected-multiple-images.json).
var index = 0 ;
// generate the counter image URL's
var caption = "gpid=" + gpids[j] ;
add_image( local_urls, false, caption,
make_local_counter_image_url( gpids[j], index, false )
) ;
add_image( online_urls, true, caption,
make_online_counter_image_url( gpids[j], index )
) ;
}
// generate the counter image URL's
var url = make_local_counter_image_url( gpids[j], index, false ) ;
local_urls.push( "<a href='" + url + "' target='_blank'>" + url + "</a>" ) ;
url = make_online_counter_image_url( gpids[j], index ) ;
online_urls.push( "<a href='" + url + "' target='_blank'>" + url + "</a>" ) ;
buf.push(
"<td>", gpids2.join( "<br>" ),
"<td>", local_urls.join( "<br>" ),
"<td>", online_urls.join( "<br>" ),
) ;
}
buf.push(
"<td>", gpids2.join( "<br>" ),
"<td>", local_urls.join( "<br>" ),
"<td>", online_urls.join( "<br>" ),
) ;
}
buf.push( "</table>" ) ;
$("#results").html( buf.join("") ).show() ;
var $results = $( buf.join("") ) ;
var onlineImages = [] ;
$results.find( "img.counter" ).each( function() {
if ( $(this).data( "url" ) )
onlineImages.push( $(this) ) ;
else
$(this).on( "load", check_image ).on( "error", check_image ) ;
} ) ;
$("#results").html( $results ).show() ;
// FUDGE! If we just insert all the online images into the page get the browser to downloaded them normally,
// a lot of them fail, I assume because Github is rate-limiting requests. We work around this by manually
// downloading them one at a time :-/
function downloadNextOnlineImage() {
if ( onlineImages.length == 0 ) {
console.log( "- Done." ) ;
return ;
}
if ( onlineImages.length % 100 == 0 )
console.log( "-", onlineImages.length, "images left..." ) ;
var $img = onlineImages.pop() ;
var url = $img.data( "url" ) ;
function onLoaded( evt ) {
check_image( evt ) ;
downloadNextOnlineImage() ;
}
$img.on( "load", onLoaded ).on( "error", onLoaded ).attr( "src", url ) ;
}
if ( onlineImages.length > 0 ) {
console.log( "Downloading online images:", onlineImages.length ) ;
downloadNextOnlineImage() ;
}
}
</script>

@ -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')}}" ;

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

@ -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( "/<vo_type>/<nat>/<theater>/<int:year>", defaults={"month":1} )
@app.route( "/<vo_type>/<nat>/<theater>/<int:year>/<int:month>" )
def get_vo_report( vo_type, nat, theater, year, month ):

Loading…
Cancel
Save