Changed how ASOP chapter preambles are managed.

master
Pacman Ghost 3 years ago
parent 764c771090
commit aea931158a
  1. 28
      asl_rulebook2/webapp/asop.py
  2. 13
      asl_rulebook2/webapp/search.py
  3. 4
      asl_rulebook2/webapp/startup.py
  4. 37
      asl_rulebook2/webapp/static/ASOP.js
  5. 4
      asl_rulebook2/webapp/static/NavPane.js
  6. 1
      asl_rulebook2/webapp/static/css/global.css
  7. 4
      asl_rulebook2/webapp/static/utils.js
  8. 1
      asl_rulebook2/webapp/templates/index.html

@ -10,6 +10,7 @@ from asl_rulebook2.webapp.utils import load_data_file
_asop = None
_asop_dir = None
_asop_preambles = None
_asop_section_content = None
_footer = None
user_css_url = None
@ -20,16 +21,16 @@ def init_asop( startup_msgs, logger ):
"""Initialize the ASOP."""
# initiailize
global _asop, _asop_dir, _asop_section_content, _footer, user_css_url
_asop, _asop_section_content, _footer = {}, {}, ""
global _asop, _asop_dir, _asop_preambles, _asop_section_content, _footer, user_css_url
_asop, _asop_preambles, _asop_section_content, _footer = {}, {}, {}, ""
# get the data directory
data_dir = app.config.get( "DATA_DIR" )
if not data_dir:
return None, None
return None, None, None
base_dir = os.path.join( data_dir, "asop/" )
if not os.path.isdir( base_dir ):
return None, None
return None, None, None
_asop_dir = base_dir
fname = os.path.join( base_dir, "asop.css" )
if os.path.isfile( fname ):
@ -39,17 +40,18 @@ def init_asop( startup_msgs, logger ):
fname = os.path.join( base_dir, "index.json" )
_asop = load_data_file( fname, "ASOP index", False, logger, startup_msgs.error )
if not _asop:
return None, None
return None, None, None
# load the ASOP content
for chapter in _asop.get( "chapters", [] ):
chapter_id = chapter[ "chapter_id" ]
# load the chapter preamble
preamble = _render_template( chapter["chapter_id"] + "-0.html" )
preamble = _render_template( chapter_id + "-0.html" )
if preamble:
chapter["preamble"] = preamble
_asop_preambles[chapter_id] = preamble
# load the content for each section
for section_no, section in enumerate( chapter.get( "sections", [] ) ):
section_id = "{}-{}".format( chapter["chapter_id"], 1+section_no )
section_id = "{}-{}".format( chapter_id, 1+section_no )
section[ "section_id" ] = section_id
content = _render_template( section_id + ".html" )
_asop_section_content[ section_id ] = content
@ -58,7 +60,7 @@ def init_asop( startup_msgs, logger ):
footer = _render_template( "footer.html" )
_footer = tag_ruleids( footer, None )
return _asop, _asop_section_content
return _asop, _asop_preambles, _asop_section_content
# ---------------------------------------------------------------------
@ -82,6 +84,14 @@ def get_asop_footer():
abort( 404 )
return _footer
@app.route( "/asop/preamble/<chapter_id>" )
def get_asop_preamble( chapter_id ):
"""Return the specified ASOP chapter preamble."""
content = _asop_preambles.get( chapter_id )
if not content:
abort( 404 )
return content
@app.route( "/asop/section/<section_id>" )
def get_asop_section( section_id ):
"""Return the specified ASOP section."""

