mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
Fix default dashlet
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with iTop. If not, see <http://www.gnu.org/licenses/>
|
||||
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 {
|
||||
|
||||
@@ -936,6 +936,13 @@ Call $this->AddInitialAttributeFlags($sAttCode, $iFlags) for all the initial att
|
||||
<preferred_height>1</preferred_height>
|
||||
<configuration/>
|
||||
</dashlet>
|
||||
<dashlet id="DashletUnknown" _delta="define">
|
||||
<label>UI:DashletUnknown:Label</label>
|
||||
<icon>images/dashlet-unknown.png</icon>
|
||||
<description>UI:DashletUnknown:Description</description>
|
||||
<can_be_created>false</can_be_created>
|
||||
<configuration/>
|
||||
</dashlet>
|
||||
</dashlets>
|
||||
<property_types _delta="define">
|
||||
<property_type id="Dashboard" xsi:type="Combodo-AbstractPropertyType"/>
|
||||
|
||||
@@ -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}'");
|
||||
}
|
||||
|
||||
@@ -14,4 +14,6 @@ git commit -a # Trivially resolved like this
|
||||
|
||||
git mv copy foo
|
||||
git commit
|
||||
```
|
||||
```
|
||||
|
||||
DO NOT SQUASH the branch NEVER !
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
*
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
|
||||
Reference in New Issue
Block a user