Allow underscores/spaces in ruleid's.

master
Pacman Ghost 3 years ago
parent 4443a662c5
commit 42a1b16709
  1. 4
      asl_rulebook2/webapp/content.py
  2. 9
      asl_rulebook2/webapp/static/ContentPane.js
  3. 2
      asl_rulebook2/webapp/static/SearchPane.js
  4. 21
      asl_rulebook2/webapp/static/SearchResult.js
  5. 2
      asl_rulebook2/webapp/static/utils.js
  6. BIN
      asl_rulebook2/webapp/tests/fixtures/full/KGS-background.png
  7. BIN
      asl_rulebook2/webapp/tests/fixtures/full/KGS-icon.png
  8. 16
      asl_rulebook2/webapp/tests/fixtures/full/Kampfgruppe Scherer.chapters
  9. 12
      asl_rulebook2/webapp/tests/fixtures/full/Kampfgruppe Scherer.footnotes
  10. 8
      asl_rulebook2/webapp/tests/fixtures/full/Kampfgruppe Scherer.index
  11. 11
      asl_rulebook2/webapp/tests/fixtures/full/Kampfgruppe Scherer.targets
  12. 2
      asl_rulebook2/webapp/tests/test_footnotes.py
  13. 42
      asl_rulebook2/webapp/tests/test_underscores_in_ruleids.py

@ -192,7 +192,9 @@ def load_content_sets( startup_msgs, logger ):
for ruleid in cdoc.get( "targets", {} ):
# nb: we also want to detect things like A1.23-.45
_tag_ruleid_regexes[ ruleid ] = re.compile(
r"\b{}(-\.\d+)?\b".format( ruleid.replace( ".", "\\." ) )
r"\b{}(-\.\d+)?\b".format(
ruleid.replace( ".", "\\." ).replace( "_", " " )
)
)
return _content_sets

