@@ -640,6 +640,34 @@ <h5 id="statsHeader">Statistics</h5>
640640 const startInputEl = document . getElementById ( 'deleteDataStart' ) ;
641641 const untilInputEl = document . getElementById ( 'deleteDataUntil' ) ;
642642
643+ const _pad = n => String ( n ) . padStart ( 2 , '0' ) ;
644+ function toDatetimeLocalString ( date ) {
645+ if ( ! date || isNaN ( date . getTime ( ) ) ) { return '' ; }
646+ return `${ date . getFullYear ( ) } -${ _pad ( date . getMonth ( ) + 1 ) } -${ _pad ( date . getDate ( ) ) } T${ _pad ( date . getHours ( ) ) } :${ _pad ( date . getMinutes ( ) ) } ` ;
647+ }
648+
649+ function syncDeleteInputsWithGraphRange ( start , end ) {
650+ if ( start ) { startInputEl . value = toDatetimeLocalString ( start ) ; }
651+ if ( end ) { untilInputEl . value = toDatetimeLocalString ( end ) ; }
652+ }
653+
654+ // Initialize delete data inputs with the time range currently shown in the graph.
655+ // event_starts_after/event_ends_before are set when URL params (start_time/end_time) are present.
656+ { % if event_starts_after % }
657+ ( function ( ) {
658+ try {
659+ var _start = new Date ( '{{ event_starts_after }}' ) ;
660+ var _end = { % if event_ends_before % } new Date ( '{{ event_ends_before }}' ) { % else % } null { % endif % } ;
661+ syncDeleteInputsWithGraphRange ( _start , _end ) ;
662+ } catch ( e ) { /* ignore invalid date strings */ }
663+ } ) ( ) ;
664+ { % endif % }
665+
666+ // Keep delete data inputs in sync when the user changes the graph date picker
667+ document . addEventListener ( 'graphDateRangeChanged' , function ( e ) {
668+ syncDeleteInputsWithGraphRange ( e . detail . startDate , e . detail . endDate ) ;
669+ } ) ;
670+
643671 async function deleteData ( sourceValue , startValue , untilValue ) {
644672 const params = { } ;
645673 if ( sourceValue ) {
0 commit comments