Changed the timing of the startup query.

master
Pacman Ghost 3 years ago
parent 4bd84227e6
commit 1486594c0f
  1. 59
      asl_rulebook2/webapp/static/MainApp.js
  2. 11
      asl_rulebook2/webapp/static/SearchPane.js

@ -77,11 +77,7 @@ gMainApp.component( "main-app", {
this.getFootnoteIndex(),
this.getASOP(),
] ).then( () => {
this.isLoaded = true ;
gEventBus.emit( "app-loaded" ) ;
$( "#watermark" ).css( "opacity", 0.15 ) ;
this.showStartupMsgs() ;
$( "#query-string" ).focus() ; // nb: because autofocus on the <input> doesn't work :-/
this.onStartupDone() ;
} ).catch( () => {
// NOTE: Each individual Promise should report their own errors i.e. what could we do here,
// other than show a generic "startup failed" error?
@ -115,21 +111,6 @@ 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 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", targetCdocId, 1 ) ;
} ) ;
}
} ).catch( (errorMsg) => {
showErrorMsg( "Couldn't get the content docs.", errorMsg ) ;
} ) ;
@ -212,9 +193,9 @@ gMainApp.component( "main-app", {
} ) ;
},
showStartupMsgs() {
onStartupDone() {
// show any startup messages
return getJSON( gGetStartupMsgsUrl ).then( (resp) => { //eslint-disable-line no-undef
getJSON( gGetStartupMsgsUrl ).then( (resp) => { //eslint-disable-line no-undef
[ "info", "warning", "error" ].forEach( (msgType) => {
if ( ! resp[msgType] )
return ;
@ -227,6 +208,40 @@ gMainApp.component( "main-app", {
} ).catch( (errorMsg) => {
showErrorMsg( "Couldn't get the startup messages.", errorMsg ) ;
} ) ;
// check if we should start with a query
let queryString = gUrlParams.get( "query" ) || gUrlParams.get( "q" ) ;
if ( window.location.hash != "" )
queryString = window.location.hash.substring( 1 ) ;
if ( queryString != null && queryString != undefined ) {
// yup - make it so
// NOTE: The content pane flickers as it shows the cover page, then jumps to search result.
// I tried opening the PDF at the target destination, but the same thing still happens :-(
gEventBus.emit( "search", queryString ) ;
} else {
// 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 this.contentDocs ) {
if ( this.contentDocs[cdocId].targets == undefined )
continue
if ( targetCdocId == null || Object.keys(this.contentDocs[cdocId].targets).length > Object.keys(this.contentDocs[targetCdocId].targets).length )
targetCdocId = cdocId ;
}
if ( targetCdocId != null ) {
Vue.nextTick( () => {
gEventBus.emit( "show-page", targetCdocId, 1 ) ;
} ) ;
}
}
// update the UI
$( "#watermark" ).css( "opacity", 0.15 ) ;
this.$nextTick( () => {
$( "#query-string" ).focus() ; // nb: because autofocus on the <input> doesn't work :-/
} ) ;
// notify everyone that startup has completed
this.isLoaded = true ;
gEventBus.emit( "app-loaded" ) ;
},
onEscapePressed() {

@ -1,4 +1,4 @@
import { gMainApp, gAppConfig, gUrlParams, gEventBus } from "./MainApp.js" ;
import { gMainApp, gAppConfig, gEventBus } from "./MainApp.js" ;
import { gUserSettings, saveUserSettings } from "./UserSettings.js" ;
import { postURL, findTargets, getPrimaryTarget, linkifyAutoRuleids, fixupSearchHilites, hideFootnotes } from "./utils.js" ;
@ -71,15 +71,6 @@ gMainApp.component( "search-box", {
}
} ) ;
gEventBus.on( "app-loaded", () => {
// check if we should start off with a query
let queryString = gUrlParams.get( "query" ) || gUrlParams.get( "q" ) || gAppConfig.WEBAPP_INITIAL_QUERY_STRING ;
if ( window.location.hash != "" )
queryString = window.location.hash.substring( 1 ) ;
if ( queryString != null && queryString != undefined )
gEventBus.emit( "search-for", queryString ) ;
} ) ;
gEventBus.on( "tab-activated", (tabbedPages, tabId) => {
// set focus to the query string input box
if ( tabbedPages.tabbedPagesId == "nav" && tabId == "search" )

Loading…
Cancel
Save