From 6d06fdc082c0a655f930d99312f5a41a54338f3b Mon Sep 17 00:00:00 2001 From: Taka Date: Thu, 21 May 2020 06:21:24 +0000 Subject: [PATCH] Show in the UI which VASL extension vehicles/ordnance came from. --- .../webapp/data/extensions/bfp-bj-v403.json | 2 ++ .../webapp/data/extensions/bfp-cobra-v403.json | 2 ++ .../webapp/data/extensions/bfp-pif-v403.json | 2 ++ .../webapp/data/extensions/kgs-v1.1.json | 2 ++ vasl_templates/webapp/main.py | 15 +++++++++++++++ .../webapp/static/css/select-vo-dialog.css | 4 +++- vasl_templates/webapp/static/vo.js | 9 +++++++++ .../webapp/tests/test_vehicles_ordnance.py | 5 ++++- vasl_templates/webapp/vo.py | 1 + 9 files changed, 40 insertions(+), 2 deletions(-) diff --git a/vasl_templates/webapp/data/extensions/bfp-bj-v403.json b/vasl_templates/webapp/data/extensions/bfp-bj-v403.json index 7a1bf95..1107c7a 100644 --- a/vasl_templates/webapp/data/extensions/bfp-bj-v403.json +++ b/vasl_templates/webapp/data/extensions/bfp-bj-v403.json @@ -3,6 +3,8 @@ "parentExtensionId": "adf", "extensionId": "adf-bj", "version": "4.03", +"displayName": "Blood & Jungle", +"displayNameAbbrev": "B+J", "id_range": [ 900, 999 ], "japanese": { diff --git a/vasl_templates/webapp/data/extensions/bfp-cobra-v403.json b/vasl_templates/webapp/data/extensions/bfp-cobra-v403.json index cd3a831..f10cbce 100644 --- a/vasl_templates/webapp/data/extensions/bfp-cobra-v403.json +++ b/vasl_templates/webapp/data/extensions/bfp-cobra-v403.json @@ -3,6 +3,8 @@ "parentExtensionId": "adf", "extensionId": "adf-cobra", "version": "4.03", +"displayName": "Operation Cobra", +"displayNameAbbrev": "Op. Cobra", "id_range": [ 850, 899 ], "comment": "These are F (flamethrower) and C (Culin) versions of the same vehicles (from Operation Cobra).", diff --git a/vasl_templates/webapp/data/extensions/bfp-pif-v403.json b/vasl_templates/webapp/data/extensions/bfp-pif-v403.json index 4c9beea..429df5f 100644 --- a/vasl_templates/webapp/data/extensions/bfp-pif-v403.json +++ b/vasl_templates/webapp/data/extensions/bfp-pif-v403.json @@ -2,6 +2,8 @@ "parentExtensionId": "adf", "extensionId": "adf-pif", +"displayName": "Poland In Flames", +"displayNameAbbrev": "PiF", "version": "4.03", "id_range": [ 800, 849 ], diff --git a/vasl_templates/webapp/data/extensions/kgs-v1.1.json b/vasl_templates/webapp/data/extensions/kgs-v1.1.json index 0dfb87c..f480018 100644 --- a/vasl_templates/webapp/data/extensions/kgs-v1.1.json +++ b/vasl_templates/webapp/data/extensions/kgs-v1.1.json @@ -2,6 +2,8 @@ "extensionId": "f97", "version": "v1.1", +"displayName": "Kampfgruppe Scherer", +"displayNameAbbrev": "KGS", "russian": { diff --git a/vasl_templates/webapp/main.py b/vasl_templates/webapp/main.py index 0756965..4d232e2 100644 --- a/vasl_templates/webapp/main.py +++ b/vasl_templates/webapp/main.py @@ -67,12 +67,16 @@ _APP_CONFIG_DEFAULTS = { # Bodhgaya, India (APR/19) @app.route( "/app-config" ) def get_app_config(): """Get the application config.""" + + # include the basic app config vals = { key: app.config.get( key, default ) for key,default in _APP_CONFIG_DEFAULTS.items() } for key in ["APP_NAME","APP_VERSION","APP_DESCRIPTION","APP_HOME_URL"]: vals[ key ] = getattr( vasl_templates.webapp.config.constants, key ) + + # include information about VASSAL and VASL from vasl_templates.webapp.vassal import VassalShim try: vals[ "VASSAL_VERSION" ] = VassalShim.get_version() @@ -80,6 +84,17 @@ def get_app_config(): logging.error( "Can't check the VASSAL version: %s", str(ex) ) if globvars.vasl_mod: vals["VASL_VERSION"] = globvars.vasl_mod.vasl_version + + # include information about VASL extensions + if globvars.vasl_mod and globvars.vasl_mod.extns: + vals["VASL_EXTENSIONS"] = {} + for extn in globvars.vasl_mod.extns: + extn_info = {} + for key in ("version","displayName","displayNameAbbrev"): + if key in extn[1]: + extn_info[ key ] = extn[1][ key ] + vals["VASL_EXTENSIONS"][ extn[1]["extensionId"] ] = extn_info + return jsonify( vals ) # --------------------------------------------------------------------- diff --git a/vasl_templates/webapp/static/css/select-vo-dialog.css b/vasl_templates/webapp/static/css/select-vo-dialog.css index 89dfadd..b88a6f2 100644 --- a/vasl_templates/webapp/static/css/select-vo-dialog.css +++ b/vasl_templates/webapp/static/css/select-vo-dialog.css @@ -13,8 +13,10 @@ #select-vo .select2-dropdown .vo-entry img { height: 3.5em ; margin-right: 0.5em ; } #select-vo .select2-dropdown .vo-entry .content { display: flex ; flex-direction: column ; justify-content: center ; } #select-vo .select2-dropdown .vo-entry.small-piece img { height: 2.7em ; margin-left: 0.4em ; margin-right: 0.9em ; } -#select-vo .select2-dropdown .vo-entry .vo-type { font-size: 80% ; font-style: italic ; color: #888 ; } +#select-vo .select2-dropdown .vo-entry .vo-type { font-size: 80% ; font-style: italic ; color: #666 ; } +#select-vo .select2-dropdown .vo-entry .vo-extn { font-size: 70% ; font-style: italic ; color: #888 ; } #select-vo .select2-results__option--highlighted[aria-selected] .vo-type { color: #eee ; } +#select-vo .select2-results__option--highlighted[aria-selected] .vo-extn { color: #eee ; } #select-vo .select2-dropdown .vo-entry input.select-vo-image { width: 15px ; position: relative ; top: 10px ; } /* -------------------------------------------------------------------- */ diff --git a/vasl_templates/webapp/static/vo.js b/vasl_templates/webapp/static/vo.js index 79bf512..72e7d96 100644 --- a/vasl_templates/webapp/static/vo.js +++ b/vasl_templates/webapp/static/vo.js @@ -20,11 +20,20 @@ function add_vo( vo_type, player_no ) var div_class = "vo-entry" ; if ( is_small_vasl_piece( vo_entry ) ) div_class += " small-piece" ; + var extn_name ; + if ( vo_entry.extn_id ) { + extn_name = gAppConfig.VASL_EXTENSIONS[ vo_entry.extn_id ].displayNameAbbrev ; + if ( ! extn_name ) + extn_name = gAppConfig.VASL_EXTENSIONS[ vo_entry.extn_id ].displayName ; + if ( ! extn_name ) + extn_name = vo_entry.extn_id ; + } var buf2 = [ "
", "", "
", vo_entry.name, vo_entry.type ? " ("+vo_entry.type+")" : "", + extn_name ? " [" + extn_name + "]" : "", "
", "
" ] ; diff --git a/vasl_templates/webapp/tests/test_vehicles_ordnance.py b/vasl_templates/webapp/tests/test_vehicles_ordnance.py index 6ed0179..8c1cf19 100644 --- a/vasl_templates/webapp/tests/test_vehicles_ordnance.py +++ b/vasl_templates/webapp/tests/test_vehicles_ordnance.py @@ -795,7 +795,10 @@ def add_vo( webdriver, vo_type, player_no, name ): entries = find_children( "#select-vo .select2-results li" ) if name.endswith( "s" ): name = name[:-1] - matches = [ e for e in entries if e.text == name ] + matches = [ e + for e in entries + if re.sub( r" \[.+\]$", "", e.text ) == name # nb: remove extension ID's + ] assert len(matches) == 1 elem = matches[0] webdriver.execute_script( "arguments[0].scrollIntoView()", elem ) diff --git a/vasl_templates/webapp/vo.py b/vasl_templates/webapp/vo.py index 8c5e502..0d7b883 100644 --- a/vasl_templates/webapp/vo.py +++ b/vasl_templates/webapp/vo.py @@ -198,6 +198,7 @@ def _apply_extn_info( listings, extn_fname, extn_info, vo_index, vo_type ): else: prev_gpids = "(none)" vo_entry["gpid"] = entry["gpid"] + # NOTE: We can't really set the extension ID here because the counter is also in the core VASL module. logger.debug( " - %s => %s", prev_gpids, vo_entry["gpid"] ) else: # add a new vehicle/ordnance