Load content docs on demand.

master
Pacman Ghost 3 years ago
parent 25bd56739b
commit 45c6c5e48f
  1. 42
      asl_rulebook2/webapp/static/ContentPane.js
  2. 16
      asl_rulebook2/webapp/static/MainApp.js
  3. 10
      asl_rulebook2/webapp/tests/test_startup.py

@ -6,11 +6,14 @@ import { findTargets, showErrorMsg, showNotificationMsg, hideFootnotes } from ".
gMainApp.component( "content-pane", {
props: [ "contentDocs" ],
data() { return {
loadedContentDocs: {},
} ; },
template: `
<div>
<tabbed-pages tabbedPagesId="content" ref="tabbedPages">
<tabbed-page v-for="cdoc in contentDocs" :tabId=cdoc.cdoc_id :caption=cdoc.title :key=cdoc.cdoc_id >
<tabbed-page v-for="cdoc in loadedContentDocs" :tabId=cdoc.cdoc_id :caption=cdoc.title :key=cdoc.cdoc_id >
<content-doc :cdoc=cdoc />
</tabbed-page>
</tabbed-pages>
@ -34,16 +37,47 @@ gMainApp.component( "content-pane", {
mounted() {
const showContentDoc = (cdocId) => {
this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId
// check if the content doc has already been loaded
let cdoc = this.loadedContentDocs[ cdocId ] ;
if ( cdoc == undefined ) {
// nope - load it
this.loadedContentDocs[ cdocId ] = this.contentDocs[ cdocId ] ;
}
this.$nextTick( () => {
this.$refs.tabbedPages.activateTab( cdocId ) ; // nb: tabId == cdocId
} ) ;
return (cdoc == undefined) ;
}
gEventBus.on( "show-target", (cdocId, ruleid) => { //eslint-disable-line no-unused-vars
showContentDoc( cdocId ) ;
let wasLoaded = showContentDoc( cdocId ) ;
if ( wasLoaded ) {
// FUDGE! If we just loaded a new content doc, it won't have been around to receive
// the "show-target" event, so we re-issue it here. This might cause some minor
// problems (e.g. footnotes showing twice), but we seem to be OK.
this.$nextTick( () => {
gEventBus.emit( "show-target", cdocId, ruleid ) ;
} ) ;
}
} ) ;
gEventBus.on( "show-page", (cdocId, pageNo) => { //eslint-disable-line no-unused-vars
showContentDoc( cdocId ) ;
let wasLoaded = showContentDoc( cdocId ) ;
if ( wasLoaded ) {
// FUDGE! If we just loaded a new content doc, it won't have been around to receive
// the "show-page" event, so we re-issue it here.
this.$nextTick( () => {
gEventBus.emit( "show-page", cdocId, pageNo ) ;
} ) ;
}
} ) ;
},
beforeUpdate() {
// make sure the test empty document is loaded
let cdoc = this.contentDocs[ "empty" ] ;
if ( cdoc != undefined )
this.loadedContentDocs[ "empty" ] = cdoc ;
},
methods: {
showFootnotes( footnotes ) {

@ -115,11 +115,19 @@ gMainApp.component( "main-app", {
resp["empty"] = { "cdoc_id": "empty", "title": "Empty document" } ; // nb: for testing porpoises
self.contentDocs = resp ;
self.installContentDocs( resp ) ;
// start off showing the first content doc
let cdocIds = Object.keys( resp ) ;
if ( cdocIds.length > 0 ) {
// start off showing the main ASL rulebook
// NOTE: To avoid forcing the user to configure which document this is, we assume that
// it's the one with the most targets.
let targetCdocId = null ;
for ( let cdocId in self.contentDocs ) {
if ( self.contentDocs[cdocId].targets == undefined )
continue
if ( targetCdocId == null || Object.keys(self.contentDocs[cdocId].targets).length > Object.keys(self.contentDocs[targetCdocId].targets).length )
targetCdocId = cdocId ;
}
if ( targetCdocId != null ) {
Vue.nextTick( () => {
gEventBus.emit( "show-page", cdocIds[0], 1 ) ; // FIXME! which cdoc do we choose?
gEventBus.emit( "show-page", targetCdocId, 1 ) ;
} ) ;
}
} ).catch( (errorMsg) => {

@ -19,16 +19,6 @@ def test_load_content_docs( webapp, webdriver ):
# for it), and we degrade gracefully.
assert len( find_children( "#content .tabbed-page" ) ) == 0
# test handling of an invalid targets file
webapp.control_tests.set_data_dir( "invalid-targets" )
init_webapp( webapp, webdriver, warnings=["Couldn't load \"test.targets\"."] )
assert len( find_children( "#content .tabbed-page" ) ) == 1
# test handling of an invalid footnotes file
webapp.control_tests.set_data_dir( "invalid-footnotes" )
init_webapp( webapp, webdriver, warnings=["Couldn't load \"test.footnotes\"."] )
assert len( find_children( "#content .tabbed-page" ) ) == 1
# ---------------------------------------------------------------------
def test_init_search( webapp, webdriver ):

Loading…
Cancel
Save