N°1386 - Advanced Search: Navigation in list - Browse this list - new version

This commit is contained in:
acognet
2023-05-22 13:40:46 +02:00
parent d4e64bc479
commit f4545615cb
12 changed files with 141 additions and 69 deletions

View File

@@ -1315,7 +1315,7 @@ abstract class DBObject implements iDisplay
* @throws \CoreException
* @throws \DictExceptionMissingString
*/
public static function MakeHyperLink($sObjClass, $sObjKey, $sHtmlLabel = '', $sUrlMakerClass = null, $bWithNavigationContext = true, $bArchived = false, $bObsolete = false, $bIgnorePreview = false, $sFilter = null)
public static function MakeHyperLink($sObjClass, $sObjKey, $sHtmlLabel = '', $sUrlMakerClass = null, $bWithNavigationContext = true, $bArchived = false, $bObsolete = false, $bIgnorePreview = false, $bInBasket = false)
{
if ($sObjKey <= 0) {
return '<em>'.Dict::S('UI:UndefinedObject').'</em>';
@@ -1377,10 +1377,11 @@ abstract class DBObject implements iDisplay
}
if ($bClickable && (strlen($sUrl) > 0)) {
if ($sFilter != null) {
$sUrl = $sUrl.'&filter='.$sFilter;
if ($bInBasket) {
$sHLink = "<a class=\"object-ref-link object-in-basket\" data-href=\"$sUrl\">$sIcon$sHtmlLabel</a>";
} else {
$sHLink = "<a class=\"object-ref-link\" href=\"$sUrl\" >$sIcon$sHtmlLabel</a>";
}
$sHLink = "<a class=\"object-ref-link\" href=\"$sUrl\">$sIcon$sHtmlLabel</a>";
} else {
$sHLink = $sIcon.$sHtmlLabel;
}
@@ -1408,7 +1409,7 @@ abstract class DBObject implements iDisplay
* @throws CoreException
* @throws DictExceptionMissingString
*/
public function GetHyperlink($sUrlMakerClass = null, $bWithNavigationContext = true, $sLabel = null, $bIgnorePreview = false, $sFilter = null)
public function GetHyperlink($sUrlMakerClass = null, $bWithNavigationContext = true, $sLabel = null, $bIgnorePreview = false, $bInBasket = false)
{
if ($sLabel === null) {
$sLabel = $this->GetName();
@@ -1416,7 +1417,7 @@ abstract class DBObject implements iDisplay
$bArchived = $this->IsArchived();
$bObsolete = $this->IsObsolete();
return self::MakeHyperLink(get_class($this), $this->GetKey(), $sLabel, $sUrlMakerClass, $bWithNavigationContext, $bArchived, $bObsolete, $bIgnorePreview, $sFilter);
return self::MakeHyperLink(get_class($this), $this->GetKey(), $sLabel, $sUrlMakerClass, $bWithNavigationContext, $bArchived, $bObsolete, $bIgnorePreview, $bInBasket);
}
/**

View File

@@ -436,7 +436,8 @@ try
}
//N°1386 - Advanced Search: Navigation in list - Browse this list
$sFilter = utils::ReadParam('filter', null, false, 'raw');
$sBackUrl = utils::ReadPostedParam('back_url', '', false, 'raw');
$sFilter = utils::ReadPostedParam('filter', null, false, 'raw');
$sList = utils::ReadPostedParam('listNavigation', null, false, 'string');
$aList = [];
if ($sList != null) {
@@ -445,7 +446,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));
$oP->SetContentLayout(PageContentFactory::MakeForObjectDetails($oObj, $oP->IsPrintableVersion() ? cmdbAbstractObject::ENUM_DISPLAY_MODE_PRINT : cmdbAbstractObject::ENUM_DISPLAY_MODE_VIEW, $sFilter, $aList, $sBackUrl));
$oObj->DisplayDetails($oP);
}
}

View File

@@ -48,6 +48,7 @@ class DataTable extends UIContentBlock
protected $aAjaxData;
protected $aDisplayColumns;
protected $aResultColumns;
protected $sFilter;
/**
* @var string
*/
@@ -221,8 +222,25 @@ class DataTable extends UIContentBlock
return json_encode($this->aInitDisplayData);
}
/**
* @return string
*/
public function GetFilter()
{
return $this->sFilter;
}
/**
* @param string $sFilter
*/
public function setFilter($sFilter): void
{
$this->sFilter = $sFilter;
}
/**
* Get $aInitDisplayData
*
* @return array
*/
public function GetInitDisplayData(): array

View File

@@ -585,17 +585,18 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
]);
$oDataTable->SetDisplayColumns($aColumnDefinition);
$oDataTable->SetResultColumns($oCustomSettings->aColumns);
$oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams));
$oDataTable->SetFilter($oSet->GetFilter()->ToOQL(true));
$oDataTable->SetInitDisplayData(AjaxRenderController::GetDataForTable($oSet, $aClassAliases, $aColumnsToLoad, $sIdName, $aExtraParams, 1, true));
// row actions
if (isset($aExtraParams['row_actions'])) {
$oDataTable->SetRowActions($aExtraParams['row_actions']);
}
if (isset($aExtraParams['creation_in_modal_js_handler'])){
if (isset($aExtraParams['creation_in_modal_js_handler'])) {
$oDataTable->SetModalCreationHandler($aExtraParams['creation_in_modal_js_handler']);
}
return $oDataTable;
}

