mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 18:48:51 +02:00
N°2598 - When refreshing a list, loosing page and order - change of dashboard refresh mecanism
This commit is contained in:
@@ -275,4 +275,9 @@ class Alert extends UIContentBlock
|
||||
{
|
||||
return $this->sSectionStateStorageKey;
|
||||
}
|
||||
|
||||
public function GetJSRefresh(): string
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,8 @@ class DashletBadge extends DashletContainer
|
||||
protected $sCreateActionUrl;
|
||||
/** @var string */
|
||||
protected $sCreateActionLabel;
|
||||
/** @var array */
|
||||
protected $aRefreshParams;
|
||||
|
||||
/**
|
||||
* DashletBadge constructor.
|
||||
@@ -41,7 +43,7 @@ class DashletBadge extends DashletContainer
|
||||
* @param string $sCreateActionUrl
|
||||
* @param string $sCreateActionLabel
|
||||
*/
|
||||
public function __construct(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '')
|
||||
public function __construct(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '', array $aRefreshParams)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
@@ -51,6 +53,7 @@ class DashletBadge extends DashletContainer
|
||||
$this->sClassLabel = $sClassLabel;
|
||||
$this->sCreateActionUrl = $sCreateActionUrl;
|
||||
$this->sCreateActionLabel = $sCreateActionLabel;
|
||||
$this->aRefreshParams = $aRefreshParams;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,8 +168,21 @@ class DashletBadge extends DashletContainer
|
||||
public function SetClassLabel(string $sClassLabel): DashletBadge
|
||||
{
|
||||
$this->sClassLabel = $sClassLabel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function GetJSRefresh(): string
|
||||
{
|
||||
return "$('#".$this->sId."').block();
|
||||
$.post('ajax.render.php?operation=refreshDashletCount&style=count',
|
||||
".json_encode($this->aRefreshParams).",
|
||||
function(data){
|
||||
$('#".$this->sId."').find('.ibo-dashlet-badge--action-list-count').html(data.count);
|
||||
$('#".$this->sId."').unblock();
|
||||
});
|
||||
|
||||
$('#".$this->sId."').unblock();";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,9 +9,11 @@ namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\tJSRefreshCallback;
|
||||
|
||||
class DashletContainer extends UIContentBlock
|
||||
{
|
||||
use tJSRefreshCallback;
|
||||
public const BLOCK_CODE = 'ibo-dashlet';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/layouts/content-block/layout';
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ namespace Combodo\iTop\Application\UI\Base\Component\Dashlet;
|
||||
|
||||
class DashletFactory
|
||||
{
|
||||
public static function MakeForDashletBadge(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '')
|
||||
public static function MakeForDashletBadge(string $sClassIconUrl, string $sHyperlink, string $iCount, string $sClassLabel, string $sCreateActionUrl = '', string $sCreateActionLabel = '', array $aRefreshParams = [])
|
||||
{
|
||||
return new DashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel);
|
||||
return new DashletBadge($sClassIconUrl, $sHyperlink, $iCount, $sClassLabel, $sCreateActionUrl, $sCreateActionLabel, $aRefreshParams);
|
||||
}
|
||||
|
||||
public static function MakeForDashletHeaderStatic(string $sTitle, string $sIconUrl)
|
||||
|
||||
@@ -37,7 +37,7 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
|
||||
{
|
||||
public const TWIG_TAG_NAME = 'UIDataTable';
|
||||
public const UI_BLOCK_CLASS_NAME = DataTable::class;
|
||||
|
||||
|
||||
/**
|
||||
* @param \WebPage $oPage
|
||||
* @param string $sListId
|
||||
@@ -267,6 +267,12 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
|
||||
$oSet->SetLimit($oCustomSettings->iDefaultPageSize);
|
||||
}
|
||||
|
||||
if (sizeof($oCustomSettings->aColumns) == 0)
|
||||
{
|
||||
$oCustomSettings->aColumns = $oDefaultSettings->aColumns;
|
||||
$oCustomSettings->aSortOrder = $oDefaultSettings->aSortOrder;
|
||||
}
|
||||
|
||||
// Load only the requested columns
|
||||
$aColumnsToLoad = array();
|
||||
foreach ($oCustomSettings->aColumns as $sAlias => $aColumnsInfo) {
|
||||
@@ -746,24 +752,28 @@ class DataTableUIBlockFactory extends AbstractUIBlockFactory
|
||||
return $aOptions;
|
||||
}
|
||||
|
||||
public static function MakeForStaticData(string $sTitle, array $aColumns, array $aData, ?string $sId = null)
|
||||
public static function MakeForStaticData(string $sTitle, array $aColumns, array $aData, ?string $sId = null, array $aExtraParams = [],
|
||||
string $sFilter = "")
|
||||
{
|
||||
$oBlock = new UIContentBlock();
|
||||
$oTitle = TitleUIBlockFactory::MakeNeutral($sTitle, 3);
|
||||
$oBlock->AddSubBlock($oTitle);
|
||||
$oTable = new StaticTable($sId);
|
||||
$oTable = new StaticTable($sId, [], $aExtraParams);
|
||||
$oTable->SetColumns($aColumns);
|
||||
$oTable->SetData($aData);
|
||||
$oTable->SetFilter($sFilter);
|
||||
|
||||
$oBlock->AddSubBlock($oTable);
|
||||
|
||||
return $oBlock;
|
||||
}
|
||||
|
||||
public static function MakeForForm(string $sRef, array $aColumns, array $aData = []): FormTable
|
||||
public static function MakeForForm(string $sRef, array $aColumns, array $aData = [], string $sFilter= ''): FormTable
|
||||
{
|
||||
$oTable = new FormTable("datatable_".$sRef);
|
||||
$oTable->SetRef($sRef);
|
||||
$oTable->SetColumns($aColumns);
|
||||
$oTable->SetFilter($sFilter);
|
||||
|
||||
foreach ($aData as $iRowId => $aRow) {
|
||||
$oRow = new FormTableRow($sRef, $aColumns, $aRow, $iRowId);
|
||||
|
||||
@@ -19,7 +19,6 @@ class FormTableRow extends UIBlock
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-formtablerow';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtablerow/layout';
|
||||
public const DEFAULT_JS_TEMPLATE_REL_PATH = 'base/components/datatable/static/formtablerow/layout';
|
||||
|
||||
/** @var string */
|
||||
private $sRef;
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace Combodo\iTop\Application\UI\Base\Component\DataTable\StaticTable;
|
||||
|
||||
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
use Combodo\iTop\Application\UI\Base\tJSRefreshCallback;
|
||||
use utils;
|
||||
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2020 Combodo SARL
|
||||
@@ -15,6 +17,8 @@ use Combodo\iTop\Application\UI\Base\Layout\UIContentBlock;
|
||||
*/
|
||||
class StaticTable extends UIContentBlock
|
||||
{
|
||||
use tJSRefreshCallback;
|
||||
|
||||
// Overloaded constants
|
||||
public const BLOCK_CODE = 'ibo-datatable';
|
||||
public const DEFAULT_HTML_TEMPLATE_REL_PATH = 'base/components/datatable/static/layout';
|
||||
@@ -51,12 +55,16 @@ class StaticTable extends UIContentBlock
|
||||
* ]
|
||||
*/
|
||||
private $aData;
|
||||
private $aExtraParams;
|
||||
/*@var string $sUrlForRefresh*/
|
||||
private $sFilter;
|
||||
|
||||
public function __construct(string $sId = null, array $aContainerCSSClasses = [])
|
||||
public function __construct(string $sId = null, array $aContainerCSSClasses = [], array $aExtraParams = [])
|
||||
{
|
||||
parent::__construct($sId, $aContainerCSSClasses);
|
||||
$this->aColumns = [];
|
||||
$this->aData = [];
|
||||
$this->aExtraParams = $aExtraParams;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,4 +99,27 @@ class StaticTable extends UIContentBlock
|
||||
$this->aData = $aData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $sUrlForRefresh
|
||||
*/
|
||||
public function SetFilter($sFilter): void
|
||||
{
|
||||
$this->sFilter = $sFilter;
|
||||
}
|
||||
|
||||
public function GetJSRefresh(): string
|
||||
{
|
||||
//$('#".$this->sId."').DataTable().clear().rows.add(data).draw()
|
||||
$aParams = [
|
||||
'style' => 'list',
|
||||
'filter' => $this->sFilter,
|
||||
'extra_params' => $this->aExtraParams,
|
||||
];
|
||||
|
||||
return "$.post('".utils::GetAbsoluteUrlAppRoot()."pages/ajax.render.php?operation=refreshDashletList', ".json_encode($aParams).",
|
||||
function (data) {
|
||||
$('#".$this->sId."').DataTable().clear();
|
||||
$('#".$this->sId."').dataTable().fnAddData(data);
|
||||
});";
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,8 @@ class Panel extends UIContentBlock
|
||||
*
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function GetSubBlocks(): array {
|
||||
public function GetSubBlocks(): array
|
||||
{
|
||||
$aSubBlocks = [];
|
||||
foreach ($this->GetContentAreas() as $oContentArea) {
|
||||
$aSubBlocks = array_merge($aSubBlocks, $oContentArea->GetSubBlocks());
|
||||
@@ -353,4 +354,9 @@ class Panel extends UIContentBlock
|
||||
|
||||
return $aSubBlocks;
|
||||
}
|
||||
|
||||
public function GetJSRefresh(): string
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user