You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.3 KiB
145 lines
4.3 KiB
import { gMainApp, gAppConfig, gContentDocs, gEventBus } from "./MainApp.js" ;
|
|
import { showWarningMsg } from "./utils.js" ;
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
gMainApp.component( "nav-pane", {
|
|
|
|
data() { return {
|
|
ruleInfo: [],
|
|
} ; },
|
|
|
|
template: `
|
|
<div>
|
|
<tabbed-pages>
|
|
<tabbed-page tabId="search" caption="Search" >
|
|
<nav-pane-search />
|
|
</tabbed-page>
|
|
<tabbed-page tabId="chapters" caption="Chapters" >
|
|
<nav-pane-chapters />
|
|
</tabbed-page>
|
|
</tabbed-pages>
|
|
<rule-info :ruleInfo=ruleInfo @close=closeRuleInfo />
|
|
</div>`,
|
|
|
|
created() {
|
|
|
|
gEventBus.on( "show-target", (cdocId, ruleid) => {
|
|
if ( gAppConfig.DISABLE_AUTO_SHOW_RULE_INFO )
|
|
return ;
|
|
// get the Q+A and annotations for the target being opened
|
|
// 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", 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 " + ruleid + ". <div class='pre'>" + errorMsg + "</div>" ) ;
|
|
} ) ;
|
|
} ) ;
|
|
|
|
// close the rule info popup if Escape is pressed
|
|
gEventBus.on( "escape-pressed", () => {
|
|
if ( $( ".growl-footnote" ).length > 0 )
|
|
return ; // nb: unless a footnote on-screen (let the Escape close that instead)
|
|
this.closeRuleInfo() ;
|
|
} ) ;
|
|
|
|
},
|
|
|
|
methods: {
|
|
closeRuleInfo() {
|
|
// close the rule info popup
|
|
let isOpen = this.ruleInfo.length > 0 ;
|
|
this.ruleInfo = [] ;
|
|
return isOpen ;
|
|
},
|
|
},
|
|
|
|
} ) ;
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
gMainApp.component( "nav-pane-search", {
|
|
|
|
data() { return {
|
|
seqNo: 0, // nb: for the test suite
|
|
} ; },
|
|
|
|
template: `
|
|
<search-box id="search-box" @search=onSearch />
|
|
<search-results :data-seqno=seqNo id="search-results" />
|
|
`,
|
|
|
|
created() {
|
|
// notify the test suite that the search results are now available
|
|
gEventBus.on( "search-done", () => {
|
|
this.seqNo += 1 ;
|
|
} ) ;
|
|
},
|
|
|
|
methods: {
|
|
|
|
onSearch( queryString ) {
|
|
// run the search (handled elsewhere)
|
|
if ( $("#rule-info").css( "display" ) != "none" )
|
|
return ; // nb: dont respond to key-presses if the rule info popup is open
|
|
gEventBus.emit( "search", queryString ) ;
|
|
},
|
|
|
|
},
|
|
|
|
} ) ;
|
|
|
|
// --------------------------------------------------------------------
|
|
|
|
gMainApp.component( "nav-pane-chapters", {
|
|
|
|
data() { return {
|
|
chapters: [],
|
|
} ; },
|
|
|
|
template: `
|
|
<accordian>
|
|
<accordian-pane v-if="chapters.length > 0" v-for="c in chapters"
|
|
:key=c :paneKey=c[0] :entries=c[1].sections
|
|
:title=c[1].title :iconUrl=c[1].icon :backgroundUrl=c[1].background
|
|
@pane-expanded=onChapterPaneExpanded(c[0],c[1])
|
|
@entry-clicked=onChapterSectionClicked
|
|
/>
|
|
<div v-else class="no-chapters"> No chapters. </div>
|
|
</accordian>
|
|
`,
|
|
|
|
created() {
|
|
// initialize the chapters
|
|
gEventBus.on( "app-loaded", () => {
|
|
Object.values( gContentDocs ).forEach( (cdoc) => {
|
|
if ( ! cdoc.chapters )
|
|
return ;
|
|
cdoc.chapters.forEach( (chapter) => {
|
|
this.chapters.push( [ cdoc.cdoc_id, chapter ] ) ;
|
|
} ) ;
|
|
} ) ;
|
|
} ) ;
|
|
},
|
|
|
|
methods: {
|
|
|
|
onChapterPaneExpanded( cdocId, chapter ) {
|
|
// show the first page of the specified chapter
|
|
gEventBus.emit( "show-page", cdocId, chapter.page_no ) ;
|
|
},
|
|
|
|
onChapterSectionClicked( cdocId, entry ) {
|
|
// show the chapter section's target
|
|
gEventBus.emit( "show-target", cdocId, entry.ruleid ) ;
|
|
|
|
},
|
|
},
|
|
|
|
} ) ;
|
|
|