From 3fa658edb54556b07195ebe8a0211d78d09f34ed Mon Sep 17 00:00:00 2001 From: Eric Espie Date: Tue, 27 Jan 2026 17:52:36 +0100 Subject: [PATCH] Cleanup Dashboard and dashlet unused methods and ajax end points --- application/menunode.class.inc.php | 31 -- pages/ajax.render.php | 195 ----------- sources/Application/Dashboard/Dashboard.php | 327 +----------------- .../Dashboard/RuntimeDashboard.php | 162 +-------- .../Application/Dashlet/Base/DashletBadge.php | 63 ---- .../Dashlet/Base/DashletGroupBy.php | 322 ----------------- .../Dashlet/Base/DashletGroupByBars.php | 76 ---- .../Dashlet/Base/DashletGroupByPie.php | 50 --- .../Dashlet/Base/DashletGroupByTable.php | 44 --- .../Dashlet/Base/DashletHeaderDynamic.php | 174 ---------- .../Dashlet/Base/DashletHeaderStatic.php | 40 --- .../Dashlet/Base/DashletObjectList.php | 74 ---- .../Dashlet/Base/DashletPlainText.php | 10 - 13 files changed, 10 insertions(+), 1558 deletions(-) diff --git a/application/menunode.class.inc.php b/application/menunode.class.inc.php index 0b1087a4d..7f9fee610 100644 --- a/application/menunode.class.inc.php +++ b/application/menunode.class.inc.php @@ -1312,37 +1312,6 @@ class DashboardMenuNode extends MenuNode $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'"); } } - - /** - * @param WebPage $oPage - * @throws CoreException - * @throws Exception - */ - public function RenderEditor(WebPage $oPage) - { - $oDashboard = $this->GetDashboard(); - if ($oDashboard != null) { - //$oDashboard->RenderEditor($oPage); - } else { - $oPage->p("Error: failed to load dashboard file: '{$this->sDashboardFile}'"); - } - } - - /** - * @param $oDashlet - * @throws Exception - */ - public function AddDashlet($oDashlet) - { - $oDashboard = $this->GetDashboard(); - if ($oDashboard != null) { - $oDashboard->AddDashlet($oDashlet); - $oDashboard->Save(); - } else { - throw new Exception("Error: failed to load dashboard file: '{$this->sDashboardFile}'"); - } - } - } /** diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 34d42b10e..cab5d5b8b 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -904,50 +904,6 @@ try { } break; - case 'save_dashboard': - $sDashboardId = utils::ReadParam('dashboard_id', '', false, 'context_param'); - - $aExtraParams = utils::ReadParam('extra_params', [], false, 'raw_data'); - $sReloadURL = utils::ReadParam('reload_url', '', false, utils::ENUM_SANITIZATION_FILTER_URL); - appUserPreferences::SetPref('display_original_dashboard_'.$sDashboardId, false); - $sJSExtraParams = json_encode($aExtraParams); - $aParams = []; - $aParams['layout_class'] = utils::ReadParam('layout_class', ''); - $aParams['title'] = utils::ReadParam('title', '', false, 'raw_data'); - $aParams['auto_reload'] = utils::ReadParam('auto_reload', false); - $aParams['auto_reload_sec'] = utils::ReadParam('auto_reload_sec', 300); - $aParams['cells'] = utils::ReadParam('cells', [], false, 'raw_data'); - - $oDashboard = new RuntimeDashboard($sDashboardId); - $oDashboard->FromParams($aParams); - $bIsNew = $oDashboard->Save(); - - $sDashboardFile = addslashes(utils::ReadParam('file', '', false, 'string')); - $sDashboardDivId = preg_replace('/[^a-zA-Z0-9_]/', '', $sDashboardId); - $sOperation = 'reload_dashboard'; - if ($bIsNew) { - // Trigger a reload of the current page since the dashboard just changed - $oPage->add_script( - <<add_script( - <<FromParams($aParams); - $oDashboard->SetReloadURL($sReloadURL); - $oDashboard->Render($oPage, true /* bEditMode */, $aExtraParams); - break; - - case 'dashboard_editor': - $sId = utils::ReadParam('id', '', false, 'context_param'); - $aExtraParams = utils::ReadParam('extra_params', [], false, 'raw_data'); - $aExtraParams['dashboard_div_id'] = utils::Sanitize($sId, '', 'element_identifier'); - $sDashboardFile = utils::ReadParam('file', '', false, 'string'); - $sReloadURL = utils::ReadParam('reload_url', '', false, utils::ENUM_SANITIZATION_FILTER_URL); - $oDashboard = RuntimeDashboard::GetDashboardToEdit($sDashboardFile, $sId); - if (!is_null($oDashboard)) { - if (!empty($sReloadURL)) { - $oDashboard->SetReloadURL($sReloadURL); - } - $oDashboard->RenderEditor($oPage, $aExtraParams); - } - break; - - case 'new_dashlet_id': - $sDashboardDivId = utils::ReadParam("dashboardid"); - $bIsCustomized = true; // Only called at runtime when customizing a dashboard - $iRow = utils::ReadParam("iRow", 0, false, utils::ENUM_SANITIZATION_FILTER_INTEGER); - $iCol = utils::ReadParam("iCol", 0, false, utils::ENUM_SANITIZATION_FILTER_INTEGER); - $sDashletIdOrig = utils::ReadParam("dashletid", '', false, utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER); - $sFinalDashletId = Dashboard::GetDashletUniqueId($bIsCustomized, $sDashboardDivId, $iRow, $iCol, $sDashletIdOrig); - $oPage = new AjaxPage(''); - $oPage->SetOutputDataOnly(true); - $oPage->add($sFinalDashletId); - break; - - case 'new_dashlet': - require_once(APPROOT.'application/forms.class.inc.php'); - require_once(APPROOT.'application/dashlet.class.inc.php'); - $sDashletClass = utils::ReadParam('dashlet_class', '', false, utils::ENUM_SANITIZATION_FILTER_PHP_CLASS); - $sDashletId = utils::ReadParam('dashlet_id', '', false, utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER); - if (is_subclass_of($sDashletClass, 'Dashlet')) { - $oDashlet = new $sDashletClass(new ModelReflectionRuntime(), $sDashletId); - $offset = $oPage->start_capture(); - $oDashlet->DoRender($oPage, true /* bEditMode */, false /* bEnclosingDiv */); - $sHtml = addslashes($oPage->end_capture($offset)); - $sHtml = str_replace("\n", '', $sHtml); - $sHtml = str_replace("\r", '', $sHtml); - $oPage->add_script("$('#dashlet_$sDashletId').html('$sHtml');"); // in ajax web page add_script has the same effect as add_ready_script - // but is executed BEFORE all 'ready_scripts' - $oForm = $oDashlet->GetForm(); // Rebuild the form since the values/content changed - $oForm->SetSubmitParams(utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php', ['operation' => 'update_dashlet_property']); - $sHtml = addslashes($oForm->RenderAsPropertySheet($oPage, true /* bReturnHtml */, '.itop-dashboard')); - $sHtml = str_replace("\n", '', $sHtml); - $sHtml = str_replace("\r", '', $sHtml); - $oPage->add_script("$('#dashlet_properties_$sDashletId').html('$sHtml')"); // in ajax web page add_script has the same effect as add_ready_script // but is executed BEFORE all 'ready_scripts' - } - break; - - case 'update_dashlet_property': - require_once(APPROOT.'application/forms.class.inc.php'); - require_once(APPROOT.'application/dashlet.class.inc.php'); - $aExtraParams = utils::ReadParam('extra_params', [], false, utils::ENUM_SANITIZATION_FILTER_RAW_DATA); - $aParams = utils::ReadParam('params', [], false, utils::ENUM_SANITIZATION_FILTER_RAW_DATA); // raw_data because we need different filter depending on the options - $sDashletClass = utils::Sanitize($aParams['attr_dashlet_class'], DashletUnknown::class, utils::ENUM_SANITIZATION_FILTER_PHP_CLASS); // Dashlet PHP class or DashletUnknown if impl isn't present in the installed extensions - $sDashletType = utils::Sanitize($aParams['attr_dashlet_type'], '', utils::ENUM_SANITIZATION_FILTER_PHP_CLASS); // original Dashlet PHP class, could be non-existing on the iTop instance (XML definition loading) - $sDashletId = utils::Sanitize($aParams['attr_dashlet_id'], '', utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER); - $aUpdatedProperties = utils::Sanitize($aParams['updated'], [], utils::ENUM_SANITIZATION_FILTER_ELEMENT_IDENTIFIER); // Code of the changed properties as an array: 'attr_xxx', 'attr_xxy' etc - $aPreviousValues = utils::Sanitize($aParams['previous_values'], [], utils::ENUM_SANITIZATION_FILTER_RAW_DATA); // hash array: 'attr_xxx' => 'old_value' - no sanitization as values will be handled in the Dashlet object - - if (is_subclass_of($sDashletClass, 'Dashlet')) { - /** @var \Dashlet $oDashlet */ - $oDashlet = new $sDashletClass(new ModelReflectionRuntime(), $sDashletId); - $oDashlet->SetDashletType($sDashletType); - $oForm = $oDashlet->GetForm(); - $aValues = $oForm->ReadParams(); // hash array: 'xxx' => 'new_value' - - $aCurrentValues = $aValues; - $aUpdatedDecoded = []; - foreach ($aUpdatedProperties as $sProp) { - $sDecodedProp = str_replace('attr_', '', $sProp); // Remove the attr_ prefix - // Set the previous value - if (isset($aPreviousValues[$sProp]) && $aPreviousValues[$sProp] != '') { - $aCurrentValues[$sDecodedProp] = $aPreviousValues[$sProp]; - } else { - if (gettype($aCurrentValues[$sDecodedProp]) == "array") { - $aCurrentValues[$sDecodedProp] = []; - } else { - $aCurrentValues[$sDecodedProp] = ''; - } - } - $aUpdatedDecoded[] = $sDecodedProp; - } - - $oDashlet->FromParams($aCurrentValues); - $sPrevClass = get_class($oDashlet); - $oDashlet = $oDashlet->Update($aValues, $aUpdatedDecoded); - $sNewClass = get_class($oDashlet); - if ($sNewClass != $sPrevClass) { - $oPage->add_ready_script("$('#dashlet_$sDashletId').dashlet('option', {dashlet_class: '$sNewClass'});"); - } - if ($oDashlet->IsRedrawNeeded()) { - $oBlock = $oDashlet->DoRender($oPage, true, false, $aExtraParams); - $sHtml = ConsoleBlockRenderer::RenderBlockTemplateInPage($oPage, $oBlock); - $sHtml = json_encode($sHtml); - $oPage->add_script("$('#dashlet_$sDashletId').html({$sHtml});"); - } - if ($oDashlet->IsFormRedrawNeeded()) { - $oForm = $oDashlet->GetForm(); // Rebuild the form since the values/content changed - $oForm->SetSubmitParams(utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php', ['operation' => 'update_dashlet_property', 'extra_params' => $aExtraParams]); - $sHtml = $oForm->RenderAsPropertySheet($oPage, true, '.itop-dashboard'); - $sHtml = json_encode($sHtml); - $oPage->add_script("$('#dashlet_properties_$sDashletId').html({$sHtml});"); - } - } - break; - - case 'dashlet_creation_dlg': - $sOQL = utils::ReadParam('oql', '', false, 'raw_data'); - RuntimeDashboard::GetDashletCreationDlgFromOQL($oPage, $sOQL); - break; - - case 'add_dashlet': - $oForm = RuntimeDashboard::GetDashletCreationForm(); - $aValues = $oForm->ReadParams(); - - $sDashletClass = $aValues['dashlet_class']; - $sMenuId = $aValues['menu_id']; - - if (is_subclass_of($sDashletClass, 'Dashlet')) { - $oDashlet = new $sDashletClass(new ModelReflectionRuntime(), 0); - $oDashlet->FromParams($aValues); - - ApplicationMenu::LoadAdditionalMenus(); - $index = ApplicationMenu::GetMenuIndexById($sMenuId); - $oMenu = ApplicationMenu::GetMenuNode($index); - $oMenu->AddDashlet($oDashlet); - // navigate to the dashboard page - if ($aValues['open_editor']) { - $oPage->add_ready_script("window.location.href='".addslashes(utils::GetAbsoluteUrlAppRoot().'pages/UI.php?c[menu]='.urlencode($sMenuId))."&edit=1';"); // reloads the page, doing a GET even if we arrived via a POST - } - } - break; - case 'shortcut_list_dlg': $sOQL = utils::ReadParam('oql', '', false, 'raw_data'); $sTableSettings = utils::ReadParam('table_settings', '', false, 'raw_data'); diff --git a/sources/Application/Dashboard/Dashboard.php b/sources/Application/Dashboard/Dashboard.php index 7342068c1..23c987c09 100644 --- a/sources/Application/Dashboard/Dashboard.php +++ b/sources/Application/Dashboard/Dashboard.php @@ -19,16 +19,10 @@ use Combodo\iTop\DesignElement; use Combodo\iTop\PropertyType\PropertyTypeDesign; use Combodo\iTop\PropertyType\Serializer\XMLSerializer; use DashboardLayout; -use DesignerBooleanField; -use DesignerForm; -use DesignerHiddenField; -use DesignerIntegerField; -use DesignerTextField; use Dict; use DOMException; use InvalidParameterException; use MetaModel; -use ReflectionClass; use utils; /** @@ -154,7 +148,7 @@ abstract class Dashboard $oNewDashlet = $this->InitDashletFromDOMNode($oDomNode); $aDashletOrder[] = ['rank' => $iRank, 'dashlet' => $oNewDashlet]; } - usort($aDashletOrder, [get_class($this), 'SortOnRank']); + usort($aDashletOrder, [$this, 'SortOnRank']); $aDashletList = []; foreach ($aDashletOrder as $aItem) { $aDashletList[] = $aItem['dashlet']; @@ -162,7 +156,7 @@ abstract class Dashboard $aCellOrder[] = ['rank' => $iCellRank, 'dashlets' => $aDashletList]; } } - usort($aCellOrder, [get_class($this), 'SortOnRank']); + usort($aCellOrder, [$this, 'SortOnRank']); foreach ($aCellOrder as $aItem) { $this->aCells[] = $aItem['dashlets']; } @@ -206,7 +200,7 @@ abstract class Dashboard * * @return int */ - public static function SortOnRank($aItem1, $aItem2) + public function SortOnRank($aItem1, $aItem2) { return ($aItem1['rank'] > $aItem2['rank']) ? +1 : -1; } @@ -231,21 +225,6 @@ abstract class Dashboard } } - /** - * @return string - * @throws \Exception - */ - public function ToXml() - { - $oMainNode = $this->CreateEmptyDashboard(); - - $this->ToDOMNode($oMainNode); - - $sXml = $oMainNode->ownerDocument->saveXML(); - - return $sXml; - } - /** * @return DesignElement * @throws \DOMException @@ -264,95 +243,6 @@ abstract class Dashboard return $oMainNode; } - /** - * @param \DOMElement $oDefinition - */ - public function ToDOMNode($oDefinition) - { - /** @var \DOMDocument $oDoc */ - $oDoc = $oDefinition->ownerDocument; - - $oNode = $oDoc->createElement('layout', $this->sLayoutClass); - $oDefinition->appendChild($oNode); - - $oNode = $oDoc->createElement('title', $this->sTitle); - $oDefinition->appendChild($oNode); - - $oAutoReloadNode = $oDoc->createElement('auto_reload'); - $oDefinition->appendChild($oAutoReloadNode); - $oNode = $oDoc->createElement('enabled', $this->bAutoReload ? 'true' : 'false'); - $oAutoReloadNode->appendChild($oNode); - $oNode = $oDoc->createElement('interval', $this->iAutoReloadSec); - $oAutoReloadNode->appendChild($oNode); - - $oCellsNode = $oDoc->createElement('cells'); - $oDefinition->appendChild($oCellsNode); - - $iCellRank = 0; - foreach ($this->aCells as $aCell) { - $oCellNode = $oDoc->createElement('cell'); - $oCellNode->setAttribute('id', $iCellRank); - $oCellsNode->appendChild($oCellNode); - $oCellRank = $oDoc->createElement('rank', $iCellRank); - $oCellNode->appendChild($oCellRank); - $iCellRank++; - - $iDashletRank = 0; - $oDashletsNode = $oDoc->createElement('dashlets'); - $oCellNode->appendChild($oDashletsNode); - /** @var \Dashlet $oDashlet */ - foreach ($aCell as $oDashlet) { - $oNode = $oDoc->createElement('dashlet'); - $oDashletsNode->appendChild($oNode); - $oNode->setAttribute('id', $oDashlet->GetID()); - $oNode->setAttribute('xsi:type', $oDashlet->GetDashletType()); - $oDashletRank = $oDoc->createElement('rank', $iDashletRank); - $oNode->appendChild($oDashletRank); - $iDashletRank++; - $oDashlet->ToDOMNode($oNode); - } - } - } - - /** - * @param array $aParams - */ - public function FromParams($aParams) - { - $this->sLayoutClass = $aParams['layout_class']; - if (!is_subclass_of($this->sLayoutClass, DashboardLayout::class)) { - throw new InvalidParameterException('Invalid parameter layout_class "'.$aParams['layout_class'].'"'); - } - $this->sTitle = $aParams['title']; - $this->bAutoReload = $aParams['auto_reload'] == 'true'; - $this->iAutoReloadSec = max(MetaModel::GetConfig()->Get('min_reload_interval'), (int)$aParams['auto_reload_sec']); - - foreach ($aParams['cells'] as $aCell) { - $aCellDashlets = []; - foreach ($aCell as $aDashletParams) { - $sDashletClass = $aDashletParams['dashlet_class']; - $sId = $aDashletParams['dashlet_id']; - /** @var \Dashlet $oNewDashlet */ - $oNewDashlet = $this->oDashletFactory->CreateDashlet($sDashletClass, $sId); - if (isset($aDashletParams['dashlet_type'])) { - $oNewDashlet->SetDashletType($aDashletParams['dashlet_type']); - } - $oForm = $oNewDashlet->GetForm(); - $oForm->SetParamsContainer($sId); - $oForm->SetPrefix(''); - $aValues = $oForm->ReadParams(); - $oNewDashlet->FromParams($aValues); - $aCellDashlets[] = $oNewDashlet; - } - $this->aCells[] = $aCellDashlets; - } - - } - - public function Save() - { - } - public function PersistDashboard(string $sXml): bool { return true; @@ -441,106 +331,6 @@ abstract class Dashboard $this->iAutoReloadSec = max(MetaModel::GetConfig()->Get('min_reload_interval'), (int)$iAutoReloadSec); } - /** - * @param \Dashlet $oDashlet - */ - public function AddDashlet($oDashlet) - { - $sId = $this->GetNewDashletId(); - $oDashlet->SetId($sId); - $this->aCells[] = [$oDashlet]; - } - - /** - * @param WebPage $oPage * - * @param array $aExtraParams - * - * @throws \ReflectionException - * @throws \Exception - */ - public function RenderProperties($oPage, $aExtraParams = []) - { - // menu to pick a layout and edit other properties of the dashboard - $oPage->add('
'.Dict::S('UI:DashboardEdit:Properties').'
'); - $sUrl = utils::GetAbsoluteUrlAppRoot(); - - $oPage->add('
'.Dict::S('UI:DashboardEdit:Layout').'
'); - $oPage->add('
'); - foreach (get_declared_classes() as $sLayoutClass) { - if (is_subclass_of($sLayoutClass, 'DashboardLayout')) { - $oReflection = new ReflectionClass($sLayoutClass); - if (!$oReflection->isAbstract()) { - $aCallSpec = [$sLayoutClass, 'GetInfo']; - $aInfo = call_user_func($aCallSpec); - $sChecked = ($this->sLayoutClass == $sLayoutClass) ? 'checked' : ''; - $oPage->add(''); // title="" on either the img or the label does nothing ! - } - } - } - $oPage->add('
'); - - $oForm = new DesignerForm(); - - $oField = new DesignerHiddenField('dashboard_id', '', $this->sId); - $oForm->AddField($oField); - - $oField = new DesignerTextField('dashboard_title', Dict::S('UI:DashboardEdit:DashboardTitle'), $this->sTitle); - $oForm->AddField($oField); - - $oField = new DesignerBooleanField('auto_reload', Dict::S('UI:DashboardEdit:AutoReload'), $this->bAutoReload); - $oForm->AddField($oField); - - $oField = new DesignerIntegerField('auto_reload_sec', Dict::S('UI:DashboardEdit:AutoReloadSec'), $this->iAutoReloadSec); - $oField->SetBoundaries(MetaModel::GetConfig()->Get('min_reload_interval'), null); // no upper limit - $oForm->AddField($oField); - - $this->SetFormParams($oForm, $aExtraParams); - $oForm->RenderAsPropertySheet($oPage, false, '.itop-dashboard'); - - $oPage->add('
'); - - $sRateTitle = addslashes(Dict::Format('UI:DashboardEdit:AutoReloadSec+', MetaModel::GetConfig()->Get('min_reload_interval'))); - $oPage->add_ready_script( - <<Render($oPage, $aDashlets, $bEditMode, $aExtraParams); $oPage->AddUiBlock($oDashboard); - $bFromDasboardPage = isset($aExtraParams['from_dashboard_page']) ? isset($aExtraParams['from_dashboard_page']) : false; + $bFromDashboardPage = isset($aExtraParams['from_dashboard_page']) ? isset($aExtraParams['from_dashboard_page']) : false; - if ($bFromDasboardPage) { + if ($bFromDashboardPage) { $sTitleForHTML = utils::HtmlEntities(Dict::S($this->sTitle)); $sHtml = "
{$sTitleForHTML}
"; if ($oPage instanceof iTopWebPage) { @@ -602,89 +393,6 @@ JS return $oDashboard; } - /** - * @param WebPage $oPage - * - * @throws \ReflectionException - * @throws \Exception - */ - public function RenderDashletsSelection(WebPage $oPage) - { - // Toolbox/palette to drag and drop dashlets - $oPage->add('
'.Dict::S('UI:DashboardEdit:Dashlets').'
'); - $sUrl = utils::GetAbsoluteUrlAppRoot(); - - $oPage->add('
'); - $aAvailableDashlets = $this->GetAvailableDashlets(); - foreach ($aAvailableDashlets as $sDashletClass => $aInfo) { - $oPage->add(''); - } - $oPage->add('
'); - - $oPage->add('
'); - $oPage->add_ready_script("$('.dashlet_icon').draggable({cursor: 'move', helper: 'clone', appendTo: 'body', zIndex: 10000, revert:'invalid'});"); - } - - /** - * @param WebPage $oPage - * @param array $aExtraParams - */ - public function RenderDashletsProperties(WebPage $oPage, $aExtraParams = []) - { - // Toolbox/palette to edit the properties of each dashlet - $oPage->add('
'.Dict::S('UI:DashboardEdit:DashletProperties').'
'); - - /** @var \DashboardLayoutMultiCol $oLayout */ - $oLayout = new $this->sLayoutClass(); - - $oPage->add('
'); - foreach ($this->aCells as $iCellIdx => $aCell) { - /** @var \Dashlet $oDashlet */ - foreach ($aCell as $oDashlet) { - if ($oDashlet->IsVisible()) { - $oPage->add(''); - } - } - } - $oPage->add('
'); - - $oPage->add('
'); - } - - /** - * Return an array of dashlets available for selection. - * - * @return array - * @throws \Combodo\iTop\Application\Dashlet\DashletException - * @throws \DOMFormatException - */ - protected function GetAvailableDashlets(): array - { - /** @var DashletService $oDashletService */ - $oDashletService = MetaModel::GetService('DashletService'); - return $oDashletService->GetAvailableDashlets(); - } - - /** - * @return int|mixed - */ - protected function GetNewDashletId() - { - $iNewId = 0; - foreach ($this->aCells as $aDashlets) { - /** @var \Dashlet $oDashlet */ - foreach ($aDashlets as $oDashlet) { - $iNewId = max($iNewId, (int)$oDashlet->GetID()); - } - } - - return $iNewId + 1; - } - /** * Prepare dashlet for rendering (eg. change its ID or another processing). * Meant to be overloaded. @@ -771,27 +479,4 @@ JS $this->aGridDashlets[] = $aGridDashlet; } } - - public function ToModelData(): mixed - { - $this->sLayoutClass = DashboardLayoutGrid::class; - $this->sTitle = $aDashboardValues['title']; - $iRefresh = $aDashboardValues['refresh']; - $this->bAutoReload = $iRefresh > 0; - $this->iAutoReloadSec = $iRefresh; - - foreach ($aDashboardValues['pos_dashlets'] as $sId => $aPosDashlet) { - $aGridDashlet = []; - $aGridDashlet['position_x'] = $aPosDashlet['position_x'] ?? 0; - $aGridDashlet['position_y'] = $aPosDashlet['position_y'] ?? 0; - $aGridDashlet['width'] = $aPosDashlet['width'] ?? 2; - $aGridDashlet['height'] = $aPosDashlet['height'] ?? 1; - $aDashlet = $aPosDashlet['dashlet']; - $sType = $aDashlet['type']; - $oDashlet = DashletFactory::GetInstance()->CreateDashlet($sType, $sId); - $oDashlet->FromModelData($aDashlet['properties']); - $aGridDashlet['dashlet'] = $oDashlet; - $this->aGridDashlets[] = $aGridDashlet; - } - } } diff --git a/sources/Application/Dashboard/RuntimeDashboard.php b/sources/Application/Dashboard/RuntimeDashboard.php index d14aea1e6..1279ad9ce 100644 --- a/sources/Application/Dashboard/RuntimeDashboard.php +++ b/sources/Application/Dashboard/RuntimeDashboard.php @@ -66,18 +66,6 @@ class RuntimeDashboard extends Dashboard $oForm->SetSubmitParams(utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php', ['operation' => 'update_dashlet_property', 'extra_params' => $aExtraParams]); } - /** - * @inheritDoc - * @return bool $bIsNew - * @throws \Exception - */ - public function Save() - { - $sXml = $this->ToXml(); - - return $this->PersistDashboard($sXml); - } - /** * @param string $sXml * @@ -530,152 +518,6 @@ EOF ); } - /** - * @param WebPage $oPage - * - * @param array $aExtraParams - * - * @throws \ArchivedObjectException - * @throws \CoreException - * @throws \ReflectionException - * @throws \Exception - */ - public function RenderEditor($oPage, $aExtraParams = []) - { - if (isset($aExtraParams['this->class'])) { - $oObj = MetaModel::GetObject($aExtraParams['this->class'], $aExtraParams['this->id']); - $aRenderParams = ['query_params' => $oObj->ToArgsForQuery()]; - } else { - $aRenderParams = $aExtraParams; - } - $aRenderParams['dashboard_div_id'] = $aExtraParams['dashboard_div_id']; - $sJSExtraParams = json_encode($aExtraParams); - $oPage->add('
'); - $oPage->add('
'); - $this->SetCustomFlag(true); - $this->Render($oPage, true, $aRenderParams); - $oPage->add('
'); - $oPage->add('
'); - $this->RenderProperties($oPage, $aExtraParams); - $this->RenderDashletsSelection($oPage); - $this->RenderDashletsProperties($oPage, $aExtraParams); - $oPage->add('
'); - $oPage->add('
'); // For exchanging messages between the panes, same as in the designer - $oPage->add('
'); - - $sDialogTitle = Dict::S('UI:DashboardEdit:Title'); - $sOkButtonLabel = Dict::S('UI:Button:Save'); - $sCancelButtonLabel = Dict::S('UI:Button:Cancel'); - - $sId = json_encode($this->sId); - $sLayoutClass = json_encode($this->sLayoutClass); - $sAutoReload = $this->bAutoReload ? 'true' : 'false'; - $sAutoReloadSec = (string)$this->iAutoReloadSec; - $sTitle = json_encode($this->sTitle); - $sFile = json_encode($this->GetDefinitionFile()); - $sUrl = utils::GetAbsoluteUrlAppRoot().'pages/ajax.render.php'; - $sReloadURL = json_encode($this->GetReloadURL()); - - $sExitConfirmationMessage = addslashes(Dict::S('UI:NavigateAwayConfirmationMessage')); - $sCancelConfirmationMessage = addslashes(Dict::S('UI:CancelConfirmationMessage')); - $sAutoApplyConfirmationMessage = addslashes(Dict::S('UI:AutoApplyConfirmationMessage')); - - $oPage->add_ready_script( - << .itop-dashboard').width($('#dashboard_editor').width() - dashboard_prop_size); - -// We check when we finish click on the pane with the resize slider -// if the pane size changed (% 5px), if it's the case we save the value in userpref -$('#dashboard_editor > .itop-dashboard').on('mouseup',function (){ - var iWidthDiff = $(this).width() - ($('#dashboard_editor').width() - dashboard_prop_size); - if( Math.abs(iWidthDiff) > 5){ - dashboard_prop_size = iWidthDiff; - SetUserPreference('dashboard_prop_size', $('#dashboard_editor').width() - $(this).width(), true); - } -}); - -window.onbeforeunload = function() { - if (!window.bLeavingOnUserAction) - { - var oDashboard = $('.itop-dashboard').data('itopRuntimedashboard'); - if (oDashboard) - { - if (oDashboard.is_dirty()) - { - return '$sExitConfirmationMessage'; - } - if (oDashboard.is_modified()) - { - return '$sExitConfirmationMessage'; - } - } - } - // return nothing ! safer for IE -}; -JS - ); - $oPage->add_ready_script(""); - } - /** * @param string|null $sOQL * @@ -902,6 +744,10 @@ JS * * @param array $aExtraParams * + * @throws \CoreException + * @throws \CoreUnexpectedValue + * @throws \MySQLException + * @throws \OQLException * @since 2.7.0 N°2735 */ private function UpdateDashletUserPrefs(Dashlet $oDashlet, $sDashletIdOrig, array $aExtraParams) diff --git a/sources/Application/Dashlet/Base/DashletBadge.php b/sources/Application/Dashlet/Base/DashletBadge.php index ed4b5554a..f44bccc3c 100644 --- a/sources/Application/Dashlet/Base/DashletBadge.php +++ b/sources/Application/Dashlet/Base/DashletBadge.php @@ -60,67 +60,4 @@ class DashletBadge extends Dashlet return $oDashletContainer; } - - /** - * @inheritdoc - */ - public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = []) - { - $oDashletContainer = new DashletContainer($this->sId, ['dashlet-content']); - - $sClass = $this->aProperties['class']; - $sIconUrl = utils::HtmlEntities($this->oModelReflection->GetClassIcon($sClass, false)); - $sClassLabel = $this->oModelReflection->GetName($sClass); - $sId = $this->sId; - $sClassCreate = Dict::Format('UI:ClickToCreateNew', $sClassLabel); - - $sHtml = << - -
-HTML; - - $oDashletContainer->AddHtml($sHtml); - - return $oDashletContainer; - } - - protected static $aClassList = null; - - /** - * @inheritdoc - * - * @throws \Exception - */ - public function GetPropertiesFields(DesignerForm $oForm) - { - if (is_null(self::$aClassList)) { - // Cache the ordered list of classes (ordered on the label) - // (has a significant impact when editing a page with lots of badges) - // - $aClasses = []; - foreach ($this->oModelReflection->GetClasses('bizmodel', true /*exclude links*/) as $sClass) { - $aClasses[$sClass] = $this->oModelReflection->GetName($sClass); - } - asort($aClasses); - - self::$aClassList = []; - foreach ($aClasses as $sClass => $sLabel) { - $sIconUrl = $this->oModelReflection->GetClassIcon($sClass, false); - if ($sIconUrl == '') { - // The icon does not exist, let's use a transparent one of the same size. - $sIconUrl = utils::GetAbsoluteUrlAppRoot().'images/transparent_32_32.png'; - } - self::$aClassList[] = ['value' => $sClass, 'label' => $sLabel, 'icon' => $sIconUrl]; - } - } - - $oField = new DesignerIconSelectionField('class', Dict::S('UI:DashletBadge:Prop-Class'), $this->aProperties['class']); - $oField->SetAllowedValues(self::$aClassList); - - $oForm->AddField($oField); - } } diff --git a/sources/Application/Dashlet/Base/DashletGroupBy.php b/sources/Application/Dashlet/Base/DashletGroupBy.php index f3f569ba4..c97b6230f 100644 --- a/sources/Application/Dashlet/Base/DashletGroupBy.php +++ b/sources/Application/Dashlet/Base/DashletGroupBy.php @@ -258,297 +258,6 @@ abstract class DashletGroupBy extends Dashlet return $oPanel; } - /** - * @return array - */ - protected function MakeSimulatedData() - { - $sQuery = $this->aProperties['query']; - - $oQuery = $this->oModelReflection->GetQuery($sQuery); - $sClass = $oQuery->GetClass(); - - $aDisplayValues = []; - if ($this->oModelReflection->IsValidAttCode($sClass, $this->sGroupByAttCode)) { - $aAttributeTypes = $this->oModelReflection->ListAttributes($sClass); - $sAttributeType = $aAttributeTypes[$this->sGroupByAttCode]; - if (is_subclass_of($sAttributeType, 'AttributeDateTime') || $sAttributeType == 'AttributeDateTime') { - // Note: an alternative to this somewhat hardcoded way of doing things would be to implement... - //$oExpr = Expression::FromOQL($this->sGroupByExpr); - //$aTranslationData = array($oQuery->GetClassAlias() => array($this->sGroupByAttCode => new ScalarExpression(date('Y-m-d H:i:s', $iTime)))); - //$sRawValue = CMDBSource::QueryToScalar('SELECT '.$oExpr->Translate($aTranslationData)->Render()); - //$sValueLabel = $oExpr->MakeValueLabel(oFilter, $sRawValue, $sRawValue); - // Anyhow, this requires : - // - an update to the prototype of MakeValueLabel() so that it takes ModelReflection parameters - // - propose clever date/times samples - - $aValues = []; - switch ($this->sFunction) { - case 'hour': - $aValues = [8, 9, 15, 18]; - break; - - case 'month': - $aValues = ['2013 '.Dict::S('Month-11'), '2013 '.Dict::S('Month-12'), '2014 '.Dict::S('Month-01'), '2014 '.Dict::S('Month-02'), '2014 '.Dict::S('Month-03')]; - break; - - case 'day_of_week': - $aValues = [Dict::S('DayOfWeek-Monday'), Dict::S('DayOfWeek-Wednesday'), Dict::S('DayOfWeek-Thursday'), Dict::S('DayOfWeek-Friday')]; - break; - - case 'day_of_month': - $aValues = [Dict::S('Month-03').' 30', Dict::S('Month-03').' 31', Dict::S('Month-04').' 01', Dict::S('Month-04').' 02', Dict::S('Month-04').' 03']; - break; - } - foreach ($aValues as $sValue) { - $aDisplayValues[] = ['label' => $sValue, 'value' => (int)rand(1, 15)]; - } - } elseif (is_subclass_of($sAttributeType, 'AttributeEnum') || $sAttributeType == 'AttributeEnum') { - $aAllowed = $this->oModelReflection->GetAllowedValues_att($sClass, $this->sGroupByAttCode); - if ($aAllowed) { // null for non enums - foreach ($aAllowed as $sValue => $sValueLabel) { - $iCount = (int)rand(2, 100); - $aDisplayValues[] = [ - 'label' => $sValueLabel, - 'value' => $iCount, - ]; - } - } - } else { - $aDisplayValues[] = ['label' => 'a', 'value' => 123]; - $aDisplayValues[] = ['label' => 'b', 'value' => 321]; - $aDisplayValues[] = ['label' => 'c', 'value' => 456]; - } - } - - return $aDisplayValues; - } - - /** - * @inheritdoc - */ - public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = []) - { - $oDashletContainer = new DashletContainer(null, ['dashlet-content']); - $oDashletContainer->AddHtml('error!'); - - return $oDashletContainer; - } - - /** - * @inheritdoc - */ - public function GetPropertiesFields(DesignerForm $oForm) - { - $oField = new DesignerTextField('title', Dict::S('UI:DashletGroupBy:Prop-Title'), $this->aProperties['title']); - $oForm->AddField($oField); - - $oField = new DesignerLongTextField('query', Dict::S('UI:DashletGroupBy:Prop-Query'), $this->aProperties['query']); - $oField->SetMandatory(); - $oField->AddCSSClass("ibo-query-oql"); - $oField->AddCSSClass("ibo-is-code"); - $oForm->AddField($oField); - - try { - // Group by field: build the list of possible values (attribute codes + ...) - $aGroupBy = $this->GetGroupByOptions($this->aProperties['query']); - - $oField = new DesignerComboField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), $this->aProperties['group_by']); - $oField->SetMandatory(); - $oField->SetAllowedValues($aGroupBy); - } catch (Exception $e) { - $oField = new DesignerTextField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), $this->aProperties['group_by']); - $oField->SetReadOnly(); - $aGroupBy = []; - } - $oForm->AddField($oField); - - $aStyles = [ - 'pie' => Dict::S('UI:DashletGroupByPie:Label'), - 'bars' => Dict::S('UI:DashletGroupByBars:Label'), - 'table' => Dict::S('UI:DashletGroupByTable:Label'), - ]; - - $oField = new DesignerComboField('style', Dict::S('UI:DashletGroupBy:Prop-Style'), $this->aProperties['style']); - $oField->SetMandatory(); - $oField->SetAllowedValues($aStyles); - $oForm->AddField($oField); - - $aFunctionAttributes = $this->GetNumericAttributes($this->aProperties['query']); - $aFunctions = $this->GetAllowedFunctions($aFunctionAttributes); - $oSelectorField = new DesignerFormSelectorField('aggregation_function', Dict::S('UI:DashletGroupBy:Prop-Function'), $this->aProperties['aggregation_function']); - $oForm->AddField($oSelectorField); - $oSelectorField->SetMandatory(); - // Count sub-menu - $oSubForm = new DesignerForm(); - $oSelectorField->AddSubForm($oSubForm, Dict::S('UI:GroupBy:count'), 'count'); - foreach ($aFunctions as $sFct => $sLabel) { - $oSubForm = new DesignerForm(); - $oField = new DesignerComboField('aggregation_attribute', Dict::S('UI:DashletGroupBy:Prop-FunctionAttribute'), $this->aProperties['aggregation_attribute']); - $oField->SetMandatory(); - $oField->SetAllowedValues($aFunctionAttributes); - $oSubForm->AddField($oField); - $oSelectorField->AddSubForm($oSubForm, $sLabel, $sFct); - } - - $aOrderField = []; - - if (isset($this->aProperties['group_by']) && isset($aGroupBy[$this->aProperties['group_by']])) { - $aOrderField['attribute'] = $aGroupBy[$this->aProperties['group_by']]; - } - - if ($this->aProperties['aggregation_function'] == 'count') { - $aOrderField['function'] = Dict::S('UI:GroupBy:count'); - } else { - $aOrderField['function'] = $aFunctions[$this->aProperties['aggregation_function']]; - } - $oSelectorField = new DesignerFormSelectorField('order_by', Dict::S('UI:DashletGroupBy:Prop-OrderField'), $this->aProperties['order_by']); - $oForm->AddField($oSelectorField); - $oSelectorField->SetMandatory(); - foreach ($aOrderField as $sField => $sLabel) { - $oSubForm = new DesignerForm(); - if ($sField == 'function') { - $oField = new DesignerIntegerField('limit', Dict::S('UI:DashletGroupBy:Prop-Limit'), $this->aProperties['limit']); - $oSubForm->AddField($oField); - } - $oSelectorField->AddSubForm($oSubForm, $sLabel, $sField); - } - - $aOrderDirections = [ - 'asc' => Dict::S('UI:DashletGroupBy:Order:asc'), - 'desc' => Dict::S('UI:DashletGroupBy:Order:desc'), - ]; - $sOrderDirection = empty($this->aProperties['order_direction']) ? $this->sOrderDirection : $this->aProperties['order_direction']; - $oField = new DesignerComboField('order_direction', Dict::S('UI:DashletGroupBy:Prop-OrderDirection'), $sOrderDirection); - $oField->SetMandatory(); - $oField->SetAllowedValues($aOrderDirections); - $oForm->AddField($oField); - - } - - /** - * @return array - */ - protected function GetOrderBy() - { - if (is_null($this->sClass)) { - return []; - } - - return [ - $this->aProperties['group_by'] => $this->oModelReflection->GetLabel($this->sClass, $this->aProperties['group_by']), - '_itop_'.$this->aProperties['aggregation_function'].'_' => Dict::S('UI:GroupBy:'.$this->aProperties['aggregation_function']), - ]; - } - - /** - * @param array $aFunctionAttributes - * - * @return array - */ - protected function GetAllowedFunctions($aFunctionAttributes) - { - $aFunctions = []; - - if (!empty($aFunctionAttributes) || is_null($this->sClass)) { - $aFunctions['sum'] = Dict::S('UI:GroupBy:sum'); - $aFunctions['avg'] = Dict::S('UI:GroupBy:avg'); - $aFunctions['min'] = Dict::S('UI:GroupBy:min'); - $aFunctions['max'] = Dict::S('UI:GroupBy:max'); - } - - return $aFunctions; - } - - /** - * @param string $sOql - * - * @return array - */ - protected function GetNumericAttributes($sOql) - { - $aFunctionAttributes = []; - try { - $oQuery = $this->oModelReflection->GetQuery($sOql); - $sClass = $oQuery->GetClass(); - if (is_null($sClass)) { - return $aFunctionAttributes; - } - foreach ($this->oModelReflection->ListAttributes($sClass) as $sAttCode => $sAttType) { - switch ($sAttType) { - case 'AttributeDecimal': - case 'AttributeDuration': - case 'AttributeInteger': - case 'AttributePercentage': - case 'AttributeSubItem': // TODO: Known limitation: no unit displayed (values in sec) - $sLabel = $this->oModelReflection->GetLabel($sClass, $sAttCode); - $aFunctionAttributes[$sAttCode] = $sLabel; - break; - } - } - } catch (Exception $e) { - // In case the OQL is bad - } - - return $aFunctionAttributes; - } - - /** - * @inheritdoc - */ - public function Update($aValues, $aUpdatedFields) - { - if (in_array('query', $aUpdatedFields)) { - try { - $sCurrQuery = $aValues['query']; - $oCurrSearch = $this->oModelReflection->GetQuery($sCurrQuery); - $sCurrClass = $oCurrSearch->GetClass(); - - $sPrevQuery = $this->aProperties['query']; - $oPrevSearch = $this->oModelReflection->GetQuery($sPrevQuery); - $sPrevClass = $oPrevSearch->GetClass(); - - if ($sCurrClass != $sPrevClass) { - $this->bFormRedrawNeeded = true; - // wrong but not necessary - unset($aUpdatedFields['group_by']); - $this->aProperties['group_by'] = ''; - } - } catch (Exception $e) { - $this->bFormRedrawNeeded = true; - } - } - $oDashlet = parent::Update($aValues, $aUpdatedFields); - - if (in_array('style', $aUpdatedFields)) { - switch ($aValues['style']) { - // Style changed, mutate to the specified type of chart - case 'pie': - $oDashlet = new DashletGroupByPie($this->oModelReflection, $this->sId); - break; - - case 'bars': - $oDashlet = new DashletGroupByBars($this->oModelReflection, $this->sId); - break; - - case 'table': - $oDashlet = new DashletGroupByTable($this->oModelReflection, $this->sId); - break; - } - $oDashlet->FromParams($aValues); - $oDashlet->bRedrawNeeded = true; - $oDashlet->bFormRedrawNeeded = true; - } - if (in_array('aggregation_attribute', $aUpdatedFields) || in_array('order_direction', $aUpdatedFields) || in_array('order_by', $aUpdatedFields) || in_array('limit', $aUpdatedFields)) { - $oDashlet->bRedrawNeeded = true; - } - if (in_array('group_by', $aUpdatedFields) || in_array('aggregation_function', $aUpdatedFields)) { - $oDashlet->bRedrawNeeded = true; - $oDashlet->bFormRedrawNeeded = true; - } - - return $oDashlet; - } - /** * @inheritdoc */ @@ -556,35 +265,4 @@ abstract class DashletGroupBy extends Dashlet { return true; } - - /** - * @inheritdoc - */ - public function GetPropertiesFieldsFromOQL(DesignerForm $oForm, $sOQL = null) - { - $oField = new DesignerTextField('title', Dict::S('UI:DashletGroupBy:Prop-Title'), ''); - $oForm->AddField($oField); - - $oField = new DesignerHiddenField('query', Dict::S('UI:DashletGroupBy:Prop-Query'), $sOQL); - $oField->SetMandatory(); - $oField->AddCSSClass("ibo-query-oql"); - $oField->AddCSSClass("ibo-is-code"); - $oForm->AddField($oField); - - if (!is_null($sOQL)) { - $oField = new DesignerComboField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), null); - $aGroupBy = $this->GetGroupByOptions($sOQL); - $oField->SetAllowedValues($aGroupBy); - } else { - // Creating a form for reading parameters! - $oField = new DesignerTextField('group_by', Dict::S('UI:DashletGroupBy:Prop-GroupBy'), null); - } - $oField->SetMandatory(); - - $oForm->AddField($oField); - - $oField = new DesignerHiddenField('style', '', $this->aProperties['style']); - $oField->SetMandatory(); - $oForm->AddField($oField); - } } diff --git a/sources/Application/Dashlet/Base/DashletGroupByBars.php b/sources/Application/Dashlet/Base/DashletGroupByBars.php index af1b7d022..2af9474e7 100644 --- a/sources/Application/Dashlet/Base/DashletGroupByBars.php +++ b/sources/Application/Dashlet/Base/DashletGroupByBars.php @@ -33,80 +33,4 @@ class DashletGroupByBars extends DashletGroupBy parent::__construct($oModelReflection, $sId); $this->aProperties['style'] = 'bars'; } - - /** - * @inheritdoc - */ - public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = []) - { - $oDashletContainer = new DashletContainer(null, ['dashlet-content']); - - $sTitle = $this->aProperties['title']; - - $sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM) - - $HTMLsTitle = ($sTitle != '') ? '

'.utils::HtmlEntities($sTitle).'

' : ''; - $oDashletContainer->AddHtml("
$HTMLsTitle
"); - - $aDisplayValues = $this->MakeSimulatedData(); - - $aNames = []; - foreach ($aDisplayValues as $idx => $aValue) { - $aNames[$idx] = $aValue['label']; - } - $sJSNames = json_encode($aNames); - - $sJson = json_encode($aDisplayValues); - $oPage->add_ready_script( - <<aProperties['title']; - - $sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM) - - $HTMLsTitle = ($sTitle != '') ? '

'.utils::HtmlEntities($sTitle).'

' : ''; - $oDashletContainer->AddHtml("
$HTMLsTitle
"); - - $aDisplayValues = $this->MakeSimulatedData(); - - $aColumns = []; - $aNames = []; - foreach ($aDisplayValues as $idx => $aValue) { - $aColumns[] = ['series_'.$idx, (int)$aValue['value']]; - $aNames['series_'.$idx] = $aValue['label']; - } - $sJSColumns = json_encode($aColumns); - $sJSNames = json_encode($aNames); - $oPage->add_ready_script( - <<aProperties['style'] = 'table'; } - - /** - * @inheritdoc - */ - public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = []) - { - $oDashletContainer = new DashletContainer(); - - $aDisplayValues = $this->MakeSimulatedData(); - $iTotal = 0; - foreach ($aDisplayValues as $iRow => $aDisplayData) { - $iTotal += $aDisplayData['value']; - } - - $sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM) - - $sHtml = ''; - $sHtml .= '
'; - $sHtml .= '
'; - $sHtml .= '

'.Dict::Format('UI:Pagination:HeaderNoSelection', $iTotal).'

'; - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - foreach ($aDisplayValues as $aDisplayData) { - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - $sHtml .= ''; - } - $sHtml .= ''; - $sHtml .= '
'.$this->sGroupByLabel.''.Dict::S('UI:GroupBy:Count').'
'.$aDisplayData['label'].''.$aDisplayData['value'].'
'; - $sHtml .= '
'; - - $sHtml .= '
'; - - $oDashletContainer->AddHtml($sHtml); - - return $oDashletContainer; - } } diff --git a/sources/Application/Dashlet/Base/DashletHeaderDynamic.php b/sources/Application/Dashlet/Base/DashletHeaderDynamic.php index 4c7be7278..0f633eed4 100644 --- a/sources/Application/Dashlet/Base/DashletHeaderDynamic.php +++ b/sources/Application/Dashlet/Base/DashletHeaderDynamic.php @@ -149,178 +149,4 @@ class DashletHeaderDynamic extends Dashlet return $oPanel; } - - /** - * @inheritdoc - */ - public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = []) - { - $sTitle = utils::HtmlEntities($this->aProperties['title']); - $sIcon = $this->aProperties['icon']; - $sSubtitle = utils::HtmlEntities($this->aProperties['subtitle']); - $sQuery = $this->aProperties['query']; - $sGroupBy = $this->aProperties['group_by']; - - $aValueLabels = []; - $aValues = []; - try { - $oQuery = $this->oModelReflection->GetQuery($sQuery); - $sClass = $oQuery->GetClass(); - $aValues = $this->GetValues(); - foreach ($aValues as $sValue) { - $aValueLabels[] = $this->oModelReflection->GetValueLabel($sClass, $sGroupBy, $sValue); - } - } catch (UnknownClassOqlException $e) { - $aValueLabels[] = $e->GetUserFriendlyDescription(); - $aValues[] = 1; - } - - $oIconSelect = $this->oModelReflection->GetIconSelectionField('icon'); - $sIconPath = utils::HtmlEntities($oIconSelect->MakeFileUrl($sIcon)); - - $oDashletContainer = new DashletContainer(null, ['dashlet-content']); - - $sHtml = ''; - $sHtml .= ''; - - $sBlockId = 'block_fake_'.$this->sId.($bEditMode ? '_edit' : ''); // make a unique id (edition occuring in the same DOM) - - $iTotal = 0; - - $sHtml .= '
'; - $sHtml .= '
'; - $sHtml .= ''; - $sHtml .= ''; - foreach ($aValueLabels as $sValueLabel) { - $sHtml .= ' '; - } - $sHtml .= ''; - $sHtml .= ''; - foreach ($aValues as $sValue) { - $iCount = rand(2, 100); - $iTotal += $iCount; - $sHtml .= ' '; - } - $sHtml .= ''; - $sHtml .= '
'.$sValueLabel.'
'.$iCount.'
'; - $sHtml .= '
'; - - $sTitle = $this->oModelReflection->DictString($sTitle); - $sSubtitle = $this->oModelReflection->DictFormat($sSubtitle, $iTotal); - - $sHtml .= '

'.utils::HtmlEntities($sTitle).'

'; - $sHtml .= ''.utils::HtmlEntities($sSubtitle).''; - $sHtml .= '
'; - - $oDashletContainer->AddHtml($sHtml); - - return $oDashletContainer; - - } - - /** - * @inheritdoc - */ - public function GetPropertiesFields(DesignerForm $oForm) - { - $oField = new DesignerTextField('title', Dict::S('UI:DashletHeaderDynamic:Prop-Title'), $this->aProperties['title']); - $oForm->AddField($oField); - - $oField = $this->oModelReflection->GetIconSelectionField('icon', Dict::S('UI:DashletHeaderDynamic:Prop-Icon'), $this->aProperties['icon']); - $oField->AddAllowedValue(['value' => '', 'label' => Dict::S('UI:DashletIcon:None'), 'icon' => '']); - $oForm->AddField($oField); - - $oField = new DesignerTextField('subtitle', Dict::S('UI:DashletHeaderDynamic:Prop-Subtitle'), $this->aProperties['subtitle']); - $oForm->AddField($oField); - - $oField = new DesignerLongTextField('query', Dict::S('UI:DashletHeaderDynamic:Prop-Query'), $this->aProperties['query']); - $oField->SetMandatory(); - $oField->AddCSSClass("ibo-query-oql"); - $oField->AddCSSClass("ibo-is-code"); - $oForm->AddField($oField); - - try { - // Group by field: build the list of possible values (attribute codes + ...) - $oQuery = $this->oModelReflection->GetQuery($this->aProperties['query']); - $sClass = $oQuery->GetClass(); - $aGroupBy = $this->GetGroupByOptions($this->aProperties['query']); - $oField = new DesignerComboField('group_by', Dict::S('UI:DashletHeaderDynamic:Prop-GroupBy'), $this->aProperties['group_by']); - $oField->SetMandatory(); - $oField->SetAllowedValues($aGroupBy); - } catch (Exception $e) { - $oField = new DesignerTextField('group_by', Dict::S('UI:DashletHeaderDynamic:Prop-GroupBy'), $this->aProperties['group_by']); - $oField->SetReadOnly(); - } - $oForm->AddField($oField); - - $oField = new DesignerComboField('values', Dict::S('UI:DashletHeaderDynamic:Prop-Values'), $this->aProperties['values']); - $oField->MultipleSelection(true); - if (isset($sClass) && $this->oModelReflection->IsValidAttCode($sClass, $this->aProperties['group_by'])) { - $aValues = $this->oModelReflection->GetAllowedValues_att($sClass, $this->aProperties['group_by']); - $oField->SetAllowedValues($aValues); - } else { - $oField->SetReadOnly(); - } - $oForm->AddField($oField); - } - - /** - * @inheritdoc - */ - public function Update($aValues, $aUpdatedFields) - { - if (in_array('query', $aUpdatedFields)) { - try { - $sCurrQuery = $aValues['query']; - $oCurrSearch = $this->oModelReflection->GetQuery($sCurrQuery); - $sCurrClass = $oCurrSearch->GetClass(); - - $sPrevQuery = $this->aProperties['query']; - $oPrevSearch = $this->oModelReflection->GetQuery($sPrevQuery); - $sPrevClass = $oPrevSearch->GetClass(); - - if ($sCurrClass != $sPrevClass) { - $this->bFormRedrawNeeded = true; - // wrong but not necessary - unset($aUpdatedFields['group_by']); - $this->aProperties['group_by'] = ''; - $this->aProperties['values'] = []; - } - } catch (Exception $e) { - $this->bFormRedrawNeeded = true; - } - } - if (in_array('group_by', $aUpdatedFields)) { - $this->bFormRedrawNeeded = true; - $this->aProperties['values'] = []; - } - - return parent::Update($aValues, $aUpdatedFields); - } - - /** - * @inheritdoc - */ - protected function PropertyFromDOMNode($oDOMNode, $sProperty) - { - if ($sProperty == 'icon') { - $oIconField = $this->oModelReflection->GetIconSelectionField('icon'); - - return $oIconField->ValueFromDOMNode($oDOMNode); - } else { - return parent::PropertyFromDOMNode($oDOMNode, $sProperty); - } - } - - /** - * @inheritdoc - */ - protected function PropertyToDOMNode($oDOMNode, $sProperty, $value) - { - if ($sProperty == 'icon') { - $oIconField = $this->oModelReflection->GetIconSelectionField('icon'); - $oIconField->ValueToDOMNode($oDOMNode, $value); - } else { - parent::PropertyToDOMNode($oDOMNode, $sProperty, $value); - } - } } diff --git a/sources/Application/Dashlet/Base/DashletHeaderStatic.php b/sources/Application/Dashlet/Base/DashletHeaderStatic.php index b81c7db15..da31ca372 100644 --- a/sources/Application/Dashlet/Base/DashletHeaderStatic.php +++ b/sources/Application/Dashlet/Base/DashletHeaderStatic.php @@ -55,44 +55,4 @@ class DashletHeaderStatic extends Dashlet return DashletFactory::MakeForDashletHeaderStatic($this->oModelReflection->DictString($sTitle), $sIconPath); } - - /** - * @inheritdoc - */ - public function GetPropertiesFields(DesignerForm $oForm) - { - $oField = new DesignerTextField('title', Dict::S('UI:DashletHeaderStatic:Prop-Title'), $this->aProperties['title']); - $oForm->AddField($oField); - - $oField = $this->oModelReflection->GetIconSelectionField('icon', Dict::S('UI:DashletHeaderStatic:Prop-Icon'), $this->aProperties['icon']); - $oField->AddAllowedValue(['value' => '', 'label' => Dict::S('UI:DashletIcon:None'), 'icon' => '']); - $oForm->AddField($oField); - } - - /** - * @inheritdoc - */ - protected function PropertyFromDOMNode($oDOMNode, $sProperty) - { - if ($sProperty == 'icon') { - $oIconField = $this->oModelReflection->GetIconSelectionField('icon'); - - return $oIconField->ValueFromDOMNode($oDOMNode); - } else { - return parent::PropertyFromDOMNode($oDOMNode, $sProperty); - } - } - - /** - * @inheritdoc - */ - protected function PropertyToDOMNode($oDOMNode, $sProperty, $value) - { - if ($sProperty == 'icon') { - $oIconField = $this->oModelReflection->GetIconSelectionField('icon'); - $oIconField->ValueToDOMNode($oDOMNode, $value); - } else { - parent::PropertyToDOMNode($oDOMNode, $sProperty, $value); - } - } } diff --git a/sources/Application/Dashlet/Base/DashletObjectList.php b/sources/Application/Dashlet/Base/DashletObjectList.php index 9595ec308..0c2e382e8 100644 --- a/sources/Application/Dashlet/Base/DashletObjectList.php +++ b/sources/Application/Dashlet/Base/DashletObjectList.php @@ -77,44 +77,6 @@ class DashletObjectList extends Dashlet return $oPanel; } - - /** - * @inheritdoc - */ - public function RenderNoData($oPage, $bEditMode = false, $aExtraParams = []) - { - $oDashletContainer = new DashletContainer($this->sId, ['dashlet-content']); - $sTitle = $this->aProperties['title']; - $sQuery = $this->aProperties['query']; - $bShowMenu = $this->aProperties['menu']; - $sHtmlTitle = utils::HtmlEntities($this->oModelReflection->DictString($sTitle)); - if ($sHtmlTitle != '') { - $sHtmlTitle = '

'.$sHtmlTitle.'

'; - } - $oQuery = $this->oModelReflection->GetQuery($sQuery); - $sClass = $oQuery->GetClass(); - $sId = $this->sId; - $sMessage = Dict::S('UI:NoObjectToDisplay'); - $sMenu = ''; - if ($bShowMenu) { - $sMenu = '

'.Dict::Format('UI:ClickToCreateNew', $this->oModelReflection->GetName($sClass)).'

'; - } - - $sHtml = << -

$sHtmlTitle

-
-

$sMessage

-$sMenu -
- -HTML; - - $oDashletContainer->AddHtml($sHtml); - - return $oDashletContainer; - } - public function GetDBSearch($aExtraParams = []) { $sQuery = $this->aProperties['query']; @@ -130,24 +92,6 @@ HTML; return DBObjectSearch::FromOQL($sQuery, $aQueryParams); } - /** - * @inheritdoc - */ - public function GetPropertiesFields(DesignerForm $oForm) - { - $oField = new DesignerTextField('title', Dict::S('UI:DashletObjectList:Prop-Title'), $this->aProperties['title']); - $oForm->AddField($oField); - - $oField = new DesignerLongTextField('query', Dict::S('UI:DashletObjectList:Prop-Query'), $this->aProperties['query']); - $oField->SetMandatory(); - $oField->AddCSSClass("ibo-query-oql"); - $oField->AddCSSClass("ibo-is-code"); - $oForm->AddField($oField); - - $oField = new DesignerBooleanField('menu', Dict::S('UI:DashletObjectList:Prop-Menu'), $this->aProperties['menu']); - $oForm->AddField($oField); - } - /** * @inheritdoc */ @@ -155,22 +99,4 @@ HTML; { return true; } - - /** - * @inheritdoc - */ - public function GetPropertiesFieldsFromOQL(DesignerForm $oForm, $sOQL = null) - { - $oField = new DesignerTextField('title', Dict::S('UI:DashletObjectList:Prop-Title'), ''); - $oForm->AddField($oField); - - $oField = new DesignerHiddenField('query', Dict::S('UI:DashletObjectList:Prop-Query'), $sOQL); - $oField->SetMandatory(); - $oField->AddCSSClass("ibo-query-oql"); - $oField->AddCSSClass("ibo-is-code"); - $oForm->AddField($oField); - - $oField = new DesignerBooleanField('menu', Dict::S('UI:DashletObjectList:Prop-Menu'), $this->aProperties['menu']); - $oForm->AddField($oField); - } } diff --git a/sources/Application/Dashlet/Base/DashletPlainText.php b/sources/Application/Dashlet/Base/DashletPlainText.php index 7ce3b5a07..a491a93ca 100644 --- a/sources/Application/Dashlet/Base/DashletPlainText.php +++ b/sources/Application/Dashlet/Base/DashletPlainText.php @@ -50,14 +50,4 @@ class DashletPlainText extends Dashlet return DashletFactory::MakeForDashletPlainText($sText, $sId); } - - /** - * @inheritdoc - */ - public function GetPropertiesFields(DesignerForm $oForm) - { - $oField = new DesignerLongTextField('text', Dict::S('UI:DashletPlainText:Prop-Text'), $this->aProperties['text']); - $oField->SetMandatory(); - $oForm->AddField($oField); - } }