diff --git a/composer.json b/composer.json index e6f1511..1d0b1af 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Perform batch jobs inside of WordPress.", "type": "wordpress-plugin", "license": "GPL v3", - "version": "1.2.0", + "version": "1.2.1", "authors": [ { "name": "Philip Downer", diff --git a/js/dist/ramsey-batch.min.js b/js/dist/ramsey-batch.min.js index f1fca06..7d72d8e 100644 --- a/js/dist/ramsey-batch.min.js +++ b/js/dist/ramsey-batch.min.js @@ -1 +1 @@ -!function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e){jQuery(document).ready(function(t){var e={items:[]};e.batchName,e.totalItems=e.items.length,e.currentItem=0,e.itemsComplete=0;var n,o,r,a,c=t('button[name="batchJobTrigger"]');function s(){a.html("Done. Processed ".concat(e.totalItems," of ").concat(e.totalItems," items!")),console.log("Batch is complete! Processed ".concat(e.totalItems," of ").concat(e.totalItems," items!")),e.items=[],e.totalItems=e.items.length,e.currentItem=0,e.itemsComplete=0,n.prop("disabled",!1)}function i(n){return new Promise(function(o,c){var s,i;e.currentItem+=1,s=e.currentItem,i=s/e.totalItems*100,a.text("Processing ".concat(s," of ").concat(e.totalItems," items...")),r.css({width:"".concat(i,"%")}),console.log("Current item:",n),t.ajax({url:ajaxurl,method:"POST",data:{action:"ramsey-batch-item",item:n,batchName:e.batchName},success:function(t){return console.log(t),t.success?(e.itemsComplete++,"warn"==t.data.type?console.warn(t.data.reason,t):console.log(t.data.reason,t),o()):(console.error(t.data.reason,t),c())}})})}function u(){e.items.reduce(function(t,e,n){return t.then(function(){return i(e)})},Promise.resolve()).then(s)}function l(c){return new Promise(function(s,i){n=t(c),e.batchName=n.data("batchName");var u=e.batchName.replace(new RegExp("\\\\","g"),"");o=t('tr.progressMeter[data-batch-name="'.concat(u,'"]')),r=o.find(".meter"),a=o.find(".status"),o.show(),n.prop("disabled",!0),function(t){var e=Promise.resolve();return t.forEach(function(t){e=e.then(function(e){return e=void 0===e?[]:e,new Promise(function(n,o){if("file"!==t.type)return e.push({name:t.name,value:t.value}),n(e);var r=new FileReader;if(r.onload=function(o){return e.push({name:t.name,value:o.target.result}),n(e)},!t.files.length)return n(e);r.readAsBinaryString(t.files[0])})})}),e}(n.closest("tr").find("input,textarea").get()).then(function(o){t.ajax({url:ajaxurl,method:"POST",data:{action:"ramsey-batch",batchName:e.batchName,formElementData:o}}).done(function(t){return t.success?(console.log("Starting batch!",u,t.data.items),o=t.data.items,e.items=Object.values(o),e.totalItems=e.items.length,e.totalItems?(a.text("Found ".concat(e.totalItems," items...")),s()):(a.text("No items found."),n.prop("disabled",!1),r.css({width:"100%"}),s("No items found."))):i(t.data.reason);var o})})})}t(c).on("click",function(t){l(t.target).then(u,function(t){throw new Error(t)})})})}]); \ No newline at end of file +!function(t){var e={};function n(o){if(e[o])return e[o].exports;var r=e[o]={i:o,l:!1,exports:{}};return t[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=t,n.c=e,n.d=function(t,e,o){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:o})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var r in t)n.d(o,r,function(e){return t[e]}.bind(null,r));return o},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=0)}([function(t,e){jQuery(document).ready(function(t){var e={items:[]};e.batchName,e.totalItems=e.items.length,e.currentItem=0,e.itemsComplete=0;var n,o,r,a,c=t('button[name="batchJobTrigger"]');function s(){a.html("Done. Processed ".concat(e.totalItems," of ").concat(e.totalItems," items!")),console.log("Batch is complete! Processed ".concat(e.totalItems," of ").concat(e.totalItems," items!")),e.items=[],e.totalItems=e.items.length,e.currentItem=0,e.itemsComplete=0,n.prop("disabled",!1)}function i(n){return new Promise(function(o,c){var s,i;e.currentItem+=1,s=e.currentItem,i=s/e.totalItems*100,a.text("Processing ".concat(s," of ").concat(e.totalItems," items...")),r.css({width:"".concat(i,"%")}),console.log("Current item:",n),t.ajax({url:ajaxurl,method:"POST",data:{action:"ramsey-batch-item",item:n,batchName:e.batchName},success:function(t){return console.log(t),t.success?(e.itemsComplete++,"warn"==t.data.type?console.warn(t.data.reason,t):console.log(t.data.reason,t),o()):(console.error(t.data.reason,t),c())}})})}function u(){e.items.reduce(function(t,e,n){return t.then(function(){return i(e)})},Promise.resolve()).then(s)}function l(c){return new Promise(function(s,i){n=t(c),o.show(),n.prop("disabled",!0),function(t){var e=Promise.resolve();return t.forEach(function(t){e=e.then(function(e){return e=void 0===e?[]:e,new Promise(function(n,o){if("file"!==t.type)return e.push({name:t.name,value:t.value}),n(e);var r=new FileReader;if(r.onload=function(o){return e.push({name:t.name,value:o.target.result}),n(e)},!t.files.length)return n(e);r.readAsBinaryString(t.files[0])})})}),e}(n.closest("tr").find("input,textarea").get()).then(function(o){t.ajax({url:ajaxurl,method:"POST",data:{action:"ramsey-batch",batchName:e.batchName,formElementData:o}}).done(function(t){return t.success?(console.log("Starting batch!",e.batchName,t.data.items),o=t.data.items,e.items=Object.values(o),e.totalItems=e.items.length,e.totalItems?(a.text("Found ".concat(e.totalItems," items...")),s()):(a.text("No items found."),n.prop("disabled",!1),r.css({width:"100%"}),s("No items found."))):i(t.data.reason);var o})})})}t(c).on("click",function(n){e.batchName=t(n.target).data("batchName");var c=e.batchName.replace(new RegExp("\\\\","g"),"");o=t('tr.progressMeter[data-batch-name="'.concat(c,'"]')),(r=o.find(".meter")).css({width:"0%"}),(a=o.find(".status")).text(""),l(n.target).then(u,function(t){throw new Error(t)})})})}]); \ No newline at end of file diff --git a/js/src/ramsey-batch.js b/js/src/ramsey-batch.js index 772928e..4591311 100644 --- a/js/src/ramsey-batch.js +++ b/js/src/ramsey-batch.js @@ -165,18 +165,6 @@ jQuery(document).ready($ => { function startBatch(trigger) { return new Promise((resolve, reject) => { currentButton = $(trigger); - ramseyBatch.batchName = currentButton.data("batchName"); - const batchNameClean = ramseyBatch.batchName.replace( - new RegExp("\\\\", "g"), - "" - ); - - progressMeter = $( - `tr.progressMeter[data-batch-name="${batchNameClean}"]` - ); - progressBar = progressMeter.find(".meter"); - statusMsg = progressMeter.find(".status"); - progressMeter.show(); currentButton.prop("disabled", true); @@ -196,7 +184,11 @@ jQuery(document).ready($ => { return reject(response.data.reason); } - console.log("Starting batch!", batchNameClean, response.data.items); + console.log( + "Starting batch!", + ramseyBatch.batchName, + response.data.items + ); updateItems(response.data.items); @@ -220,6 +212,20 @@ jQuery(document).ready($ => { // Handle the initial trigger $(buttons).on("click", e => { + ramseyBatch.batchName = $(e.target).data("batchName"); + let cleanBatchName = ramseyBatch.batchName.replace( + new RegExp("\\\\", "g"), + "" + ); + + progressMeter = $(`tr.progressMeter[data-batch-name="${cleanBatchName}"]`); + progressBar = progressMeter.find(".meter"); + progressBar.css({ + width: `0%` + }); + statusMsg = progressMeter.find(".status"); + statusMsg.text(""); + startBatch(e.target).then(processBatchItems, response => { throw new Error(response); }); diff --git a/package.json b/package.json index eb90265..9d7e652 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "wp-ramsey-batch", - "version": "1.2.0", + "version": "1.2.1", "description": "Provides a framework to handle large data processing jobs by breaking it into smaller chunks and running each job individually via AJAX requests. ", "main": "wp-ramsey-batch.php", "repository": "https://github.com/RamseyInHouse/wp-ramsey-batch", diff --git a/wp-ramsey-batch.php b/wp-ramsey-batch.php index d689cc4..ac3aad9 100644 --- a/wp-ramsey-batch.php +++ b/wp-ramsey-batch.php @@ -3,7 +3,7 @@ Plugin Name: Ramsey Batch Plugin URI: https://www.daveramsey.com Description: Provides a framework and UI for running batch jobs inside of WordPress. -Version: 1.2.0 +Version: 1.2.1 Author: Philip Downer, Alex MacArthur License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html