瀏覽代碼

#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

git-svn-id: http://svn.code.sf.net/p/itop/code/trunk@3145 a333f486-631f-4898-b8df-5754b55c2be0

dflaven 11 年之前
父節點
當前提交
8762a41dd3
共有 5 個文件被更改,包括 86 次插入5 次删除
  1. 6 4
      application/cmdbabstract.class.inc.php
  2. 40 1
      application/displayblock.class.inc.php
  3. 9 0
      core/config.class.inc.php
  4. 10 0
      js/utils.js
  5. 21 0
      pages/ajax.render.php

+ 6 - 4
application/cmdbabstract.class.inc.php

@@ -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());
 		}
 	}
 	

+ 40 - 1
application/displayblock.class.inc.php

@@ -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;

+ 9 - 0
core/config.class.inc.php

@@ -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 - 0
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();
+		}
+	);
 }

+ 21 - 0
pages/ajax.render.php

@@ -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.");
 	}