mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-17 14:28:53 +02:00
Import feature
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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] = '';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user