diff --git a/application/dashboard.class.inc.php b/application/dashboard.class.inc.php index beccb856fd..6929b4c8df 100644 --- a/application/dashboard.class.inc.php +++ b/application/dashboard.class.inc.php @@ -210,7 +210,6 @@ abstract class Dashboard $sClass = static::GetDashletClassFromType($sDashletType); /** @var \Dashlet $oNewDashlet */ $oNewDashlet = $this->oDashletFactory->CreateDashlet($sClass, $sId); - $oNewDashlet->SetDashletType($sDashletType); $oNewDashlet->FromDOMNode($oDomNode); return $oNewDashlet; @@ -1492,13 +1491,7 @@ JS // Get the list of possible dashlets that support a creation from // an OQL - $aAllDashlets = DashletService::GetInstance()->GetAvailableDashlets(); - $aDashlets = []; - foreach ($aAllDashlets as $sDashletClass => $aInfo) { - if ($aInfo['can_create_by_oql']) { - $aDashlets[$sDashletClass] = ['label' => $aInfo['label'], 'class' => $sDashletClass, 'icon' => $aInfo['icon']]; - } - } + $aDashlets = DashletService::GetInstance()->GetAvailableDashlets('can_create_by_oql'); $oSelectorField = new DesignerFormSelectorField('dashlet_class', Dict::S('UI:DashletCreation:DashletType'), ''); $oForm->AddField($oSelectorField); diff --git a/application/dashboardlayout.class.inc.php b/application/dashboardlayout.class.inc.php index 97baeb149b..fac86d1b62 100644 --- a/application/dashboardlayout.class.inc.php +++ b/application/dashboardlayout.class.inc.php @@ -16,6 +16,7 @@ // // You should have received a copy of the GNU Affero General Public License // along with iTop. If not, see +use Combodo\iTop\Application\Dashlet\Service\DashletService; use Combodo\iTop\Application\UI\Base\Component\Html\Html; use Combodo\iTop\Application\UI\Base\Layout\Dashboard\DashboardColumn; use Combodo\iTop\Application\UI\Base\Layout\Dashboard\DashboardLayout as DashboardLayoutUIBlock; @@ -138,18 +139,16 @@ abstract class DashboardLayoutMultiCol extends DashboardLayout foreach ($aDashlets as $oDashlet) { if ($oDashlet::IsVisible()) { $sDashletId = $oDashlet->GetID(); - $sDashletClass = get_class($oDashlet); + $sDashletClass = $oDashlet->GetDashletType(); $aDashletDenormalizedProperties = $oDashlet->GetDenormalizedProperties(); - // $aDashletsInfo = $sDashletClass::GetInfo(); - // - // // TODO 3.3 Gather real position and height/width if any. - // // Also set minimal height/width - // $iPositionX = null; - // $iPositionY = null; - // $iWidth = array_key_exists('preferred_width', $aDashletsInfo) ? $aDashletsInfo['preferred_width'] : 1; - // $iHeight = array_key_exists('preferred_height', $aDashletsInfo) ? $aDashletsInfo['preferred_height'] : 1; - // $oDashboardGrid->AddDashlet($oDashlet->DoRender($oPage, $bEditMode, true /* bEnclosingDiv */, $aExtraParams), $sDashletId, $sDashletClass, $aDashletDenormalizedProperties, $iPositionX, $iPositionY, $iWidth, $iHeight); - $oDashboardColumn->AddUIBlock($oDashlet->DoRender($oPage, $bEditMode, true /* bEnclosingDiv */, $aExtraParams)); + $aDashletsInfo = DashletService::GetInstance()->GetDashletDefinition($sDashletClass); + + // Also set minimal height/width + $iPositionX = $aPosDashlet['position_x'] ?? 0; + $iPositionY = $aPosDashlet['position_y'] ?? 0; + $iWidth = max($aPosDashlet['width'], array_key_exists('min_width', $aDashletsInfo) ? $aDashletsInfo['min_width'] : 1); + $iHeight = max($aPosDashlet['height'], array_key_exists('min_height', $aDashletsInfo) ? $aDashletsInfo['min_height'] : 1); + $oDashboardGrid->AddDashlet($oDashlet->DoRender($oPage, $bEditMode, true /* bEnclosingDiv */, $aExtraParams), $sDashletId, $sDashletClass, $aDashletDenormalizedProperties, $iPositionX, $iPositionY, $iWidth, $iHeight); } } } else { diff --git a/application/datamodel.application.xml b/application/datamodel.application.xml index ab70e7faaf..db04f74264 100644 --- a/application/datamodel.application.xml +++ b/application/datamodel.application.xml @@ -936,6 +936,13 @@ Call $this->AddInitialAttributeFlags($sAttCode, $iFlags) for all the initial att 1 + + + images/dashlet-unknown.png + UI:DashletUnknown:Description + false + + diff --git a/application/menunode.class.inc.php b/application/menunode.class.inc.php index b8c53a83d1..2e39d63822 100644 --- a/application/menunode.class.inc.php +++ b/application/menunode.class.inc.php @@ -1323,7 +1323,7 @@ class DashboardMenuNode extends MenuNode { $oDashboard = $this->GetDashboard(); if ($oDashboard != null) { - $oDashboard->RenderEditor($oPage); + //$oDashboard->RenderEditor($oPage); } else { $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'"); } diff --git a/git-split.md b/git-split.md index 72ad002542..6d102344a0 100644 --- a/git-split.md +++ b/git-split.md @@ -14,4 +14,6 @@ git commit -a # Trivially resolved like this git mv copy foo git commit -``` \ No newline at end of file +``` + +DO NOT SQUASH the branch NEVER ! \ No newline at end of file diff --git a/sources/Application/Dashboard/Layout/DashboardLayoutGrid.php b/sources/Application/Dashboard/Layout/DashboardLayoutGrid.php index d5d1ef9af2..51e9618c5a 100644 --- a/sources/Application/Dashboard/Layout/DashboardLayoutGrid.php +++ b/sources/Application/Dashboard/Layout/DashboardLayoutGrid.php @@ -21,8 +21,11 @@ class DashboardLayoutGrid extends \DashboardLayout $oDashboardLayout->SetGrid($oDashboardGrid); foreach ($aDashlets as $aPosDashlet) { /** @var \Dashlet $oDashlet */ + if (!array_key_exists('dashlet', $aPosDashlet)) { + continue; + } $oDashlet = $aPosDashlet['dashlet']; - if ($oDashlet::IsVisible()) { + if ($oDashlet) { $sDashletId = $oDashlet->GetID(); $sDashletClass = $oDashlet->GetDashletType(); $aDashletDenormalizedProperties = $oDashlet->GetDenormalizedProperties(); diff --git a/sources/Application/Dashlet/Dashlet.php b/sources/Application/Dashlet/Dashlet.php index ab64a8e8d0..079b453aff 100644 --- a/sources/Application/Dashlet/Dashlet.php +++ b/sources/Application/Dashlet/Dashlet.php @@ -29,8 +29,6 @@ use OQLException; use UnknownClassOqlException; use utils; -require_once(APPROOT.'application/forms.class.inc.php'); - /** * Base class for all 'dashlets' (i.e. widgets to be inserted into a dashboard) * diff --git a/sources/Application/Dashlet/DashletFactory.php b/sources/Application/Dashlet/DashletFactory.php index b5c132e767..e53ad8d4d8 100644 --- a/sources/Application/Dashlet/DashletFactory.php +++ b/sources/Application/Dashlet/DashletFactory.php @@ -37,7 +37,8 @@ class DashletFactory public function CreateDashlet(string $sClass, string $sId): Dashlet { if (!DashletService::GetInstance()->IsDashletAvailable($sClass)) { - throw new DashletException("Dashlet ".json_encode($sClass)." is not available"); + $sClass = 'DashletUnknown'; + //throw new DashletException("Dashlet ".json_encode($sClass)." is not available"); } /** @var Dashlet $oDashlet */ diff --git a/sources/Application/Dashlet/Service/DashletService.php b/sources/Application/Dashlet/Service/DashletService.php index 2c2abccfa3..851369b734 100644 --- a/sources/Application/Dashlet/Service/DashletService.php +++ b/sources/Application/Dashlet/Service/DashletService.php @@ -36,11 +36,34 @@ class DashletService * @throws \Combodo\iTop\Application\Dashlet\DashletException * @throws \DOMFormatException */ - public function GetAvailableDashlets(): array + public function GetAvailableDashlets(string $sCategory = ''): array { $this->InitDashletDefinitions(); + $aFilteredDashlets = []; - return $this->aDashlets; + switch ($sCategory) { + case 'can_be_created': + foreach ($this->aDashlets as $aDashlet) { + if ($aDashlet['can_be_created']) { + $aFilteredDashlets[] = $aDashlet; + } + } + break; + + case 'can_create_by_oql': + foreach ($this->aDashlets as $aDashlet) { + if ($aDashlet['can_create_by_oql']) { + $aFilteredDashlets[] = $aDashlet; + } + } + break; + + default: + $aFilteredDashlets = $this->aDashlets; + break; + } + + return $aFilteredDashlets; } /** @@ -131,6 +154,7 @@ class DashletService 'preferred_width' => intval($oDashletNode->GetChildText('preferred_width', '2')), 'preferred_height' => intval($oDashletNode->GetChildText('preferred_height', '1')), 'can_create_by_oql' => boolval($oDashletNode->GetChildText('can_create_by_oql', 'false')), + 'can_be_created' => boolval($oDashletNode->GetChildText('can_be_created', 'true')), ]; $this->aDashlets[$sType] = $aInfo; } diff --git a/sources/Application/UI/Base/Layout/DashletPanel/DashletPanelFactory.php b/sources/Application/UI/Base/Layout/DashletPanel/DashletPanelFactory.php index 6c30900e63..0bf22e7fcc 100644 --- a/sources/Application/UI/Base/Layout/DashletPanel/DashletPanelFactory.php +++ b/sources/Application/UI/Base/Layout/DashletPanel/DashletPanelFactory.php @@ -10,7 +10,7 @@ class DashletPanelFactory { $oDashletPanel = new DashletPanel($sId); - $aAvailableDashlets = DashletService::GetInstance()->GetAvailableDashlets(); + $aAvailableDashlets = DashletService::GetInstance()->GetAvailableDashlets('can_be_created'); foreach ($aAvailableDashlets as $sDashletClass => $aDashletInformation) { $oDashletEntry = new DashletEntry($sDashletClass, $aDashletInformation['label'], $aDashletInformation['description'], $aDashletInformation['icon']);