@@ -53,30 +53,7 @@ function get_stop_marker(stop) {
5353 }
5454 } )
5555 . on ( 'click' , async ( e ) => {
56- const panel = document . querySelector ( '#virtual-board-panel' ) ;
57- {
58- const old_tbody = panel . querySelector ( 'tbody' ) ;
59- const loading_tbody = document . createElement ( 'tbody' ) ;
60- const loading_row = document . createElement ( 'tr' ) ;
61- const loading_td = document . createElement ( 'td' ) ;
62- loading_td . innerHTML = '<i class="bi bi-arrow-clockwise loading-icon"></i> Зареждане...' ;
63- loading_row . appendChild ( loading_td ) ;
64- loading_tbody . appendChild ( loading_row ) ;
65-
66- old_tbody . replaceWith ( loading_tbody ) ;
67- }
68- panel . querySelector ( '#stop_name' ) . textContent = `[${ stop . code . toString ( ) . padStart ( 4 , '0' ) } ] ${ stop . names . bg } ` ;
69- panel . classList . remove ( 'd-none' ) ;
70- const times = await load_stop_times ( stop . code ) ;
71- const new_tbody = display_stop_times ( times ) ;
72- const old_tbody = panel . querySelector ( 'tbody' ) ;
73- if ( old_tbody ) {
74- old_tbody . replaceWith ( new_tbody ) ;
75- }
76- const last_updated_el = panel . querySelector ( '#last-updated' ) ;
77- last_updated_el . setAttribute ( 'data-timestamp' , ( Date . now ( ) / 1000 ) . toString ( ) ) ;
78- last_updated_el . textContent = determine_time_ago ( Date . now ( ) / 1000 ) ;
79-
56+ await update_stop_times ( stop . code ) ;
8057 } )
8158 . on ( 'popupclose' , ( e ) => {
8259 e . target . unbindPopup ( ) ;
@@ -85,6 +62,41 @@ function get_stop_marker(stop) {
8562 return marker ;
8663}
8764
65+ async function update_stop_times ( stop_code ) {
66+ const panel = document . querySelector ( '#virtual-board-panel' ) ;
67+ const refresh_btn = panel . querySelector ( '#refresh-virtual-board' ) ;
68+ const last_updated_el = panel . querySelector ( '#last-updated' ) ;
69+ last_updated_el . setAttribute ( 'data-timestamp' , '' ) ;
70+ last_updated_el . textContent = '' ;
71+ refresh_btn . dataset . code = stop_code ;
72+ refresh_btn . disabled = true ;
73+ {
74+ const old_tbody = panel . querySelector ( 'tbody' ) ;
75+ const loading_tbody = document . createElement ( 'tbody' ) ;
76+ const loading_row = document . createElement ( 'tr' ) ;
77+ const loading_td = document . createElement ( 'td' ) ;
78+ loading_td . classList . add ( 'text-center' , 'py-3' ) ;
79+ loading_td . innerHTML = '<div class="spinner-border spinner-border-sm" role="status"></div> Зареждане...' ;
80+ loading_row . appendChild ( loading_td ) ;
81+ loading_tbody . appendChild ( loading_row ) ;
82+
83+ old_tbody . replaceWith ( loading_tbody ) ;
84+ }
85+ const stop = stops . get ( stop_code ) ;
86+ panel . querySelector ( '#stop_name' ) . textContent = `[${ stop . code . toString ( ) . padStart ( 4 , '0' ) } ] ${ stop . names . bg } ` ;
87+ panel . classList . remove ( 'd-none' ) ;
88+ const times = await load_stop_times ( stop . code ) ;
89+ const new_tbody = display_stop_times ( times ) ;
90+ const old_tbody = panel . querySelector ( 'tbody' ) ;
91+ if ( old_tbody ) {
92+ old_tbody . replaceWith ( new_tbody ) ;
93+ }
94+ refresh_btn . disabled = false ;
95+ last_updated_el . setAttribute ( 'data-timestamp' , ( Date . now ( ) / 1000 ) . toString ( ) ) ;
96+ last_updated_el . textContent = determine_time_ago ( Date . now ( ) / 1000 ) ;
97+ }
98+ window . update_stop_times = update_stop_times ;
99+
88100function are_stops_shown ( map ) {
89101 const zoom = map . getZoom ( ) ;
90102 return zoom >= 17 ;
0 commit comments