Panel: Remove PanelEnhanced as the Panel now has all the necessary options

This commit is contained in:
Molkobain
2021-03-04 17:56:34 +01:00
parent 3bc130c802
commit 1e64e0c741
8 changed files with 59 additions and 152 deletions

View File

@@ -25,6 +25,8 @@ use Combodo\iTop\Application\UI\Base\iUIBlock;
use Combodo\iTop\Application\UI\Base\Layout\iUIContentBlock;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
use Combodo\iTop\Application\UI\Base\tUIContentAreas;
use MetaModel;
use ormStyle;
/**
* Class Panel
@@ -92,6 +94,8 @@ class Panel extends UIContentBlock
/** @var string DEFAULT_COLOR */
public const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL;
/** @var string Default color for a panel displaying info about a datamodel class */
public const DEFAULT_COLOR_FOR_CLASS = self::ENUM_COLOR_BLUE;
/** @var null */
public const DEFAULT_ICON_URL = null;
/** @var string */
@@ -244,6 +248,44 @@ class Panel extends UIContentBlock
return $this;
}
/**
* Set the panel's color from an ormStyle directly.
*
* Use cases:
* - Display information about a datamodel class
* - Display information about a particular enum value (linked objects)
*
* @param \ormStyle $oStyle
*
* @return $this
*/
public function SetColorFromOrmStyle(ormStyle $oStyle)
{
$sColor = empty($oStyle->GetMainColor()) ? static::DEFAULT_COLOR : $oStyle->GetMainColor();
$this->SetColor($sColor);
return $this;
}
/**
* Set the panel's color to the one corresponding to the $sClass datamodel class
*
* @param string $sClass
*
* @return $this
*/
public function SetColorFromClass(string $sClass)
{
$oStyle = MetaModel::GetClassStyle($sClass);
if (empty($oStyle)) {
$this->SetColor(static::DEFAULT_COLOR_FOR_CLASS);
} else {
$this->SetColorFromOrmStyle($oStyle);
}
return $this;
}
/**
* @see static::$oSubTitleBlock
* @return bool

View File

@@ -1,75 +0,0 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Base\Component\Panel;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
class PanelEnhanced extends Panel
{
public const BLOCK_CODE = 'ibo-panel-enhanced';
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/panel/panelenhanced';
/** @var UIContentBlock */
protected $oSubTitleBlock;
/** @var string */
protected $sIconUrl;
/**
* PanelEnhanced constructor.
*
* @param $sTitle
* @param $sIconUrl
*/
public function __construct(string $sTitle, string $sIconUrl)
{
parent::__construct($sTitle);
$this->oSubTitleBlock = new UIContentBlock();
$this->sIconUrl = $sIconUrl;
}
/**
* @return UIContentBlock
*/
public function GetSubTitleBlock(): UIContentBlock
{
return $this->oSubTitleBlock;
}
/**
* @param \Combodo\iTop\Application\UI\Base\Layout\UIContentBlock $oSubTitleBlock
*
* @return PanelEnhanced
*/
public function SetSubTitleBlock(UIContentBlock $oSubTitleBlock): PanelEnhanced
{
$this->oSubTitleBlock = $oSubTitleBlock;
return $this;
}
/**
* @return string
*/
public function GetIconUrl(): string
{
return $this->sIconUrl;
}
/**
* @param string $sIconUrl
*
* @return PanelEnhanced
*/
public function SetIcon(string $sIconUrl): PanelEnhanced
{
$this->sIconUrl = $sIconUrl;
return $this;
}
}

View File

@@ -171,24 +171,7 @@ class PanelUIBlockFactory extends AbstractUIBlockFactory
public static function MakeForClass(string $sClass, string $sTitle)
{
$oPanel = new Panel($sTitle);
self::SetClassColor($sClass, $oPanel);
return $oPanel;
}
/**
* Make a basis Panel component
*
* @param string $sTitle
* @param String $sIconUrl
*
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
*/
public static function MakeEnhancedNeutral(string $sTitle, string $sIconUrl)
{
$oPanel = new PanelEnhanced($sTitle, $sIconUrl);
// TODO 3.0.0: Change this to class color when done
$oPanel->SetColor(Panel::ENUM_COLOR_BLUE);
$oPanel->SetColorFromClass($sClass);
return $oPanel;
}