@@ -33,7 +33,9 @@ createApp({
33
33
annotationId : '' ,
34
34
object : null , // ?
35
35
image : null , // ?
36
- searchPhrase : '' ,
36
+ // if null, &img in query string will be the phrase.
37
+ // if '' the phrase will be empty.
38
+ searchPhrase : null ,
37
39
dateFrom : DATE_MIN ,
38
40
dateTo : DATE_MAX ,
39
41
facets : { } ,
@@ -98,7 +100,7 @@ createApp({
98
100
}
99
101
100
102
this . setSelectionFromAddressBar ( )
101
- this . search ( true )
103
+ this . search ( )
102
104
} ,
103
105
watch : {
104
106
'selection.searchPhrase' ( ) {
@@ -459,7 +461,7 @@ createApp({
459
461
per_page : this . selection . perPage ,
460
462
page : this . selection . page ,
461
463
sort : 'or1' ,
462
- query : this . selection . searchPhrase ,
464
+ query : ( this . selection . searchPhrase || '' ) . trim ( ) ,
463
465
filters : this . selection . facets
464
466
}
465
467
if ( this . selection . dateFrom > DATE_MIN || this . selection . dateTo < DATE_MAX ) {
@@ -696,7 +698,18 @@ createApp({
696
698
for ( let facet of Object . keys ( this . selection . facets ) ) {
697
699
searchParams [ `f.${ facet } ` ] = this . selection . facets [ facet ] . join ( '|' )
698
700
}
699
- utils . setQueryString ( searchParams )
701
+
702
+ let defaults = {
703
+ // make sure q is always in the query string, even if ''
704
+ q : 'DEFAULT' ,
705
+ pag : 1 ,
706
+ ppg : ITEMS_PER_PAGE ,
707
+ daf : DATE_MIN ,
708
+ dat : DATE_MAX ,
709
+ sup : 0 ,
710
+ }
711
+
712
+ utils . setQueryString ( searchParams , defaults )
700
713
} ,
701
714
setSelectionFromAddressBar ( ) {
702
715
let searchParams = new URLSearchParams ( window . location . search ) ;
@@ -705,16 +718,19 @@ createApp({
705
718
this . selection . image = searchParams . get ( 'img' ) || ''
706
719
this . selection . showSuppliedText = searchParams . get ( 'sup' ) === '1'
707
720
this . selection . annotationId = searchParams . get ( 'ann' ) || ''
708
- this . selection . dateFrom = searchParams . get ( 'daf' ) || DATE_MIN
709
- this . selection . dateTo = searchParams . get ( 'dat' ) || DATE_MAX
710
- // this.description.script = searchParams.get('scr') || ''
721
+ this . selection . dateFrom = this . _getNumberFromString ( searchParams . get ( 'daf' ) , DATE_MIN )
722
+ this . selection . dateTo = this . _getNumberFromString ( searchParams . get ( 'dat' ) , DATE_MAX )
723
+ // this.description.script = searchParams.get('scr') || ''
711
724
712
- this . selection . searchPhrase = searchParams . get ( 'q' ) || ''
713
- if ( ! this . selection . searchPhrase && this . selection . image ) {
725
+ this . selection . searchPhrase = searchParams . get ( 'q' )
726
+ if ( this . selection . searchPhrase === null && this . selection . image ) {
714
727
this . selection . searchPhrase = this . selection . image . replace ( / \. [ ^ . ] + $ / , '' )
728
+ } else {
729
+ this . selection . searchPhrase = ( this . selection . searchPhrase || '' ) . trim ( )
715
730
}
716
- this . selection . page = parseInt ( searchParams . get ( 'pag' ) || '1' )
717
- this . selection . perPage = parseInt ( searchParams . get ( 'ppg' ) || ITEMS_PER_PAGE )
731
+
732
+ this . selection . page = this . _getNumberFromString ( searchParams . get ( 'pag' ) , 1 )
733
+ this . selection . perPage = this . _getNumberFromString ( searchParams . get ( 'ppg' ) , ITEMS_PER_PAGE )
718
734
719
735
for ( let facet of Object . keys ( this . getFacetDefinitions ( ) ) ) {
720
736
let options = searchParams . get ( `f.${ facet } ` )
@@ -723,5 +739,11 @@ createApp({
723
739
}
724
740
}
725
741
} ,
742
+ _getNumberFromString ( stringValue , defaultValue = 0 ) {
743
+ let res = parseInt ( stringValue )
744
+ let ret = isNaN ( res ) ? defaultValue : res
745
+ console . log ( stringValue , res , defaultValue , ret )
746
+ return ret
747
+ }
726
748
}
727
749
} ) . mount ( '#search' ) ;
0 commit comments