N°2847 - Dashlet badge

This commit is contained in:
Eric
2020-10-29 17:08:03 +01:00
parent 6e584cded4
commit 8a1d17551b
8 changed files with 289 additions and 58 deletions

View File

@@ -19,6 +19,7 @@
use Combodo\iTop\Application\UI\Component\Badge\BadgeFactory;
use Combodo\iTop\Application\UI\Component\Button\ButtonFactory;
use Combodo\iTop\Application\UI\Component\Dashlet\DashletFactory;
use Combodo\iTop\Application\UI\Component\Html\Html;
use Combodo\iTop\Application\UI\Component\Toolbar\Toolbar;
use Combodo\iTop\Application\UI\iUIBlock;
@@ -712,65 +713,13 @@ class DisplayBlock
$sHtml .= $oObj->GetDetails($oPage); // Still used ???
}
break;
case 'actions':
$sClass = $this->m_oFilter->GetClass();
$oAppContext = new ApplicationContext();
$bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false;
if ($bContextFilter && is_null($this->m_oSet))
{
foreach($oAppContext->GetNames() as $sFilterCode)
{
$sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null);
if (!is_null($sContextParamValue) && ! empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode))
{
$this->AddCondition($sFilterCode, $sContextParamValue);
}
}
$aQueryParams = array();
if (isset($aExtraParams['query_params']))
{
$aQueryParams = $aExtraParams['query_params'];
}
$this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams);
$this->m_oSet->SetShowObsoleteData($this->m_bShowObsoleteData);
}
$iCount = $this->m_oSet->Count();
$sClassLabel = MetaModel::GetName($sClass);
$sClassIconUrl = MetaModel::GetClassIcon($sClass, false);
$sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.rawurlencode($this->m_oFilter->serialize());
$sCreateActionHtml = '';
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY))
{
$sCreateActionUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.'&'.$oAppContext->GetForLink();
$sCreateActionLabel = Dict::Format('UI:Button:Create');
$sCreateActionHtml .= <<<HTML
<a class="ibo-dashlet-badge--action-create" href="$sCreateActionUrl">
<span class="ibo-dashlet-badge--action-create-icon fas fa-plus"></span>
<span class="ibo-dashlet-badge--action-create-label">$sCreateActionLabel</span>
</a>
HTML;
}
$sHtml .= <<<HTML
<div class="ibo-dashlet-badge--body">
<div class="ibo-dashlet-badge--icon-container">
<img class="ibo-dashlet-badge--icon" src="$sClassIconUrl" />
</div>
<div class="ibo-dashlet-badge--actions">
<a class="ibo-dashlet-badge--action-list" href="$sHyperlink">
<span class="ibo-dashlet-badge--action-list-count">$iCount</span>
<span class="ibo-dashlet-badge--action-list-label">$sClassLabel</span>
</a>
$sCreateActionHtml
</div>
</div>
HTML;
break;
$oBlock = $this->RenderActions($aExtraParams);
break;
case 'summary':
$oBlock = $this->RenderSummary($aExtraParams, $sHtml);
$oBlock = $this->RenderSummary($aExtraParams);
break;
case 'csv':
@@ -1279,7 +1228,6 @@ JS
/**
* @param array $aExtraParams
* @param string $sHtml
*
* @return iUIBlock
*
@@ -1291,7 +1239,7 @@ JS
* @throws \MySQLHasGoneAwayException
* @throws \OQLException
*/
protected function RenderSummary(array $aExtraParams, string $sHtml): iUIBlock
protected function RenderSummary(array $aExtraParams): iUIBlock
{
$sClass = $this->m_oFilter->GetClass();
$oAppContext = new ApplicationContext();
@@ -1371,6 +1319,53 @@ JS
}
return $oBlock;
}
/**
* @param array $aExtraParams
*
* @return iUIBlock
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \CoreWarning
* @throws \DictExceptionMissingString
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
*/
protected function RenderActions(array $aExtraParams): iUIBlock
{
$sClass = $this->m_oFilter->GetClass();
$oAppContext = new ApplicationContext();
$bContextFilter = isset($aExtraParams['context_filter']) ? isset($aExtraParams['context_filter']) != 0 : false;
if ($bContextFilter && is_null($this->m_oSet)) {
foreach ($oAppContext->GetNames() as $sFilterCode) {
$sContextParamValue = $oAppContext->GetCurrentValue($sFilterCode, null);
if (!is_null($sContextParamValue) && !empty($sContextParamValue) && MetaModel::IsValidFilterCode($sClass, $sFilterCode)) {
$this->AddCondition($sFilterCode, $sContextParamValue);
}
}
$aQueryParams = array();
if (isset($aExtraParams['query_params'])) {
$aQueryParams = $aExtraParams['query_params'];
}
$this->m_oSet = new CMDBObjectSet($this->m_oFilter, array(), $aQueryParams);
$this->m_oSet->SetShowObsoleteData($this->m_bShowObsoleteData);
}
$iCount = $this->m_oSet->Count();
$sClassLabel = MetaModel::GetName($sClass);
$sClassIconUrl = MetaModel::GetClassIcon($sClass, false);
$sHyperlink = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=search&'.$oAppContext->GetForLink().'&filter='.rawurlencode($this->m_oFilter->serialize());
if (UserRights::IsActionAllowed($sClass, UR_ACTION_MODIFY)) {
$sCreateActionUrl = utils::GetAbsoluteUrlAppRoot().'pages/UI.php?operation=new&class='.$sClass.'&'.$oAppContext->GetForLink();
$sCreateActionLabel = Dict::Format('UI:Button:Create');
$oBlock = DashletFactory::MakeForDashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel);
} else {
$oBlock = DashletFactory::MakeForDashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel);
}
return $oBlock;
}
}

