Fix default dashlet

This commit is contained in:
Eric Espie
2026-01-19 16:17:38 +01:00
parent 8e16d24d85
commit 805e306712
10 changed files with 55 additions and 28 deletions

View File

@@ -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)
*

View File

@@ -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 */

View File

@@ -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;
}