- new feature: auto_reload. A display block can automatically reload itself at a specified time interval

SVN:trunk[256]
This commit is contained in:
Denis Flaven
2010-01-17 14:41:27 +00:00
parent 960dd649a8
commit 500bd849af
3 changed files with 96 additions and 3 deletions

View File

@@ -189,6 +189,40 @@ class DisplayBlock
$sHtml = '';
$aExtraParams = array_merge($aExtraParams, $this->m_aParams);
$aExtraParams['block_id'] = $sId;
$sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
$bAutoReload = false;
if (isset($aExtraParams['auto_reload']))
{
switch($aExtraParams['auto_reload'])
{
case 'fast':
$bAutoReload = true;
$iReloadInterval = utils::GetConfig()->GetFastReloadInterval()*1000;
break;
case 'standard':
case 'true':
case true:
$bAutoReload = true;
$iReloadInterval = utils::GetConfig()->GetStandardReloadInterval()*1000;
break;
default:
if (is_numeric($aExtraParams['auto_reload']))
{
$bAutoReload = true;
$iReloadInterval = $aExtraParams['auto_reload']*1000;
}
else
{
// incorrect config, ignore it
$bAutoReload = false;
}
}
}
$sFilter = $this->m_oFilter->serialize(); // Used either for asynchronous or auto_reload
if (!$this->m_bAsynchronous)
{
// render now
@@ -199,8 +233,6 @@ class DisplayBlock
else
{
// render it as an Ajax (asynchronous) call
$sFilter = $this->m_oFilter->serialize();
$sExtraParams = addslashes(str_replace('"', "'", json_encode($aExtraParams))); // JSON encode, change the style of the quotes and escape them
$sHtml .= "<div id=\"$sId\" class=\"display_block loading\">\n";
$sHtml .= $oPage->GetP("<img src=\"../images/indicator_arrows.gif\"> Loading...");
$sHtml .= "</div>\n";
@@ -215,7 +247,14 @@ class DisplayBlock
$("#'.$sId.' .listResults").tablesorter( { headers: { 0:{sorter: false }}, widgets: [\'zebra\']} ); // sortable and zebra tables
}
);
</script>'; // TO DO: add support for $aExtraParams in asynchronous/Ajax mode
</script>';
}
if ($bAutoReload)
{
$sHtml .= '
<script language="javascript">
setInterval("ReloadBlock(\''.$sId.'\', \''.$this->m_sStyle.'\', \''.$sFilter.'\', \"'.$sExtraParams.'\")", '.$iReloadInterval.');
</script>';
}
return $sHtml;
}

View File

@@ -18,6 +18,8 @@ class ConfigException extends CoreException
define ('DEFAULT_MIN_DISPLAY_LIMIT', 10);
define ('DEFAULT_MAX_DISPLAY_LIMIT', 15);
define ('DEFAULT_STANDARD_RELOAD_INTERVAL', 5*60);
define ('DEFAULT_FAST_RELOAD_INTERVAL', 1*60);
class Config
{
@@ -43,6 +45,15 @@ class Config
*/
protected $m_iMaxDisplayLimit;
/**
* @var integer Number of seconds between two reloads of the display (standard)
*/
protected $m_iStandardReloadInterval;
/**
* @var integer Number of seconds between two reloads of the display (fast)
*/
protected $m_iFastReloadInterval;
public function __construct($sConfigFile, $bLoadConfig = true)
{
$this->m_sFile = $sConfigFile;
@@ -136,6 +147,8 @@ class Config
$this->m_iMinDisplayLimit = isset($MySettings['min_display_limit']) ? trim($MySettings['min_display_limit']) : DEFAULT_MIN_DISPLAY_LIMIT;
$this->m_iMaxDisplayLimit = isset($MySettings['max_display_limit']) ? trim($MySettings['max_display_limit']) : DEFAULT_MAX_DISPLAY_LIMIT;
$this->m_iStandardReloadInterval = isset($MySettings['standard_reload_interval']) ? trim($MySettings['standard_reload_interval']) : DEFAULT_STANDARD_RELOAD_INTERVAL;
$this->m_iFastReloadInterval = isset($MySettings['fast_reload_interval']) ? trim($MySettings['fast_reload_interval']) : DEFAULT_FAST_RELOAD_INTERVAL;
}
protected function Verify()
@@ -204,6 +217,16 @@ class Config
return $this->m_iMaxDisplayLimit;
}
public function GetStandardReloadInterval()
{
return $this->m_iStandardReloadInterval;
}
public function GetFastReloadInterval()
{
return $this->m_iFastReloadInterval;
}
public function SetDBHost($sDBHost)
{
$this->m_sDBHost = $sDBHost;
@@ -239,6 +262,16 @@ class Config
$this->m_iMaxDisplayLimit = $iMaxDisplayLimit;
}
public function SetStandardReloadInterval($iStandardReloadInterval)
{
$this->m_iStandardReloadInterval = $iStandardReloadInterval;
}
public function SetFastReloadInterval($iFastReloadInterval)
{
$this->m_iFastReloadInterval = $iFastReloadInterval;
}
public function FileIsWritable()
{
return is_writable($this->m_sFile);
@@ -278,6 +311,8 @@ class Config
fwrite($hFile, "\n");
fwrite($hFile, "\t'min_display_limit' => {$this->m_iMinDisplayLimit},\n");
fwrite($hFile, "\t'max_display_limit' => {$this->m_iMaxDisplayLimit},\n");
fwrite($hFile, "\t'standard_reload_interval' => {$this->m_iStandardReloadInterval},\n");
fwrite($hFile, "\t'fast_reload_interval' => {$this->m_iFastReloadInterval},\n");
fwrite($hFile, ");\n");
fwrite($hFile, "\n/**\n");

View File

@@ -18,6 +18,25 @@ function ReloadTruncatedList(divId, sSerializedFilter, sExtraParams)
}
);
}
/**
* Reload any block -- used for periodic auto-reload
*/
function ReloadBlock(divId, sStyle, sSerializedFilter, sExtraParams)
{
$('#'+divId).addClass('loading');
//$('#'+divId).blockUI();
$.get('ajax.render.php?filter='+sSerializedFilter+'&style='+sStyle,
{ operation: 'ajax', extra_params: sExtraParams },
function(data){
$('#'+divId).empty();
$('#'+divId).append(data);
$('#'+divId).removeClass('loading');
$('#'+divId+' .listResults').tableHover(); // hover tables
$('#'+divId+' .listResults').tablesorter( { headers: { 0:{sorter: false }}, widgets: ['zebra']} ); // sortable and zebra tables
//$('#'+divId).unblockUI();
}
);
}
/**
* Update the display and value of a file input widget when the user picks a new file