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

@@ -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);
}
/**