@@ -60,7 +60,8 @@ public static function render_admin_page() {
6060 <label for="smoothgenerator-progress-bar" style="display: block;">
6161 <?php
6262 printf (
63- 'Generating %s… ' ,
63+ 'Generating %s %s… ' ,
64+ number_format_i18n ( $ current_job ->amount ),
6465 esc_html ( $ current_job ->generator_slug )
6566 );
6667 ?>
@@ -148,29 +149,30 @@ public static function render_admin_page() {
148149 }
149150
150151 /**
151- * Script to run the progress bar.
152+ * Script to interact with heartbeat and run the progress bar.
152153 *
153154 * @return void
154155 */
155156 protected static function heartbeat_script () {
156157 ?>
157158 <script>
158159 ( function( $ ) {
159- var $progress = $( '#smoothgenerator-progress-bar' );
160- var $controls = $( '[id^="generate_"]' );
161- var $cancel = $( '#cancel_job' );
160+ const $document = $( document );
161+ const $progress = $( '#smoothgenerator-progress-bar' );
162+ const $controls = $( '[id^="generate_"]' );
163+ const $cancel = $( '#cancel_job' );
162164
163- $( document ) .on( 'ready', function () {
165+ $document.on( 'ready', function () {
164166 wp.heartbeat.disableSuspend();
165- wp.heartbeat.connectNow();
166167 wp.heartbeat.interval( 'fast' );
168+ wp.heartbeat.connectNow();
167169 } );
168170
169- $( document ) .on( 'heartbeat-send', function ( event, data ) {
171+ $document.on( 'heartbeat-send', function ( event, data ) {
170172 data.smoothgenerator = 'check_async_job_progress';
171173 } );
172174
173- $( document ) .on( 'heartbeat-tick', function ( event, data ) {
175+ $document.on( 'heartbeat-tick', function ( event, data ) {
174176 // Heartbeat and other admin-ajax calls don't trigger wp-cron, so we have to do it manually.
175177 $.ajax( {
176178 url: data.smoothgenerator_ping_cron,
@@ -180,19 +182,19 @@ protected static function heartbeat_script() {
180182 } );
181183
182184 if ( 'object' === typeof data.smoothgenerator_async_job_progress ) {
183- var value = parseInt( data.smoothgenerator_async_job_progress.processed );
185+ const value = parseInt( data.smoothgenerator_async_job_progress.processed );
184186 if ( value > 0 ) {
185187 $progress.prop( 'value', value );
186188 }
187189 } else if ( 'complete' === data.smoothgenerator_async_job_progress && $progress.is( ':visible' ) ) {
188- var max = $progress.prop( 'max' );
189- $progress.prop( 'value', max );
190+ $progress.prop( 'value', $progress.prop( 'max' ) );
190191 $progress.parent().append( '✅' );
192+ $progress.siblings( 'label' ).first().append( ' Done!' );
191193 $controls.add( $cancel ).prop( 'disabled', function ( i, val ) {
192194 return ! val;
193195 } );
194- $( document ) .off( 'heartbeat-send' );
195- $( document ) .off( 'heartbeat-tick' );
196+ $document.off( 'heartbeat-send' );
197+ $document.off( 'heartbeat-tick' );
196198 }
197199 } );
198200 } )( jQuery );
0 commit comments