View File

@@ -51,6 +51,7 @@ class Navigation extends UIContentBlock
protected $iIdLast = 0;
protected $aList = [];
protected $sFilter;
protected $sBackUrl;
protected $sClass;
/**
@@ -61,16 +62,17 @@ 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 $sId = null)
public function __construct(string $sClass, int $iIdx, array $aList, string $sFilter, string $sBackUrl, ?string $sId = null)
{
parent::__construct($sId);
$this->iCount = count($aList);
if ( $this->iCount == 0) {
if ($this->iCount == 0) {
return new UIContentBlock();
}
$this->sClass = $sClass;
$this->aList = $aList;
$this->sFilter = $sFilter;
$this->sBackUrl = $sBackUrl;
$this->iIdx = $iIdx;
if ($this->iIdx>0) {
$this->iIdFirst = $aList[0];
@@ -100,39 +102,56 @@ class Navigation extends UIContentBlock
private function GetUrlFromId($iId)
{
$sUrl = iTopStandardURLMaker::MakeObjectURL($this->sClass, $iId).'&filter='.urlencode($this->sFilter);
$sUrl = iTopStandardURLMaker::MakeObjectURL($this->sClass, $iId);
return $sUrl;
}
/**
* @return int|mixed
* @return string
*/
public function GetUrlFirst()
public function GetUrlFirst(): string
{
return $this->GetUrlFromId( $this->iIdFirst);
return $this->GetUrlFromId($this->iIdFirst);
}
/**
* @return string
*/
public function GetUrlPrev(): string
{
return $this->GetUrlFromId($this->iIdPrev);
}
/**
* @return string
*/
public function GetUrlNext(): string
{
return $this->GetUrlFromId($this->iIdNext);
}
/**
* @return int|mixed
*/
public function GetUrlPrev()
public function GetUrlLast(): string
{
return $this->GetUrlFromId( $this->iIdPrev);
return $this->GetUrlFromId($this->iIdLast);
}
/**
* @return int|mixed
* @return string
*/
public function GetUrlNext()
public function GetBackUrl(): string
{
return $this->GetUrlFromId( $this->iIdNext);
return $this->sBackUrl;
}
/**
* @return int|mixed
* @return string
*/
public function GetUrlLast()
public function GetFilter(): string
{
return $this->GetUrlFromId( $this->iIdLast);
return $this->sFilter;
}
/**
@@ -143,11 +162,6 @@ class Navigation extends UIContentBlock
return json_encode($this->aList);
}
public function GetUrlSearch(){
$sAbsoluteUrl = utils::GetAbsoluteUrlAppRoot();
return "{$sAbsoluteUrl}pages/UI.php?operation=search&filter=".urlencode(urlencode('["'.$this->sFilter.'",[],[]]'));
}
/**
* @return bool
*/

View File

