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

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

@ -25,21 +25,21 @@ gMainApp.component( "nav-pane", {
created() {
// 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 )
return ;
// 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
// the right thing to do - what if there is a ruleid that is the same multiple content docs,
// 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 exists in multiple content set,
// 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) => {
if ( resp.length > 0 ) {
// install the rule info entries
this.ruleInfo = resp ;
}
} ).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" ) ; } ) ;
}
// check if the query string is just a target
// check if the query string is just a ruleid
let targets = findTargets( queryString, null ) ;
if ( targets && targets.length > 0 ) {
// yup - just show it directly (first one, if multiple)
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() ;
return ;
}
@ -106,7 +106,7 @@ gMainApp.component( "search-results", {
if ( resp.length > 0 && resp[0].sr_type == "index" ) {
let target = getPrimaryTarget( resp[0] ) ;
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
onSearchDone() ;

@ -86,7 +86,7 @@ gMainApp.component( "index-sr", {
// open the search result's primary target
let target = getPrimaryTarget( this.sr ) ;
if ( target )
gEventBus.emit( "show-target", target.cdoc_id, target.target ) ;
gEventBus.emit( "show-target", target.cdoc_id, target.ruleid ) ;
},
onToggleRulerefs() {
@ -127,9 +127,9 @@ gMainApp.component( "index-sr", {
let target = getPrimaryTarget( this.sr ) ;
if ( ! target )
return null ;
target = target.target ;
if ( isRuleid( target ) )
return target[0] ;
let ruleid = target.ruleid ;
if ( isRuleid( ruleid ) )
return ruleid[0] ; // nb: we assume the 1st letter of the ruleid is the chapter ID
return null ;
},
@ -143,11 +143,11 @@ gMainApp.component( "ruleid", {
props: [ "csetId", "ruleId" ],
data() { return {
cdocId: null, target: null,
cdocId: null, ruleid: null,
} ; },
// 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() {
// 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.
// TBH, that stuff would probably be better off as a separate content set, anyway.
this.cdocId = targets[0].cdoc_id ;
this.target = targets[0].target ;
this.ruleid = targets[0].ruleid ;
}
},
methods: {
onClick() {
// 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
let pos = target.indexOf( "-" ) ;
// NOTE: A "ruleid" is a rule ID (e.g. "A1.23") within a specific document. Hopefully, these will
// 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 ) {
// 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 )
targets = targets.filter( (m) => m.cset_id == csetId ) ;
return targets ;

@ -51,7 +51,7 @@ def test_targets( webapp, webdriver ):
ruleid_elems[ ruleid ].click()
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( "1a", "content-set-1" )
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" )
assert len(elems) == 6
elems = find_children( ".entry", elems[1] )
@ -120,7 +120,7 @@ def test_chapters( webapp, webdriver ):
do_test( 2, 1, ( "content-set-1!linked", "2b" ) )
# 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:
return ( None, None )
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 ) )
target = elem.get_attribute( "data-target" )
return ( tab_id, target )
ruleid = elem.get_attribute( "data-ruleid" )
return ( tab_id, ruleid )
# ---------------------------------------------------------------------

Loading…
Cancel
Save