Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions js/plugin-report.js
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
jQuery(document).ready( function( $ ){

var rtpr_slugs = plugin_report_vars.plugin_slugs;
var rtpr_slugs_array = rtpr_slugs.split(',');
var rtpr_nrof_plugins = rtpr_slugs_array.length;
var rtpr_progress = 0;
var rtpr_done = false;
const rtpr_slugs = plugin_report_vars.plugin_slugs;
const rtpr_slugs_array = rtpr_slugs.split(',');
const rtpr_nrof_plugins = rtpr_slugs_array.length;
let rtpr_progress = 0;
let rtpr_done = false;


function rtpr_process_next_plugin(){
if( rtpr_slugs_array.length > 0 ){
var slug = rtpr_slugs_array.shift();
const slug = rtpr_slugs_array.shift();
if( $( '.plugin-report-row-temp-' + slug ).length ){
rtpr_get_plugin_info( slug );
} else {
rtpr_process_next_plugin();
}
}
// update the progress information on the page
var perc = Math.ceil( ( rtpr_progress / rtpr_nrof_plugins ) * 100 );
const perc = Math.ceil( ( rtpr_progress / rtpr_nrof_plugins ) * 100 );
if( perc < 100 ){
if( ! $( '#plugin-report-progress' ).find( 'progress' ).length ){
$( '#plugin-report-progress' ).html( '<progress max="100" value="0"></progress>' );
}
$( '#plugin-report-progress progress' ).prop( 'value', perc );
rtpr_progress++;
} else {
// Remove the progress bar.
$('#plugin-report-progress').html( '' );
// Guard against duplicate finalization caused by recursive calls.
if ( rtpr_done ) {
return;
}
rtpr_done = true;
// initialize sorting on table
new Tablesort(document.getElementById('plugin-report-table'));
// Create the export button.
$('#plugin-report-buttons').empty().append('<button class="button" id="plugin-report-export-btn">' + plugin_report_vars.export_btn + '</button>');
// Export button event handler.
$('#plugin-report-export-btn').off('click').on('click', function( e ){
e.preventDefault();
// Call the function that does the exporting.
rtpr_export_table();
});
}
} else {
// Remove the progress bar.
$('#plugin-report-progress').html( '' );
// Guard against duplicate finalization caused by recursive calls.
if ( rtpr_done ) {
return;
}
rtpr_done = true;
// initialize sorting on table
new Tablesort(document.getElementById('plugin-report-table'));
// Create the export button.
$('#plugin-report-buttons').empty().append('<button class="button" id="plugin-report-export-btn">' + plugin_report_vars.export_btn + '</button>');
// Export button event handler.
$('#plugin-report-export-btn').off('click').on('click', function( e ){
e.preventDefault();
// Call the function that does the exporting.
rtpr_export_table();
});
}
}


function rtpr_get_plugin_info( slug ){
var data = {
const data = {
'action': 'rt_get_plugin_info',
'slug': slug,
'nonce': plugin_report_vars.ajax_nonce
};

jQuery.post( ajaxurl, data, function(response) {
// parse the response
obj = jQuery.parseJSON(response);
const obj = JSON.parse(response);
// replace the temporary table row with the new data
$('#plugin-report-table .plugin-report-row-temp-' + slug ).replaceWith( obj.html );
// on to the next...
Expand All @@ -69,8 +69,8 @@ jQuery(document).ready( function( $ ){

// Export CSV file.
function rtpr_export_table(){
var csv_data = '';
var counter = 0;
let csv_data = '';
let counter = 0;
// Loop trough the table header to add the header cells.
$('#plugin-report-table thead tr').each(function(){
// Use a column counter, because we'll need ot insert two extra columns.
Expand Down Expand Up @@ -102,7 +102,7 @@ jQuery(document).ready( function( $ ){
csv_data += $(this).text().replace(/,/g, ".") + ',';
// If this is one of the first two columns, add a url column.
if( counter <2 ){
var href = '';
let href = '';
$(this).find('a').each(function(){
// Get the href attribute, but strip any url vars to keep it short.
href = $(this).attr('href').split('#')[0].split('?')[0];
Expand All @@ -116,8 +116,8 @@ jQuery(document).ready( function( $ ){
csv_data += "\n";
});
// Create a link element, clickit and remove it.
var link = document.createElement( 'a' );
var now = new Date();
const link = document.createElement( 'a' );
const now = new Date();
link.download = 'plugin-report-' + now.getFullYear() + '-' + String( '0' + (now.getMonth()+1) ).slice(-2) + '-' + String( '0' + now.getDate() ).slice(-2) + '.csv';
link.href = URL.createObjectURL( new Blob( [ "\ufeff", csv_data ], {type: 'text/csv; header=present'} ) );
link.click();
Expand Down
Loading