Auto refresh the locks list using ajax. See ajax_refresh conf var.
authorLeonardo Sápiras <l.sapiras@gmail.com>
Sun, 30 May 2010 20:25:05 +0000 (22:25 +0200)
committerioguix <ioguix@free.fr>
Sun, 30 May 2010 20:25:05 +0000 (22:25 +0200)
Patch by Leonardo Sápiras during the gsoc2010, plus some external edits based on Alexey reviews and mine.

classes/Misc.php
conf/config.inc.php-dist
database.php
js/locks.js [new file with mode: 0644]
lang/english.php
lang/portuguese-br.php
lang/portuguese-pt.php
lang/recoded/english.php
lang/recoded/portuguese-br.php
lang/recoded/portuguese-pt.php
themes/default/global.css

index 6694d0690117fe6a21ebf2aab2cfd26b4082033b..44efb55421a94077780a46aaca6f99efc9ff5b24 100644 (file)
                                } else if (isset($conf['use_xhtml_strict']) && $conf['use_xhtml_strict']) {
                                        echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Strict.dtd\">\n";
                                } else {
-                                       echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-Transitional.dtd\">\n";
+                                       echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";
                                }
                                echo "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"{$lang['applocale']}\" lang=\"{$lang['applocale']}\"";
                                if (strcasecmp($lang['applangdir'], 'ltr') != 0) echo " dir=\"", htmlspecialchars($lang['applangdir']), "\"";
index 65a5b2472d126d3aa6db96a0ecee8a17715cdb44..da7038d5f1846bc859b1636b58a6a25d62efc3e3 100644 (file)
        // (e.g. 7.3 )
        $conf['help_base'] = 'http://www.postgresql.org/docs/%s/interactive/';
        
+       // Configuration for ajax scripts
+       // Time in seconds. If set to 0, refreshing data using ajax will be disabled (locks and activity pages)
+       $conf['ajax_refresh'] = 3;
+       
        /*****************************************
         * Don't modify anything below this line *
         *****************************************/
index 8b4ced1f58712707c109efc4e58c463d6c39473e..283b4d3f736f1f5a2882a0926343b1ff9ca6bfd9 100755 (executable)
@@ -11,6 +11,7 @@
 
        $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : '';
        if (!isset($msg)) $msg = '';
+       $scripts = '';
 
        function _highlight($string, $term) {
                return str_replace($term, "<b>{$term}</b>", $string);
                $misc->printTable($processes, $columns, $actions, $lang['strnodata']);
        }
 
