Skip to content

Commit

Permalink
Reworked exports and filtering
Browse files Browse the repository at this point in the history
 * Exports now generated by sending the list of ids to export
 * Allows arbitrary JS filtering without having to do the same on the server
 * Had to branch slick grid to deprivatize some of DataView's internals

re Design:#3360
  • Loading branch information
bobbysmith007 authored and root committed Feb 23, 2017
1 parent abf2174 commit 9f643cd
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[submodule "assets/SlickGrid"]
path = assets/SlickGrid
url = git@github.com:mleibman/SlickGrid.git
url = git@github.com:AccelerationNet/SlickGrid.git
[submodule "php-sql-parser"]
path = php-sql-parser
url = git@github.com:AccelerationNet/php-sql-parser.git
11 changes: 11 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@ For detailed information, please view:

https://github.com/AccelerationNet/wp-db-table-editor/commits

Version: 1.6.0 - 2017-02-23
* New (customized) version of SlickGrid (branched from 6pac@github)
* allow access to the default filter and the filtered items
* Handle exports by sending a list of ids to export rather than
trying to recreate the full filter set serverside. Allows rather
arbitrary JS filtering functions without having to get nitty gritty
on the server

Version: 1.5.6 - 2017-02-22
* allow easy button column width configuration

Version: 1.5.5 - 2016-12-16
* fix deprecated constructor

Expand Down
8 changes: 8 additions & 0 deletions ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version: 1.6.0 - 2017-02-23
* New (customized) version of SlickGrid (branched from 6pac@github)
* allow access to the default filter and the filtered items
* Handle exports by sending a list of ids to export rather than
trying to recreate the full filter set serverside. Allows rather
arbitrary JS filtering functions without having to get nitty gritty
on the server

Version: 1.5.6 - 2017-02-22
* allow easy button column width configuration

Expand Down
2 changes: 1 addition & 1 deletion assets/SlickGrid
Submodule SlickGrid updated 121 files
14 changes: 5 additions & 9 deletions assets/db-table-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,11 @@ DBTableEditor.rowButtonFormatter = function(row, cell, value, columnDef, dataCon
DBTableEditor.exportCSV = function(){
var args=jQuery.extend({}, DBTableEditor.query, DBTableEditor.hashQuery);
var cols = DBTableEditor.data.columns;
jQuery(DBTableEditor.grid.getHeaderRow())
.find(':input').each(function(i, el){
var $el = jQuery(el),name = $el.attr('name'), val = $el.val(), c = cols[i+1];
if(val.length>0){
if(c.isDate) args[name]=DBTableEditor.toISO8601(val);
else args[name]=val;
}
});

args.ids=[];
jQuery.each(DBTableEditor.dataView.getFilteredItems(), function(idx, item){
args.ids.push(item.id);
});
args.ids = args.ids.join(',');
delete(args["page"]);
var url = ajaxurl+'?action=dbte_export_csv&table='+DBTableEditor.id
+'&'+jQuery.param(args);
Expand Down
25 changes: 12 additions & 13 deletions db-table-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,22 +529,21 @@ function dbte_export_csv(){
global $wpdb;
$cur = dbte_current(@$_REQUEST['table']);
if(!$cur) return;
if($cur->editcap && !current_user_can($cur->editcap)) return;
// if($cur->editcap && !current_user_can($cur->editcap)) return;
$id_col = $cur->id_column;
$ids = @$_REQUEST['ids'];
$tbl = $cur->table;

$wheres = array();
$filtered=false;
foreach($_REQUEST as $k=>$v){
if(strpos($k, "filter-")===0){
$k = str_replace('filter-','', $k);
if($cur->auto_date && dbte_is_date($v)) $wheres[] = $wpdb->prepare("$k = %s", $v);
else $wheres[] = $wpdb->prepare("$tbl.$k LIKE %s", '%'.$v.'%');
$filtered = true;
}
$wheres = Array();
if($ids){
$ids = explode(',', $ids);
$ids[]=-1;
// ensures that our sql is ok / escaped
foreach($ids as $idx=>$id){$ids[$idx] = intval($id);}
$ids = implode(', ', $ids);
$wheres[] = " $tbl.$id_col in ( $ids ) ";
}

$tbl = $cur->table;
$title = $cur->title;
if($filtered) $title .= '-filtered';
$data = $cur->getData(array("where"=>$wheres));
$columns = $data->columnNames;
$rows = $data->rows;
Expand Down

0 comments on commit 9f643cd

Please sign in to comment.