N°1408 - Asynchronous load of dashboard tab

This commit is contained in:
Eric
2018-10-15 15:51:44 +02:00
parent db4b8b2f43
commit ebb5ede613
4 changed files with 45 additions and 19 deletions

View File

@@ -398,15 +398,13 @@ EOF
$this->aFieldsMap[$sAttCode] = $sInputId;
}
/**
* @param \iTopWebPage $oPage
* @param $bEditMode
*
* @throws \CoreException
* @throws \Exception
*/
public function DisplayDashboards($oPage, $bEditMode)
protected function DisplayDashboardTabs($oPage, $bEditMode)
{
if ($bEditMode || $this->IsNew())
{
@@ -429,24 +427,41 @@ EOF
continue;
} // Process only dashboards attributes...
$oPage->SetCurrentTab($oAttDef->GetLabel());
// Load the dashboard
$oDashboard = $oAttDef->GetDashboard();
if (is_null($oDashboard))
{
continue;
}
$bCanEdit = UserRights::IsAdministrator() || $oAttDef->IsUserEditable();
$sDivId = $oDashboard->GetId();
$oPage->add('<div class="dashboard_contents" id="'.$sDivId.'">');
$aExtraParams = array('query_params' => $this->ToArgsForQuery());
$oDashboard->Render($oPage, false, $aExtraParams, $bCanEdit);
$oPage->add('</div>');
$oPage->AddAjaxTab($oAttDef->GetLabel(), utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php?operation=dashboard&class='.get_class($this).'&id='.$this->GetKey().'&attcode='.$oAttDef->GetCode());
}
}
/**
* @param \iTopWebPage $oPage
* @param $sAttCode
*
* @throws \Exception
*/
public function DisplayDashboard($oPage, $sAttCode)
{
$sClass = get_class($this);
$oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode);
if (!$oAttDef instanceof AttributeDashboard)
{
throw new CoreException(Dict::S('UI:Error:InvalidDashboard'));
}
// Load the dashboard
$oDashboard = $oAttDef->GetDashboard();
if (is_null($oDashboard))
{
throw new CoreException(Dict::S('UI:Error:InvalidDashboard'));
}
$bCanEdit = UserRights::IsAdministrator() || $oAttDef->IsUserEditable();
$sDivId = $oDashboard->GetId();
$oPage->add('<div class="dashboard_contents" id="'.$sDivId.'">');
$aExtraParams = array('query_params' => $this->ToArgsForQuery());
$oDashboard->Render($oPage, false, $aExtraParams, $bCanEdit);
$oPage->add('</div>');
}
/**
* @param \WebPage $oPage
* @param bool $bEditMode
@@ -945,7 +960,7 @@ EOF
$oPage->SetCurrentTab(Dict::S('UI:PropertiesTab'));
$this->DisplayBareProperties($oPage, $bEditMode);
$this->DisplayBareRelations($oPage, $bEditMode);
$this->DisplayDashboards($oPage, $bEditMode);
$this->DisplayDashboardTabs($oPage, $bEditMode);
//$oPage->SetCurrentTab(Dict::S('UI:HistoryTab'));
//$this->DisplayBareHistory($oPage, $bEditMode);
$oPage->AddAjaxTab(Dict::S('UI:HistoryTab'),

View File

@@ -442,6 +442,7 @@ Dict::Add('EN US', 'English', 'English', array(
'UI:Error:ObjectAlreadyCreated' => 'Error: the object has already been created!',
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Error: invalid stimulus "%1$s" on object %2$s in state "%3$s".',
'UI:Error:InvalidDashboardFile' => 'Error: invalid dashboard file',
'UI:Error:InvalidDashboard' => 'Error: invalid dashboard',
'UI:GroupBy:Count' => 'Count',
'UI:GroupBy:Count+' => 'Number of elements',

View File

@@ -309,6 +309,7 @@ Dict::Add('FR FR', 'French', 'Français', array(
'UI:Error:ObjectAlreadyCreated' => 'Erreur: l\'objet a déjà été créé !',
'UI:Error:Invalid_Stimulus_On_Object_In_State' => 'Erreur: le stimulus "%1$s" n\'est pas valide pour l\'objet %2$s dans l\'état "%3$s".',
'UI:Error:InvalidDashboardFile' => 'Erreur: Le fichier tableau de bord est invalide',
'UI:Error:InvalidDashboard' => 'Erreur: Le tableau de bord est invalide',
'UI:GroupBy:Count' => 'Nombre',
'UI:GroupBy:Count+' => 'Nombre d\'éléments',
'UI:CountOfObjects' => '%1$d objets correspondants aux critères.',

View File

@@ -910,6 +910,15 @@ try
}
break;
case 'dashboard':
$oPage->SetContentType('text/html');
$id = (int)utils::ReadParam('id', 0);
$sAttCode = utils::ReadParam('attcode', '');
/** @var \cmdbAbstractObject $oObj */
$oObj = MetaModel::GetObject($sClass, $id);
$oObj->DisplayDashboard($oPage, $sAttCode);
break;
case 'export_dashboard':
$sDashboardId = utils::ReadParam('id', '', false, 'raw_data');
$sDashboardFile = utils::ReadParam('file', '', false, 'raw_data');