Plugin Directory

Changeset 2253769


Ignore:
Timestamp:
03/03/2020 05:31:24 PM (6 years ago)
Author:
bobbysmith007
Message:

Readding missing paging 1.8.2

Location:
wp-db-table-editor/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • wp-db-table-editor/trunk/DBTableEditor.class.php

    r2253723 r2253769  
    4444
    4545class DBTE_DataTable {
    46   var $rows,$columns, $columnNames;
     46  var $rows,$columns, $columnNames, $totalRows, $offset, $page_size, $page_idx;
    4747  function  __construct($args=null){
    4848    global $wpdb;
     
    5050    $sql = @$args['sql'];
    5151    $where = @$args['where'];
    52     $limit = @$args['limit'];
    53     if(!$limit) $limit = 25000;
    54     $offset = @$args['offset'];
    55     if(!$offset) $offset = 0;
     52    $this->page_size = @$args['page_size'];
     53    $this->page_idx = @$args['page_idx'];
     54    $limit = $this->page_size;
     55    $offset = $this->page_size * $this->page_idx;
     56   
    5657    if($sql){
     58      $sql = preg_replace('/SELECT/i', 'SELECT SQL_CALC_FOUND_ROWS', $sql, 1);
    5759      if($where){
    5860        // this has sometimes gone wrong
     
    6567      // error_log("Got sql:\n".$sql);
    6668      $this->rows = $wpdb->get_results($sql, ARRAY_N);
     69      $this->$offset = $offset;
    6770      if($wpdb->last_error){
    6871        error_log("Failed to execute query:\n$sql\nERR:".$wpdb->last_error."\n");
     
    7881        }
    7982      }
     83      $this->totalRows = intval($wpdb->get_var('SELECT FOUND_ROWS();'));
     84
    8085    }else if(@$args['rows']){
    8186      $this->rows = $args['rows'];
     
    8489      $this->columns = $args['columns'];
    8590    }
    86     else{ // handle building columns from wpdb
    87       $this->columnNames = $cnames = $wpdb->get_col_info('name');
    88       $ctypes = $wpdb->get_col_info('type');
    89       $this->columns = Array();
    90       for($i=0; $i < count($cnames) ; $i++){
    91         $this->columns[]=Array('name'=>$cnames[$i], 'type'=>$ctypes[$i]);
    92       }
    93     }
    9491  }
    9592}
     
    105102  $columnFilters, $columnNameMap, $save_cb, $insert_cb, $update_cb, $delete_cb,
    106103  $export_id_field,
    107   $id_column, $auto_date, $async_data;
     104  $id_column, $auto_date, $async_data, $page_size, $page_idx, $offset;
     105
    108106  function __construct($args=null){
    109107    $args = wp_parse_args($args, array('cap'=>'edit_others_posts'));
     
    112110    if(!$this->title) $this->title = $this->table;
    113111    if(!$this->id_column) $this->id_column = 'id';
     112    if(!$this->page_size) $this->page_size = 10000;
     113    if(!$this->page_idx) $this->page_idx = rval('dbte_page_num');
     114    if(!$this->page_idx) $this->page_idx = 0;
     115    if(!$this->offset) $this->offset = $this->page_size * $this->page_idx;
    114116    if(!isset($args['auto_date'])) $this->auto_date=true;
     117    if(is_null($this->nodelete)) $this->nodelete = $this->noedit;
     118    if(is_null($this->noinsert)) $this->noinsert = $this->noedit;
    115119  }
    116120  /*
     
    126130    else if($fn) $args['rows'] = $fn($args);
    127131    else $args["sql"] ="SELECT * FROM $this->table";
     132   
     133    $args['page_idx'] = $this->page_idx;
     134    $args['page_size'] = $this->page_size;
     135    $args['offset'] = $this->offset;
     136
    128137    $this->data = new DBTE_DataTable($args);
    129138    return $this->data;
  • wp-db-table-editor/trunk/ReleaseNotes.txt

    r2253723 r2253769  
     1Version: 1.8.2 - 2019-03-03
     2    * Get automatic results paging working again
     3
    14Version: 1.8.1 - 2019-02-27
    25    * A bad merge deleted my automatic paging that was added
  • wp-db-table-editor/trunk/assets/db-table-editor.js

    r2251550 r2253769  
    2727    for (var i = 0; i < vars.length; i++) {
    2828      var pair = vars[i].split('=');
    29       obj[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1]);
     29      if(pair[0]){
     30        obj[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1]);
     31      }
    3032    }
    3133    return obj;
     
    264266DBTableEditor.updatePagingInfo = function(){
    265267  var cnt = DBTableEditor.dataView.getPagingInfo()["totalRows"];
    266   jQuery('.db-table-editor-row-count').text (sprintf(translations['row_count'], cnt, DBTableEditor.data.rows.length));
     268  var max = DBTableEditor.offset + DBTableEditor.data.rows.length;
     269  jQuery('.db-table-editor-row-count').text (
     270    sprintf(translations['row_count'],
     271            cnt, DBTableEditor.offset, max,
     272            DBTableEditor.data.totalRows));
     273  jQuery('.dbte-page .prev').toggle(DBTableEditor.data.page_idx > 0);
     274  jQuery('.dbte-page .next').toggle(max < DBTableEditor.data.totalRows);
     275
    267276};
    268277
     
    581590};
    582591
     592DBTableEditor.refresh = function dbte_refresh(){
     593  newL = window.location.pathname +'?';
     594  jQuery.each(DBTableEditor.query, function(k, v){
     595    newL+="&"+encodeURIComponent(k)+"=";
     596    if(v) newL += encodeURIComponent(v);
     597  });
     598  window.location = newL;
     599}
     600
     601DBTableEditor.next = function dbte_next(){
     602  console.log('Nav to next page');
     603  DBTableEditor.query['dbte_page_num'] = Number(DBTableEditor.data.page_idx)+1;
     604  DBTableEditor.refresh();
     605}
     606
     607DBTableEditor.prev = function dbte_prev(){
     608  console.log('Nav to prev page');
     609  DBTableEditor.query['dbte_page_num'] = Number(DBTableEditor.data.page_idx)-1;
     610  DBTableEditor.refresh();
     611}
     612
     613
    583614DBTableEditor.onload = function(opts){
    584615  // TODO: switch to objects so there can be more than one table to edit *sigh*
     
    600631  }
    601632  else return console.log("No Data for DBTableEditor");
    602 };
     633  jQuery('body').on('click', '.dbte-page .prev', DBTableEditor.prev);
     634  jQuery('body').on('click', '.dbte-page .next', DBTableEditor.next);
     635};
  • wp-db-table-editor/trunk/db-table-editor.php

    r2253723 r2253769  
    55Plugin URI: http://github.com/AcceleratioNet/wp-db-table-editor
    66Description: A plugin that adds "tools" pages to edit database tables
    7 Version: 1.8.1
     7Version: 1.8.2
    88Author: Russ Tyndall @ Acceleration.net
    99Author URI: http://www.acceleration.net
     
    4343 * the currently selected instance
    4444 */
     45
     46if ( !function_exists('prep_name') ) {
     47  function prep_name($n){
     48    $n = str_replace(" ", "_", trim($n));
     49    return $n;
     50  }
     51}
     52
     53if ( !function_exists('prepped_dict_value') ) {
     54  function pdv_names($name){
     55    $o = $name;
     56    $n = trim($name);
     57    return  array(
     58      $o, $n,
     59      preg_replace('/ /', "_", $n),
     60      preg_replace('/-/', "_",$n),
     61      preg_replace('/(-|\s)+/', "_",$n)
     62    );
     63  }
     64    function pdv_clean_v($v){
     65      $v = trim(strip_tags( rawurldecode($v) ));
     66      if($v === "") $v = null;
     67      return $v;
     68    }
     69    function pdv_prep_v($v, $implode=true){
     70      if (is_array($v)){
     71        foreach($v as $k=>$d){
     72          $v[$k]=pdv_clean_v($d);
     73        }
     74        if($implode) $v = implode(',', $v);
     75      }
     76      else if (is_string($v)){
     77        $v = pdv_clean_v($v);
     78      }
     79      return $v;
     80    }
     81    function prepped_dict_value($name, $dict, $implode=true){
     82      $names = pdv_names($name);
     83      foreach($names as $n){
     84        $v = isset($dict[$n]) ? $dict[$n] : null;
     85        if($v !== null){
     86          $pv = pdv_prep_v($v, $implode);
     87          return $pv;
     88        }
     89      }
     90      return null;
     91    }
     92}
     93
     94
     95if ( !function_exists('rval') ) {
     96  // gets a value from the request collection
     97  // Duplicated from functions for completeness
     98  function rval( $name, $implode=true ){
     99    return prepped_dict_value($name, $_REQUEST, $implode);
     100  }
     101}
     102
     103
    45104global $DBTE_INSTANCES, $DBTE_CURRENT;
    46105$DBTE_INSTANCES = Array();
     
    156215                    array('slick-grid-js', 'jquery', 'json2', 'moment-js', 'dbte-date-editor-js', 'sprintf-js'));
    157216  $translation_array = array(
    158     'row_count' => __( 'Showing %d of %d rows - items with unsaved changes are not filtered', 'wp-db-table-editor' ),
     217    'row_count' => __( 'Showing %d rows in %d-%d of %d rows - items with unsaved changes are not filtered', 'wp-db-table-editor' ),
    159218    'confirm_delete_row' => __( 'Are you sure you wish to remove this row', 'wp-db-table-editor' ),
    160219    'delete_button' => __( 'Delete this Row', 'wp-db-table-editor' )
     
    254313  $exportButtonLabel = __('Export to CSV', 'wp-db-table-editor');
    255314  $clearFiltersButtonLabel = __('Clear Filters', 'wp-db-table-editor');
    256   $rowCountLabel = __('Showing 0 of 0 rows', 'wp-db-table-editor');
     315  $rowCountLabel = __('Showing 0 rows in 0-0 of 0 rows', 'wp-db-table-editor');
    257316  $confirmationMessage = __('You have unsaved data, are you sure you want to quit', 'wp-db-table-editor');
    258317  $o = <<<EOT
     
    274333    </div>
    275334    <div class="db-table-editor-row-count" >$rowCountLabel</div>
     335    <button class="prev">← prev</button>
     336    <button class="next">next →</button>
    276337    <div class="db-table-editor"></div>
    277338    <script type="text/javascript">
     
    378439  global $wpdb; // this is how you get access to the database
    379440  $d = $_REQUEST['data'];
    380   $tbl= $_REQUEST['table'];
     441  $tbl= rval('table');
    381442  $cur = dbte_current($tbl);
    382443  if(!$cur) return;
     
    488549function dbte_delete_cb(){
    489550  global $wpdb;
    490   $id = $_REQUEST['dataid'];
    491   $tbl= $_REQUEST['table'];
     551  $id = rval('dataid');
     552  $tbl= rval('table');
    492553  $cur = dbte_current($tbl);
    493554  if(!$cur) return;
     
    547608function dbte_export_csv(){
    548609  global $wpdb;
    549   $cur = dbte_current(@$_REQUEST['table']);
     610  $cur = dbte_current(rval('table'));
    550611  if(!$cur) return;
    551612  // if($cur->editcap && !current_user_can($cur->editcap)) return;
    552613  $id_col = $cur->id_column;
    553   $ids = @$_REQUEST['ids'];
     614  $ids = rval('ids');
    554615  $tbl = $cur->table;
    555616  $exidf = $cur->export_id_field;
Note: See TracChangeset for help on using the changeset viewer.