From 6134a181d1910910021d52b196601a3fa6775c39 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leonardo=20S=C3=A1piras?= Date: Wed, 9 Jun 2010 21:40:20 +0200 Subject: [PATCH] Add auto-refresh process and prepared xact using ajax This patch rename the existing js/locks.js as js/database.js and factorise the code to use it from both page. --- database.php | 22 +++++++++++++++--- js/locks.js | 64 ---------------------------------------------------- 2 files changed, 19 insertions(+), 67 deletions(-) delete mode 100644 js/locks.js diff --git a/database.php b/database.php index f075b9a1..31e4d0a3 100755 --- a/database.php +++ b/database.php @@ -391,6 +391,18 @@ $misc->printTabs('database','processes'); $misc->printMsg($msg); + if (strlen($msg) === 0) { + echo "
icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}"; + } + + echo "
"; + currentProcesses(); + echo "
"; + } + + function currentProcesses($isAjax = false) { + global $data, $misc, $lang; + // Display prepared transactions if($data->hasPreparedXacts()) { echo "

{$lang['strpreparedxacts']}

\n"; @@ -469,6 +481,8 @@ if (!isset($processes->fields['query_start'])) unset($columns['start_time']); $misc->printTable($processes, $columns, $actions, $lang['strnodata']); + + if ($isAjax) exit; } function currentLocks($isAjax = false) { @@ -529,7 +543,7 @@ echo "
icon('Refresh')."\" alt=\"{$lang['strrefresh']}\" title=\"{$lang['strrefresh']}\"/> {$lang['strrefresh']}"; - echo "
"; + echo "
"; currentLocks(); echo "
"; } @@ -604,11 +618,12 @@ /* shortcuts: these functions exit the script */ if ($action == 'tree') doTree(); if ($action == 'refresh_locks') currentLocks(true); + if ($action == 'refresh_processes') currentProcesses(true); /* normal flow */ - if ($action == 'locks') { + if ($action == 'locks' or $action == 'processes') { $scripts = "\n"; - $scripts .= ""; + $scripts .= ""; $refreshTime = $conf['ajax_refresh'] * 1000; @@ -620,6 +635,7 @@ $scripts .= "load_icon: '". $misc->icon('Loading') ."',\n"; $scripts .= "server:'{$_REQUEST['server']}',\n"; $scripts .= "dbname:'{$_REQUEST['database']}',\n"; + $scripts .= "action:'refresh_{$action}',\n"; $scripts .= "errmsg: '". str_replace("'", "\'", $lang['strconnectionfail']) ."',\n"; $scripts .= "};\n"; $scripts .= "\n"; diff --git a/js/locks.js b/js/locks.js deleted file mode 100644 index d532bd6f..00000000 --- a/js/locks.js +++ /dev/null @@ -1,64 +0,0 @@ -$(document).ready(function() { - - var timeid = query = null; - var controlLink = $('#control'); - var errmsg = $('

'+Database.errmsg+'

') - .insertBefore(controlLink) - .hide(); - var loading = $('[loading]') - .insertAfter(controlLink) - .hide(); - - function refreshLocksTable() { - if (Database.ajax_time_refresh > 0) { - loading.show(); - query = $.ajax({ - type: 'GET', - dataType: 'html', - data: {server: Database.server, database: Database.dbname, action: 'refresh_locks'}, - url: 'database.php', - cache: false, - contentType: 'application/x-www-form-urlencoded', - success: function(html) { - $('#locks_block').html(html); - timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh) - }, - error: function() { - controlLink.click(); - errmsg.show(); - }, - complete: function () { - loading.hide(); - } - }); - } - } - - controlLink.toggle( - function() { - $(errmsg).hide(); - timeid = window.setTimeout(refreshLocksTable, Database.ajax_time_refresh); - controlLink.html(' ' - + Database.str_stop.text + '   ' - ); - }, - function() { - $(errmsg).hide(); - $(loading).hide(); - window.clearInterval(timeid); - query.abort(); - controlLink.html(' ' - + Database.str_start.text - ); - } - ); - - /* preload images */ - $('#control img').hide() - .attr('src', Database.str_start.icon) - .attr('src', Database.str_stop.icon) - .show(); - - /* start refreshing */ - controlLink.click(); -}); -- 2.39.5