diff --git a/js/dashboard.js b/js/dashboard.js index c604d262a..b76da68c0 100644 --- a/js/dashboard.js +++ b/js/dashboard.js @@ -387,7 +387,7 @@ $(function() text: 'Select a dashboard file to import', title: 'Dahsboard Import', close_btn: 'Close', - submit_to: GetAbsoluteUrlAppRoot()+'pages/ajax.render.php?operation=import_dashboard' + submit_to: GetAbsoluteUrlAppRoot()+'pages/UI.php?route=dashboard.import' }, // the constructor diff --git a/pages/ajax.render.php b/pages/ajax.render.php index a2149b3db..34d42b10e 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -867,37 +867,6 @@ try { $oObj->DisplayDashboard($oPage, $sAttCode); break; - case 'import_dashboard': - $oPage = new JsonPage(); - $oPage->SetOutputDataOnly(true); - - $sTransactionId = utils::ReadParam('transaction_id', '', false, 'transaction_id'); - if (!utils::IsTransactionValid($sTransactionId, true)) { - throw new SecurityException('ajax.render.php import_dashboard : invalid transaction_id'); - } - $sDashboardId = utils::ReadParam('id', '', false, 'raw_data'); - $sDashboardFileRelative = utils::ReadParam('file', '', false, 'raw_data'); - - $sDashboardFile = RuntimeDashboard::GetDashboardFileFromRelativePath($sDashboardFileRelative); - - $oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sDashboardId); - $aResult = ['error' => '']; - if (!is_null($oDashboard)) { - try { - $oDoc = utils::ReadPostedDocument('dashboard_upload_file'); - $oDashboard->FromXml($oDoc->GetData()); - $oDashboard->Save(); - } catch (DOMException $e) { - $aResult = ['error' => Dict::S('UI:Error:InvalidDashboardFile')]; - } catch (Exception $e) { - $aResult = ['error' => $e->getMessage()]; - } - } else { - $aResult['error'] = 'Dashboard id="'.$sDashboardId.'" not found.'; - } - $oPage->SetData($aResult); - break; - case 'toggle_dashboard': $oPage->SetContentType('text/html'); $sDashboardId = utils::ReadParam('dashboard_id', '', false, 'raw_data'); diff --git a/sources/Application/Dashboard/Controller/DashboardController.php b/sources/Application/Dashboard/Controller/DashboardController.php index 85c605dc2..ff089e604 100644 --- a/sources/Application/Dashboard/Controller/DashboardController.php +++ b/sources/Application/Dashboard/Controller/DashboardController.php @@ -23,6 +23,8 @@ use Combodo\iTop\PropertyType\Serializer\XMLSerializer; use Combodo\iTop\Service\DependencyInjection\ServiceLocator; use DBObjectSearch; use DBObjectSet; +use Dict; +use DOMException; use Exception; use IssueLog; use ModelReflectionRuntime; @@ -179,4 +181,38 @@ class DashboardController extends Controller return $oPage; } + + public function OperationImport() + { + $oPage = new JsonPage(); + $oPage->SetOutputDataOnly(true); + + $sTransactionId = utils::ReadParam('transaction_id', '', false, 'transaction_id'); + if (!utils::IsTransactionValid($sTransactionId, true)) { + throw new SecurityException('ajax.render.php import_dashboard : invalid transaction_id'); + } + $sDashboardId = utils::ReadParam('id', '', false, 'raw_data'); + $sDashboardFileRelative = utils::ReadParam('file', '', false, 'raw_data'); + + $sDashboardFile = RuntimeDashboard::GetDashboardFileFromRelativePath($sDashboardFileRelative); + + $oDashboard = RuntimeDashboard::GetDashboard($sDashboardFile, $sDashboardId); + $aResult = ['error' => '']; + if (!is_null($oDashboard)) { + try { + $oDoc = utils::ReadPostedDocument('dashboard_upload_file'); + $oDashboard->FromXml($oDoc->GetData()); + $oDashboard->PersistDashboard($oDoc->GetData()); + } catch (DOMException $e) { + $aResult = ['error' => Dict::S('UI:Error:InvalidDashboardFile')]; + } catch (Exception $e) { + $aResult = ['error' => $e->getMessage()]; + } + } else { + $aResult['error'] = 'Dashboard id="'.$sDashboardId.'" not found.'; + } + $oPage->SetData($aResult); + + return $oPage; + } } diff --git a/sources/Application/Dashboard/Dashboard.php b/sources/Application/Dashboard/Dashboard.php index a5766641b..a27b19b90 100644 --- a/sources/Application/Dashboard/Dashboard.php +++ b/sources/Application/Dashboard/Dashboard.php @@ -750,8 +750,8 @@ JS public function FromModelData(mixed $aDashboardValues) { $this->sLayoutClass = DashboardLayoutGrid::class; - $this->sTitle = $aDashboardValues['title']; - $iRefresh = $aDashboardValues['refresh']; + $this->sTitle = $aDashboardValues['title'] ?? ''; + $iRefresh = $aDashboardValues['refresh'] ?? 0; $this->bAutoReload = $iRefresh > 0; $this->iAutoReloadSec = $iRefresh; diff --git a/sources/PropertyType/ValueType/Branch/ValueTypePropertyTree.php b/sources/PropertyType/ValueType/Branch/ValueTypePropertyTree.php index 0b6a399c9..44e2fba4b 100644 --- a/sources/PropertyType/ValueType/Branch/ValueTypePropertyTree.php +++ b/sources/PropertyType/ValueType/Branch/ValueTypePropertyTree.php @@ -100,9 +100,11 @@ PHP; $oChildNode = $oDOMNode->GetOptionalElement($sId); if ($oChildNode) { $aResults[$sId] = $oChild->DeserializeFromDOMNode($oChildNode); - } else { + } elseif (is_a($oChild, 'Combodo-ValueType-Collection')) { // For flat arrays, no node with $sId is present $aResults[$sId] = $oChild->DeserializeFromDOMNode($oDOMNode); + } else { + $aResults[$sId] = ''; } }