Skip to content

Commit e0d7977

Browse files
committed
Guard rail for duplicate executions
Many plugins result in duplicate execution and therefore two download CSV buttons . Fixes #75
1 parent a218327 commit e0d7977

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

js/plugin-report.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
jQuery(document).ready( function( $ ){
22

3-
var rtpr_slugs = plugin_report_vars.plugin_slugs;
4-
var rtpr_slugs_array = rtpr_slugs.split(',');
5-
var rtpr_nrof_plugins = rtpr_slugs_array.length;
6-
var rtpr_progress = 0;
3+
var rtpr_slugs = plugin_report_vars.plugin_slugs;
4+
var rtpr_slugs_array = rtpr_slugs.split(',');
5+
var rtpr_nrof_plugins = rtpr_slugs_array.length;
6+
var rtpr_progress = 0;
7+
var rtpr_done = false;
78

89

910
function rtpr_process_next_plugin(){
@@ -23,19 +24,25 @@ jQuery(document).ready( function( $ ){
2324
}
2425
$( '#plugin-report-progress progress' ).prop( 'value', perc );
2526
rtpr_progress++;
26-
} else {
27-
// Remove the progress bar.
28-
$('#plugin-report-progress').html( '' );
29-
// initialize sorting on table
30-
new Tablesort(document.getElementById('plugin-report-table'));
31-
// Create the export button.
32-
$('#plugin-report-buttons').append('<button class="button" href="#" id="plugin-report-export-btn">' + plugin_report_vars.export_btn + '</button>');
33-
// Export button event handler.
34-
$('#plugin-report-export-btn').click( function( e ){
35-
// Call the function that does the exporting.
36-
rtpr_export_table();
37-
});
38-
}
27+
} else {
28+
// Remove the progress bar.
29+
$('#plugin-report-progress').html( '' );
30+
// Guard against duplicate finalization caused by recursive calls.
31+
if ( rtpr_done ) {
32+
return;
33+
}
34+
rtpr_done = true;
35+
// initialize sorting on table
36+
new Tablesort(document.getElementById('plugin-report-table'));
37+
// Create the export button.
38+
$('#plugin-report-buttons').empty().append('<button class="button" id="plugin-report-export-btn">' + plugin_report_vars.export_btn + '</button>');
39+
// Export button event handler.
40+
$('#plugin-report-export-btn').off('click').on('click', function( e ){
41+
e.preventDefault();
42+
// Call the function that does the exporting.
43+
rtpr_export_table();
44+
});
45+
}
3946
}
4047

4148

0 commit comments

Comments
 (0)