From 9ebcbf245929ca68d732767a93104c3f93328b23 Mon Sep 17 00:00:00 2001 From: acognet Date: Wed, 24 May 2023 11:41:06 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B01386=20-=20Advanced=20Search:=20Navigati?= =?UTF-8?q?on=20in=20list=20-=20Browse=20this=20list=20-=20fix=20=20displa?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/dbobject.class.php | 14 +++++--------- pages/UI.php | 2 +- .../DataTable/DataTableUIBlockFactory.php | 17 ++++++++++++++--- .../Layout/PageContent/PageContentFactory.php | 9 ++++++--- .../Indirect/BlockIndirectLinkSetViewTable.php | 6 +++++- sources/Controller/AjaxRenderController.php | 17 +++++++++-------- .../components/datatable/layout.ready.js.twig | 6 +----- .../base/components/navigation/layout.html.twig | 4 ++-- .../base/components/navigation/layout.js.twig | 2 +- 9 files changed, 44 insertions(+), 33 deletions(-) diff --git a/core/dbobject.class.php b/core/dbobject.class.php index 50bf65621..7175ba91a 100644 --- a/core/dbobject.class.php +++ b/core/dbobject.class.php @@ -1116,29 +1116,25 @@ abstract class DBObject implements iDisplay * * @see \Combodo\iTop\Form\Field\Field for rendering in portal forms */ - public function GetAsHTML($sAttCode, $bLocalize = true) + public function GetAsHTML($sAttCode, $bLocalize = true, $bInBasket = false) { $sClass = get_class($this); $oAtt = MetaModel::GetAttributeDef($sClass, $sAttCode); - if ($oAtt->IsExternalKey(EXTKEY_ABSOLUTE)) - { + if ($oAtt->IsExternalKey(EXTKEY_ABSOLUTE)) { //return $this->Get($sAttCode.'_friendlyname'); /** @var \AttributeExternalKey $oAtt */ $sTargetClass = $oAtt->GetTargetClass(EXTKEY_ABSOLUTE); $iTargetKey = $this->Get($sAttCode); - if ($iTargetKey < 0) - { + if ($iTargetKey < 0) { // the key points to an object that exists only in memory... no hyperlink points to it yet return ''; - } - else - { + } else { $sHtmlLabel = utils::EscapeHtml($this->Get($sAttCode.'_friendlyname')); $bArchived = $this->IsArchived($sAttCode); $bObsolete = $this->IsObsolete($sAttCode); - return $this->MakeHyperLink($sTargetClass, $iTargetKey, $sHtmlLabel, null, true, $bArchived, $bObsolete); + return $this->MakeHyperLink($sTargetClass, $iTargetKey, $sHtmlLabel, null, true, $bArchived, $bObsolete, false, $bInBasket); } } diff --git a/pages/UI.php b/pages/UI.php index a9f6ef8b2..97d824213 100644 --- a/pages/UI.php +++ b/pages/UI.php @@ -438,7 +438,7 @@ 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'); - $sList = utils::ReadPostedParam('listNavigation', null, false, 'string'); + $sList = utils::ReadPostedParam('list_navigation', null, false, 'string'); $aList = []; if ($sList != null) { $aList = json_decode($sList); diff --git a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php index 93a9f4e3e..0ebe5713b 100644 --- a/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php +++ b/sources/Application/UI/Base/Component/DataTable/DataTableUIBlockFactory.php @@ -572,21 +572,32 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory $aExtraParams['table_id'] = $sTableId; $aExtraParams['list_id'] = $sListId; + $oFilter = $oSet->GetFilter(); + + $sBasketAliasClass = $oFilter->GetFirstJoinedClassAlias(); + if ($sBasketAliasClass === 'Link') { + $sLinkToBasket = $sBasketAliasClass.'/'.$sTargetAttr; + $sBasketAliasClass = 'Remote'; + } else { + $sLinkToBasket = $sBasketAliasClass; + } $oDataTable->SetOptions($aOptions); $oDataTable->SetAjaxUrl(utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php"); $oDataTable->SetAjaxData([ "operation" => 'search', - "filter" => $oSet->GetFilter()->serialize(), + "filter" => $oFilter->serialize(), "columns" => $oCustomSettings->aColumns, "extra_params" => $aExtraParams, "class_aliases" => $aClassAliases, "select_mode" => $sSelectMode, + "basket" => $sLinkToBasket, ]); $oDataTable->SetDisplayColumns($aColumnDefinition); $oDataTable->SetResultColumns($oCustomSettings->aColumns); - $oDataTable->SetFilter($oSet->GetFilter()->ToOQL(true)); - $oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams, 1, true)); + $oFilter->SetSelectedClasses([$sBasketAliasClass]); + $oDataTable->SetFilter($oFilter->ToOQL(true)); + $oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams, 1, $sLinkToBasket)); // row actions if (isset($aExtraParams['row_actions'])) { diff --git a/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php b/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php index 4b91590ac..bbb4060c9 100644 --- a/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php +++ b/sources/Application/UI/Base/Layout/PageContent/PageContentFactory.php @@ -52,19 +52,22 @@ class PageContentFactory * @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX * * @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view. + * @param string $sBasketFilter filter to find list of objects in basket + * @param array $aBasketList list of id of objects in basket + * @param string $sBackUrl url to go back to list of ojects in basket * * @param \DBObject $oObject * * @return \Combodo\iTop\Application\UI\Base\Layout\PageContent\PageContentWithSideContent * @throws \CoreException */ - public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE, $sFilter = null, $aList = [], $sBackUrl = null) + public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE, $sBasketFilter = null, $aBasketList = [], $sBackUrl = null) { $oLayout = new PageContentWithSideContent(); - if ($sFilter != null) { - $oNavigationBlock = NavigationUIBlockFactory::MakeStandard($oObject, $sFilter, $aList, $sBackUrl); + if ($sBasketFilter != null) { + $oNavigationBlock = NavigationUIBlockFactory::MakeStandard($oObject, $sBasketFilter, $aBasketList, $sBackUrl); if ($oNavigationBlock != null) { $oLayout->AddSubBlock($oNavigationBlock); } diff --git a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php index 573d8df6b..c0595df7f 100644 --- a/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php +++ b/sources/Application/UI/Links/Indirect/BlockIndirectLinkSetViewTable.php @@ -120,8 +120,12 @@ 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 *//** @noinspection OneTimeUseVariablesInspection */ + /** @noinspection PhpUnnecessaryLocalVariableInspection */ + /** @noinspection OneTimeUseVariablesInspection */ $sAttCodesToDisplay = implode(',', $aAttCodesToDisplay); return $sAttCodesToDisplay; diff --git a/sources/Controller/AjaxRenderController.php b/sources/Controller/AjaxRenderController.php index 06f0ac543..c7768b661 100644 --- a/sources/Controller/AjaxRenderController.php +++ b/sources/Controller/AjaxRenderController.php @@ -62,7 +62,7 @@ class AjaxRenderController * @throws \MySQLException * @throws \MySQLHasGoneAwayException */ - public static function GetDataForTable(DBObjectSet $oSet, array $aClassAliases, array $aColumnsLoad, string $sIdName = "", array $aExtraParams = [], int $iDrawNumber = 1, bool $bInBasket = false) + public static function GetDataForTable(DBObjectSet $oSet, array $aClassAliases, array $aColumnsLoad, string $sIdName = "", array $aExtraParams = [], int $iDrawNumber = 1, string $sLinkToBasket = "") { if (isset($aExtraParams['show_obsolete_data'])) { $bShowObsoleteData = $aExtraParams['show_obsolete_data']; @@ -80,7 +80,7 @@ class AjaxRenderController if (isset($aObject[$sAlias]) && !is_null($aObject[$sAlias])) { $aObj[$sAlias."/_key_"] = $aObject[$sAlias]->GetKey(); $aObj[$sAlias."/_key_/raw"] = $aObject[$sAlias]->GetKey(); - $aObj[$sAlias."/hyperlink"] = $aObject[$sAlias]->GetHyperlink(null, true, null, false, $bInBasket); + $aObj[$sAlias."/hyperlink"] = $aObject[$sAlias]->GetHyperlink(null, true, null, false, ($sLinkToBasket === $sAlias)); $aObj[$sAlias."/friendlyname"] = $aObject[$sAlias]->Get('friendlyname'); // N°5943 Protection against $aColumnsLoad having less class aliases than $aClassAliases, this is in case the method's consumer isn't passing data correctly @@ -95,14 +95,13 @@ class AjaxRenderController } foreach ($aColumnsLoad[$sAlias] as $sAttCode) { - $aObj[$sAlias."/".$sAttCode] = $aObject[$sAlias]->GetAsHTML($sAttCode); + $aObj[$sAlias."/".$sAttCode] = $aObject[$sAlias]->GetAsHTML($sAttCode, true, ($sLinkToBasket === $sAlias."/".$sAttCode)); + $bExcludeRawValue = false; // Only retrieve raw (stored) value for simple fields - foreach (cmdbAbstractObject::GetAttDefClassesToExcludeFromMarkupMetadataRawValue() as $sAttDefClassToExclude) - { + foreach (cmdbAbstractObject::GetAttDefClassesToExcludeFromMarkupMetadataRawValue() as $sAttDefClassToExclude) { $oAttDef = MetaModel::GetAttributeDef($sClass, $sAttCode); - if (is_a($oAttDef, $sAttDefClassToExclude, true)) - { + if (is_a($oAttDef, $sAttDefClassToExclude, true)) { $bExcludeRawValue = true; break; } @@ -490,7 +489,9 @@ class AjaxRenderController $oSet = new DBObjectSet($oFilter, $aOrderBy, $aQueryParams, null, $iEnd - $iStart, $iStart); $oSet->OptimizeColumnLoad($aColumnsLoad); - return self::GetDataForTable($oSet, $aClassAliases, $aColumnsLoad, $sIdName, $aExtraParams, $iDrawNumber, true); + $sLinkToBasket = utils::ReadParam('basket', '', false, 'string'); + + return self::GetDataForTable($oSet, $aClassAliases, $aColumnsLoad, $sIdName, $aExtraParams, $iDrawNumber, $sLinkToBasket); } /** diff --git a/templates/base/components/datatable/layout.ready.js.twig b/templates/base/components/datatable/layout.ready.js.twig index a80b85002..79bda9199 100644 --- a/templates/base/components/datatable/layout.ready.js.twig +++ b/templates/base/components/datatable/layout.ready.js.twig @@ -111,7 +111,6 @@ var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ e.preventDefault(); }); {% else %} - $('#{{ oUIBlock.GetId() }}_wrapper').find('.object-in-basket').on('click', function (event) { event.preventDefault(); @@ -150,7 +149,6 @@ var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ e.preventDefault(); }); {% else %} - $('#{{ oUIBlock.GetId() }}_wrapper').find('.object-in-basket').on('click', function (event) { event.preventDefault(); @@ -164,7 +162,6 @@ var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({ $('#basket{{ oUIBlock.GetId() }}').submit(); } ); - {% endif %} }, {% endif %} @@ -479,5 +476,4 @@ if (window.ResizeObserver) {% if oUIBlock.HasRowActions() %} {% include 'base/components/datatable/row-actions/handler.js.twig' %} -{% endif %} -console.warn('ici-lala'); \ No newline at end of file +{% endif %} \ No newline at end of file diff --git a/templates/base/components/navigation/layout.html.twig b/templates/base/components/navigation/layout.html.twig index b0ad88700..ed3c29424 100644 --- a/templates/base/components/navigation/layout.html.twig +++ b/templates/base/components/navigation/layout.html.twig @@ -4,9 +4,9 @@ class="{{ oUIBlock.GetBlocksInheritanceCSSClassesAsString() }} {{ oUIBlock.GetAdditionalCSSClassesAsString() }} {{ oUIBlock.GetCSSColorClass() }} {% if oUIBlock.IsHidden() %}ibo-is-hidden{% endif %} ibo-is-opened" data-role="ibo-navigation"> {% block iboNavigation %}
- + - +
{% if oUIBlock.HasPrec() %}
diff --git a/templates/base/components/navigation/layout.js.twig b/templates/base/components/navigation/layout.js.twig index 6bd436e2f..f2e04442a 100644 --- a/templates/base/components/navigation/layout.js.twig +++ b/templates/base/components/navigation/layout.js.twig @@ -1,6 +1,6 @@ {# @copyright Copyright (C) 2010-2021 Combodo SARL #} {# @license http://opensource.org/licenses/AGPL-3.0 #} -console.warn('ICI'); + $('#{{ oUIBlock.GetId() }}-back').on('click', function () { window.location = '{{ oUIBlock.GetBackUrl()|raw }}'; });