diff --git a/application/displayblock.class.inc.php b/application/displayblock.class.inc.php index c6ff1f1eb..5dfdc5a5d 100644 --- a/application/displayblock.class.inc.php +++ b/application/displayblock.class.inc.php @@ -58,17 +58,23 @@ class DisplayBlock * @param \DBSearch $oFilter list of cmdbObjects to be displayed into the block * @param string $sStyle one of : * * @param bool $bAsynchronous * @param array $aParams * @param \DBObjectSet $oSet + * + * @throws \ApplicationException */ public function __construct(DBSearch $oFilter, $sStyle = 'list', $bAsynchronous = false, $aParams = array(), $oSet = null) { @@ -88,6 +94,116 @@ class DisplayBlock $this->m_bShowObsoleteData = utils::ShowObsoleteData(); } } + + /** + * @param string $sStyle + * + * @return string[] + */ + protected function GetAllowedParams(string $sStyle): array + { + $aAllowedParams = [ + 'actions' => [ + 'context_filter', /** int if != 0 filter with user context */ + ], + 'chart' => [ + 'chart_type', /** string 'pie' or 'bars' */ + 'group_by', /** string group by att code */ + 'group_by_expr', /** string group by expression */ + 'group_by_label', /** string aggregation column name */ + 'aggregation_function', /** string aggregation function ('count', 'sum', 'avg', 'min', 'max', ...) */ + 'aggregation_attribute', /** string att code used for aggregation */ + 'limit', /** int limit the chart results */ + 'order_by', /** string either 'attribute' group_by attcode or 'function' aggregation_function value */ + 'order_direction', /** string order direction 'asc' or 'desc' */ + 'chart_title', /** string title */ + ], + 'chart_ajax' => [ + 'chart_type', /** string 'pie' or 'bars' */ + 'group_by', /** string group by att code */ + 'group_by_expr', /** string group by expression */ + 'group_by_label', /** string aggregation column name */ + 'aggregation_function', /** string aggregation function ('count', 'sum', 'avg', 'min', 'max', ...) */ + 'aggregation_attribute', /** string att code used for aggregation */ + 'limit', /** int limit the chart results */ + 'order_by', /** string either 'attribute' group_by attcode or 'function' aggregation_function value */ + 'order_direction', /** string order direction 'asc' or 'desc' */ + ], + 'count' => [ + 'group_by', /** string group by att code */ + 'group_by_expr', /** string group by expression */ + 'group_by_label', /** string aggregation column name */ + 'aggregation_function', /** string aggregation function ('count', 'sum', 'avg', 'min', 'max', ...) */ + 'aggregation_attribute', /** string att code used for aggregation */ + 'limit', /** int limit the chart results */ + 'order_by', /** string either 'attribute' group_by attcode or 'function' aggregation_function value */ + 'order_direction', /** string order direction 'asc' or 'desc' */ + ], + 'csv' => [], + 'join' => array_merge([ + 'display_aliases', /** string comma separated list of class aliases to display */ + 'group_by', /** string group by att code */ + ], DataTableFactory::GetAllowedParams()), + 'links' => DataTableFactory::GetAllowedParams(), + 'list' => array_merge([ + 'update_history', /** bool add breadcrumb entry */ + ], DataTableFactory::GetAllowedParams()), + 'list_search' => array_merge([ + 'update_history', /** bool add breadcrumb entry */ + ], DataTableFactory::GetAllowedParams()), + 'search' => array_merge([ + 'baseClass', /** string search root class */ + 'open', /** bool open the search panel by default */ + 'result_list_outer_selector', /** string js selector of the search result display */ + 'search_header_force_dropdown', /** string Search class selection dropdown html code */ + 'action', /** string search URL */ + 'table_inner_id', /** string html id of the results table */ + ], DataTableFactory::GetAllowedParams()), + 'summary' => [ + 'status[block]', /** string object 'status' att code */ + 'status_codes[block]', /** string comma separated list of object states */ + 'title[block]', /** string title */ + 'label[block]', /** string label */ + 'context_filter', /** int if != 0 filter with user context */ + ], + ]; + + $aAllowedGeneralParams = [ + 'show_obsolete_data', /** bool display obsolete data */ + 'currentId', /** string current block id overridden by $sId argument */ + 'query_params', /** array query parameters */ + 'this->id', /** int Id of the current object */ + 'this->class', /** string class of the current object */ + 'order_by', /** string comma separated list of attCodes */ + 'auto_reload', /** bool|string|numeric 'fast' (reload faster) or 'standard' (= true or 'true') (reload standard) or reload interval value (numeric) */ + 'c[menu]', /** string current navigation menu */ + 'c[org_id]', /** int current filtered organization */ + 'dashboard_div_id', /** string dashboard html div id */ + ]; + + if (isset($aAllowedParams[$sStyle])) { + return array_merge($aAllowedGeneralParams, $aAllowedParams[$sStyle]); + } + + return $aAllowedGeneralParams; + } + + /** + * @param string $sStyle + * @param array $aParams + * + * @throws \ApplicationException + */ + protected function CheckParams(string $sStyle, array $aParams) + { + $aAllowedParams = $this->GetAllowedParams($sStyle); + + foreach (array_keys($aParams) as $sParamName) { + if (!in_array($sParamName, $aAllowedParams)) { + throw new ApplicationException("Unknown parameter $sParamName for DisplayBlock $sStyle"); + } + } + } public function GetFilter() { @@ -327,6 +443,7 @@ HTML; { $sHtml = ''; $oBlock = null; + $this->CheckParams($this->m_sStyle, $aExtraParams); // Add the extra params into the filter if they make sense for such a filter $bDoSearch = utils::ReadParam('dosearch', false); $aQueryParams = array(); @@ -823,6 +940,19 @@ JS return $oBlock; } + /** + * @param array $aExtraParams + * + * @return string[] + */ + protected function GetAllowedActionsParams(array $aExtraParams) + { + return [ + 'context_filter', /** int if != 0 filter with user context */ + 'query_params', /** array query parameters */ + ]; + } + /** * @param array $aExtraParams * diff --git a/pages/ajax.render.php b/pages/ajax.render.php index 1595c913d..223a84e99 100644 --- a/pages/ajax.render.php +++ b/pages/ajax.render.php @@ -17,8 +17,6 @@ * You should have received a copy of the GNU Affero General Public License */ -use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableFactory; -use Combodo\iTop\Application\UI\Base\Component\DataTable\DataTableSettings; use Combodo\iTop\Application\UI\Base\Layout\ActivityPanel\ActivityEntry\ActivityEntryFactory; use Combodo\iTop\Controller\AjaxRenderController; use Combodo\iTop\Renderer\BlockRenderer; @@ -659,7 +657,6 @@ try $oKPI = new ExecutionKPI(); $oDisplayBlock = new DisplayBlock($oFilter, $sStyle, false); $aExtraParams['display_limit'] = true; - $aExtraParams['truncated'] = true; $oDisplayBlock->RenderContent($oPage, $aExtraParams); $oKPI->ComputeAndReport('Data fetch and format'); } diff --git a/pages/ajax.searchform.php b/pages/ajax.searchform.php index 21a8300ba..4e75ff612 100644 --- a/pages/ajax.searchform.php +++ b/pages/ajax.searchform.php @@ -97,7 +97,6 @@ try } $aExtraParams['display_limit'] = true; - $aExtraParams['truncated'] = true; if (isset($sListId)) { diff --git a/sources/application/UI/Base/Component/DataTable/DataTableFactory.php b/sources/application/UI/Base/Component/DataTable/DataTableFactory.php index 2d71c5be2..54e1e113f 100644 --- a/sources/application/UI/Base/Component/DataTable/DataTableFactory.php +++ b/sources/application/UI/Base/Component/DataTable/DataTableFactory.php @@ -763,4 +763,26 @@ class DataTableFactory return $oTable; } + + public static function GetAllowedParams(): array + { + return [ + 'surround_with_panel', /** bool embed table into a Panel */ + 'menu', /** bool display table menu */ + 'view_link', /** bool display the friendlyname column with links to the objects details */ + 'link_attr', /** string link att code */ + 'object_id', /** int Id of the object linked */ + 'target_attr', /** string target att code of the link */ + 'selection_mode', /** bool activate selection */ + 'selection_type', /** string 'multiple' or 'single' */ + 'extra_fields', /** string comma separated list of link att code to display ('alias.attcode')*/ + 'zlist', /** string name of the zlist to display when 'extra_fields' is not set */ + 'display_limit', /** bool if true pagination is used (default = true) */ + 'table_id', /** string datatable id */ + 'cssCount', /** string external counter (input hidden) js selector */ + 'selected_rows', /** array list of Ids already selected when displaying the datatable */ + 'display_aliases', /** string comma separated list of class aliases to display */ + 'list_id', /** string list outer id */ + ]; + } } \ No newline at end of file diff --git a/sources/application/search/searchform.class.inc.php b/sources/application/search/searchform.class.inc.php index 44b0514af..129324602 100644 --- a/sources/application/search/searchform.class.inc.php +++ b/sources/application/search/searchform.class.inc.php @@ -183,7 +183,6 @@ class SearchForm $sStyle = "ibo-search-form"; $sStyle .= ($bOpen == 'true') ? '' : ' closed'; $sStyle .= ($bAutoSubmit === true) ? '' : ' no_auto_submit'; -//(string $sTitle = '', array $aSubBlocks = [], string $sColor = self::DEFAULT_COLOR, ?string $sId = null) $oUiSearchBlock = new Panel(Dict::Format('UI:SearchFor_Class_Objects', $sClassesCombo), [],Panel::ENUM_COLOR_CYAN, $sSearchFormId); $oUiSearchBlock->SetCSSClasses("ibo-search-form-panel display_block"); $oUiBlock->AddSubBlock($oUiSearchBlock); @@ -258,15 +257,6 @@ class SearchForm $aListParams['table_inner_id'] = "table_inner_id_{$sSearchFormId}"; } - if (isset($aExtraParams['result_list_outer_selector'])) - { - $sDataConfigListSelector = $aExtraParams['result_list_outer_selector']; - } - else - { - $sDataConfigListSelector = $aExtraParams['table_inner_id']; - } - $sDebug = utils::ReadParam('debug', 'false', false, 'parameter'); if ($sDebug == 'true') { @@ -286,7 +276,7 @@ class SearchForm $aSearchParams = array( 'criterion_outer_selector' => "#fs_{$sSearchFormId}_criterion_outer", 'result_list_outer_selector' => "#{$aExtraParams['result_list_outer_selector']}", - 'data_config_list_selector' => "#{$sDataConfigListSelector}", + 'data_config_list_selector' => "#{$aExtraParams['result_list_outer_selector']}", 'endpoint' => utils::GetAbsoluteUrlAppRoot().'pages/ajax.searchform.php', 'init_opened' => $bOpen, 'auto_submit' => $bAutoSubmit,