View File

@@ -157,6 +157,9 @@ return array(
'Combodo\\iTop\\Application\\UI\\Component\\Breadcrumbs\\Breadcrumbs' => $baseDir . '/sources/application/UI/Component/Breadcrumbs/Breadcrumbs.php',
'Combodo\\iTop\\Application\\UI\\Component\\Button\\Button' => $baseDir . '/sources/application/UI/Component/Button/Button.php',
'Combodo\\iTop\\Application\\UI\\Component\\Button\\ButtonFactory' => $baseDir . '/sources/application/UI/Component/Button/ButtonFactory.php',
'Combodo\\iTop\\Application\\UI\\Component\\Dashlet\\Dashlet' => $baseDir . '/sources/application/UI/Component/Dashlet/Dashlet.php',
'Combodo\\iTop\\Application\\UI\\Component\\Dashlet\\DashletBadge' => $baseDir . '/sources/application/UI/Component/Dashlet/DashletBadge.php',
'Combodo\\iTop\\Application\\UI\\Component\\Dashlet\\DashletFactory' => $baseDir . '/sources/application/UI/Component/Dashlet/DashletFactory.php',
'Combodo\\iTop\\Application\\UI\\Component\\FieldSet\\FieldSet' => $baseDir . '/sources/application/UI/Component/FieldSet/FieldSet.php',
'Combodo\\iTop\\Application\\UI\\Component\\Field\\Field' => $baseDir . '/sources/application/UI/Component/Field/Field.php',
'Combodo\\iTop\\Application\\UI\\Component\\Form\\Form' => $baseDir . '/sources/application/UI/Component/Form/Form.php',

View File

@@ -387,6 +387,9 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
'Combodo\\iTop\\Application\\UI\\Component\\Breadcrumbs\\Breadcrumbs' => __DIR__ . '/../..' . '/sources/application/UI/Component/Breadcrumbs/Breadcrumbs.php',
'Combodo\\iTop\\Application\\UI\\Component\\Button\\Button' => __DIR__ . '/../..' . '/sources/application/UI/Component/Button/Button.php',
'Combodo\\iTop\\Application\\UI\\Component\\Button\\ButtonFactory' => __DIR__ . '/../..' . '/sources/application/UI/Component/Button/ButtonFactory.php',
'Combodo\\iTop\\Application\\UI\\Component\\Dashlet\\Dashlet' => __DIR__ . '/../..' . '/sources/application/UI/Component/Dashlet/Dashlet.php',
'Combodo\\iTop\\Application\\UI\\Component\\Dashlet\\DashletBadge' => __DIR__ . '/../..' . '/sources/application/UI/Component/Dashlet/DashletBadge.php',
'Combodo\\iTop\\Application\\UI\\Component\\Dashlet\\DashletFactory' => __DIR__ . '/../..' . '/sources/application/UI/Component/Dashlet/DashletFactory.php',
'Combodo\\iTop\\Application\\UI\\Component\\FieldSet\\FieldSet' => __DIR__ . '/../..' . '/sources/application/UI/Component/FieldSet/FieldSet.php',
'Combodo\\iTop\\Application\\UI\\Component\\Field\\Field' => __DIR__ . '/../..' . '/sources/application/UI/Component/Field/Field.php',
'Combodo\\iTop\\Application\\UI\\Component\\Form\\Form' => __DIR__ . '/../..' . '/sources/application/UI/Component/Form/Form.php',

View File

@@ -0,0 +1,18 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Component\Dashlet;
use Combodo\iTop\Application\UI\UIBlock;
class Dashlet extends UIBlock
{
public const BLOCK_CODE = 'ibo-dashlet';
public const HTML_TEMPLATE_REL_PATH = 'components/dashlet/layout';
}

View File

@@ -0,0 +1,168 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Component\Dashlet;
class DashletBadge extends Dashlet
{
public const BLOCK_CODE = 'ibo-dashlet-badge';
public const HTML_TEMPLATE_REL_PATH = 'components/dashlet/dashletbadge';
/** @var string */
protected $sClassIconUrl;
/** @var string */
protected $sHyperlink;
/** @var string */
protected $iCount;
/** @var string */
protected $sClassLabel;
/** @var string */
protected $sCreateActionUrl;
/** @var string */
protected $sCreateActionLabel;
/**
* DashletBadge constructor.
*
* @param string $sClassIconUrl
* @param string $sHyperlink
* @param string $iCount
* @param string $sClassLabel
* @param string $sCreateActionUrl
* @param string $sCreateActionLabel
*/
public function __construct(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '')
{
parent::__construct();
$this->sClassIconUrl = $sClassIconUrl;
$this->sHyperlink = $sHyperlink;
$this->iCount = $iCount;
$this->sClassLabel = $sClassLabel;
$this->sCreateActionUrl = $sCreateActionUrl;
$this->sCreateActionLabel = $sCreateActionLabel;
}
/**
* @return string
*/
public function GetCreateActionUrl(): string
{
return $this->sCreateActionUrl;
}
/**
* @param string $sCreateActionUrl
*
* @return DashletBadge
*/
public function SetCreateActionUrl(string $sCreateActionUrl): DashletBadge
{
$this->sCreateActionUrl = $sCreateActionUrl;
return $this;
}
/**
* @return string
*/
public function GetCreateActionLabel(): string
{
return $this->sCreateActionLabel;
}
/**
* @param string $sCreateActionLabel
*
* @return DashletBadge
*/
public function SetCreateActionLabel(string $sCreateActionLabel): DashletBadge
{
$this->sCreateActionLabel = $sCreateActionLabel;
return $this;
}
/**
* @return string
*/
public function GetClassIconUrl(): string
{
return $this->sClassIconUrl;
}
/**
* @param string $sClassIconUrl
*
* @return DashletBadge
*/
public function SetClassIconUrl(string $sClassIconUrl): DashletBadge
{
$this->sClassIconUrl = $sClassIconUrl;
return $this;
}
/**
* @return string
*/
public function GetHyperlink(): string
{
return $this->sHyperlink;
}
/**
* @param string $sHyperlink
*
* @return DashletBadge
*/
public function SetHyperlink(string $sHyperlink): DashletBadge
{
$this->sHyperlink = $sHyperlink;
return $this;
}
/**
* @return string
*/
public function GetCount(): string
{
return $this->iCount;
}
/**
* @param string $iCount
*
* @return DashletBadge
*/
public function SetCount(string $iCount): DashletBadge
{
$this->iCount = $iCount;
return $this;
}
/**
* @return string
*/
public function GetClassLabel(): string
{
return $this->sClassLabel;
}
/**
* @param string $sClassLabel
*
* @return DashletBadge
*/
public function SetClassLabel(string $sClassLabel): DashletBadge
{
$this->sClassLabel = $sClassLabel;
return $this;
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
namespace Combodo\iTop\Application\UI\Component\Dashlet;
class DashletFactory
{
public static function MakeForDashletBadge(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '')
{
return new DashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel);
}
}

View File

@@ -0,0 +1,21 @@
{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
<div class="ibo-dashlet-badge--body">
<div class="ibo-dashlet-badge--icon-container">
<img class="ibo-dashlet-badge--icon" src="{{ oUIBlock.GetClassIconUrl() }}"/>
</div>
<div class="ibo-dashlet-badge--actions">
<a class="ibo-dashlet-badge--action-list" href="{{ oUIBlock.GetHyperlink() }}">
<span class="ibo-dashlet-badge--action-list-count">{{ oUIBlock.GetCount() }}</span>
<span class="ibo-dashlet-badge--action-list-label">{{ oUIBlock.GetClassLabel() }}</span>
</a>
{% if oUIBlock.GetCreateActionUrl() is not empty %}
<a class="ibo-dashlet-badge--action-create" href="{{ oUIBlock.GetCreateActionUrl() }}">
<span class="ibo-dashlet-badge--action-create-icon fas fa-plus"></span>
<span class="ibo-dashlet-badge--action-create-label">{{ oUIBlock.GetCreateActionLabel() }}</span>
</a>
{% endif %}
</div>
</div>
{% endapply %}

View File

@@ -0,0 +1,5 @@
{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
{# @license http://opensource.org/licenses/AGPL-3.0 #}
{% apply spaceless %}
{% endapply %}