[Phpmyadmin-git] [SCM] phpMyAdmin branch, master, updated. RELEASE_3_4_7_1-23849-gd39a230

Rouslan Placella roccivic at users.sourceforge.net
Fri Dec 2 01:55:33 CET 2011


The branch, master has been updated
       via  d39a2309922e5646034262a37024b1bdb363a207 (commit)
      from  14b9e4cfa3673f36ae02e508f164cd9bdf0a4a26 (commit)


- Log -----------------------------------------------------------------
commit d39a2309922e5646034262a37024b1bdb363a207
Author: asdfrede <asdfrede at users.sourceforge.net>
Date:   Fri Dec 2 00:48:19 2011 +0000

    Fixed bug #3408377 - Deleting table from the DB does not change the table counter

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog          |    1 +
 db_structure.php   |   13 +++---
 js/db_structure.js |  116 +++++++++++++++++++++++++++++++++++++++------------
 js/functions.js    |    3 +
 js/messages.php    |   10 ++++
 tbl_create.php     |    6 +-
 6 files changed, 112 insertions(+), 37 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 45d46a5..bc69949 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -61,6 +61,7 @@ phpMyAdmin - ChangeLog
 + patch #3432835 [interface] Add useful intermediate pages to pageselector
 + [interface] Improved index editor
 + View editing via a generated ALTER VIEW
+- bug #3408377 [interface] Deleting table from the DB does not change the table counter
 
 3.4.9.0 (not yet released)
 - bug #3442028 [edit] Inline editing enum fields with null shows no dropdown
diff --git a/db_structure.php b/db_structure.php
index 16df6a7..aae36e6 100644
--- a/db_structure.php
+++ b/db_structure.php
@@ -14,6 +14,7 @@ $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.16.custom.js';
 $GLOBALS['js_include'][] = 'db_structure.js';
 $GLOBALS['js_include'][] = 'tbl_change.js';
 $GLOBALS['js_include'][] = 'jquery/timepicker.js';
+$GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
 
 /**
  * Prepares the tables list if the user where not redirected to this script
@@ -244,8 +245,8 @@ foreach ($tables as $keyname => $each_table) {
     if ($is_show_stats) {
         if (isset($formatted_overhead)) {
             $overhead = '<a href="tbl_structure.php?'
-                . $tbl_url_query . '#showusage">' . $formatted_overhead
-                . ' ' . $overhead_unit . '</a>' . "\n";
+                . $tbl_url_query . '#showusage"><span>' . $formatted_overhead
+                . '</span> <span class="unit">' . $overhead_unit . '</span></a>' . "\n";
             unset($formatted_overhead);
             $overhead_check .=
                 "document.getElementById('checkbox_tbl_" . ($i + 1) . "').checked = true;";
@@ -472,8 +473,8 @@ foreach ($tables as $keyname => $each_table) {
         <?php if ($is_show_stats) { ?>
     <td class="value tbl_size"><a
         href="tbl_structure.php?<?php echo $tbl_url_query; ?>#showusage"
-        ><?php echo $formatted_size . ' ' . $unit; ?></a></td>
-    <td class="value"><?php echo $overhead; ?></td>
+        ><?php echo '<span>' . $formatted_size . '</span> <span class="unit">' . $unit . '</span>'; ?></a></td>
+    <td class="value tbl_overhead"><?php echo $overhead; ?></td>
         <?php } // end if ?>
     <?php } elseif ($table_is_view) { ?>
     <td class="value">-</td>
@@ -502,7 +503,7 @@ if ($is_show_stats) {
 </tbody>
 <tbody id="tbl_summary_row">
 <tr><th></th>
-    <th align="center" nowrap="nowrap">
+    <th align="center" nowrap="nowrap" class="tbl_num">
         <?php
             // for blobstreaming - if the number of tables is 0, set tableReductionCount to 0
             // (we don't want negative numbers here)
@@ -543,7 +544,7 @@ if (!($cfg['PropertiesNumColumns'] > 1)) {
 if ($is_show_stats) {
     ?>
     <th class="value tbl_size"><?php echo $sum_formatted . ' ' . $unit; ?></th>
-    <th class="value"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
+    <th class="value tbl_overhead"><?php echo $overhead_formatted . ' ' . $overhead_unit; ?></th>
     <?php
 }
 ?>
diff --git a/js/db_structure.js b/js/db_structure.js
index c00bd45..f9d9c13 100644
--- a/js/db_structure.js
+++ b/js/db_structure.js
@@ -20,35 +20,90 @@
 
 /**
  * Adjust number of rows and total size in the summary
- * when emptying or dropping a table
- *
- * @param jQuery object     $this_anchor
+ * when truncating, creating, dropping or inserting into a table
  */
