diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php
index 5620933fd..ba8407716 100644
--- a/application/displayblock.class.inc.php
+++ b/application/displayblock.class.inc.php
@@ -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 .= <<
-
- $sCreateActionLabel
-
-HTML;
- }
-
- $sHtml .= <<
-
-

-
-
-
-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;
}
}
diff --git a/lib/composer/autoload_classmap.php b/lib/composer/autoload_classmap.php
index d9d863682..dfc923bbd 100644
--- a/lib/composer/autoload_classmap.php
+++ b/lib/composer/autoload_classmap.php
@@ -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',
diff --git a/lib/composer/autoload_static.php b/lib/composer/autoload_static.php
index d284dd0f3..8fa5f0f59 100644
--- a/lib/composer/autoload_static.php
+++ b/lib/composer/autoload_static.php
@@ -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',
diff --git a/sources/application/UI/Component/Dashlet/Dashlet.php b/sources/application/UI/Component/Dashlet/Dashlet.php
new file mode 100644
index 000000000..21da4ce0f
--- /dev/null
+++ b/sources/application/UI/Component/Dashlet/Dashlet.php
@@ -0,0 +1,18 @@
+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;
+ }
+
+
+}
\ No newline at end of file
diff --git a/sources/application/UI/Component/Dashlet/DashletFactory.php b/sources/application/UI/Component/Dashlet/DashletFactory.php
new file mode 100644
index 000000000..6b9b7b20c
--- /dev/null
+++ b/sources/application/UI/Component/Dashlet/DashletFactory.php
@@ -0,0 +1,18 @@
+
+
+
 }})
+
+
+
+{% endapply %}
\ No newline at end of file
diff --git a/templates/components/dashlet/layout.html.twig b/templates/components/dashlet/layout.html.twig
new file mode 100644
index 000000000..69b8087c9
--- /dev/null
+++ b/templates/components/dashlet/layout.html.twig
@@ -0,0 +1,5 @@
+{# @copyright Copyright (C) 2010-2020 Combodo SARL #}
+{# @license http://opensource.org/licenses/AGPL-3.0 #}
+{% apply spaceless %}
+
+{% endapply %}
\ No newline at end of file