@ -125,7 +125,14 @@ gMainApp.component( "content-pane", {
let buf = [] ;
function addCaption( footnote, caption, style ) {
buf.push( "<div class='header' ", style ? "style='"+style+"'" : "", ">",
"<span class='caption'>", caption.caption, " ("+caption.ruleid+")", "</span>", " ",
"<span class='caption'>"
) ;
let ruleid = caption.ruleid.replace( "_", " " ) ;
if ( caption.caption )
buf.push( caption.caption, " ("+ruleid+")" ) ;
else
buf.push( ruleid ) ;
buf.push( "</span>", " ",
"<span class='footnote-id'>", "["+footnote.display_name+"]", "</span>",
"</div>" ) ;
}

@ -258,6 +258,8 @@ gMainApp.component( "search-results", {
// check if the query string is just a ruleid
let targets = findTargets( queryString, null ) ;
if ( targets == null || targets == undefined || targets.length == 0 )
targets = findTargets( queryString.replace( " ", "_" ), null ) ;
if ( targets && targets.length > 0 ) {
// yup - just show it directly (first one, if multiple)
this.searchResults = null ;

@ -149,8 +149,18 @@ gMainApp.component( "index-sr", {
if ( ! target )
return null ;
let ruleid = target.ruleid ;
if ( isRuleid( ruleid ) )
return ruleid[0] ; // nb: we assume the 1st letter of the ruleid is the chapter ID
if ( isRuleid( ruleid ) ) {
let pos = ruleid.indexOf( "_" ) ;
if ( pos > 0 )
return ruleid.substring( 0, pos ) ; // e.g. "KGS_CG3" -> "KGS"
let match = ruleid.match( /^[A-Z]+/ ) ;
if ( match ) {
let chapterId = match[0] ;
if ( chapterId.substring( chapterId.length-2 ) == "CG" )
chapterId = chapterId.substring( 0, chapterId.length-1 ) ; // e.g. "OCG3" -> "O"
return chapterId ;
}
}
return null ;
},
@ -201,7 +211,12 @@ gMainApp.component( "ruleid", {
} ; },
// NOTE: This bit of HTML is sensitive to spaces :-/
template: `<span class="ruleid" :class="{unknown:!ruleid}">{{delim[0]}}<a v-if=ruleid @click=onClick :title=title>{{ruleId}}</a><span v-else>{{ruleId}}</span>{{delim[1]}}{{sep}}</span>`,
// NOTE: Unfortunately, PDF destinations can't have spaces (see add_pdf_dests.py), so we need to
// do a bit of hackery to simulate them :-( We could allow spaces in the ruleid's, and transparently
// convert them to underscores when we create the PDF destinations, but it's probably better
// to force them to be defined with underscores (and convert them to spaces in the UI), so that
// it's a bit clearer what's going on.
template: `<span class="ruleid" :class="{unknown:!ruleid}">{{delim[0]}}<a v-if=ruleid @click=onClick :title=title>{{ruleId.replace('_',' ')}}</a><span v-else>{{ruleId}}</span>{{delim[1]}}{{sep}}</span>`,
created() {
// check if the rule is one we know about

@ -41,7 +41,7 @@ export function findTargets( ruleid, csetId )
export function isRuleid( val )
{
// check if the value looks like a ruleid
return val.match( /^[A-Z](\.|CG)?\d/ ) ;
return val.match( /^[A-Z]+_?(\.|CG)?\d/ ) ;
}
export function getASOPChapterIdFromSectionId( sectionId )

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

@ -0,0 +1,16 @@
[
{ "title": "Kampfgrupper Scherer",
"chapter_id": "KGS",
"page_no": 1,
"sections": [
{ "caption": ".1 - .9 Miscellaneous", "page_no": 5 },
{ "caption": "KGS1: Snow-Sangar", "ruleid": "KGS1" },
{ "caption": "KGS2: Terrain", "ruleid": "KGS2" },
{ "caption": "KGS3: German Army Characteristics", "ruleid": "KGS3" },
{ "caption": "KGS4: Russian Army Characteristics", "ruleid": "KGS4" },
{ "caption": "KGS5: Glossary Of Terms", "ruleid": "KGS5" }
]
}
]

@ -0,0 +1,12 @@
{
"KGS": {
"39": {
"captions": [ { "ruleid": "KGS_CG1" } ],
"content": "These areas were vital to maintaining either the supply depot or the aerial bridgehead for Cholm. The loss of even one of these areas could well have spelled doom to the besieged garrison."
}
}
}

@ -0,0 +1,8 @@
[
{ "title": "Flugfeld Security Blocks, Sector G or Haarnadelkurve Block Bonus",
"content": "Flugfeld Security Blocks: Blocks 4, 9, 14 and 17. See KGS CG1.",
"ruleids": [ "KGS_CG1" ]
}
]

@ -0,0 +1,11 @@
{
"KGS1": { "caption": "SNOW-SANGAR", "page_no": 7 },
"KGS2": { "caption": "TERRAIN", "page_no": 7 },
"KGS3": { "caption": "GERMAN ARMY CHARACTERISTICS", "page_no": 10 },
"KGS4": { "caption": "Russian Army Characteristics", "page_no": 11 },
"KGS5": { "caption": "Glossary Of Terms", "page_no": 13 },
"KGS_CG1": { "caption": "Flugfeld Security Blocks, Sector G or Haarnadelkurve Block Bonus", "page_no": 15 }
}

@ -68,7 +68,7 @@ def test_footnotes( webdriver, webapp ):
"content": "This footnote is also for ruleid 1b1.1."
} ] )
do_test( "1b.2", [ {
"caption": " (1b.2)", "footnote_id": "X20",
"caption": "1b.2", "footnote_id": "X20",
"content": None
} ] )

@ -0,0 +1,42 @@
""" Test underscores in ruleid's. """
from asl_rulebook2.webapp.tests.test_search import do_search
from asl_rulebook2.webapp.tests.utils import init_webapp, refresh_webapp, \
wait_for, get_curr_target, get_last_footnote_msg
# ---------------------------------------------------------------------
def test_search_results( webdriver, webapp ):
"""Test presentation of ruleid's in search results."""
# initialize
webapp.control_tests.set_data_dir( "full" )
init_webapp( webapp, webdriver )
# check the presentation of ruleid's in search results
results = do_search( "flugfeld" )
assert len(results) == 1
assert results[0]["ruleids"] == [ "KGS CG1" ] # nb: no underscore
# test searching for a ruleid that has an underscore
for ruleid in ( "kgs cg1", "kgs_cg1" ):
refresh_webapp( webdriver )
results = do_search( ruleid )
assert results == []
assert get_curr_target() == ( 'kampfgruppe-scherer!', 'KGS_CG1' )
# ---------------------------------------------------------------------
def test_footnotes( webdriver, webapp ):
"""Test presentation of ruleid's in footnotes."""
# initialize
webapp.control_tests.set_data_dir( "full" )
init_webapp( webapp, webdriver )
# search for a rule that has an underscore in its ruleid, and has a footnote
do_search( "flugfeld" )
assert get_curr_target() == ( 'kampfgruppe-scherer!', 'KGS_CG1' )
wait_for( 2,
lambda: "<span class='caption'>KGS CG1</span>" in get_last_footnote_msg()
)
Loading…
Cancel
Save