save dashboard controller

This commit is contained in:
Eric Espie
2026-01-14 16:57:19 +01:00
parent 0bc6f5d56a
commit 15c8f5903b
4 changed files with 41 additions and 24 deletions

View File

@@ -12,6 +12,8 @@ use Combodo\iTop\Application\UI\Base\Component\Toolbar\ToolbarUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\Dashboard\DashboardLayout as DashboardLayoutUIBlock;
use Combodo\iTop\Application\WebPage\iTopWebPage;
use Combodo\iTop\Application\WebPage\WebPage;
use Combodo\iTop\DesignDocument;
use Combodo\iTop\DesignElement;
use Combodo\iTop\PropertyType\PropertyTypeDesign;
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
@@ -206,21 +208,33 @@ abstract class Dashboard
*/
public function ToXml()
{
$oDoc = new DOMDocument();
$oDoc->formatOutput = true; // indent (must be loaded with option LIBXML_NOBLANKS)
$oDoc->preserveWhiteSpace = true; // otherwise the formatOutput option would have no effect
$oMainNode = $oDoc->createElement('dashboard');
$oMainNode->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");
$oDoc->appendChild($oMainNode);
$oMainNode = $this->CreateEmptyDashboard();
$this->ToDOMNode($oMainNode);
$sXml = $oDoc->saveXML();
$sXml = $oMainNode->ownerDocument->saveXML();
return $sXml;
}
/**
* @return DesignElement
* @throws \DOMException
*/
public function CreateEmptyDashboard(): DesignElement
{
$oDoc = new DesignDocument();
$oDoc->formatOutput = true; // indent (must be loaded with option LIBXML_NOBLANKS)
$oDoc->preserveWhiteSpace = true; // otherwise the formatOutput option would have no effect
/** @var DesignElement $oMainNode */
$oMainNode = $oDoc->createElement('dashboard');
$oMainNode->setAttribute('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance');
$oDoc->appendChild($oMainNode);
return $oMainNode;
}
/**
* @param \DOMElement $oDefinition
*/

View File

@@ -853,7 +853,7 @@ Call $this->AddInitialAttributeFlags($sAttCode, $iFlags) for all the initial att
</classes>
<property_types _delta="define">
<property_type id="Dashboard" xsi:type="Combodo-AbstractPropertyType"/>
<property_type id="Combodo-Dashboard-Grid" xsi:type="Combodo-PropertyType">
<property_type id="DashboardGrid" xsi:type="Combodo-PropertyType">
<extends>Dashboard</extends>
<definition xsi:type="Combodo-ValueType-PropertyTree">
<label>Dashboard</label>

View File

@@ -13,9 +13,14 @@ use Combodo\iTop\Application\WebPage\JsonPage;
use Combodo\iTop\Controller\AbstractController;
use Combodo\iTop\Forms\Block\FormBlockService;
use Combodo\iTop\ItopSdkFormDemonstrator\Helper\ItopSdkFormDemonstratorLog;
use Combodo\iTop\PropertyType\PropertyType;
use Combodo\iTop\PropertyType\Serializer\XMLSerializer;
use Combodo\iTop\Service\DependencyInjection\ServiceLocator;
use Dashboard;
use Exception;
use IssueLog;
use ModelReflectionRuntime;
use RuntimeDashboard;
use utils;
class DashboardController extends Controller
@@ -87,25 +92,23 @@ class DashboardController extends Controller
try {
// Get the form block from the service (and the compiler)
$oRequest = $this->getRequest();
$oFormBlock = FormBlockService::GetInstance()->GetFormBlockById('dashboard_type', 'Dashboard');
$oBuilder = $this->GetFormBuilder($oFormBlock, []);
$oFormBlock = FormBlockService::GetInstance()->GetFormBlockById('DashboardGrid', 'Dashboard');
$oBuilder = $this->GetFormBuilder($oFormBlock, $aValues);
$oForm = $oBuilder->getForm();
$oForm->handleRequest($oRequest);
if ($oForm->isSubmitted()) {
if ($oForm->isValid()) {
// Save XML
// if ($oForm->isSubmitted()) {
// if ($oForm->isValid()) {
}
// Compute blocks to redraw
$this->HandleFormSubmitted($oFormBlock, $oForm);
}
// Save XML
$oDashboard = new RuntimeDashboard($aValues['id']);
$oDomNode = $oDashboard->CreateEmptyDashboard();
XMLSerializer::GetInstance()->Serialize($aValues, $oDomNode, 'DashboardGrid', 'Dashboard');
$oDashboard->PersistDashboard($oDomNode->ownerDocument->saveXML());
// }
// }
} catch (Exception $e) {
ItopSdkFormDemonstratorLog::Exception($e->getMessage(), $e);
$this->DisplayPage([
'sControllerError' => $e->getMessage(),
], 'itop_error_update', Controller::ENUM_PAGE_TYPE_TURBO_FORM_AJAX);
IssueLog::Exception($e->getMessage(), $e);
return null;
}

View File

@@ -91,7 +91,7 @@ class PropertyTypeService
*/
private function SanitizeId(string $sId): string
{
$sFilteredId = preg_replace('/[^0-9a-zA-Z_]/', '', $sId);
$sFilteredId = preg_replace('/[^0-9a-zA-Z_\-]/', '', $sId);
if (strlen($sFilteredId) === 0 || $sFilteredId !== $sId) {
throw new FormBlockException('Malformed name for block: '.json_encode($sId));
}