mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 15:22:17 +02:00
N°902.2 Portal: Add support for columns sorting in BrowseBrick's "lazy" mode
(And start refactoring in ManageBrick)
This commit is contained in:
@@ -359,9 +359,16 @@ class BrowseBrickController extends BrickController
|
|||||||
}
|
}
|
||||||
$oSet->OptimizeColumnLoad($aColumnAttrs);
|
$oSet->OptimizeColumnLoad($aColumnAttrs);
|
||||||
|
|
||||||
// Sorting objects through defined order (in DM)
|
// Setting specified column sort, setting default datamodel one otherwise
|
||||||
$oSet->SetOrderByClasses();
|
$aSortedParams = $this->ExtractSortParams();
|
||||||
|
if (!empty($aSortedParams))
|
||||||
|
{
|
||||||
|
$oSet->SetOrderBy($aSortedParams);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$oSet->SetOrderByClasses();
|
||||||
|
}
|
||||||
// Retrieving results and organizing them for templating
|
// Retrieving results and organizing them for templating
|
||||||
$aItems = array();
|
$aItems = array();
|
||||||
while ($aCurrentRow = $oSet->FetchAssoc())
|
while ($aCurrentRow = $oSet->FetchAssoc())
|
||||||
@@ -423,4 +430,28 @@ class BrowseBrickController extends BrickController
|
|||||||
|
|
||||||
return $oResponse;
|
return $oResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract sort params from request and convert them to iTop OQL format
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*
|
||||||
|
* @since 2.7.0
|
||||||
|
*/
|
||||||
|
protected function ExtractSortParams()
|
||||||
|
{
|
||||||
|
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
|
||||||
|
$oRequestManipulator = $this->get('request_manipulator');
|
||||||
|
|
||||||
|
// Getting sort params
|
||||||
|
$aSortParams = $oRequestManipulator->ReadParam('aSortParams', array());
|
||||||
|
|
||||||
|
// Converting sort direction to proper format for DBObjectSet as it only accept real booleans
|
||||||
|
foreach ($aSortParams as $sAttributeAlias => $sDirection)
|
||||||
|
{
|
||||||
|
$aSortParams[$sAttributeAlias] = ($sDirection === 'true');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $aSortParams;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -881,31 +881,25 @@ class ManageBrickController extends BrickController
|
|||||||
/**
|
/**
|
||||||
* Extract sort params from request and convert them to iTop OQL format
|
* Extract sort params from request and convert them to iTop OQL format
|
||||||
*
|
*
|
||||||
* @param array $aColumnsAttrs
|
|
||||||
*
|
|
||||||
* @return array
|
* @return array
|
||||||
*
|
*
|
||||||
* @since 2.7.0
|
* @since 2.7.0
|
||||||
*/
|
*/
|
||||||
protected function ExtractSortParams($aColumnsAttrs = array())
|
protected function ExtractSortParams()
|
||||||
{
|
{
|
||||||
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
|
/** @var \Combodo\iTop\Portal\Helper\RequestManipulatorHelper $oRequestManipulator */
|
||||||
$oRequestManipulator = $this->get('request_manipulator');
|
$oRequestManipulator = $this->get('request_manipulator');
|
||||||
|
|
||||||
// Getting sort params
|
// Getting sort params
|
||||||
$aSortParams = $oRequestManipulator->ReadParam('aSortParams', array());
|
$aSortParams = $oRequestManipulator->ReadParam('aSortParams', array());
|
||||||
$aFormattedSortParams = array();
|
|
||||||
|
|
||||||
// - Adding possible multiple sort params on displayed columns
|
// Converting sort direction to proper format for DBObjectSet as it only accept real booleans
|
||||||
foreach ($aSortParams as $sKey => $aSortParam)
|
foreach ($aSortParams as $sAttributeAlias => $sDirection)
|
||||||
{
|
{
|
||||||
if (array_key_exists($aSortParam['column'], $aColumnsAttrs))
|
$aSortParams[$sAttributeAlias] = ($sDirection === 'true');
|
||||||
{
|
|
||||||
$aFormattedSortParams[$aColumnsAttrs[$aSortParam['column']]] = ($aSortParam['dir'] === 'asc');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $aFormattedSortParams;
|
return $aSortParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,7 +39,7 @@
|
|||||||
aColumnsDefinition.push({
|
aColumnsDefinition.push({
|
||||||
"width": "auto",
|
"width": "auto",
|
||||||
"searchable": true,
|
"searchable": true,
|
||||||
"sortable": (sDataLoading === '{{ constant('Combodo\\iTop\\Portal\\Brick\\AbstractBrick::ENUM_DATA_LOADING_FULL') }}'),
|
"sortable": true,
|
||||||
"title": oLevelsProperties[sKey].title,
|
"title": oLevelsProperties[sKey].title,
|
||||||
"defaultContent": "",
|
"defaultContent": "",
|
||||||
"type": "html",
|
"type": "html",
|
||||||
@@ -182,7 +182,7 @@
|
|||||||
aColumnsDefinition.push({
|
aColumnsDefinition.push({
|
||||||
"width": "auto",
|
"width": "auto",
|
||||||
"searchable": true,
|
"searchable": true,
|
||||||
"sortable": false,
|
"sortable": true,
|
||||||
"visible": !oLevelsProperties[sKey].fields[i].hidden,
|
"visible": !oLevelsProperties[sKey].fields[i].hidden,
|
||||||
"title": oLevelsProperties[sKey].fields[i].label,
|
"title": oLevelsProperties[sKey].fields[i].label,
|
||||||
"defaultContent": "",
|
"defaultContent": "",
|
||||||
@@ -252,8 +252,28 @@
|
|||||||
d.iPageNumber = Math.floor(d.start / d.length)+1;
|
d.iPageNumber = Math.floor(d.start / d.length)+1;
|
||||||
d.iListLength = d.length;
|
d.iListLength = d.length;
|
||||||
d.sDataLoading = "{{ constant('Combodo\\iTop\\Portal\\Brick\\AbstractBrick::ENUM_DATA_LOADING_LAZY') }}";
|
d.sDataLoading = "{{ constant('Combodo\\iTop\\Portal\\Brick\\AbstractBrick::ENUM_DATA_LOADING_LAZY') }}";
|
||||||
d.columns = null;
|
|
||||||
d.orders = null;
|
// Prepare sort params (formatting them for direct use by DBObjectSet)
|
||||||
|
d.aSortParams = {};
|
||||||
|
for (var iSortIdx in d.order) {
|
||||||
|
/* oSortedColumnData {column: index, dir: 'asc'|'desc'} */
|
||||||
|
var oSortedColumnData = d.order[iSortIdx];
|
||||||
|
/* sSortedColumnId (eg. 'L-1-1' for level's main column, or 'L-1-1.fields.ATTCODE' for other columns) */
|
||||||
|
var sSortedColumnId = d.columns[oSortedColumnData.column].data;
|
||||||
|
|
||||||
|
// Make proper attribute alias for OQL from column ID
|
||||||
|
// - Main level column (we have to retrieve the attcode from the level properties)
|
||||||
|
if (sSortedColumnId.indexOf('.fields') < 0) {
|
||||||
|
var sSortedAttributeAlias = sSortedColumnId+'.'+oLevelsProperties[sSortedColumnId].name_att;
|
||||||
|
}
|
||||||
|
// - Optional fields (attcode is already in the column ID, we just have to clean it)
|
||||||
|
else {
|
||||||
|
var sSortedAttributeAlias = sSortedColumnId.replace('.fields', '');
|
||||||
|
}
|
||||||
|
|
||||||
|
d.aSortParams[sSortedAttributeAlias] = (oSortedColumnData.dir === 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (d.search.value)
|
if (d.search.value)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -294,7 +294,20 @@
|
|||||||
"data": function (d) {
|
"data": function (d) {
|
||||||
d.iPageNumber = Math.floor(d.start / d.length) + 1;
|
d.iPageNumber = Math.floor(d.start / d.length) + 1;
|
||||||
d.iListLength = d.length;
|
d.iListLength = d.length;
|
||||||
d.aSortParams = d.order;
|
|
||||||
|
// Prepare sort params (formatting them for direct use by DBObjectSet)
|
||||||
|
d.aSortParams = {};
|
||||||
|
for (var iSortIdx in d.order) {
|
||||||
|
/* oSortedColumnData {column: index, dir: 'asc'|'desc'} */
|
||||||
|
var oSortedColumnData = d.order[iSortIdx];
|
||||||
|
/* sSortedColumnId (eg. 'attributes.ATT_CODE.att_code') */
|
||||||
|
var sSortedColumnId = d.columns[oSortedColumnData.column].data;
|
||||||
|
|
||||||
|
// Make proper attribute alias for OQL from column ID
|
||||||
|
sSortedColumnId = sSortedColumnId.replace(/^attributes\./, '').replace(/\.att_code$/, '');
|
||||||
|
|
||||||
|
d.aSortParams[sSortedColumnId] = (oSortedColumnData.dir === 'asc');
|
||||||
|
}
|
||||||
|
|
||||||
{% if sSearchValue is not null %}
|
{% if sSearchValue is not null %}
|
||||||
// Sets default filter value
|
// Sets default filter value
|
||||||
|
|||||||
Reference in New Issue
Block a user