From 49cf6f5fe2e17a2183b0e2f47d9eb56603c31727 Mon Sep 17 00:00:00 2001 From: acognet Date: Thu, 10 Aug 2023 12:24:01 +0200 Subject: [PATCH] Fix some strange behavior --- pages/UI.php | 5 +++-- .../UI/Base/Component/DataTable/DataTable.php | 10 +++++----- .../DataTable/DataTableUIBlockFactory.php | 2 +- .../Base/Component/Navigation/Navigation.php | 16 ++++++++-------- .../Navigation/NavigationUIBlockFactory.php | 18 +++++++++++++----- .../Indirect/BlockIndirectLinkSetViewTable.php | 2 -- .../components/datatable/layout.ready.js.twig | 5 ++++- .../components/navigation/layout.html.twig | 3 ++- .../base/components/navigation/layout.js.twig | 13 +++++++++---- 9 files changed, 45 insertions(+), 29 deletions(-) diff --git a/pages/UI.php b/pages/UI.php index 6209ad945..f14f8a5b5 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -437,7 +437,8 @@ try //N°1386 - Advanced Search: Navigation in list - Browse this list $sBackUrl = utils::ReadPostedParam('back_url', '', false, 'raw'); - $sFilter = utils::ReadPostedParam('filter', null, false, 'raw'); + $sBasketClass = utils::ReadPostedParam('basket_class', null, false, 'raw'); + $sBasketFilter = utils::ReadPostedParam('basket_filter', null, false, 'raw'); $sList = utils::ReadPostedParam('list_navigation', null, false, 'string'); $sPostedFieldsForBackUrl = utils::ReadPostedParam('back_posted_fields', "", false, 'raw'); $aList = []; @@ -447,7 +448,7 @@ try $sClassLabel = MetaModel::GetName($sClass); $oP->set_title(Dict::Format('UI:DetailsPageTitle', $oObj->GetRawName(), $sClassLabel)); // Set title will take care of the encoding - $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, $oP->IsPrintableVersion() ? cmdbAbstractObject::ENUM_DISPLAY_MODE_PRINT : cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW, $sFilter, $aList, $sBackUrl, $sPostedFieldsForBackUrl)); + $oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, $oP->IsPrintableVersion() ? cmdbAbstractObject::ENUM_DISPLAY_MODE_PRINT : cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW, $sBasketFilter, $sBasketClass, $aList, $sBackUrl, $sPostedFieldsForBackUrl)); $oObj->DisplayDetails($oP); } } diff --git a/sources/Application/UI/Base/Component/DataTable/DataTable.php b/sources/Application/UI/Base/Component/DataTable/DataTable.php index 038d98917..f5fdc109b 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTable.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTable.php @@ -48,7 +48,7 @@ class DataTable extends UIContentBlock protected $aAjaxData; protected $aDisplayColumns; protected $aResultColumns; - protected $sFilter; + protected $sBasketFilter; /** * @var string */ @@ -225,17 +225,17 @@ class DataTable extends UIContentBlock /** * @return string */ - public function GetFilter() + public function GetBasketFilter() { - return $this->sFilter; + return $this->sBasketFilter; } /** * @param string $sFilter */ - public function setFilter($sFilter): void + public function setBasketFilter($sFilter): void { - $this->sFilter = $sFilter; + $this->sBasketFilter = $sFilter; } /** diff --git a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php index 05bc8bbd3..fff0ac7cf 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php @@ -596,7 +596,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory $oDataTable->SetDisplayColumns($aColumnDefinition); $oDataTable->SetResultColumns($oCustomSettings->aColumns); $oFilter->SetSelectedClasses([$sBasketAliasClass]); - $oDataTable->SetFilter($oFilter->ToOQL(true)); + $oDataTable->SetBasketFilter($oFilter->ToOQL(true)); $oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams, 1, $sLinkToBasket)); // row actions diff --git a/sources/Application/UI/Base/Component/Navigation/Navigation.php b/sources/Application/UI/Base/Component/Navigation/Navigation.php index 872fcd974..d5cd09a3e 100644 --- a/sources/Application/UI/Base/Component/Navigation/Navigation.php +++ b/sources/Application/UI/Base/Component/Navigation/Navigation.php @@ -50,9 +50,9 @@ class Navigation extends UIContentBlock protected $iIdNext = 0; protected $iIdLast = 0; protected $aList = []; - protected $sFilter; + protected $sBasketFilter; protected $sBackUrl; - protected $sClass; + protected $sBasketClass; protected $sPostedFields; /** @@ -63,16 +63,16 @@ class Navigation extends UIContentBlock * @param string $sColorScheme Color scheme code such as "success", "failure", "active", ... {@see css/backoffice/components/_panel.scss} * @param string|null $sId */ - public function __construct(string $sClass, int $iIdx, array $aList, string $sFilter, string $sBackUrl, string $sPostedFieldsForBackUrl = "", ?string $sId = null) + public function __construct(string $sBasketClass, int $iIdx, array $aList, string $sBasketFilter, string $sBackUrl, string $sPostedFieldsForBackUrl = "", ?string $sId = null) { parent::__construct($sId); $this->iCount = count($aList); if ($this->iCount == 0) { return new UIContentBlock(); } - $this->sClass = $sClass; + $this->sBasketClass = $sBasketClass; $this->aList = $aList; - $this->sFilter = $sFilter; + $this->sBasketFilter = $sBasketFilter; $this->sBackUrl = $sBackUrl; $this->iIdx = $iIdx; if ($this->iIdx>0) { @@ -112,7 +112,7 @@ class Navigation extends UIContentBlock private function GetUrlFromId($iId) { - $sUrl = iTopStandardURLMaker::MakeObjectURL($this->sClass, $iId); + $sUrl = iTopStandardURLMaker::MakeObjectURL($this->sBasketClass, $iId); return $sUrl; } @@ -159,9 +159,9 @@ class Navigation extends UIContentBlock /** * @return string */ - public function GetFilter(): string + public function GetBasketFilter(): string { - return $this->sFilter; + return $this->sBasketFilter; } /** diff --git a/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php b/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php index e523fafff..7fbca2cd7 100644 --- a/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/Navigation/NavigationUIBlockFactory.php @@ -22,6 +22,7 @@ namespace Combodo\iTop\Application\UI\Base\Component\Navigation; use Combodo\iTop\Application\UI\Base\AbstractUIBlockFactory; use DBObjectSearch; use DBObjectSet; +use utils; /** * Class PanelUIBlockFactory @@ -48,19 +49,26 @@ class NavigationUIBlockFactory extends AbstractUIBlockFactory * * @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel */ - public static function MakeStandard($oObject, string $sFilter, array $aList = [], string $sBackUrl = '', $sPostedFieldsForBackUrl = "") + public static function MakeStandard($oObject, string $sBasketFilter, string $sBasketClass, array $aList = [], string $sBackUrl = '', $sPostedFieldsForBackUrl = "") { - if ($sFilter != null && count($aList) === 0) { - $oFilter = DBObjectSearch::FromOQL($sFilter); - $oSet = new DBObjectSet($oFilter); + if (utils::IsNotNullOrEmptyString($sBasketFilter) && count($aList) === 0) { + $oBasketFilter = DBObjectSearch::FromOQL($sBasketFilter); + $oSet = new DBObjectSet($oBasketFilter); $aList = $oSet->GetColumnAsArray('id', false); + if (utils::IsNullOrEmptyString($sBasketClass)) { + $sBasketClass = $oBasketFilter->GetClass(); + } + } + if (utils::IsNullOrEmptyString($sBasketClass)) { + $oBasketFilter = DBObjectSearch::FromOQL($sBasketFilter); + $sBasketClass = $oBasketFilter->GetClass(); } if (count($aList) === 0) { return null; } $iIdx = array_search($oObject->GetKey(), $aList); - $oNavigationBlock = new Navigation(get_class($oObject), $iIdx, $aList, $sFilter, $sBackUrl, $sPostedFieldsForBackUrl); + $oNavigationBlock = new Navigation($sBasketClass, $iIdx, $aList, $sBasketFilter, $sBackUrl, $sPostedFieldsForBackUrl); return $oNavigationBlock; } diff --git a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php index c0595df7f..b04d2128d 100644 --- a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php @@ -120,8 +120,6 @@ class BlockIndirectLinkSetViewTable extends AbstractBlockLinkSetViewTable $sAttributeLinkedSetIndirectAttCode = $oAttributeLinkedSetIndirectDefinition->GetCode(); $sAttributeLinkedSetIndirectLinkedClass = $oAttributeLinkedSetIndirectDefinition->GetTargetClass(); - \IssueLog::Error('AttributeLinkedSetIndirectAttCode:'.$sAttributeLinkedSetIndirectAttCode); - \IssueLog::Error('AttributeLinkedSetIndirectLinkedClass:'.$sAttributeLinkedSetIndirectLinkedClass); $aAttCodesToDisplay = MetaModel::GetAttributeLinkedSetIndirectDatatableAttCodesToDisplay($this->sObjectClass, $this->sAttCode, $sAttributeLinkedSetIndirectLinkedClass, $sAttributeLinkedSetIndirectAttCode); /** @noinspection PhpUnnecessaryLocalVariableInspection */ diff --git a/templates/base/components/datatable/layout.ready.js.twig b/templates/base/components/datatable/layout.ready.js.twig index 87fb1841b..5e05b583f 100644 --- a/templates/base/components/datatable/layout.ready.js.twig +++ b/templates/base/components/datatable/layout.ready.js.twig @@ -465,7 +465,10 @@ $('#datatable_dlg_{{ oUIBlock.GetId() }}').DataTableSettings(aOptions{{ sListIDF $('body').append($('
') .attr({'method': 'post', 'id': 'basket{{ oUIBlock.GetId() }}'}) .append($('') - .attr({'type': 'hidden', 'name': 'filter', 'value': "{{ oUIBlock.GetFilter()|raw }}"}) + .attr({'type': 'hidden', 'name': 'basket_filter', 'value': "{{ oUIBlock.GetBasketFilter()|raw }}"}) + ) + .append($('') + .attr({'type': 'hidden', 'name': 'basket_class', 'value': "{{ oUIBlock.GetBasketClass()|raw }}"}) ) .append($('') .attr({'type': 'hidden', 'name': 'back_url', 'value': window.location.href}) diff --git a/templates/base/components/navigation/layout.html.twig b/templates/base/components/navigation/layout.html.twig index 87ae29e2e..a85e622de 100644 --- a/templates/base/components/navigation/layout.html.twig +++ b/templates/base/components/navigation/layout.html.twig @@ -5,7 +5,8 @@ {% block iboNavigation %} - + +
diff --git a/templates/base/components/navigation/layout.js.twig b/templates/base/components/navigation/layout.js.twig index 214b59e7e..47b97db5f 100644 --- a/templates/base/components/navigation/layout.js.twig +++ b/templates/base/components/navigation/layout.js.twig @@ -2,11 +2,16 @@ {# @license http://opensource.org/licenses/AGPL-3.0 #} $('#{{ oUIBlock.GetId() }}-back').on('click', function () { - $('#ibo-form-navigation').attr('action', ' {{ oUIBlock.GetBackUrl() | raw }} '); + $('#ibo-form-navigation').attr('action', '{{ oUIBlock.GetBackUrl() | raw }}'); + $('#ibo-form-navigation').attr('method', 'post'); + $('#ibo-form-navigation').find('[name=basket_filter]').val(''); - JSON.parse('{{ oUIBlock.GetPostedFields() | raw }}', (key, value) => { - $('#ibo-form-navigation').append($('').attr({'type': 'hidden', 'name': key, 'value': value})); - }); + if ('{{ oUIBlock.GetPostedFields() | raw }}' != '') + { + JSON.parse('{{ oUIBlock.GetPostedFields() | raw }}', (key, value) => { + $('#ibo-form-navigation').append($('').attr({'type': 'hidden', 'name': key, 'value': value})); + }); + } $('#ibo-form-navigation').submit(); });