-function PMA_adjustTotals($this_anchor)
-{
-    var $parent_tr = $this_anchor.closest('tr');
-    var $rows_td = $parent_tr.find('.tbl_rows');
-    var $size_td = $parent_tr.find('.tbl_size');
-    var num_rows = parseInt($rows_td.text());
-    // set number of rows to 0
-    // (not really needed in case we are dropping the table)
-    $rows_td.text('0');
-    // set size to unknown (not sure how to get the exact
-    // value here, as an empty InnoDB table would have a size)
-    $size_td.text('-');
-
-    // try to compute a new total row number
-    if (! isNaN(num_rows)) {
-        $total_rows_td = $('#tbl_summary_row').find('.tbl_rows');
-        var total_rows = parseInt($total_rows_td.text());
-        if (! isNaN(total_rows)) {
-            $total_rows_td.text(total_rows - num_rows);
+function PMA_adjustTotals() {
+    var byteUnits = new Array(
+        PMA_messages['strB'],
+        PMA_messages['strKiB'],
+        PMA_messages['strMiB'],
+        PMA_messages['strGiB'],
+        PMA_messages['strTiB'],
+        PMA_messages['strPiB'],
+        PMA_messages['strEiB']
+    );
+    /**
+     * @var $allTr jQuery object that references all the rows in the list of tables
+     */
+    var $allTr = $("#tablesForm table.data tbody:first tr");
+    // New summary values for the table
+    var tableSum = $allTr.size();
+    var rowsSum = 0;
+    var sizeSum = 0;
+    var overheadSum = 0;
+    
+    $allTr.each(function () {
+        var $this = $(this);
+        // Get the number of rows for this SQL table
+        var strRows = $this.find('.tbl_rows').text();
+        strRows = strRows.replace(/[,.]/g , '');
+        var intRow = parseInt(strRows, 10);
+        if (! isNaN(intRow)) {
+            rowsSum += intRow;
+        }
+        // Extract the size and overhead
+        var valSize         = 0;
+        var valOverhead     = 0;
+        var strSize         = $.trim($this.find('.tbl_size span:not(.unit)').text());
+        var strSizeUnit     = $.trim($this.find('.tbl_size span.unit').text());
+        var strOverhead     = $.trim($this.find('.tbl_overhead span:not(.unit)').text());
+        var strOverheadUnit = $.trim($this.find('.tbl_overhead span.unit').text());
+        // Given a value and a unit, such as 100 and KiB, for the table size
+        // and overhead calculate their numeric values in bytes, such as 102400
+        for (var i = 0; i < byteUnits.length; i++) {
+            if (strSizeUnit == byteUnits[i]) {
+                var tmpVal = parseFloat(strSize);
+                valSize = tmpVal * Math.pow(1024, i);
+                break;
+            }
+        }
+        for (var i = 0; i < byteUnits.length; i++) {
+            if (strOverheadUnit == byteUnits[i]) {
+                var tmpVal = parseFloat(strOverhead);
+                valOverhead = tmpVal * Math.pow(1024, i);
+                break;
+            }
         }
+        sizeSum += valSize;
+        overheadSum += valOverhead;
+    });
+    // Add some commas for readablility:
+    // 1000000 becomes 1,000,000
+    var strRowSum = rowsSum + "";
+    var regex = /(\d+)(\d{3})/;
+    while (regex.test(strRowSum)) {
+        strRowSum = strRowSum.replace(regex, '$1' + ',' + '$2');
+    }
+    // Calculate the magnitude for the size and overhead values
+    var size_magnitude = 0, overhead_magnitude = 0;
+    while (sizeSum >= 1024) {
+        sizeSum /= 1024;
+        size_magnitude++;
     }
+    while (overheadSum >= 1024) {
+        overheadSum /= 1024;
+        overhead_magnitude++;
+    }
+
+    sizeSum = Math.round(sizeSum * 10) / 10;
+    overheadSum = Math.round(overheadSum * 10) / 10;
 
-    // prefix total size with "~"
-    var $total_size_td = $('#tbl_summary_row').find('.tbl_size');
-    $total_size_td.text($total_size_td.text().replace(/^/,'~'));
+    // Update summary with new data
+    var $summary = $("#tbl_summary_row");
+    $summary.find('.tbl_num').text($.sprintf(PMA_messages['strTables'], tableSum));
+    $summary.find('.tbl_rows').text(strRowSum);
+    $summary.find('.tbl_size').text(sizeSum + " " + byteUnits[size_magnitude]);
+    $summary.find('.tbl_overhead').text(overheadSum + " " + byteUnits[overhead_magnitude]);
 }
 
 $(document).ready(function() {
@@ -146,6 +201,7 @@ $(document).ready(function() {
             }
             /**Update the row count at the tableForm*/
             current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
+            PMA_adjustTotals();
         }) // end $.post()
     }) // end insert table button "Go"
 
@@ -182,6 +238,7 @@ $(document).ready(function() {
             }
             /**Update the row count at the tableForm*/
             current_insert_table.closest('tr').find('.value.tbl_rows').html(data.row_count);
+            PMA_adjustTotals();
         }) // end $.post()
     });
 
