mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
#909: faster display for the "details" of an object:
- object's history is only loaded when the "History" tab is clicked - by default the history display is truncated to the 'max_history_length' (= 50) latest modifications SVN:trunk[3145]
This commit is contained in:
@@ -255,14 +255,15 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
|
||||
|
||||
}
|
||||
|
||||
function DisplayBareHistory(WebPage $oPage, $bEditMode = false)
|
||||
function DisplayBareHistory(WebPage $oPage, $bEditMode = false, $iLimitCount = 0, $iLimitStart = 0)
|
||||
{
|
||||
// history block (with as a tab)
|
||||
$oHistoryFilter = new DBObjectSearch('CMDBChangeOp');
|
||||
$oHistoryFilter->AddCondition('objkey', $this->GetKey(), '=');
|
||||
$oHistoryFilter->AddCondition('objclass', get_class($this), '=');
|
||||
$oBlock = new HistoryBlock($oHistoryFilter, 'table', false);
|
||||
$oBlock->Display($oPage, -1);
|
||||
$oBlock->SetLimit($iLimitCount, $iLimitStart);
|
||||
$oBlock->Display($oPage, 'history');
|
||||
}
|
||||
|
||||
function DisplayBareProperties(WebPage $oPage, $bEditMode = false, $sPrefix = '', $aExtraParams = array())
|
||||
@@ -667,8 +668,9 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
|
||||
$oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
|
||||
$this->DisplayBareProperties($oPage, $bEditMode);
|
||||
$this->DisplayBareRelations($oPage, $bEditMode);
|
||||
$oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
|
||||
$this->DisplayBareHistory($oPage, $bEditMode);
|
||||
//$oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
|
||||
//$this->DisplayBareHistory($oPage, $bEditMode);
|
||||
$oPage->AddAjaxTab(Dict::S('UI:HistoryTab'), utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=history&class='.get_class($this).'&id='.$this->GetKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1210,10 +1210,35 @@ EOF
|
||||
*/
|
||||
class HistoryBlock extends DisplayBlock
|
||||
{
|
||||
protected $iLimitCount;
|
||||
protected $iLimitStart;
|
||||
|
||||
public function __construct(DBObjectSearch $oFilter, $sStyle = 'list', $bAsynchronous = false, $aParams = array(), $oSet = null)
|
||||
{
|
||||
parent::__construct($oFilter, $sStyle, $bAsynchronous, $aParams, $oSet);
|
||||
$this->iLimitStart = 0;
|
||||
$this->iLimitCount = 0;
|
||||
}
|
||||
|
||||
public function SetLimit($iCount, $iStart = 0)
|
||||
{
|
||||
$this->iLimitStart = $iStart;
|
||||
$this->iLimitCount = $iCount;
|
||||
}
|
||||
|
||||
public function GetRenderContent(WebPage $oPage, $aExtraParams = array(), $sId)
|
||||
{
|
||||
$sHtml = '';
|
||||
$bTruncated = false;
|
||||
$oSet = new CMDBObjectSet($this->m_oFilter, array('date'=>false));
|
||||
if (($this->iLimitStart > 0) || ($this->iLimitCount > 0))
|
||||
{
|
||||
$oSet->SetLimit($this->iLimitCount, $this->iLimitStart);
|
||||
if (($this->iLimitCount - $this->iLimitStart) < $oSet->Count())
|
||||
{
|
||||
$bTruncated = true;
|
||||
}
|
||||
}
|
||||
$sHtml .= "<!-- filter: ".($this->m_oFilter->ToOQL())."-->\n";
|
||||
switch($this->m_sStyle)
|
||||
{
|
||||
@@ -1239,7 +1264,21 @@ class HistoryBlock extends DisplayBlock
|
||||
|
||||
case 'table':
|
||||
default:
|
||||
$sHtml .= $this->GetHistoryTable($oPage, $oSet);
|
||||
if ($bTruncated)
|
||||
{
|
||||
$sFilter = $this->m_oFilter->serialize();
|
||||
$sHtml .= '<div id="history_container"><p>';
|
||||
$sHtml .= Dict::Format('UI:TruncatedResults', $this->iLimitCount, $oSet->Count());
|
||||
$sHtml .= ' ';
|
||||
$sHtml .= '<a href="#" onclick="DisplayHistory(\'#history_container\', \''.$sFilter.'\', 0, 0); return false;">'.Dict::S('UI:DisplayAll').'</a>';
|
||||
$sHtml .= $this->GetHistoryTable($oPage, $oSet);
|
||||
$sHtml .= '</p></div>';
|
||||
$oPage->add_ready_script("$('#{$sId} table.listResults tr:last td').addClass('truncated');");
|
||||
}
|
||||
else
|
||||
{
|
||||
$sHtml .= $this->GetHistoryTable($oPage, $oSet);
|
||||
}
|
||||
|
||||
}
|
||||
return $sHtml;
|
||||
|
||||
@@ -709,6 +709,15 @@ class Config
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
),
|
||||
'max_history_length' => array(
|
||||
'type' => 'integer',
|
||||
'description' => 'Maximum length of the history table (in the "History" tab on each object) before it gets truncated. Latest modifications are displayed first.',
|
||||
// examples... not used
|
||||
'default' => 50,
|
||||
'value' => 50,
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
),
|
||||
);
|
||||
|
||||
public function IsProperty($sPropCode)
|
||||
|
||||
10
js/utils.js
10
js/utils.js
@@ -374,4 +374,14 @@ function ShortcutListDlg(sOQL, sDataTableId, sContext)
|
||||
$('body').append(data);
|
||||
});
|
||||
return false;
|
||||
}
|
||||
|
||||
function DisplayHistory(sSelector, sFilter, iCount, iStart)
|
||||
{
|
||||
$(sSelector).block();
|
||||
var oParams = { operation: 'history_from_filter', filter: sFilter, start: iStart, count: iCount };
|
||||
$.post(GetAbsoluteUrlAppRoot()+'pages/ajax.render.php', oParams, function(data) {
|
||||
$(sSelector).html(data).unblock();
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -1264,6 +1264,27 @@ EOF
|
||||
$oPage->add("</div>");
|
||||
break;
|
||||
|
||||
case 'history':
|
||||
$oPage->SetContentType('text/html');
|
||||
$id = (int)utils::ReadParam('id', 0);
|
||||
$iStart = (int)utils::ReadParam('start', 0);
|
||||
$iCount = (int)utils::ReadParam('count', MetaModel::GetConfig()->Get('max_history_length', '50'));
|
||||
$oObj = MetaModel::GetObject($sClass, $id);
|
||||
$oObj->DisplayBareHistory($oPage, false, $iCount, $iStart);
|
||||
$oPage->add_ready_script("$('#history table.listResults').tableHover(); $('#history table.listResults').tablesorter( { widgets: ['myZebra', 'truncatedList']} );");
|
||||
break;
|
||||
|
||||
case 'history_from_filter':
|
||||
$oPage->SetContentType('text/html');
|
||||
$oHistoryFilter = CMDBSearchFilter::unserialize($sFilter);
|
||||
$iStart = (int)utils::ReadParam('start', 0);
|
||||
$iCount = (int)utils::ReadParam('count', MetaModel::GetConfig()->Get('max_history_length', '50'));
|
||||
$oBlock = new HistoryBlock($oHistoryFilter, 'table', false);
|
||||
$oBlock->SetLimit($iCount, $iStart);
|
||||
$oBlock->Display($oPage, 'history');
|
||||
$oPage->add_ready_script("$('#history table.listResults').tableHover(); $('#history table.listResults').tablesorter( { widgets: ['myZebra', 'truncatedList']} );");
|
||||
break;
|
||||
|
||||
default:
|
||||
$oPage->p("Invalid query.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user