-       /**
-        * Show the existing table locks in the current database
-       */
-       function doLocks() {
-               global $data, $misc;
-               global $lang;
+       function currentLocks($isAjax = false) {
+               global $data, $misc, $lang;
 
                // Get the info from the pg_locks view
                $variables = $data->getLocks();
 
-               $misc->printTrail('database');
-               $misc->printTabs('database','locks');
-
                $columns = array(
                        'namespace' => array(
                                'title' => $lang['strschema'],
                if (!$data->hasVirtualTransactionId()) unset($columns['vxid']);
 
                $actions = array();
-
                $misc->printTable($variables, $columns, $actions, $lang['strnodata']);
+               
+               if ($isAjax) exit;
+       }
+       
+       /**
+        * Show the existing table locks in the current database
+        */
+       function doLocks() {
+               global $data, $misc;
+               global $lang;
+
+               $misc->printTrail('database');
+               $misc->printTabs('database','locks');
+
+               echo "<br /><a id=\"control\" href=\"\"><img src=\"".$misc->icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/>&nbsp;{$lang['strrefresh']}</a>";
+
+               echo "<div id=\"locks_block\" class=\"data_block\">";
+               currentLocks();
+               echo "</div>";
+
+               echo "<a href=\"#\" class=\"bottom_link\">".$lang['strgotoppage']."</a>";
        }
 
        /**
 
        require('./admin.php');
 
+       /* shortcuts: these functions exit the script */
        if ($action == 'tree') doTree();
-       
-       $misc->printHeader($lang['strschemas']);
+       if ($action == 'refresh_locks') currentLocks(true);
+
+       /* normal flow */
+       if ($action == 'locks') {
+               $scripts  = "<script src=\"libraries/js/jquery.js\" type=\"text/javascript\"></script>";
+               $scripts .= "<script src=\"js/locks.js\" type=\"text/javascript\"></script>";
+
+               $refreshTime = $conf['ajax_refresh'] * 1000;
+
+               $scripts .= "<script type=\"text/javascript\">\n";
+               $scripts .= "var Database = {\n";
+               $scripts .= "ajax_time_refresh: {$refreshTime},\n";
+               $scripts .= "str_start: {text:'{$lang['strstart']}',icon: '". $misc->icon('Execute') ."'},\n";
+               $scripts .= "str_stop: {text:'{$lang['strstop']}',icon: '". $misc->icon('Stop') ."'},\n";
+               $scripts .= "server:'{$misc->href}',\n";
+               $scripts .= "};\n";
+               $scripts .= "</script>\n";
+       }
+
+       $misc->printHeader($lang['strdatabase'], $scripts);
        $misc->printBody();
-       
+
        switch ($action) {
                case 'find':
                        if (isset($_REQUEST['term'])) doFind(false);
        }
 
        $misc->printFooter();
-
 ?>
diff --git a/js/locks.js b/js/locks.js
new file mode 100644 (file)
index 0000000..81310e6
--- /dev/null
@@ -0,0 +1,38 @@
+$(document).ready(function() {
+
+       var timeid = null;
+       var controlLink = $('#control');
+
+       function refreshLocksTable() {
+               if (Database.ajax_time_refresh > 0) {
+                       $.ajax({
+                               type: 'GET',
+                               dataType: 'html',
+                               url: 'database.php?action=refresh_locks&' + Database.server,
+                               timeout: Database.ajax_timeout - 100,
+                               cache: false,
+                               contentType: 'application/x-www-form-urlencoded',
+                               success: function(html) {
+                                       $('#locks_block').html(html);
+                                       timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh)
+                               }
+                       });
+               }
+       }
+
+       controlLink.toggle(
+               function() {
+                       timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh);
+                       controlLink.html('<img src="'+ Database.str_stop.icon +'" alt="" />&nbsp;'
+                               + Database.str_stop.text);
+               },
+               function() {
+                       window.clearInterval(timeid);
+                       controlLink.html('<img src="'+ Database.str_start.icon +'" alt="" />&nbsp;'
+                               + Database.str_start.text
+                       );
+               }
+       );
+
+       controlLink.click();
+});
index 2683e48c6141a6b8d749f183a6baa7dbcce7eab8..3526ffcf97a25638b95b8313a97d5063cac483e4 100644 (file)
        $lang['strctype'] = 'Character Type';
        $lang['strdefaultvalues'] = 'Default values';
        $lang['strnewvalues'] = 'New values';
+       $lang['strstart'] = 'Start';
+       $lang['strstop'] = 'Stop';
+       $lang['strgotoppage'] = 'back to top';
        
        // Admin
        $lang['stradminondatabase'] = 'The following administrative tasks apply on the whole %s database.';
index e054321bab3dd58c51689a658220f077021eb037..cff37c6ff639ea7d7fb670c9fc4a32477b327da6 100644 (file)
        $lang['strselectall'] = 'Selecionar tudo';
        $lang['strunselectall'] = 'Desmarcar tudo';
        $lang['strlocale'] = 'Local';           
+       $lang['strstart'] = 'Iniciar';
+       $lang['strstop'] = 'Parar';
+       $lang['strgotoppage'] = 'Topo da página';
 
        // User-supplied SQL history
        $lang['strhistory'] = 'Histórico';
index 30f8990722ff32a49aef772d42e3ef449017e754..e9dd5a2211ebde821a14bc3204eb17db35b9260e 100644 (file)
@@ -88,6 +88,9 @@ $lang['strwhere'] = 'Onde';
 $lang['strinstead'] = 'Fazer ao invés';                                
 $lang['strwhen'] = 'Quando';                                           
 $lang['strformat'] = 'Formato';                                        
+$lang['strstart'] = 'Iniciar';
+$lang['strstop'] = 'Parar';
+$lang['strgotoppage'] = 'Topo da página';
 
 // Error handling
 $lang['strdata'] = 'Data';
index 173fb1e1318933255d6e0b53f77a184f3280624a..a4a58455cc0c91b2b3c4add5d5f38f12e6461119 100644 (file)
        $lang['strctype'] = 'Character Type';
        $lang['strdefaultvalues'] = 'Default values';
        $lang['strnewvalues'] = 'New values';
+       $lang['strstart'] = 'Start';
+       $lang['strstop'] = 'Stop';
+       $lang['strgotoppage'] = 'back to top';
        
        // Admin
        $lang['stradminondatabase'] = 'The following administrative tasks apply on the whole %s database.';
index f06dc70e24fcae7624c6fe62ae81ef290eabfd16..4f6d2b7df3a43caf83a0d42d1674a09b58510212 100644 (file)
        $lang['strselectall'] = 'Selecionar tudo';
        $lang['strunselectall'] = 'Desmarcar tudo';
        $lang['strlocale'] = 'Local';           
+       $lang['strstart'] = 'Iniciar';
+       $lang['strstop'] = 'Parar';
+       $lang['strgotoppage'] = 'Topo da p&#225;gina';
 
        // User-supplied SQL history
        $lang['strhistory'] = 'Hist&#243;rico';
index 0118574a54f11e17df0ccd5ccf540b59215dec10..31229a83381466c698745d0c16e95d10966562e8 100644 (file)
@@ -88,6 +88,9 @@ $lang['strwhere'] = 'Onde';
 $lang['strinstead'] = 'Fazer ao inv&#233;s';                           
 $lang['strwhen'] = 'Quando';                                           
 $lang['strformat'] = 'Formato';                                        
+$lang['strstart'] = 'Iniciar';
+$lang['strstop'] = 'Parar';
+$lang['strgotoppage'] = 'Topo da p&#225;gina';
 
 // Error handling
 $lang['strdata'] = 'Data';
index d3a07d6195b77db0e9db9030c35706af39b7ad3c..6946225687a3e39132dcb00536d0c314522017db 100644 (file)
@@ -455,3 +455,10 @@ pre.error
 }
 .ac_values {width:100%}
 .ac_field {border:1px solid #D9D95F}
+
+.bottom_link {
+       position: fixed; 
+       bottom: 0; 
+       right: 0;
+       padding: 5px;
+}