Tightened up some terminology (targets vs. ruleid's).

master
Pacman Ghost 3 years ago
parent 4aeeb1b809
commit 8ed8670785
  1. 30
      asl_rulebook2/webapp/static/ContentPane.js
  2. 12
      asl_rulebook2/webapp/static/MainApp.js
  3. 10
      asl_rulebook2/webapp/static/NavPane.js
  4. 6
      asl_rulebook2/webapp/static/SearchPane.js
  5. 16
      asl_rulebook2/webapp/static/SearchResult.js
  6. 16
      asl_rulebook2/webapp/static/utils.js
  7. 6
      asl_rulebook2/webapp/tests/test_content_sets.py
  8. 6
      asl_rulebook2/webapp/tests/utils.py

@ -18,7 +18,7 @@ gMainApp.component( "content-pane", {
const showContentDoc = (cdocId) => { const showContentDoc = (cdocId) => {
this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId
} }
gEventBus.on( "show-target", (cdocId, target) => { //eslint-disable-line no-unused-vars gEventBus.on( "show-target", (cdocId, ruleid) => { //eslint-disable-line no-unused-vars
showContentDoc( cdocId ) ; showContentDoc( cdocId ) ;
} ) ; } ) ;
gEventBus.on( "show-page", (cdocId, pageNo) => { //eslint-disable-line no-unused-vars gEventBus.on( "show-page", (cdocId, pageNo) => { //eslint-disable-line no-unused-vars
@ -34,16 +34,16 @@ gMainApp.component( "content-doc", {
props: [ "cdoc" ], props: [ "cdoc" ],
data() { return { data() { return {
target: null, pageNo: null, ruleid: null, pageNo: null,
noContent: gUrlParams.get( "no-content" ), noContent: gUrlParams.get( "no-content" ),
} ; }, } ; },
template: ` template: `
<div class="content-doc" :data-target=target > <div class="content-doc" :data-ruleid=ruleid >
<div v-if=noContent class="disabled"> <div v-if=noContent class="disabled">
<div style='margin-bottom:0.25em;'>&mdash;&mdash;&mdash; Content disabled &mdash;&mdash;&mdash; </div> <div style='margin-bottom:0.25em;'>&mdash;&mdash;&mdash; Content disabled &mdash;&mdash;&mdash; </div>
{{cdoc.title}} {{cdoc.title}}
<div v-if=target> target = {{target}} </div> <div v-if=ruleid> ruleid = {{ruleid}} </div>
<div v-else-if=pageNo> page = {{pageNo}} </div> <div v-else-if=pageNo> page = {{pageNo}} </div>
</div> </div>
<iframe v-else-if=cdoc.url :src=makeDocUrl /> <iframe v-else-if=cdoc.url :src=makeDocUrl />
@ -52,18 +52,18 @@ gMainApp.component( "content-doc", {
created() { created() {
gEventBus.on( "show-target", (cdocId, target) => { gEventBus.on( "show-target", (cdocId, ruleid) => {
if ( cdocId != this.cdoc.cdoc_id || !target ) if ( cdocId != this.cdoc.cdoc_id || !ruleid )
return ; return ;
let targets = findTargets( target, this.cdoc.parent_cset_id ) ; let targets = findTargets( ruleid, this.cdoc.parent_cset_id ) ;
if ( ! targets || targets.length == 0 ) { if ( ! targets || targets.length == 0 ) {
showErrorMsg( "Unknown target: " + target ) ; showErrorMsg( "Unknown ruleid: " + ruleid ) ;
return ; return ;
} }
// scroll to the specified target // scroll to the specified ruleid
// FUDGE! We give the tab time to show itself before we scroll to the target. // FUDGE! We give the tab time to show itself before we scroll to the ruleid.
setTimeout( () => { setTimeout( () => {
this.target = target ; this.ruleid = ruleid ;
this.pageNo = null ; this.pageNo = null ;
}, 50 ) ; }, 50 ) ;
} ) ; } ) ;
@ -72,10 +72,10 @@ gMainApp.component( "content-doc", {
if ( cdocId != this.cdoc.cdoc_id ) if ( cdocId != this.cdoc.cdoc_id )
return ; return ;
// scroll to the specified page // scroll to the specified page
// FUDGE! We give the tab time to show itself before we scroll to the target. // FUDGE! We give the tab time to show itself before we scroll to the page.
setTimeout( () => { setTimeout( () => {
this.pageNo = pageNo ; this.pageNo = pageNo ;
this.target = null ; this.ruleid = null ;
}, 50 ) ; }, 50 ) ;
} ) ; } ) ;
@ -85,8 +85,8 @@ gMainApp.component( "content-doc", {
makeDocUrl() { makeDocUrl() {
let url = this.cdoc.url ; let url = this.cdoc.url ;
if ( this.target ) if ( this.ruleid )
url += "#nameddest=" + this.target ; url += "#nameddest=" + this.ruleid ;
else if ( this.pageNo ) else if ( this.pageNo )
url += "#page=" + this.pageNo ; url += "#page=" + this.pageNo ;
return url ; return url ;

@ -115,14 +115,14 @@ gMainApp.component( "main-app", {
Object.values( contentDocs ).forEach( (cdoc) => { Object.values( contentDocs ).forEach( (cdoc) => {
if ( ! cdoc.targets ) if ( ! cdoc.targets )
return ; return ;
for ( let target in cdoc.targets ) { for ( let ruleid in cdoc.targets ) {
let key = target.toLowerCase() ; let ruleidLC = ruleid.toLowerCase() ;
if ( ! gTargetIndex[ key ] ) if ( ! gTargetIndex[ ruleidLC ] )
gTargetIndex[ key ] = [] ; gTargetIndex[ ruleidLC ] = [] ;
gTargetIndex[ key ].push( { gTargetIndex[ ruleidLC ].push( {
cset_id: cdoc.parent_cset_id, cset_id: cdoc.parent_cset_id,
cdoc_id: cdoc.cdoc_id, cdoc_id: cdoc.cdoc_id,
target: target ruleid: ruleid
} ) ; } ) ;
} }
} ) ; } ) ;

@ -25,21 +25,21 @@ gMainApp.component( "nav-pane", {
created() { created() {
// show any Q+A and annotations when a target is opened // show any Q+A and annotations when a target is opened
gEventBus.on( "show-target", (cdocId, target) => { gEventBus.on( "show-target", (cdocId, ruleid) => {
if ( gAppConfig.DISABLE_AUTO_SHOW_RULE_INFO ) if ( gAppConfig.DISABLE_AUTO_SHOW_RULE_INFO )
return ; return ;
// get the rule info for the target being opened // get the rule info for the target being opened
// NOTE: Targets are associated with a content doc, but the Q+A is global, which is not quite // NOTE: Targets are associated with a content set, but the Q+A is global, which is not quite
// the right thing to do - what if there is a ruleid that is the same multiple content docs, // the right thing to do - what if there is a ruleid that exists in multiple content set,
// but is referenced in the Q+A? Hopefully, this will never happen... :-/ // but is referenced in the Q+A? Hopefully, this will never happen... :-/
let url = gGetRuleInfoUrl.replace( "RULEID", target ) ; //eslint-disable-line no-undef let url = gGetRuleInfoUrl.replace( "RULEID", ruleid ) ; //eslint-disable-line no-undef
$.getJSON( url, (resp) => { $.getJSON( url, (resp) => {
if ( resp.length > 0 ) { if ( resp.length > 0 ) {
// install the rule info entries // install the rule info entries
this.ruleInfo = resp ; this.ruleInfo = resp ;
} }
} ).fail( (xhr, status, errorMsg) => { } ).fail( (xhr, status, errorMsg) => {
showWarningMsg( "Couldn't get the Q+A for " + target + ". <div class='pre'>" + errorMsg + "</div>" ) ; showWarningMsg( "Couldn't get the Q+A for " + ruleid + ". <div class='pre'>" + errorMsg + "</div>" ) ;
} ) ; } ) ;
} ) ; } ) ;

@ -73,12 +73,12 @@ gMainApp.component( "search-results", {
Vue.nextTick( () => { gEventBus.emit( "search-done" ) ; } ) ; Vue.nextTick( () => { gEventBus.emit( "search-done" ) ; } ) ;
} }
// check if the query string is just a target // check if the query string is just a ruleid
let targets = findTargets( queryString, null ) ; let targets = findTargets( queryString, null ) ;
if ( targets && targets.length > 0 ) { if ( targets && targets.length > 0 ) {
// yup - just show it directly (first one, if multiple) // yup - just show it directly (first one, if multiple)
this.searchResults = null ; this.searchResults = null ;
gEventBus.emit( "show-target", targets[0].cdoc_id, targets[0].target ) ; gEventBus.emit( "show-target", targets[0].cdoc_id, targets[0].ruleid ) ;
onSearchDone() ; onSearchDone() ;
return ; return ;
} }
@ -106,7 +106,7 @@ gMainApp.component( "search-results", {
if ( resp.length > 0 && resp[0].sr_type == "index" ) { if ( resp.length > 0 && resp[0].sr_type == "index" ) {
let target = getPrimaryTarget( resp[0] ) ; let target = getPrimaryTarget( resp[0] ) ;
if ( target ) if ( target )
gEventBus.emit( "show-target", target.cdoc_id, target.target ) ; gEventBus.emit( "show-target", target.cdoc_id, target.ruleid ) ;
} }
// flag that the search was completed // flag that the search was completed
onSearchDone() ; onSearchDone() ;

@ -86,7 +86,7 @@ gMainApp.component( "index-sr", {
// open the search result's primary target // open the search result's primary target
let target = getPrimaryTarget( this.sr ) ; let target = getPrimaryTarget( this.sr ) ;
if ( target ) if ( target )
gEventBus.emit( "show-target", target.cdoc_id, target.target ) ; gEventBus.emit( "show-target", target.cdoc_id, target.ruleid ) ;
}, },
onToggleRulerefs() { onToggleRulerefs() {
@ -127,9 +127,9 @@ gMainApp.component( "index-sr", {
let target = getPrimaryTarget( this.sr ) ; let target = getPrimaryTarget( this.sr ) ;
if ( ! target ) if ( ! target )
return null ; return null ;
target = target.target ; let ruleid = target.ruleid ;
if ( isRuleid( target ) ) if ( isRuleid( ruleid ) )
return target[0] ; return ruleid[0] ; // nb: we assume the 1st letter of the ruleid is the chapter ID
return null ; return null ;
}, },
@ -143,11 +143,11 @@ gMainApp.component( "ruleid", {
props: [ "csetId", "ruleId" ], props: [ "csetId", "ruleId" ],
data() { return { data() { return {
cdocId: null, target: null, cdocId: null, ruleid: null,
} ; }, } ; },
// NOTE: This bit of HTML is sensitive to spaces :-/ // NOTE: This bit of HTML is sensitive to spaces :-/
template: `<span class="ruleid" :class="{unknown:!target}">[<a v-if=target @click=onClick>{{ruleId}}</a><span v-else>{{ruleId}}</span>]</span>`, template: `<span class="ruleid" :class="{unknown:!ruleid}">[<a v-if=ruleid @click=onClick>{{ruleId}}</a><span v-else>{{ruleId}}</span>]</span>`,
created() { created() {
// check if the rule is one we know about // check if the rule is one we know about
@ -157,14 +157,14 @@ gMainApp.component( "ruleid", {
// ever adds Chapter Z stuff to the main index, but we'll cross that bridge if and when we come to it. // ever adds Chapter Z stuff to the main index, but we'll cross that bridge if and when we come to it.
// TBH, that stuff would probably be better off as a separate content set, anyway. // TBH, that stuff would probably be better off as a separate content set, anyway.
this.cdocId = targets[0].cdoc_id ; this.cdocId = targets[0].cdoc_id ;
this.target = targets[0].target ; this.ruleid = targets[0].ruleid ;
} }
}, },
methods: { methods: {
onClick() { onClick() {
// show the target // show the target
gEventBus.emit( "show-target", this.cdocId, this.target ) ; gEventBus.emit( "show-target", this.cdocId, this.ruleid ) ;
}, },
}, },

@ -16,15 +16,21 @@ export function getPrimaryTarget( indexSearchResult )
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
export function findTargets( target, csetId ) export function findTargets( ruleid, csetId )
{ {
// check if the target is known to us // NOTE: A "ruleid" is a rule ID (e.g. "A1.23") within a specific document. Hopefully, these will
let pos = target.indexOf( "-" ) ; // be unique across the entire corpus, but we can't guarantee that (Chapter Z, anyone? :-/), so we
// also have the concept of a "target", which is a ruleid plus the content set it's in.
// One can only hope that ruleid's are unique in this context, even if there are multiple documents
// in each content set...
// check if the ruleid is known to us
let pos = ruleid.indexOf( "-" ) ;
if ( pos >= 0 ) { if ( pos >= 0 ) {
// NOTE: For ruleid's of the form "A12.3-.4", we want to target "A12.3". // NOTE: For ruleid's of the form "A12.3-.4", we want to target "A12.3".
target = target.substring( 0, pos ) ; ruleid = ruleid.substring( 0, pos ) ;
} }
let targets = gTargetIndex[ target.toLowerCase() ] ; let targets = gTargetIndex[ ruleid.toLowerCase() ] ;
if ( targets && csetId ) if ( targets && csetId )
targets = targets.filter( (m) => m.cset_id == csetId ) ; targets = targets.filter( (m) => m.cset_id == csetId ) ;
return targets ; return targets ;

@ -51,7 +51,7 @@ def test_targets( webapp, webdriver ):
ruleid_elems[ ruleid ].click() ruleid_elems[ ruleid ].click()
wait_for( 2, lambda: get_curr_target() == (expected, ruleid) ) wait_for( 2, lambda: get_curr_target() == (expected, ruleid) )
# test clicking on ruleid targets # test clicking on ruleid's
do_test( "4b", "content-set-1!linked" ) do_test( "4b", "content-set-1!linked" )
do_test( "1a", "content-set-1" ) do_test( "1a", "content-set-1" )
do_test( "cs2d", "content-set-2" ) do_test( "cs2d", "content-set-2" )
@ -91,7 +91,7 @@ def test_chapters( webapp, webdriver ):
}, },
] ]
# check that the chapter section with a missing ruleid is not clickable # check that the chapter section with a missing target is not clickable
elems = find_children( "#nav .tabbed-page[data-tabid='chapters'] .accordian-pane" ) elems = find_children( "#nav .tabbed-page[data-tabid='chapters'] .accordian-pane" )
assert len(elems) == 6 assert len(elems) == 6
elems = find_children( ".entry", elems[1] ) elems = find_children( ".entry", elems[1] )
@ -120,7 +120,7 @@ def test_chapters( webapp, webdriver ):
do_test( 2, 1, ( "content-set-1!linked", "2b" ) ) do_test( 2, 1, ( "content-set-1!linked", "2b" ) )
# try to show an unknown target # try to show an unknown target
do_test( 3, 3, "Unknown target:" ) do_test( 3, 3, "Unknown ruleid:" )
# --------------------------------------------------------------------- # ---------------------------------------------------------------------

@ -81,10 +81,10 @@ def get_curr_target():
if not elem: if not elem:
return ( None, None ) return ( None, None )
tab_id = elem.get_attribute( "data-tabid" ) tab_id = elem.get_attribute( "data-tabid" )
# check the current target # check the current ruleid
elem = find_child( "#content .tabbed-page[data-tabid='{}'] .content-doc".format( tab_id ) ) elem = find_child( "#content .tabbed-page[data-tabid='{}'] .content-doc".format( tab_id ) )
target = elem.get_attribute( "data-target" ) ruleid = elem.get_attribute( "data-ruleid" )
return ( tab_id, target ) return ( tab_id, ruleid )
# --------------------------------------------------------------------- # ---------------------------------------------------------------------

Loading…
Cancel
Save