mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 11:38:44 +02:00
N°2844 - Refactor Panel to include a configurable header
- TitleForObjectDetails no longer exists, use the ObjectDetails's properties instead
This commit is contained in:
@@ -44,30 +44,27 @@ class ObjectDetails extends Panel
|
||||
/**
|
||||
* ObjectDetails constructor.
|
||||
*
|
||||
* @param \DBObject $oObject The object for which we display the details
|
||||
* @param string $sMode See \cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
|
||||
* @param string|null $sId ID of the block itself, not the $oObject ID
|
||||
* @param \DBObject $oObject The object for which we display the details
|
||||
* @param string $sMode See \cmdbAbstractObject::ENUM_OBJECT_MODE_XXX
|
||||
* @param string|null $sId ID of the block itself, not the $oObject ID
|
||||
*
|
||||
* @throws \ArchivedObjectException
|
||||
* @throws \CoreException
|
||||
* @throws \DictExceptionMissingString
|
||||
*/
|
||||
public function __construct(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE, ?string $sId = null) {
|
||||
public function __construct(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_OBJECT_MODE, ?string $sId = null)
|
||||
{
|
||||
$this->sClassName = get_class($oObject);
|
||||
$this->sClassLabel = MetaModel::GetName($this->GetClassName());
|
||||
$this->sObjectId = $oObject->GetKey();
|
||||
// Note: We get the raw name as only the front-end consumer knows when and how to encode it.
|
||||
$this->sObjectName = $oObject->GetRawName();
|
||||
$this->sObjectMode = $sMode;
|
||||
$this->sIconUrl = $oObject->GetIcon(false);
|
||||
|
||||
if(MetaModel::HasStateAttributeCode($this->sClassName)) {
|
||||
$this->sStatusCode = $oObject->GetState();
|
||||
$this->sStatusLabel = $oObject->GetStateLabel();
|
||||
$this->sStatusColor = UIHelper::GetColorFromStatus($this->sClassName, $this->sStatusCode);
|
||||
}
|
||||
parent::__construct($this->sObjectName, [], static::DEFAULT_COLOR, $sId);
|
||||
|
||||
parent::__construct('', [], static::DEFAULT_COLOR, $sId);
|
||||
$this->ComputeIconUrl($oObject);
|
||||
$this->ComputeState($oObject);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,4 +156,44 @@ class ObjectDetails extends Panel
|
||||
{
|
||||
return $this->sStatusColor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function HasSubTitle(): bool
|
||||
{
|
||||
return !empty($this->sStatusCode);
|
||||
}
|
||||
|
||||
protected function ComputeIconUrl(DBObject $oObject): void
|
||||
{
|
||||
// Default icon is the class icon
|
||||
$sIconUrl = $oObject->GetIcon(false);
|
||||
// Note: Class icons are a square image with no margin around, so they need to be zoomed out in the medallion
|
||||
$sIconCoverMethod = static::ENUM_ICON_COVER_METHOD_ZOOMOUT;
|
||||
// Use object image from semantic attribute only if it's not the default image
|
||||
if (!$oObject->IsNew() && MetaModel::HasImageAttributeCode($this->sClassName)) {
|
||||
$sImageAttCode = MetaModel::GetImageAttributeCode($this->sClassName);
|
||||
if (!empty($sImageAttCode)) {
|
||||
/** @var \ormDocument $oImage */
|
||||
$oImage = $oObject->Get($sImageAttCode);
|
||||
if (!$oImage->IsEmpty()) {
|
||||
$sIconUrl = $oImage->GetDisplayURL($this->sClassName, $this->sObjectId, $sImageAttCode);
|
||||
$sIconCoverMethod = static::ENUM_ICON_COVER_METHOD_COVER;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->SetIcon($sIconUrl, $sIconCoverMethod, true);
|
||||
}
|
||||
|
||||
protected function ComputeState(DBObject $oObject): void
|
||||
{
|
||||
if (MetaModel::HasStateAttributeCode($this->sClassName)) {
|
||||
$this->sStatusCode = $oObject->GetState();
|
||||
$this->sStatusLabel = $oObject->GetStateLabel();
|
||||
$this->sStatusColor = UIHelper::GetColorFromStatus($this->sClassName, $this->sStatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user