@@ -310,6 +310,14 @@ function initIndicatorForm(dataSource, studyUnit) {
310310
311311 clearAppliedFiltersContainer ( ) ;
312312 renderChartsContainer ( data , dataSource , studyUnit , formData . get ( 'csrfmiddlewaretoken' ) ) ;
313+
314+ const firstChart = Array . isArray ( data . charts ) && data . charts . find ( c => ! c . is_relative ) ;
315+ if ( firstChart ) {
316+ const total = ( firstChart . series || [ ] ) . reduce (
317+ ( sum , s ) => sum + ( s . data || [ ] ) . reduce ( ( a , b ) => a + ( Number ( b ) || 0 ) , 0 ) , 0
318+ ) ;
319+ updateSearchButtonTotal ( total ) ;
320+ }
313321 } )
314322 . catch ( error => {
315323 console . error ( 'Error:' , error ) ;
@@ -354,9 +362,57 @@ function initIndicatorForm(dataSource, studyUnit) {
354362 }
355363}
356364
365+ function updateSearchButtonTotal ( total ) {
366+ const el = document . getElementById ( 'indicator-search-total' ) ;
367+ if ( ! el ) return ;
368+ el . textContent = typeof total === 'number' ? total . toLocaleString ( ) : total ;
369+ }
370+
371+ function initGoToSearchButton ( ) {
372+ const btn = document . getElementById ( 'indicator-go-to-search' ) ;
373+ if ( ! btn ) return ;
374+
375+ btn . addEventListener ( 'click' , ( event ) => {
376+ event . preventDefault ( ) ;
377+
378+ const searchUrl = ( btn . dataset . searchUrl || '' ) . trim ( ) ;
379+ if ( ! searchUrl ) return ;
380+
381+ const menuForm = document . getElementById ( 'indicator-filter-form' ) ;
382+ const filters = menuForm && window . SearchGatewayFilterForm
383+ ? window . SearchGatewayFilterForm . serializeForm ( menuForm )
384+ : { } ;
385+
386+ const scopeFromUrl = getScopeFilterFromUrl ( ) ;
387+ const existingScope = filters . scope ;
388+ const hasScopeInFilters = Array . isArray ( existingScope )
389+ ? existingScope . some ( v => String ( v || '' ) . trim ( ) )
390+ : ! ! String ( existingScope || '' ) . trim ( ) ;
391+ if ( ! hasScopeInFilters && scopeFromUrl ) {
392+ filters . scope = scopeFromUrl ;
393+ }
394+
395+ delete filters . breakdown_variable ;
396+
397+ const params = new URLSearchParams ( ) ;
398+ Object . entries ( filters ) . forEach ( ( [ key , value ] ) => {
399+ if ( value == null || value === '' ) return ;
400+ if ( Array . isArray ( value ) ) {
401+ value . forEach ( v => { if ( v != null && v !== '' ) params . append ( key , v ) ; } ) ;
402+ } else {
403+ params . append ( key , value ) ;
404+ }
405+ } ) ;
406+
407+ const query = params . toString ( ) ;
408+ window . open ( query ? `${ searchUrl } ?${ query } ` : searchUrl , '_blank' ) ;
409+ } ) ;
410+ }
411+
357412document . addEventListener ( 'DOMContentLoaded' , ( ) => {
358413 initIndicatorControlBarSelects ( ) ;
359414 initScopeControls ( ) ;
415+ initGoToSearchButton ( ) ;
360416} ) ;
361417
362418if ( typeof window !== 'undefined' && typeof window . gettext !== 'function' ) {
0 commit comments