@@ -217,16 +274,19 @@ $(document).ready(function() {
             $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
                 if (data.success == true) {
                     PMA_ajaxShowMessage(data.message);
+                    // Adjust table statistics
+                    var $tr = $this_anchor.closest('tr');
+                    $tr.find('.tbl_rows').text('0');
+                    $tr.find('.tbl_size, .tbl_overhead').text('-');
                     //Fetch inner span of this anchor
                     //and replace the icon with its disabled version
                     var span = $this_anchor.html().replace(/b_empty/, 'bd_empty');
-                    PMA_adjustTotals($this_anchor);
-
                     //To disable further attempts to truncate the table,
                     //replace the a element with its inner span (modified)
                     $this_anchor
                         .replaceWith(span)
                         .removeClass('truncate_table_anchor');
+                    PMA_adjustTotals();
                 } else {
                     PMA_ajaxShowMessage(PMA_messages['strErrorProcessingRequest'] + " : " + data.error, false);
                 }
@@ -267,8 +327,8 @@ $(document).ready(function() {
             $.get(url, {'is_js_confirmed' : 1, 'ajax_request' : true}, function(data) {
                 if (data.success == true) {
                     PMA_ajaxShowMessage(data.message);
-                    PMA_adjustTotals($this_anchor);
                     $curr_row.hide("medium").remove();
+                    PMA_adjustTotals();
 
                     if (window.parent && window.parent.frame_navigation) {
                         window.parent.frame_navigation.location.reload();
diff --git a/js/functions.js b/js/functions.js
index 08b8655..1e2bbad 100644
--- a/js/functions.js
+++ b/js/functions.js
@@ -2131,6 +2131,9 @@ $(document).ready(function() {
 
                             //Sort the table
                             $(tables_table).PMA_sort_table('th');
+                            
+                            // Adjust summary row
+                            PMA_adjustTotals();
                         }
 
                         //Refresh navigation frame as a new table has been added
diff --git a/js/messages.php b/js/messages.php
index 2534567..5aba16f 100644
--- a/js/messages.php
+++ b/js/messages.php
@@ -121,6 +121,16 @@ $js_messages['strBytesReceived'] = __('Bytes received');
 $js_messages['strConnections'] = __('Connections');
 $js_messages['strProcesses'] = __('Processes');
 
+/* summary row */
+$js_messages['strB'] = __('B');
+$js_messages['strKiB'] = __('KiB');
+$js_messages['strMiB'] = __('MiB');
+$js_messages['strGiB'] = __('GiB');
+$js_messages['strTiB'] = __('TiB');
+$js_messages['strPiB'] = __('PiB');
+$js_messages['strEiB'] = __('EiB');
+$js_messages['strTables'] = __('%d table(s)');
+
 /* l10n: Questions is the name of a MySQL Status variable */
 $js_messages['strQuestions'] = __('Questions');
 $js_messages['strTraffic'] = __('Traffic');
diff --git a/tbl_create.php b/tbl_create.php
index ae42d75..63cd26a 100644
--- a/tbl_create.php
+++ b/tbl_create.php
@@ -261,7 +261,7 @@ if (isset($_REQUEST['do_save_data'])) {
                 }
 
                 if (isset($formatted_overhead)) {
-                        $overhead = $formatted_overhead . ' ' . $overhead_unit;
+                        $overhead = '<span>' . $formatted_overhead . '</span> <span class="unit">' . $overhead_unit . '</span>';
                         unset($formatted_overhead);
                     } else {
                         $overhead = '-';
@@ -310,8 +310,8 @@ if (isset($_REQUEST['do_save_data'])) {
             $new_table_string .= '<td> <dfn title="' . PMA_getCollationDescr($tbl_stats['Collation']) . '">'. $tbl_stats['Collation'] .'</dfn></td>' . "\n";
 
             if ($is_show_stats) {
-                $new_table_string .= '<td class="value"> <a href="tbl_structure.php' . PMA_generate_common_url($tbl_url_params) . '#showusage" >' . $formatted_size . ' ' . $unit . '</a> </td>' . "\n" ;
-                $new_table_string .= '<td class="value">' . $overhead . '</td>' . "\n" ;
+                $new_table_string .= '<td class="value tbl_size"> <a href="tbl_structure.php' . PMA_generate_common_url($tbl_url_params) . '#showusage" ><span>' . $formatted_size . '</span> <span class="unit">' . $unit . '</class></a> </td>' . "\n" ;
+                $new_table_string .= '<td class="value tbl_overhead">' . $overhead . '</td>' . "\n" ;
             }
 
             $new_table_string .= '</tr>' . "\n";


hooks/post-receive
-- 
phpMyAdmin




More information about the Git mailing list