Changeset 2606867
- Timestamp:
- 09/29/2021 03:11:39 PM (5 years ago)
- Location:
- gf-sort-export
- Files:
-
- 2 deleted
- 10 edited
- 1 copied
-
tags/1.1.0 (copied) (copied from gf-sort-export/trunk)
-
tags/1.1.0/assets (deleted)
-
tags/1.1.0/gf-sort-export.php (modified) (2 diffs)
-
tags/1.1.0/public/js/gf-sort-export.jquery.js (modified) (3 diffs)
-
tags/1.1.0/public/js/gf-sort-export.jquery.min.js (modified) (1 diff)
-
tags/1.1.0/readme.txt (modified) (3 diffs)
-
tags/1.1.0/src/SortExportPlugin.php (modified) (4 diffs)
-
trunk/assets (deleted)
-
trunk/gf-sort-export.php (modified) (2 diffs)
-
trunk/public/js/gf-sort-export.jquery.js (modified) (3 diffs)
-
trunk/public/js/gf-sort-export.jquery.min.js (modified) (1 diff)
-
trunk/readme.txt (modified) (3 diffs)
-
trunk/src/SortExportPlugin.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
gf-sort-export/tags/1.1.0/gf-sort-export.php
r2586143 r2606867 8 8 * License: GPL2 9 9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 * Version: 1. 0.010 * Version: 1.1.0 11 11 */ 12 12 … … 22 22 23 23 add_action('gform_loaded', static function () { 24 // start plugin25 24 new SortExportPlugin(); 26 25 }); -
gf-sort-export/tags/1.1.0/public/js/gf-sort-export.jquery.js
r2586143 r2606867 6 6 /** 7 7 * Sorts the list items by moving active items to the top. 8 * @since 1.0.0 9 * @param form_id The form id. 10 * @param $list The items list element. 8 11 */ 9 function sortItems( list) {10 var items = $('li', list);12 function sortItems(form_id, $list) { 13 var items = $('li', $list); 11 14 items.sort(function (a, b) { 12 15 // select all always on top. … … 20 23 return a === b ? 0 : (a < b ? 1 : -1); 21 24 }); 22 list.append(items); 23 list.sortable('refresh'); 25 $list.append(items); 26 $list.sortable('refresh'); 27 28 storeOrder(form_id, $list); 29 } 30 31 /** 32 * Stores the current sort order for the form. 33 * @since 1.1.0 34 * @param form_id The form id. 35 * @param $list The items list element. 36 */ 37 function storeOrder(form_id, $list) { 38 if (ajaxurl === undefined) { 39 return; 40 } 41 42 $.post(ajaxurl, { 43 action: 'gf-sort-export-store-order', 44 form_id: form_id, 45 order: $list.sortable('toArray', {attribute: 'rel'}) 46 }); 47 } 48 49 /** 50 * Sorts the list based on the stored order. 51 * @since 1.1.0 52 * @param form_id The form id. 53 * @param $list The items list element. 54 */ 55 function setListOrder(form_id, $list) { 56 if (ajaxurl === undefined) { 57 return; 58 } 59 60 $.get(ajaxurl, { 61 action: 'gf-sort-export-get-order', 62 form_id: form_id, 63 dataType: 'json' 64 }, function (order) { 65 if (order.length === 0) { 66 // Do nothing if we have no stored order. 67 return; 68 } 69 70 var $items = $('li', $list); 71 // Select all stored values 72 $items.find('input[type=checkbox]').each(function () { 73 if (order.includes($(this).val())) { 74 $(this).attr('checked', true).trigger('change', true); 75 } 76 }); 77 78 // Reset the stored order 79 $items.sort(function (a, b) { 80 // select all always on top. 81 if ($(b).find('#select_all').length > 0) { 82 return 1; 83 } 84 85 // Get sort index. Will be -1 if the item is not in the order array. 86 a = order.indexOf($(a).attr('rel')); 87 b = order.indexOf($(b).attr('rel')); 88 89 // No need to sort 90 if (a === b) { 91 return 0; 92 } 93 94 // Left or right is not in the array. Push them to the bottom. 95 if (a === -1 || b === -1) { 96 return a === -1 ? 1 : -1; 97 } 98 99 // regular sort based on the index 100 return a < b ? -1 : 1; 101 }); 102 $list.append($items); 103 }); 24 104 } 25 105 26 106 $(function () { 27 var $list = $('#export_field_list'); 28 var timeout; 107 var $list = $('#export_field_list'), 108 $export_form = $('#export_form'), 109 updating = false, 110 timeout; 111 112 $export_form 113 .on('change', function () { 114 // Keep track of whether we are updating the list. 115 updating = true; 116 }); 117 118 $list.on('DOMSubtreeModified', function () { 119 if (!updating) { 120 // Prevent endless loop. If we aren't updating don't trigger this event. 121 return; 122 } 123 124 // If the list is empty, we wait for it to fill up. 125 if ($list.find('li').length > 0) { 126 updating = false; 127 setListOrder($export_form.val(), $list); 128 } 129 }); 29 130 30 131 $list 31 132 // Only sort active items, and not the header. 32 .sortable({items: "> li:not(:first-child).active"}) 133 .sortable({ 134 items: "> li:not(:first-child).active", 135 cancel: "> li:not(.active)", 136 update: function () { 137 storeOrder($export_form.val(), $list) 138 } 139 }) 33 140 // Add active class for selected items. 34 141 .on('change', 'input[type=checkbox]', function (e, is_propagated) { 35 $(this).parent('li').toggleClass('active', $(this).is(':checked')); 142 $parent = $(this).parent('li'); 143 $parent.toggleClass('active', $(this).is(':checked')); 144 $parent.attr('rel', $(this).is(':checked') ? $(this).val() : null); 36 145 37 146 // Trigger change event on all fields to update class. … … 45 154 clearTimeout(timeout); 46 155 timeout = setTimeout(function () { 47 sortItems($ list);156 sortItems($export_form.val(), $list); 48 157 }, 1250); 49 158 } -
gf-sort-export/tags/1.1.0/public/js/gf-sort-export.jquery.min.js
r2586143 r2606867 1 (function($){function sortItems( list){var items=$("li",list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});list.append(items);list.sortable("refresh")}$(function(){var $list=$("#export_field_list");var timeout;$list.sortable({items:"> li:not(:first-child).active"}).on("change","input[type=checkbox]",function(e,is_propagated){$(this).parent("li").toggleClass("active",$(this).is(":checked"));if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($list)},1250)}})})})(jQuery);1 (function($){function sortItems(form_id,$list){var items=$("li",$list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});$list.append(items);$list.sortable("refresh");storeOrder(form_id,$list)}function storeOrder(form_id,$list){if(ajaxurl===undefined){return}$.post(ajaxurl,{action:"gf-sort-export-store-order",form_id:form_id,order:$list.sortable("toArray",{attribute:"rel"})})}function setListOrder(form_id,$list){if(ajaxurl===undefined){return}$.get(ajaxurl,{action:"gf-sort-export-get-order",form_id:form_id,dataType:"json"},function(order){if(order.length===0){return}var $items=$("li",$list);$items.find("input[type=checkbox]").each(function(){if(order.includes($(this).val())){$(this).attr("checked",true).trigger("change",true)}});$items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=order.indexOf($(a).attr("rel"));b=order.indexOf($(b).attr("rel"));if(a===b){return 0}if(a===-1||b===-1){return a===-1?1:-1}return a<b?-1:1});$list.append($items)})}$(function(){var $list=$("#export_field_list"),$export_form=$("#export_form"),updating=false,timeout;$export_form.on("change",function(){updating=true});$list.on("DOMSubtreeModified",function(){if(!updating){return}if($list.find("li").length>0){updating=false;setListOrder($export_form.val(),$list)}});$list.sortable({items:"> li:not(:first-child).active",cancel:"> li:not(.active)",update:function(){storeOrder($export_form.val(),$list)}}).on("change","input[type=checkbox]",function(e,is_propagated){$parent=$(this).parent("li");$parent.toggleClass("active",$(this).is(":checked"));$parent.attr("rel",$(this).is(":checked")?$(this).val():null);if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($export_form.val(),$list)},1250)}})})})(jQuery); -
gf-sort-export/tags/1.1.0/readme.txt
r2588276 r2606867 3 3 Plugin URI: https://apogi.dev/ 4 4 Donate link: https://www.paypal.me/doekenorg 5 Tags: apogi, gravity forms, export, csv, sort, order, drag, drop 5 Tags: apogi, gravity forms, export, csv, sort, order, drag, drop, store 6 6 Requires at least: 4.0 7 7 Requires PHP: 7.1 8 8 Tested up to: 5.8 9 Stable tag: 1. 0.09 Stable tag: 1.1.0 10 10 License: GPLv2 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html 12 12 13 Control the order of the fields during the export of entries.13 Control (and persist) the order of the fields during the export of entries. 14 14 15 15 == Description == … … 19 19 After selecting the fields you wish to export, the plugin will group these fields, after which you can drag & drop them in the desired order. Then click "Download Export File". The fields in the CSV output will now be in that order. 20 20 21 The provided sort order is also persisted for every form. So you don't have to resort it for every export. 22 21 23 To limit visual clutter, this plugin also removes all disabled subfields from the export list. 22 24 … … 25 27 26 28 == Changelog == 29 = 1.1.0 - 2021-09-29 = 30 * Feature: Store the export sort order for every form. 31 27 32 = 1.0.0 - 2021-08-18 28 33 * Feature: Drag & sort the export fields. -
gf-sort-export/tags/1.1.0/src/SortExportPlugin.php
r2586143 r2606867 15 15 public function __construct() 16 16 { 17 add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'load_scripts'])); 18 add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disable_inactive_subfields'])); 17 add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'loadScripts'])); 18 add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disableInactiveSubfields'])); 19 add_action('wp_ajax_gf-sort-export-store-order', \Closure::fromCallable([$this, 'storeOrder'])); 20 add_action('wp_ajax_gf-sort-export-get-order', \Closure::fromCallable([$this, 'getOrder'])); 19 21 } 20 22 … … 23 25 * @since 1.0.0 24 26 */ 25 private function load _scripts(): void27 private function loadScripts(): void 26 28 { 27 29 if (rgget('page') !== 'gf_export' || !in_array(rgget('view'), ['', 'export_entry'], true)) { … … 50 52 * @return mixed[] The updated form object. 51 53 */ 52 private function disable _inactive_subfields(array $form): array54 private function disableInactiveSubfields(array $form): array 53 55 { 54 56 foreach ($form['fields'] as $i => $field) { … … 62 64 return $form; 63 65 } 66 67 /** 68 * Returns the stored order (if any) for a specific form. 69 * @since 1.1.0 70 */ 71 private function getOrder(): void 72 { 73 $option = sprintf('gf-sort-export-order-%d', $_GET['form_id'] ?? 0); 74 wp_send_json(get_option($option, [])); 75 } 76 77 /** 78 * Stores the sort order for the provided form. 79 * @since 1.1.0 80 */ 81 private function storeOrder(): void 82 { 83 $allowed_fields = ['form_id', 'order']; 84 $data = array_intersect_key($_POST, array_flip($allowed_fields)); 85 86 $form = \GFAPI::get_form($form_id = $data['form_id'] ?? 0); 87 if (!$form) { 88 wp_send_json_error(null, 404); 89 90 return; 91 } 92 93 $option = sprintf('gf-sort-export-order-%d', $form_id); 94 update_option($option, $data['order'] ?: [], false); 95 96 wp_send_json_success(); 97 } 64 98 } -
gf-sort-export/trunk/gf-sort-export.php
r2586143 r2606867 8 8 * License: GPL2 9 9 * License URI: https://www.gnu.org/licenses/gpl-2.0.html 10 * Version: 1. 0.010 * Version: 1.1.0 11 11 */ 12 12 … … 22 22 23 23 add_action('gform_loaded', static function () { 24 // start plugin25 24 new SortExportPlugin(); 26 25 }); -
gf-sort-export/trunk/public/js/gf-sort-export.jquery.js
r2586143 r2606867 6 6 /** 7 7 * Sorts the list items by moving active items to the top. 8 * @since 1.0.0 9 * @param form_id The form id. 10 * @param $list The items list element. 8 11 */ 9 function sortItems( list) {10 var items = $('li', list);12 function sortItems(form_id, $list) { 13 var items = $('li', $list); 11 14 items.sort(function (a, b) { 12 15 // select all always on top. … … 20 23 return a === b ? 0 : (a < b ? 1 : -1); 21 24 }); 22 list.append(items); 23 list.sortable('refresh'); 25 $list.append(items); 26 $list.sortable('refresh'); 27 28 storeOrder(form_id, $list); 29 } 30 31 /** 32 * Stores the current sort order for the form. 33 * @since 1.1.0 34 * @param form_id The form id. 35 * @param $list The items list element. 36 */ 37 function storeOrder(form_id, $list) { 38 if (ajaxurl === undefined) { 39 return; 40 } 41 42 $.post(ajaxurl, { 43 action: 'gf-sort-export-store-order', 44 form_id: form_id, 45 order: $list.sortable('toArray', {attribute: 'rel'}) 46 }); 47 } 48 49 /** 50 * Sorts the list based on the stored order. 51 * @since 1.1.0 52 * @param form_id The form id. 53 * @param $list The items list element. 54 */ 55 function setListOrder(form_id, $list) { 56 if (ajaxurl === undefined) { 57 return; 58 } 59 60 $.get(ajaxurl, { 61 action: 'gf-sort-export-get-order', 62 form_id: form_id, 63 dataType: 'json' 64 }, function (order) { 65 if (order.length === 0) { 66 // Do nothing if we have no stored order. 67 return; 68 } 69 70 var $items = $('li', $list); 71 // Select all stored values 72 $items.find('input[type=checkbox]').each(function () { 73 if (order.includes($(this).val())) { 74 $(this).attr('checked', true).trigger('change', true); 75 } 76 }); 77 78 // Reset the stored order 79 $items.sort(function (a, b) { 80 // select all always on top. 81 if ($(b).find('#select_all').length > 0) { 82 return 1; 83 } 84 85 // Get sort index. Will be -1 if the item is not in the order array. 86 a = order.indexOf($(a).attr('rel')); 87 b = order.indexOf($(b).attr('rel')); 88 89 // No need to sort 90 if (a === b) { 91 return 0; 92 } 93 94 // Left or right is not in the array. Push them to the bottom. 95 if (a === -1 || b === -1) { 96 return a === -1 ? 1 : -1; 97 } 98 99 // regular sort based on the index 100 return a < b ? -1 : 1; 101 }); 102 $list.append($items); 103 }); 24 104 } 25 105 26 106 $(function () { 27 var $list = $('#export_field_list'); 28 var timeout; 107 var $list = $('#export_field_list'), 108 $export_form = $('#export_form'), 109 updating = false, 110 timeout; 111 112 $export_form 113 .on('change', function () { 114 // Keep track of whether we are updating the list. 115 updating = true; 116 }); 117 118 $list.on('DOMSubtreeModified', function () { 119 if (!updating) { 120 // Prevent endless loop. If we aren't updating don't trigger this event. 121 return; 122 } 123 124 // If the list is empty, we wait for it to fill up. 125 if ($list.find('li').length > 0) { 126 updating = false; 127 setListOrder($export_form.val(), $list); 128 } 129 }); 29 130 30 131 $list 31 132 // Only sort active items, and not the header. 32 .sortable({items: "> li:not(:first-child).active"}) 133 .sortable({ 134 items: "> li:not(:first-child).active", 135 cancel: "> li:not(.active)", 136 update: function () { 137 storeOrder($export_form.val(), $list) 138 } 139 }) 33 140 // Add active class for selected items. 34 141 .on('change', 'input[type=checkbox]', function (e, is_propagated) { 35 $(this).parent('li').toggleClass('active', $(this).is(':checked')); 142 $parent = $(this).parent('li'); 143 $parent.toggleClass('active', $(this).is(':checked')); 144 $parent.attr('rel', $(this).is(':checked') ? $(this).val() : null); 36 145 37 146 // Trigger change event on all fields to update class. … … 45 154 clearTimeout(timeout); 46 155 timeout = setTimeout(function () { 47 sortItems($ list);156 sortItems($export_form.val(), $list); 48 157 }, 1250); 49 158 } -
gf-sort-export/trunk/public/js/gf-sort-export.jquery.min.js
r2586143 r2606867 1 (function($){function sortItems( list){var items=$("li",list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});list.append(items);list.sortable("refresh")}$(function(){var $list=$("#export_field_list");var timeout;$list.sortable({items:"> li:not(:first-child).active"}).on("change","input[type=checkbox]",function(e,is_propagated){$(this).parent("li").toggleClass("active",$(this).is(":checked"));if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($list)},1250)}})})})(jQuery);1 (function($){function sortItems(form_id,$list){var items=$("li",$list);items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=$(a).hasClass("active");b=$(b).hasClass("active");return a===b?0:a<b?1:-1});$list.append(items);$list.sortable("refresh");storeOrder(form_id,$list)}function storeOrder(form_id,$list){if(ajaxurl===undefined){return}$.post(ajaxurl,{action:"gf-sort-export-store-order",form_id:form_id,order:$list.sortable("toArray",{attribute:"rel"})})}function setListOrder(form_id,$list){if(ajaxurl===undefined){return}$.get(ajaxurl,{action:"gf-sort-export-get-order",form_id:form_id,dataType:"json"},function(order){if(order.length===0){return}var $items=$("li",$list);$items.find("input[type=checkbox]").each(function(){if(order.includes($(this).val())){$(this).attr("checked",true).trigger("change",true)}});$items.sort(function(a,b){if($(b).find("#select_all").length>0){return 1}a=order.indexOf($(a).attr("rel"));b=order.indexOf($(b).attr("rel"));if(a===b){return 0}if(a===-1||b===-1){return a===-1?1:-1}return a<b?-1:1});$list.append($items)})}$(function(){var $list=$("#export_field_list"),$export_form=$("#export_form"),updating=false,timeout;$export_form.on("change",function(){updating=true});$list.on("DOMSubtreeModified",function(){if(!updating){return}if($list.find("li").length>0){updating=false;setListOrder($export_form.val(),$list)}});$list.sortable({items:"> li:not(:first-child).active",cancel:"> li:not(.active)",update:function(){storeOrder($export_form.val(),$list)}}).on("change","input[type=checkbox]",function(e,is_propagated){$parent=$(this).parent("li");$parent.toggleClass("active",$(this).is(":checked"));$parent.attr("rel",$(this).is(":checked")?$(this).val():null);if($(this).attr("id")==="select_all"){$list.find("input.gform_export_field").trigger("change",true)}if(!is_propagated){clearTimeout(timeout);timeout=setTimeout(function(){sortItems($export_form.val(),$list)},1250)}})})})(jQuery); -
gf-sort-export/trunk/readme.txt
r2588276 r2606867 3 3 Plugin URI: https://apogi.dev/ 4 4 Donate link: https://www.paypal.me/doekenorg 5 Tags: apogi, gravity forms, export, csv, sort, order, drag, drop 5 Tags: apogi, gravity forms, export, csv, sort, order, drag, drop, store 6 6 Requires at least: 4.0 7 7 Requires PHP: 7.1 8 8 Tested up to: 5.8 9 Stable tag: 1. 0.09 Stable tag: 1.1.0 10 10 License: GPLv2 11 11 License URI: http://www.gnu.org/licenses/gpl-2.0.html 12 12 13 Control the order of the fields during the export of entries.13 Control (and persist) the order of the fields during the export of entries. 14 14 15 15 == Description == … … 19 19 After selecting the fields you wish to export, the plugin will group these fields, after which you can drag & drop them in the desired order. Then click "Download Export File". The fields in the CSV output will now be in that order. 20 20 21 The provided sort order is also persisted for every form. So you don't have to resort it for every export. 22 21 23 To limit visual clutter, this plugin also removes all disabled subfields from the export list. 22 24 … … 25 27 26 28 == Changelog == 29 = 1.1.0 - 2021-09-29 = 30 * Feature: Store the export sort order for every form. 31 27 32 = 1.0.0 - 2021-08-18 28 33 * Feature: Drag & sort the export fields. -
gf-sort-export/trunk/src/SortExportPlugin.php
r2586143 r2606867 15 15 public function __construct() 16 16 { 17 add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'load_scripts'])); 18 add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disable_inactive_subfields'])); 17 add_action('admin_enqueue_scripts', \Closure::fromCallable([$this, 'loadScripts'])); 18 add_action('gform_form_export_page', \Closure::fromCallable([$this, 'disableInactiveSubfields'])); 19 add_action('wp_ajax_gf-sort-export-store-order', \Closure::fromCallable([$this, 'storeOrder'])); 20 add_action('wp_ajax_gf-sort-export-get-order', \Closure::fromCallable([$this, 'getOrder'])); 19 21 } 20 22 … … 23 25 * @since 1.0.0 24 26 */ 25 private function load _scripts(): void27 private function loadScripts(): void 26 28 { 27 29 if (rgget('page') !== 'gf_export' || !in_array(rgget('view'), ['', 'export_entry'], true)) { … … 50 52 * @return mixed[] The updated form object. 51 53 */ 52 private function disable _inactive_subfields(array $form): array54 private function disableInactiveSubfields(array $form): array 53 55 { 54 56 foreach ($form['fields'] as $i => $field) { … … 62 64 return $form; 63 65 } 66 67 /** 68 * Returns the stored order (if any) for a specific form. 69 * @since 1.1.0 70 */ 71 private function getOrder(): void 72 { 73 $option = sprintf('gf-sort-export-order-%d', $_GET['form_id'] ?? 0); 74 wp_send_json(get_option($option, [])); 75 } 76 77 /** 78 * Stores the sort order for the provided form. 79 * @since 1.1.0 80 */ 81 private function storeOrder(): void 82 { 83 $allowed_fields = ['form_id', 'order']; 84 $data = array_intersect_key($_POST, array_flip($allowed_fields)); 85 86 $form = \GFAPI::get_form($form_id = $data['form_id'] ?? 0); 87 if (!$form) { 88 wp_send_json_error(null, 404); 89 90 return; 91 } 92 93 $option = sprintf('gf-sort-export-order-%d', $form_id); 94 update_option($option, $data['order'] ?: [], false); 95 96 wp_send_json_success(); 97 } 64 98 }
Note: See TracChangeset
for help on using the changeset viewer.