@@ -48,20 +48,19 @@ class NavigationUIBlockFactory extends AbstractUIBlockFactory
*
* @return \Combodo\iTop\Application\UI\Base\Component\Panel\Panel
*/
public static function MakeStandard( $oObject, string $sFilter, array $aList = [])
public static function MakeStandard($oObject, string $sFilter, array $aList = [], string $sBackUrl = '')
{
\IssueLog::Error('MakeStandard'.count($aList));
if ($sFilter != null && count($aList) === 0) {
$oFilter = DBObjectSearch::FromOQL($sFilter);
$oSet = new DBObjectSet($oFilter);
$aList = $oSet->GetColumnAsArray('id', false);
}
if(count($aList) === 0) {
if (count($aList) === 0) {
return null;
}
$iIdx = array_search($oObject->GetKey(), $aList);
$oNavigationBlock = new Navigation(get_class($oObject), $iIdx, $aList, $sFilter);
$oNavigationBlock = new Navigation(get_class($oObject), $iIdx, $aList, $sFilter, $sBackUrl);
return $oNavigationBlock;
}

View File

@@ -49,21 +49,22 @@ class PageContentFactory
/**
* Make a standard object details page with the form in the middle and the logs / activity in the side panel
*
* @param \DBObject $oObject
* @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view.
*
* @see cmdbAbstractObject::ENUM_DISPLAY_MODE_XXX
*
* @param string $sMode Mode the object is being displayed (view, edit, create, ...), default is view.
*
* @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 = [])
public static function MakeForObjectDetails(DBObject $oObject, string $sMode = cmdbAbstractObject::DEFAULT_DISPLAY_MODE, $sFilter = null, $aList = [], $sBackUrl = null)
{
$oLayout = new PageContentWithSideContent();
if ($sFilter != null) {
$oNavigationBlock = NavigationUIBlockFactory::MakeStandard($oObject, $sFilter, $aList);
$oNavigationBlock = NavigationUIBlockFactory::MakeStandard($oObject, $sFilter, $aList, $sBackUrl);
if ($oNavigationBlock != null) {
$oLayout->AddSubBlock($oNavigationBlock);
}

View File

@@ -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)
public static function GetDataForTable(DBObjectSet $oSet, array $aClassAliases, array $aColumnsLoad, string $sIdName = "", array $aExtraParams = [], int $iDrawNumber = 1, bool $bInBasket = false)
{
if (isset($aExtraParams['show_obsolete_data'])) {
$bShowObsoleteData = $aExtraParams['show_obsolete_data'];
@@ -72,7 +72,7 @@ class AjaxRenderController
$oSet->SetShowObsoleteData($bShowObsoleteData);
$aResult["draw"] = $iDrawNumber;
$aResult["recordsTotal"] = $oSet->Count();
$aResult["recordsFiltered"] = $aResult["recordsTotal"] ;
$aResult["recordsFiltered"] = $aResult["recordsTotal"];
$aResult["data"] = [];
while ($aObject = $oSet->FetchAssoc()) {
$aObj = [];
@@ -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, $oSet->GetFilter()->ToOQL(true));
$aObj[$sAlias."/hyperlink"] = $aObject[$sAlias]->GetHyperlink(null, true, null, false, $bInBasket);
$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
@@ -490,7 +490,7 @@ class AjaxRenderController
$oSet = new DBObjectSet($oFilter, $aOrderBy, $aQueryParams, null, $iEnd - $iStart, $iStart);
$oSet->OptimizeColumnLoad($aColumnsLoad);
return self::GetDataForTable($oSet, $aClassAliases, $aColumnsLoad, $sIdName, $aExtraParams, $iDrawNumber);
return self::GetDataForTable($oSet, $aClassAliases, $aColumnsLoad, $sIdName, $aExtraParams, $iDrawNumber, true);
}
/**

View File

@@ -1,9 +1,18 @@
{% if oUIBlock.GetOption("select_mode") is not empty %}
var oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = [];
{% if oUIBlock.GetOption("sSelectedRows") is not empty %}
oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = {{ oUIBlock.GetOption('sSelectedRows')|raw }};
{% endif %}
var oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = [];
{% if oUIBlock.GetOption("sSelectedRows") is not empty %}
oSelectedItems{{ oUIBlock.GetOption('sListId')|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = {{ oUIBlock.GetOption('sSelectedRows')|raw }};
{% endif %}
{% endif %}
var bSelectAllowed{{ oUIBlock.GetId()|sanitize(constant('utils::ENUM_SANITIZATION_FILTER_VARIABLE_NAME')) }} = false;
$('body').append($('<form/>')
.attr({'method': 'post', 'id': 'basket{{ oUIBlock.GetId() }}'})
.append($('<input/>')
.attr({'type': 'hidden', 'name': 'filter', 'value': "{{ oUIBlock.GetFilter()|raw }}"})
)
.append($('<input/>')
.attr({'type': 'hidden', 'name': 'back_url', 'value': window.location.href})
)
);

View File

@@ -108,14 +108,25 @@ var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({
// Disable hyperlinks if necessary
{% if oUIBlock.GetOption("disable_hyperlinks") is not same as false %}
$("#{{ oUIBlock.GetId() }} a").on('click', function (e) {
e.preventDefault();
});
e.preventDefault();
});
{% else %}
$('#{{ oUIBlock.GetId() }}_wrapper').find('.object-in-basket').on('click',
function () {
console.warn('ici');
sUrl = $(this).attr('data-href');
$('#basket{{ oUIBlock.GetId() }}').attr('action', sUrl);
$('#basket{{ oUIBlock.GetId() }}').submit();
}
);
{% endif %}
},
{% else %}
drawCallback: function (settings) {
if(settings.json)
if (settings.json)
{
$(this).closest('.ibo-panel').find('.ibo-datatable--result-count').html(settings.json.recordsTotal);
}
@@ -129,12 +140,25 @@ var oTable{{ sListIDForVarSuffix }} = $('#{{ oUIBlock.GetId() }}').DataTable({
{
$(this).closest('.dataTables_wrapper').find('.dataTables_paginate, .dataTables_info').show();
}
// Disable hyperlinks if necessary
{% if oUIBlock.GetOption("disable_hyperlinks") is same as true %}
$("#{{ oUIBlock.GetId() }} a").on('click', function (e) {
e.preventDefault();
});
{% else %}
$('#{{ oUIBlock.GetId() }}_wrapper').find('.object-in-basket').on('click',
function () {
console.warn('ici');
sUrl = $(this).attr('data-href');
$('#basket{{ oUIBlock.GetId() }}').attr('action', sUrl);
$('#basket{{ oUIBlock.GetId() }}').submit();
}
);
{% endif %}
},
{% endif %}
@@ -435,17 +459,19 @@ if ($('#datatable_dlg_{{ oUIBlock.GetId() }}').hasClass('itop-datatable'))
}
$('#datatable_dlg_{{ oUIBlock.GetId() }}').DataTableSettings(aOptions{{ sListIDForVarSuffix }});
if(window.ResizeObserver){
let oTable{{ sListIDForVarSuffix }}ResizeTimeout = null;
const oTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function(){
clearTimeout(oTable{{ sListIDForVarSuffix }}ResizeTimeout);
oTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function(){
$('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust();
}, 120);
});
oTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]);
if (window.ResizeObserver)
{
let oTable{{ sListIDForVarSuffix }}ResizeTimeout = null;
const oTable{{ sListIDForVarSuffix }}Resize = new ResizeObserver(function () {
clearTimeout(oTable{{ sListIDForVarSuffix }}ResizeTimeout);
oTable{{ sListIDForVarSuffix }}ResizeTimeout = setTimeout(function () {
$('#{{ oUIBlock.GetId() }}').DataTable().columns.adjust();
}, 120);
});
oTable{{ sListIDForVarSuffix }}Resize.observe($('#{{ oUIBlock.GetId() }}')[0]);
}
{% if oUIBlock.HasRowActions() %}
{% include 'base/components/datatable/row-actions/handler.js.twig' %}
{% endif %}
{% include 'base/components/datatable/row-actions/handler.js.twig' %}
{% endif %}
console.warn('ici-lala');

View File

@@ -5,10 +5,12 @@
{% block iboNavigation %}
<form id="ibo-form-navigation" class="ibo-navigation-form" method="post">
<input type="hidden" name="listNavigation" value="{{ oUIBlock.GetList() }}"/>
<input type="hidden" name="filter" value="{{ oUIBlock.GetFilter() }}"/>
<input type="hidden" name="back-url" value="{{ oUIBlock.GetBackUrl()|raw }}"/>
<div class="ibo-form-navigation--nav fas fa-angle-up" id="{{ oUIBlock.GetId() }}-back"></div>
{% if oUIBlock.HasPrec() %}
<div class="ibo-form-navigation--nav fas fa-angle-double-left" id="{{ oUIBlock.GetId() }}-first"></div>
<div class="ibo-form-navigation--nav fas fa-angle-left" id="{{oUIBlock.GetId() }}-prev"></div>
<div class="ibo-form-navigation--nav fas fa-angle-left" id="{{ oUIBlock.GetId() }}-prev"></div>
{% else %}
&#160;&#160;&#160;
{% endif %}

View File

@@ -1,16 +1,16 @@
{# @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.GetUrlSearch()|raw }}';
$('#{{ oUIBlock.GetId() }}-back').on('click', function () {
window.location = '{{ oUIBlock.GetBackUrl()|raw }}';
});
$('#{{ oUIBlock.GetId() }}-first').on('click', function() {
$('#ibo-form-navigation').attr('action', ' {{ oUIBlock.GetUrlFirst() | raw}} ');
$('#{{ oUIBlock.GetId() }}-first').on('click', function () {
$('#ibo-form-navigation').attr('action', ' {{ oUIBlock.GetUrlFirst() | raw }} ');
$('#ibo-form-navigation').submit();
});
$('#{{ oUIBlock.GetId() }}-prev').on('click', function() {
$('#{{ oUIBlock.GetId() }}-prev').on('click', function () {
$('#ibo-form-navigation').attr('action', ' {{ oUIBlock.GetUrlPrev()| raw }} ');
$('#ibo-form-navigation').submit();
});