From c31a454d6720d78e6b9d667f63d259eb3879a216 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Wed, 25 Sep 2024 09:46:23 +0200 Subject: [PATCH 1/4] UI/DataTable: 42095, do not shift input-structure for missing SortationViewControl --- .../ILIAS/UI/src/Implementation/Component/Table/Data.php | 5 ++++- .../Component/Table/TableViewControlOrdering.php | 9 ++++++--- .../UI/tests/Component/Table/DataViewControlsTest.php | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/components/ILIAS/UI/src/Implementation/Component/Table/Data.php b/components/ILIAS/UI/src/Implementation/Component/Table/Data.php index 6efe3575ccc8..cc38a9403395 100755 --- a/components/ILIAS/UI/src/Implementation/Component/Table/Data.php +++ b/components/ILIAS/UI/src/Implementation/Component/Table/Data.php @@ -34,6 +34,7 @@ use ILIAS\UI\Component\Input\ViewControl; use ILIAS\UI\Component\Input\Container\ViewControl as ViewControlContainer; use ILIAS\Data\Range; +use ILIAS\Data\Order; class Data extends AbstractTable implements T\Data { @@ -130,9 +131,11 @@ public function applyViewControls( $data = $view_controls->getData(); $range = $data[self::VIEWCONTROL_KEY_PAGINATION]; $range = ($range instanceof Range) ? $range->croppedTo($total_count ?? PHP_INT_MAX) : null; + $order = $data[self::VIEWCONTROL_KEY_ORDERING]; + $order = ($order instanceof Order) ? $order : null; $table = $table ->withRange($range) - ->withOrder($data[self::VIEWCONTROL_KEY_ORDERING] ?? null) + ->withOrder($order) ->withSelectedOptionalColumns($data[self::VIEWCONTROL_KEY_FIELDSELECTION] ?? null); } diff --git a/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php b/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php index 6fc1a34fffa3..b709a72a78c6 100644 --- a/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php +++ b/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php @@ -21,7 +21,7 @@ namespace ILIAS\UI\Implementation\Component\Table; use ILIAS\UI\Component\Input\ViewControl\Sortation; -use ILIAS\UI\Component\Input\ViewControl\NullControl; +use ILIAS\UI\Implementation\Component\Input\ViewControl; use ILIAS\UI\Component\Table\Column\Column; use ILIAS\Data\Order; @@ -47,7 +47,7 @@ private function initialOrder(): string return array_key_first($sortable_visible_cols); } - protected function getViewControlOrdering(int|null $total_count): Sortation|NullControl + protected function getViewControlOrdering(int|null $total_count): Sortation|ViewControl\Group { $sortable_visible_cols = array_filter( @@ -58,7 +58,10 @@ protected function getViewControlOrdering(int|null $total_count): Sortation|Null if ($sortable_visible_cols === [] || ($total_count !== null && $total_count < 2) ) { - return $this->view_control_factory->nullControl(); + return $this->view_control_factory->group([ + $this->view_control_factory->nullControl(), + $this->view_control_factory->nullControl() + ]); } $sort_options = []; diff --git a/components/ILIAS/UI/tests/Component/Table/DataViewControlsTest.php b/components/ILIAS/UI/tests/Component/Table/DataViewControlsTest.php index e5f42a3d4fe5..c60859dca470 100755 --- a/components/ILIAS/UI/tests/Component/Table/DataViewControlsTest.php +++ b/components/ILIAS/UI/tests/Component/Table/DataViewControlsTest.php @@ -145,7 +145,7 @@ public function testDataTableHasNoOrderingViewControl(): void array_keys($inputs) ); $this->assertInstanceOf( - I\Input\ViewControl\NullControl::class, + I\Input\ViewControl\Group::class, $inputs[C\Table\Data::VIEWCONTROL_KEY_ORDERING] ); } @@ -173,7 +173,7 @@ public function testDataTableHasNoOrderingViewControlDueToRecordCount(): void array_keys($inputs) ); $this->assertInstanceOf( - I\Input\ViewControl\NullControl::class, + I\Input\ViewControl\Group::class, $inputs[C\Table\Data::VIEWCONTROL_KEY_ORDERING] ); } From 94658d15a9cd56b1c698488965300074e8f4cf02 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Wed, 25 Sep 2024 10:48:39 +0200 Subject: [PATCH 2/4] UI/DataTable: #41328, set initial order and range --- components/ILIAS/UI/src/Component/Table/Data.php | 5 ----- .../UI/src/Implementation/Component/Table/Data.php | 3 +-- .../Component/Table/TableViewControlOrdering.php | 7 +++++-- .../Component/Table/TableViewControlPagination.php | 14 +------------- .../ILIAS/UI/src/examples/Table/Data/base.php | 10 ++++++++-- .../ILIAS/UI/tests/Component/Table/DataTest.php | 8 -------- 6 files changed, 15 insertions(+), 32 deletions(-) diff --git a/components/ILIAS/UI/src/Component/Table/Data.php b/components/ILIAS/UI/src/Component/Table/Data.php index 0145ce801fd1..46c5221b6336 100755 --- a/components/ILIAS/UI/src/Component/Table/Data.php +++ b/components/ILIAS/UI/src/Component/Table/Data.php @@ -43,11 +43,6 @@ public function withActions(array $actions): static; */ public function withRequest(ServerRequestInterface $request): static; - /** - * Number of Rows is the amount of rows shown per page - */ - public function withNumberOfRows(int $number_of_rows): self; - /** * Not all columns are neccessarily visible; "selected optional" is the * positive list of shown columns (the non-optional columns are always shown diff --git a/components/ILIAS/UI/src/Implementation/Component/Table/Data.php b/components/ILIAS/UI/src/Implementation/Component/Table/Data.php index cc38a9403395..bcf27af0b114 100755 --- a/components/ILIAS/UI/src/Implementation/Component/Table/Data.php +++ b/components/ILIAS/UI/src/Implementation/Component/Table/Data.php @@ -29,8 +29,6 @@ use ILIAS\UI\Implementation\Component\JavaScriptBindable; use ILIAS\UI\Component\JavaScriptBindable as JSBindable; use ILIAS\Data\Factory as DataFactory; - - use ILIAS\UI\Component\Input\ViewControl; use ILIAS\UI\Component\Input\Container\ViewControl as ViewControlContainer; use ILIAS\Data\Range; @@ -133,6 +131,7 @@ public function applyViewControls( $range = ($range instanceof Range) ? $range->croppedTo($total_count ?? PHP_INT_MAX) : null; $order = $data[self::VIEWCONTROL_KEY_ORDERING]; $order = ($order instanceof Order) ? $order : null; + $table = $table ->withRange($range) ->withOrder($order) diff --git a/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php b/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php index b709a72a78c6..cd2f92058164 100644 --- a/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php +++ b/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlOrdering.php @@ -31,7 +31,7 @@ trait TableViewControlOrdering protected function initViewControlOrdering(): void { - $this->order = $this->data_factory->order($this->initialOrder(), Order::ASC); + $this->order = $this->getOrder(); } private function initialOrder(): string @@ -74,7 +74,10 @@ protected function getViewControlOrdering(int|null $total_count): Sortation|View $sort_options[$labels[0]] = $order_asc; $sort_options[$labels[1]] = $order_desc; } - return $this->view_control_factory->sortation($sort_options); + + $value = $this->getOrder()->join('', fn($ret, $key, $value) => [$key, $value]); + return $this->view_control_factory->sortation($sort_options) + ->withValue($value); } public function withOrder(?Order $order): self diff --git a/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlPagination.php b/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlPagination.php index 8cd3c2b0a9f2..5de6d8af4d58 100644 --- a/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlPagination.php +++ b/components/ILIAS/UI/src/Implementation/Component/Table/TableViewControlPagination.php @@ -31,7 +31,7 @@ trait TableViewControlPagination protected function initViewControlpagination(): void { - $this->range = $this->data_factory->range(0, $this->number_of_rows); + $this->range = $this->getRange(); } protected function getViewControlPagination(?int $total_count = null): ViewControl\Pagination|ViewControl\Group @@ -53,18 +53,6 @@ protected function getViewControlPagination(?int $total_count = null): ViewContr ]); } - public function withNumberOfRows(int $number_of_rows): self - { - $clone = clone $this; - $clone->number_of_rows = $number_of_rows; - return $clone; - } - - public function getNumberOfRows(): int - { - return $this->number_of_rows; - } - public function withRange(?Range $range): self { $clone = clone $this; diff --git a/components/ILIAS/UI/src/examples/Table/Data/base.php b/components/ILIAS/UI/src/examples/Table/Data/base.php index ae6b4a527080..3ef40a528c8a 100755 --- a/components/ILIAS/UI/src/examples/Table/Data/base.php +++ b/components/ILIAS/UI/src/examples/Table/Data/base.php @@ -157,10 +157,10 @@ public function getRows( $this->ui_factory->symbol()->icon()->custom('assets/images/standard/icon_x.svg', '', 'small'), ]; $icon = $icons[2]; - if($record['achieve'] > 80) { + if ($record['achieve'] > 80) { $icon = $icons[0]; } - if($record['achieve'] < 30) { + if ($record['achieve'] < 30) { $icon = $icons[1]; } $record['achieve'] = $icon; @@ -227,6 +227,12 @@ protected function getRecords(Range $range = null, Order $order = null): array ->data('a data table', $columns, $data_retrieval) ->withId('example_base') ->withActions($actions) + + //these are initial settings that apply if the according view control + //has not been operated, yet + ->withRange(new Range(0, 2)) + ->withOrder(new Order('achieve', Order::DESC)) + ->withRequest($request); /** diff --git a/components/ILIAS/UI/tests/Component/Table/DataTest.php b/components/ILIAS/UI/tests/Component/Table/DataTest.php index d5b20c883467..50a015f7e305 100755 --- a/components/ILIAS/UI/tests/Component/Table/DataTest.php +++ b/components/ILIAS/UI/tests/Component/Table/DataTest.php @@ -73,7 +73,6 @@ public function testDataTableBasicConstruction(): void $data = $this->getDataRetrieval(); $cols = ['f0' => $this->getTableFactory()->column()->text("col1")]; $table = $this->getTableFactory()->data('title', $cols, $data); - $this->assertEquals(800, $table->getNumberOfRows()); $this->assertInstanceOf(Order::class, $table->getOrder()); $this->assertInstanceOf(Range::class, $table->getRange()); $this->assertInstanceOf(I\Signal::class, $table->getAsyncActionSignal()); @@ -154,13 +153,6 @@ public function testDataTableWithRequest(): void $this->assertEquals($request, $table->withRequest($request)->getRequest()); } - public function testDataTableWithNumberOfRows(): void - { - $table = $this->getTable(); - $nor = 12; - $this->assertEquals($nor, $table->withNumberOfRows($nor)->getNumberOfRows()); - } - public function testDataTableWithOrder(): void { $table = $this->getTable(); From 677dc0551966c74a334f51cba987136c19ae5c72 Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 30 Sep 2024 11:05:43 +0200 Subject: [PATCH 3/4] ResourceStorage: 'withRange' instead of 'withNumberOfRows' --- .../classes/Collections/View/RequestToDataTable.php | 4 ++-- .../classes/Container/View/RequestToDataTable.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/ILIAS/ResourceStorage/classes/Collections/View/RequestToDataTable.php b/components/ILIAS/ResourceStorage/classes/Collections/View/RequestToDataTable.php index ae3f2f8ea3ae..aae0215f99a7 100755 --- a/components/ILIAS/ResourceStorage/classes/Collections/View/RequestToDataTable.php +++ b/components/ILIAS/ResourceStorage/classes/Collections/View/RequestToDataTable.php @@ -100,8 +100,8 @@ protected function buildTable(): \ILIAS\UI\Component\Table\Data $this->http->request() )->withActions( $this->action_builder->getActions() - )->withNumberOfRows( - $this->request->getItemsPerPage() + )->withRange( + new Range(0, $this->request->getItemsPerPage()) ); } diff --git a/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php b/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php index 96b5a0197c6d..3f6f9bfa60cc 100755 --- a/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php +++ b/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php @@ -184,8 +184,8 @@ protected function buildTable(): \ILIAS\UI\Component\Table\Data $this->http->request() )->withActions( $this->action_builder->getActions() - )->withNumberOfRows( - $this->request->getItemsPerPage() + )->withRange( + new Range(0, $this->request->getItemsPerPage()) ); } From b4bf3426786ba15bfb2f73a6ce650064465bb4af Mon Sep 17 00:00:00 2001 From: Nils Haagen Date: Mon, 30 Sep 2024 13:50:41 +0200 Subject: [PATCH 4/4] ResourceStorage, fix code style --- .../classes/Container/View/RequestToDataTable.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php b/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php index 3f6f9bfa60cc..7bc63de05817 100755 --- a/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php +++ b/components/ILIAS/ResourceStorage/classes/Container/View/RequestToDataTable.php @@ -45,7 +45,7 @@ class RequestToDataTable implements RequestToComponents, DataRetrieval public const F_TYPE = 'type'; public const F_MODIFICATION_DATE = 'create_date'; public const FIELD_TITLE = 'title'; - const HOME = 'HOME'; + public const HOME = 'HOME'; private \ILIAS\Data\Factory $data_factory; private \ILIAS\ResourceStorage\Services $irss; private \ILIAS\UI\Renderer $ui_renderer; @@ -127,9 +127,9 @@ protected function getBreadcrumbs(): \Generator foreach ($directories as $i => $directory) { $path_inside_zip = rtrim( - implode('/', array_slice($directories, 0, $i + 1)), - '/' - ) . '/'; + implode('/', array_slice($directories, 0, $i + 1)), + '/' + ) . '/'; $links[] = $this->ui_factory->link()->standard( $directory, $get_action($path_inside_zip)