@ -417,7 +417,7 @@ def _adjust_sort_order( results ):
# ---------------------------------------------------------------------
def init_search( content_sets, qa, errata, user_anno, asop, asop_content, startup_msgs, logger ):
def init_search( content_sets, qa, errata, user_anno, asop, asop_preambles, asop_content, startup_msgs, logger ):
"""Initialize the search engine."""
# initialize
@ -458,7 +458,7 @@ def init_search( content_sets, qa, errata, user_anno, asop, asop_content, startu
if user_anno:
_init_user_anno( curs, user_anno, logger )
if asop:
_init_asop( curs, asop, asop_content, logger )
_init_asop( curs, asop, asop_preambles, asop_content, logger )
conn.commit()
# load the search config
@ -611,15 +611,14 @@ def _do_init_anno( curs, anno, atype ):
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
def _init_asop( curs, asop, asop_content, logger ):
def _init_asop( curs, asop, asop_preambles, asop_content, logger ):
"""Add the ASOP to the search index."""
logger.info( "- Adding the ASOP." )
sr_type = "asop-entry"
fixup_chapters, fixup_sections = [], []
fixup_sections = []
nentries = 0
for chapter in asop.get( "chapters", [] ):
fixup_chapters.append( chapter )
for section in chapter.get( "sections", [] ):
content = asop_content.get( section["section_id"] )
if not content:
@ -646,8 +645,8 @@ def _init_asop( curs, asop, asop_content, logger ):
_fixup_searchable_content( sr_type, fixup_entry, make_fields )
# we also need to fixup the in-memory data structures
cset_id = None
for chapter in fixup_chapters:
_tag_ruleids_in_field( chapter, "preamble", cset_id )
for chapter_id in asop_preambles:
_tag_ruleids_in_field( asop_preambles, chapter_id, cset_id )
for section in fixup_sections:
_tag_ruleids_in_field( asop_content, section["section_id"], cset_id )
def fixup_entry( rowid, cset_id ):

@ -52,11 +52,11 @@ def init_webapp():
user_anno = init_annotations( _startup_msgs, _logger )
if user_anno:
_capabilities[ "user-anno" ] = True
asop, asop_content = init_asop( _startup_msgs, _logger )
asop, asop_preambles, asop_content = init_asop( _startup_msgs, _logger )
if asop:
_capabilities[ "asop" ] = True
init_search(
content_sets, qa, errata, user_anno, asop, asop_content,
content_sets, qa, errata, user_anno, asop, asop_preambles, asop_content,
_startup_msgs, _logger
)

@ -21,7 +21,7 @@ gMainApp.component( "asop", {
<div v-if=isActive :data-chapterid=chapterId id="asop" class="asop" >
<div class="title">
<span v-html=title />
<collapser collapserId="asop-preamble" ref="collapser" />
<collapser v-if=preamble collapserId="asop-preamble" ref="collapser" />
</div>
<collapsible collapsedHeight=5 ref="collapsible">
<div v-html=preamble class="preamble" />
@ -80,15 +80,14 @@ gMainApp.component( "asop", {
showIntro() {
// show the ASOP intro
this.title = "Advanced Sequence Of Play" ;
this.preamble = null ;
this.sections = [] ;
this.isSingleSection = true ;
this.chapterId = "intro" ;
getURL( gGetASOPIntroUrl ).then( (resp) => { //eslint-disable-line no-undef
this.sections = [ this.fixupContent( resp ) ] ;
} ).catch( (errorMsg) => {
} ).catch( (xhr) => {
// NOTE: We show the error in the content, not as a notification balloon.
this.sections = [ "Couldn't get the ASOP intro." + " <div class='pre'>" + errorMsg + "</div>" ] ;
this.sections = [ "Couldn't get the ASOP intro." + " <div class='pre'>" + xhr.statusText + "</div>" ] ;
} ) ;
} ,
@ -98,13 +97,13 @@ gMainApp.component( "asop", {
// prepare to show the ASOP chapter (with all sections combined)
this.isActive = true ;
this.title = this.makeTitle( chapter, chapter.caption ) ;
this.preamble = this.fixupContent( chapter.preamble ) ;
this.sections = chapter.sections ? Array( chapter.sections.length ) : [] ;
this.isSingleSection = false ;
this.chapterId = chapter.chapter_id ;
// show the preamble and each section
this.showPreamble( chapter.chapter_id ) ;
if ( this.sections.length == 0 )
return ;
// show each section
let addSectionContent = (sectionNo, content) => {
this.sections[ sectionNo ] =
"<div class='caption'>" + chapter.sections[sectionNo].caption + "</div>"
@ -122,11 +121,11 @@ gMainApp.component( "asop", {
let url = gGetASOPSectionUrl.replace( "SECTION_ID", sectionId ) ; //eslint-disable-line no-undef
getURL( url ).then( (resp) => {
addSectionContent( sectionNo, resp ) ;
} ).catch( (errorMsg) => {
} ).catch( (xhr) => {
// NOTE: We show the error in the content, not as a notification balloon.
this.sections[ sectionNo ] =
"Couldn't get ASOP section <tt>" + sectionId + "</tt>."
+ " <div class='pre'>" + errorMsg + "</div>" ;
+ " <div class='pre'>" + xhr.statusText + "</div>" ;
} ) ;
}
} ) ;
@ -134,15 +133,16 @@ gMainApp.component( "asop", {
showASOPSection( chapter, section ) {
this.doShowASOPSection( chapter, section, "" ) ;
// show the specified ASOP section
// show the preamble and specified ASOP section
this.showPreamble( chapter.chapter_id ) ;
let sectionId = section.section_id ;
let url = gGetASOPSectionUrl.replace( "SECTION_ID", sectionId ) ; //eslint-disable-line no-undef
getURL( url ).then( (resp) => {
this.doShowASOPSection( chapter, section, resp ) ;
} ).catch( (errorMsg) => {
} ).catch( (xhr) => {
// NOTE: We show the error in the content, not as a notification balloon.
this.sections = [
"Couldn't get ASOP section <tt>"+sectionId+"</tt>." + " <div class='pre'>" + errorMsg + "</div>"
"Couldn't get ASOP section <tt>"+sectionId+"</tt>." + " <div class='pre'>" + xhr.statusText + "</div>"
] ;
} ) ;
},
@ -164,11 +164,24 @@ gMainApp.component( "asop", {
this.doShowASOPSection( chapter, section, content ) ;
},
showPreamble( chapterId ) {
let url = gGetASOPPreambleUrl.replace( "CHAPTER_ID", chapterId ) ; //eslint-disable-line no-undef
getURL( url ).then( (resp) => {
this.preamble = this.fixupContent( resp ) ;
} ).catch( (xhr) => {
if ( xhr.status == 404 )
this.preamble = null ;
else {
this.preamble = "Couldn't get ASOP preamble <tt>" + chapterId + "</tt>."
+ " <div class='pre'>" + xhr.statusText + "</div>" ;
}
} ) ;
},
doShowASOPSection( chapter, section, content ) {
// show the specified ASOP section
this.isActive = true ;
this.title = this.makeTitle( chapter, section.caption ) ;
this.preamble = this.fixupContent( chapter.preamble ) ;
let contentOverride = gSectionContentOverrides[ section.section_id ] ;
this.sections = [ this.fixupContent( contentOverride || content ) ] ;
this.isSingleSection = true ;

@ -194,8 +194,8 @@ gMainApp.component( "nav-pane-asop", {
this.$nextTick( () => {
linkifyAutoRuleids( $( this.$refs.footer ) ) ;
} ) ;
} ).catch( (errorMsg) => {
console.log( "Couldn't get the ASOP footer: " + errorMsg ) ;
} ).catch( (xhr) => {
console.log( "Couldn't get the ASOP footer: " + xhr.statusText ) ;
} ) ;
} ) ;

@ -16,6 +16,7 @@ ul ul ul { list-style-image: url(../images/bullet3.png) ; }
/* content */
.hilite { padding: 0 2px ; background: #ffa ; }
.exc { font-style: italic ; color: #666 ; }
.exc .auto-ruleid { color: #555 ; }
.auto-ruleid { color: red ; }
.auto-ruleid:hover { background: #ffffcc ; }

@ -210,8 +210,8 @@ export function getURL( url )
return new Promise( (resolve, reject) => {
$.get( url, (resp) => {
resolve( resp ) ;
} ).fail( (xhr, status, errorMsg) => {
reject( errorMsg ) ;
} ).fail( (xhr, status, errorMsg) => { //eslint-disable-line no-unused-vars
reject( xhr ) ;
} ) ;
} ) ;
}

@ -62,6 +62,7 @@ gGetContentDocsUrl = "{{ url_for( 'get_content_docs' ) }}" ;
gGetASOPUrl = "{{ url_for( 'get_asop' ) }}" ;
gGetASOPIntroUrl = "{{ url_for( 'get_asop_intro' ) }}" ;
gGetASOPFooterUrl = "{{ url_for( 'get_asop_footer' ) }}" ;
gGetASOPPreambleUrl = "{{ url_for( 'get_asop_preamble', chapter_id='CHAPTER_ID' ) }}" ;
gGetASOPSectionUrl = "{{ url_for( 'get_asop_section', section_id='SECTION_ID' ) }}" ;
gGetStartupMsgsUrl = "{{ url_for( 'get_startup_msgs' ) }}" ;
gSearchUrl = "{{ url_for( 'search' ) }}" ;

Loading…
Cancel
Save