Skip to content

Commit

Permalink
[FIX] UI: remove Table\Data::withNumberOfRows(), consider initial ord…
Browse files Browse the repository at this point in the history
…ering and range. (ILIAS-eLearning#8106)

* Fix https://mantis.ilias.de/view.php?id=41328
* Fix https://mantis.ilias.de/view.php?id=42095
* Remove Table\Data::withNumberOfRows()
* Replace IRSS usage of removed method
  • Loading branch information
nhaagen authored and oliversamoila committed Sep 30, 2024
1 parent 9040fa8 commit 376e199
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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())
);
}

Expand Down
5 changes: 0 additions & 5 deletions components/ILIAS/UI/src/Component/Table/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
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;
use ILIAS\Data\Order;

class Data extends AbstractTable implements T\Data
{
Expand Down Expand Up @@ -130,9 +129,12 @@ 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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 = [];
Expand All @@ -71,7 +74,10 @@ protected function getViewControlOrdering(int|null $total_count): Sortation|Null
$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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down
10 changes: 8 additions & 2 deletions components/ILIAS/UI/src/examples/Table/Data/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

/**
Expand Down
8 changes: 0 additions & 8 deletions components/ILIAS/UI/tests/Component/Table/DataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
);
}
Expand Down Expand Up @@ -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]
);
}
Expand Down

0 comments on commit 376e199

Please sign in to comment.