N°3648 - FIx size of DataTable

This commit is contained in:
acognet
2021-03-11 10:30:34 +01:00
parent 710e6e49a8
commit fe5d5f3869
7 changed files with 182 additions and 76 deletions

View File

@@ -1,20 +1,7 @@
<?php
/**
* Copyright (C) 2013-2020 Combodo SARL
*
* This file is part of iTop.
*
* iTop is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* iTop is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
use Combodo\iTop\Application\Search\SearchForm;
@@ -2450,13 +2437,8 @@ JS
// So any consumer that want to get this attribute value MUST use `.attr()` and not `.data()`
// Actually the later uses a dedicated memory (that is initialized by the DOM values on page loading)
// Whereas `.attr()` uses the DOM directly
$sHTMLValue .= <<<HTML
<script>
$("[data-input-id='$iId']").attr("data-input-type", "$sInputType");
</script>
HTML;
$oPage->add_init_script('$("[data-input-id=\''.$iId.'\']").attr("data-input-type", "'.$sInputType.'");');
}
//TODO 3.0 remove the data-attcode attribute (either because it's has been moved to .field_container in 2.7 or even better because the admin. console has been reworked)
return "<div id=\"field_{$iId}\" class=\"field_value_container\"><div class=\"attribute-edit\" data-attcode=\"$sAttCode\">{$sHTMLValue}</div></div>";
}

View File

@@ -1,26 +1,6 @@
<?php
// Copyright (C) 2010-2017 Combodo SARL
//
// This file is part of iTop.
//
// iTop is free software; you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// iTop is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with iTop. If not, see <http://www.gnu.org/licenses/>
/**
* Class UILinksWidget
*
* @copyright Copyright (C) 2010-2017 Combodo SARL
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -563,18 +543,44 @@ JS
$aLinkedObjectIds = utils::ReadMultipleSelection($oFullSetFilter);
$iAdditionId = $iMaxAddedId + 1;
foreach($aLinkedObjectIds as $iObjectId)
{
foreach ($aLinkedObjectIds as $iObjectId) {
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $iObjectId, false);
if (is_object($oLinkedObj))
{
if (is_object($oLinkedObj)) {
$aRow = $this->GetFormRow($oP, $oLinkedObj, $iObjectId, array(), $oCurrentObj, $iAdditionId); // Not yet created link get negative Ids
$oRow = new FormTableRow("{$this->m_sAttCode}{$this->m_sNameSuffix}", $this->m_aTableConfig, $aRow, -$iAdditionId);
$oP->AddUiBlock($oRow);
$iAdditionId++;
} else {
$oP->p(Dict::Format('UI:Error:Object_Class_Id_NotFound', $this->m_sLinkedClass, $iObjectId));
}
else
{
}
}
/**
* @param WebPage $oP
* @param int $iMaxAddedId
* @param $oFullSetFilter
* @param DBObject $oCurrentObj
*
* @throws \ArchivedObjectException
* @throws \CoreException
*/
public function DoAddIndirectLinks(JsonPage $oP, $iMaxAddedId, $oFullSetFilter, $oCurrentObj)
{
$aLinkedObjectIds = utils::ReadMultipleSelection($oFullSetFilter);
$iAdditionId = $iMaxAddedId + 1;
foreach ($aLinkedObjectIds as $iObjectId) {
$oLinkedObj = MetaModel::GetObject($this->m_sRemoteClass, $iObjectId, false);
if (is_object($oLinkedObj)) {
$aRow = $this->GetFormRow($oP, $oLinkedObj, $iObjectId, array(), $oCurrentObj, $iAdditionId); // Not yet created link get negative Ids
$aData = [];
foreach ($aRow as $item) {
$aData[] = $item;
}
$oP->AddData($aData);
$iAdditionId++;
} else {
$oP->p(Dict::Format('UI:Error:Object_Class_Id_NotFound', $this->m_sLinkedClass, $iObjectId));
}
}

View File

@@ -466,6 +466,7 @@ return array(
'ItopCounter' => $baseDir . '/core/counter.class.inc.php',
'JSButtonItem' => $baseDir . '/application/applicationextension.inc.php',
'JSPopupMenuItem' => $baseDir . '/application/applicationextension.inc.php',
'JsonPage' => $baseDir . '/sources/application/WebPage/JsonPage.php',
'KeyValueStore' => $baseDir . '/core/counter.class.inc.php',
'ListExpression' => $baseDir . '/core/oql/expression.class.inc.php',
'ListOqlExpression' => $baseDir . '/core/oql/oqlquery.class.inc.php',

View File

@@ -696,6 +696,7 @@ class ComposerStaticInit0018331147de7601e7552f7da8e3bb8b
'ItopCounter' => __DIR__ . '/../..' . '/core/counter.class.inc.php',
'JSButtonItem' => __DIR__ . '/../..' . '/application/applicationextension.inc.php',
'JSPopupMenuItem' => __DIR__ . '/../..' . '/application/applicationextension.inc.php',
'JsonPage' => __DIR__ . '/../..' . '/sources/application/WebPage/JsonPage.php',
'KeyValueStore' => __DIR__ . '/../..' . '/core/counter.class.inc.php',
'ListExpression' => __DIR__ . '/../..' . '/core/oql/expression.class.inc.php',
'ListOqlExpression' => __DIR__ . '/../..' . '/core/oql/oqlquery.class.inc.php',

View File

@@ -508,30 +508,14 @@ try
// ui.linkswidget
case 'doAddObjects':
$oPage->SetContentType('text/html');
$sAttCode = utils::ReadParam('sAttCode', '');
$iInputId = utils::ReadParam('iInputId', '');
$sSuffix = utils::ReadParam('sSuffix', '');
$sRemoteClass = utils::ReadParam('sRemoteClass', $sClass, false, 'class');
$bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
$sJson = utils::ReadParam('json', '', false, 'raw_data');
$iMaxAddedId = utils::ReadParam('max_added_id');
$oWizardHelper = WizardHelper::FromJSON($sJson);
/** @var \DBObject $oObj */
$oObj = $oWizardHelper->GetTargetObject();
$oKPI = new ExecutionKPI();
$oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
if ($sFilter != '')
{
$oFullSetFilter = DBObjectSearch::unserialize($sFilter);
}
else
{
$oFullSetFilter = new DBObjectSearch($sRemoteClass);
}
$oWidget->DoAddObjects($oPage, $iMaxAddedId, $oFullSetFilter, $oObj);
$oKPI->ComputeAndReport('Data write');
$sResult = AjaxRenderController::DoAddObjects($oPage, $sClass, $sFilter);
break;
// ui.linkswidget
case 'doAddIndirectLinks':
$oPage = new JsonPage('');
$sResult = AjaxRenderController::DoAddIndirectLinks($oPage, $sClass, $sFilter);
break;
////////////////////////////////////////////////////////////
/// WizardHelper : see the corresponding PHP class, and JS class

View File

@@ -1,6 +1,6 @@
<?php
/**
* @copyright Copyright (C) 2010-2020 Combodo SARL
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
@@ -15,10 +15,8 @@ use BulkExport;
use BulkExportException;
use CMDBObjectSet;
use CMDBSource;
use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableSettings;
use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\ActivityPanel\ActivityEntry\ActivityEntryFactory;
use Combodo\iTop\Application\UI\Base\Layout\ActivityPanel\ActivityPanelHelper;
use Combodo\iTop\Renderer\BlockRenderer;
use DBObjectSearch;
use DBObjectSet;
@@ -28,9 +26,12 @@ use Exception;
use ExecutionKPI;
use Expression;
use InlineImage;
use JsonPage;
use MetaModel;
use ScalarExpression;
use UILinksWidget;
use utils;
use WizardHelper;
class AjaxRenderController
{
@@ -625,6 +626,16 @@ class AjaxRenderController
return $aResult;
}
/**
* @param string $sFilter
*
* @return array
* @throws \CoreException
* @throws \MissingQueryArgument
* @throws \MySQLException
* @throws \MySQLHasGoneAwayException
* @throws \OQLException
*/
public static function RefreshCount(string $sFilter): array
{
$aExtraParams = utils::ReadParam('extra_params', '', false, 'raw_data');
@@ -637,5 +648,65 @@ class AjaxRenderController
return $aResult;
}
/**
* @param string $sFilter
*
* @return string
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \OQLException
*/
public static function DoAddObjects(AjaxPage $oPage, string $sClass, string $sFilter)
{
$sAttCode = utils::ReadParam('sAttCode', '');
$iInputId = utils::ReadParam('iInputId', '');
$sSuffix = utils::ReadParam('sSuffix', '');
$sRemoteClass = utils::ReadParam('sRemoteClass', $sClass, false, 'class');
$bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
$sJson = utils::ReadParam('json', '', false, 'raw_data');
$iMaxAddedId = utils::ReadParam('max_added_id');
$oWizardHelper = WizardHelper::FromJSON($sJson);
/** @var \DBObject $oObj */
$oObj = $oWizardHelper->GetTargetObject();
$oKPI = new ExecutionKPI();
$oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
if ($sFilter != '') {
$oFullSetFilter = DBObjectSearch::unserialize($sFilter);
} else {
$oFullSetFilter = new DBObjectSearch($sRemoteClass);
}
$oWidget->DoAddObjects($oPage, $iMaxAddedId, $oFullSetFilter, $oObj);
$oKPI->ComputeAndReport('Data write');
}
/**
* @param string $sFilter
*
* @return string
* @throws \ArchivedObjectException
* @throws \CoreException
* @throws \OQLException
*/
public static function DoAddIndirectLinks(JsonPage $oPage, string $sClass, string $sFilter)
{
$sAttCode = utils::ReadParam('sAttCode', '');
$iInputId = utils::ReadParam('iInputId', '');
$sSuffix = utils::ReadParam('sSuffix', '');
$sRemoteClass = utils::ReadParam('sRemoteClass', $sClass, false, 'class');
$bDuplicates = (utils::ReadParam('bDuplicates', 'false') == 'false') ? false : true;
$sJson = utils::ReadParam('json', '', false, 'raw_data');
$iMaxAddedId = utils::ReadParam('max_added_id');
$oWizardHelper = WizardHelper::FromJSON($sJson);
/** @var \DBObject $oObj */
$oObj = $oWizardHelper->GetTargetObject();
$oKPI = new ExecutionKPI();
$oWidget = new UILinksWidget($sClass, $sAttCode, $iInputId, $sSuffix, $bDuplicates);
if ($sFilter != '') {
$oFullSetFilter = DBObjectSearch::unserialize($sFilter);
} else {
$oFullSetFilter = new DBObjectSearch($sRemoteClass);
}
$oWidget->DoAddIndirectLinks($oPage, $iMaxAddedId, $oFullSetFilter, $oObj);
$oKPI->ComputeAndReport('Data write');
}
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* @copyright Copyright (C) 2010-2021 Combodo SARL
* @license http://opensource.org/licenses/AGPL-3.0
*/
class JsonPage extends WebPage
{
protected $aData = [];
/**
* @return array
*/
public function GetData(): array
{
return $this->aData;
}
/**
* @param array $aData
*
* @return $this
*/
public function SetData(array $aData)
{
$this->aData = $aData;
return $this;
}
/**
* @param array $aDataRow
*
* @return $this
*/
public function AddData(array $aDataRow)
{
$this->aData[] = $aDataRow;
return $this;
}
public function output()
{
$this->add_header('Content-type: application/json');
foreach ($this->a_headers as $s_header) {
header($s_header);
}
$aScripts = array_merge($this->a_init_scripts, $this->a_scripts, $this->a_ready_scripts);
$aJson = [
'data' => $this->aData,
'scripts' => $aScripts,
];
echo json_encode($aJson);
}
}