From: Thierry Parmentelat Date: Thu, 28 May 2009 10:21:25 +0000 (+0000) Subject: some rustic debug/profiling tools builtin tables - users page does not autosort X-Git-Tag: PLEWWW-4.3-15~4 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=8d246b5d8b03225264c3bff7616ca368c9445b0c;p=plewww.git some rustic debug/profiling tools builtin tables - users page does not autosort --- diff --git a/planetlab/nodes/nodes.php b/planetlab/nodes/nodes.php index fca8214..3e819f4 100644 --- a/planetlab/nodes/nodes.php +++ b/planetlab/nodes/nodes.php @@ -127,7 +127,8 @@ if ( ! $nodes ) { $nifty=new PlekitNifty ('','objects-list','big'); $nifty->start(); -$headers = array (); +$headers = array (); $offset=0; +if (plc_is_admin()) { $headers["I"]="int"; $offset=1; } $headers["P"]="string"; $headers["R"]="string"; $headers["Site"]="string"; @@ -137,11 +138,10 @@ $headers["Type"]="string"; $headers["IP"]="IPAddress"; $headers["A"]="string"; $headers["S"]='int'; -if (plc_is_admin()) $headers["I"]="int"; $headers["?"]="string"; # initial sort on hostnames -$table=new PlekitTable ("nodes",$headers,4); +$table=new PlekitTable ("nodes",$headers,4+$offset); $table->start(); $peers = new Peers ($api); @@ -158,6 +158,7 @@ foreach ($nodes as $node) { $node_type = $node['node_type']; $table->row_start(); + if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id)); $peers->cell ($table,$peer_id); $table->cell (topdomain($hostname)); $table->cell (l_site_t($site_id,$login_base)); @@ -167,17 +168,17 @@ foreach ($nodes as $node) { $table->cell (l_interface_t($interface_id,$ip),array('only-if'=> !$peer_id)); $table->cell ($node['arch'],array('only-if'=> !$peer_id)); $table->cell (count($node['slice_ids'])); - if (plc_is_admin()) $table->cell(l_node_t($node_id,$node_id)); $table->cell (node_status($node)); $table->row_end(); } $notes=array(); +if (plc_is_admin()) $notes []= "I = node_id"; $notes []= "R = region"; $notes []= "A = arch"; $notes []= "S = number of slivers"; -if (plc_is_admin()) $notes []= "I = node_id"; +$notes []= "? = status"; $table->end(array('notes'=>$notes)); $nifty->end(); diff --git a/planetlab/persons/persons.php b/planetlab/persons/persons.php index 7308baa..fc77d6c 100644 --- a/planetlab/persons/persons.php +++ b/planetlab/persons/persons.php @@ -137,18 +137,19 @@ if ( ! $persons ) { $nifty=new PlekitNifty ('','objects-list','big'); $nifty->start(); -$headers = array ("Peer"=>"string", - "First"=>"string", - "Last"=>"string", - "Email"=>"string", - "Site" => "string", - "R"=>"string", - "S" => "int", - "Status"=>"string", - ); - -// initial sort on email -$table=new PlekitTable("persons",$headers,3); +$headers=array(); +if (plc_is_admin()) $headers["I"]='int'; +$headers["Peer"]="string"; +$headers["First"]="string"; +$headers["Last"]="string"; +$headers["Email"]="string"; +$headers["Site" ]= "string"; +$headers["R"]="string"; +$headers["S" ]= "int"; +$headers["Status"]="string"; + +// turn off initial sort as this slows stuff down terribly +$table=new PlekitTable("persons",$headers,-1,array('debug'=>true)); $table->start(); $peers=new Peers ($api); @@ -166,6 +167,7 @@ foreach ($persons as $person) { $table->row_start(); + if (plc_is_admin()) $table->cell(href(l_person($person_id),$person_id)); $peers->cell($table,$peer_id); $table->cell (href(l_person($person_id),$person['first_name'])); $table->cell (href(l_person($person_id),$person['last_name'])); @@ -178,6 +180,7 @@ foreach ($persons as $person) { } $notes = array(); +if (plc_is_admin()) $notes[]= "I = person_id"; $notes []= "R = roles"; $notes []= "S = number of slices"; $table->end(array('notes'=>$notes)); diff --git a/plekit/php/table.php b/plekit/php/table.php index c22b867..bb63155 100644 --- a/plekit/php/table.php +++ b/plekit/php/table.php @@ -15,7 +15,7 @@ drupal_set_html_head(' //////////////////////////////////////// // table_id: 's id tag - WARNING : do not use '-' in table ids as it's used for generating javascript code // headers: an associative array "label"=>"type" -// sort_column: the column to sort on at load-time +// sort_column: the column to sort on at load-time - set to negative number for no onload- sorting // options : an associative array to override options // - bullets1 : set to true if you want decorative bullets in column 1 (need white background) // - stripes : use diferent colors for odd and even rows @@ -24,10 +24,11 @@ drupal_set_html_head(' // - pagesize_area : boolean (default true) // - notes_area : boolean (default true) // - search_width : size in chars of the search text dialog -// - notes : an array of additional notes // - pagesize: the initial pagination size // - pagesize_def: the page size when one clicks the pagesize reset button // - max_pages: the max number of pages to display in the paginator +// - notes : an array of additional notes +// - debug: enables debug callbacks (prints out on console.log) class PlekitTable { // mandatory @@ -37,26 +38,28 @@ class PlekitTable { // options var $bullets1; // boolean - default false - display decorative bullets in column 1 var $stripes; // boolean - default true - use different colors for odd and even rows - var $caption; + var $caption; // string - never used so far var $search_area; // boolean (default true) var $pagesize_area; // boolean (default true) var $notes_area; // boolean (default true) var $search_width; // size in chars of the search text dialog - var $pagesize; // the initial pagination size + var $pagesize; // the initial pagination size var $pagesize_def; // the page size when one clicks the pagesize reset button var $max_pages; // the max number of pages to display in the paginator var $notes; // an array of additional notes + var $debug; // set to true for enabling various log messages on console.log + + // internal var $has_tfoot; function PlekitTable ($table_id,$headers,$sort_column,$options=NULL) { $this->table_id = $table_id; $this->headers = $headers; $this->sort_column = $sort_column; + $this->bullets1 = true; $this->stripes=true; - - $this->has_tfoot=false; - + $this->caption=''; $this->search_area = true; $this->pagesize_area = true; $this->notes_area = true; @@ -65,8 +68,12 @@ class PlekitTable { $this->pagesize_def = 999; $this->max_pages = 10; $this->notes = array(); + $this->debug = false; $this->set_options ($options); + + // internal + $this->has_tfoot=false; } function set_options ($options) { @@ -82,8 +89,8 @@ class PlekitTable { if (array_key_exists('pagesize',$options)) $this->pagesize=$options['pagesize']; if (array_key_exists('pagesize_def',$options)) $this->pagesize_def=$options['pagesize_def']; if (array_key_exists('max_pages',$options)) $this->max_pages=$options['max_pages']; - if (array_key_exists('notes',$options)) $this->notes=array_merge($this->notes,$options['notes']); + if (array_key_exists('debug',$options)) $this->debug=$options['debug']; } public function columns () { @@ -98,45 +105,47 @@ class PlekitTable { $classname.=" paginate-" . $this->pagesize; if ($this->bullets1) { $classname .= " bullets1"; } if ($this->stripes) { $classname .= " rowstyle-alt"; } - // instantiate paginator callback - print <<< EOF - -
-
- -EOF; + if ($this->sort_column >= 0) { $classname .= " sortable-onload-$this->sort_column"; } - if ($this->pagesize_area) - print $this->pagesize_area_html (); - if ($this->search_area) - print $this->search_area_html (); + // instantiate paginator callback + print "\n"; + + // instantiate debug hooks if needed + if ($this->debug) { + $cb_init = $this->table_id."_init"; + print "\n"; + $classname .= " sortinitiatedcallback-$cb_init"; + $cb_comp = $this->table_id."_comp"; + print "\n"; + $classname .= " sortcompletecallback-$cb_comp"; + } + // start actual table + print "
\n"; - if ($this->caption) - print ""; - print ""; - foreach ($this->headers as $label => $type) { - switch ($type) { - case "none" : - $class=""; break; - case "string": case "int": case "float": - $class="sortable"; break; - case ( strpos($type,"date-") == 0): - $class="sortable-" . $type; break; - default: - $class="sortable-sort" . $type; break; + if ($this->pagesize_area) + print $this->pagesize_area_html (); + if ($this->search_area) + print $this->search_area_html (); + + if ($this->caption) + print ""; + print ""; + foreach ($this->headers as $label => $type) { + switch ($type) { + case "none" : + $class=""; break; + case "string": case "int": case "float": + $class="sortable"; break; + case ( strpos($type,"date-") == 0): + $class="sortable-" . $type; break; + default: + $class="sortable-sort" . $type; break; + } + printf ('',$class,$label); } - printf ('',$class,$label); - } - print <<< EOF - - - -EOF; -} + print ""; + } //////////////////// // for convenience, the options that apply to the bottom area can be passed here diff --git a/plekit/table/table.css b/plekit/table/table.css index 26116cf..1386863 100644 --- a/plekit/table/table.css +++ b/plekit/table/table.css @@ -4,6 +4,11 @@ table.plekit_table { padding: 0; margin: 0 auto 1.5em auto; border-collapse:collapse; +/* this used to be hard-wired in the
$this->caption
$this->caption
%s%s
tag, but looks useless now + cellpadding:0; + cellspacing:0; + border:0; + */ } table.plekit_table>thead>tr, table.plekit_table>tbody>tr { border-left: 1px solid #C1DAD7; diff --git a/plekit/table/table.js b/plekit/table/table.js index b7d4ac4..0f86acb 100644 --- a/plekit/table/table.js +++ b/plekit/table/table.js @@ -1,5 +1,17 @@ /* $Id$ */ +var debug=false; + +/* for debugging purposes */ +function plc_timestamp () { + var now = new Date(); + return now.getMinutes() + ':' + now.getSeconds() + '.' + now.getMilliseconds() ; +} + +function plc_message (message) { + console.log ( plc_timestamp() + ' : ' + message); +} + /* when a table gets paginated, displays context info */ function plekit_table_paginator (opts,table_id) { @@ -115,6 +127,9 @@ function plekit_table_filter(table_id,pattern_id,and_id) { } function plekit_lazy_table_filter (table_id,pattern_id,and_id) { + + if (debug) plc_message ('entering plekit_lazy_table_filter'); + var table=$(table_id); var css='#'+table_id+'>tbody'; var rows = $$(css)[0].rows; @@ -149,6 +164,8 @@ function plekit_lazy_table_filter (table_id,pattern_id,and_id) { return; } + if (debug) plc_message ('inside plekit_lazy_table_filter'); + var searches=new Array(); var patterns=new Array(); if (pattern_text.length > 0) { @@ -205,6 +222,8 @@ function plekit_lazy_table_filter (table_id,pattern_id,and_id) { var end=(new Date).getTime(); var match_ms=end-start; + if (debug) plc_message ('almost at end of plekit_lazy_table_filter'); + // optimize useless calls to init, by comparing # of matching entries var previous_matching=table['previous_matching']; if (matching_entries == previous_matching) { @@ -216,7 +235,9 @@ function plekit_lazy_table_filter (table_id,pattern_id,and_id) { tablePaginater.init(table_id); var end2=(new Date).getTime(); var paginate_ms=end2-end; - + + if (debug) plc_message ('exiting plekit_lazy_table_filter with paginate_ms=' + paginate_ms); + } function plekit_table_filter_reset (table_id, pattern_id,and_id) { diff --git a/plekit/tablesort/tablesort.js b/plekit/tablesort/tablesort.js index 9b55e59..c52382c 100644 --- a/plekit/tablesort/tablesort.js +++ b/plekit/tablesort/tablesort.js @@ -25,6 +25,8 @@ * Any of these conditions can be waived if you get permission from the copyright holder. */ +var debug=false; + (function() { fdTableSort = { regExp_Currency: /^[£$€¥¤]/, @@ -127,6 +129,7 @@ fdTableSort = { fdTableSort.init(false); }, init: function(tableId) { + if (debug) plc_message ('entering tablesort.init'); if (!document.getElementsByTagName || !document.createElement || !document.getElementById) return; var tables = tableId && document.getElementById(tableId) ? [document.getElementById(tableId)] : document.getElementsByTagName("table"); @@ -286,6 +289,7 @@ fdTableSort = { }; fdTableSort.thNode = aclone = a = span = columnNumSortObj = thNode = tbl = allRowArr = rowArr = null; + if (debug) plc_message ('exiting tablesort.init'); }, initWrapper: function(e) { e = e || window.event; @@ -657,6 +661,7 @@ fdTableSort = { fdTableSort.thNode = null; }, redraw: function(tableid, identical) { + if (debug) plc_message ('entering tablesort.redraw'); if(!tableid || !(tableid in fdTableSort.tableCache)) { return; }; var dataObj = fdTableSort.tableCache[tableid]; var data = dataObj.data; @@ -691,6 +696,7 @@ fdTableSort = { }; }; tr = tds = hook = null; + if (debug) plc_message ('exiting tablesort.redraw'); }, getInnerText: function(el, allowBrTags) { if (typeof el == "string" || typeof el == "undefined") return el;