Skip to content

Commit

Permalink
UI/DataTable, UI/Input/Viewcontrols: dedicated names for viewcontrols
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Dec 3, 2024
1 parent 70bd995 commit 3392e6e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 53 deletions.
1 change: 0 additions & 1 deletion components/ILIAS/UI/src/Component/Table/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public function withId(string $id): static;
* Consumers may add additional view controls
*/
public function withAdditionalViewControl(
string $key,
ViewControlInput $view_control
): self;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Pagination extends ViewControlInput implements VCInterface\Pagination, Has
public const DEFAULT_LIMITS = [5, 10, 25, 50, 100, 250, 500, \PHP_INT_MAX];
public const FNAME_OFFSET = 'offset';
public const FNAME_LIMIT = 'limit';
private const FNAME_PAGINATION = 'pag';
protected const NUMBER_OF_VISIBLE_SECTIONS = 7;

protected Signal $internal_selection_signal;
Expand All @@ -57,9 +58,10 @@ public function __construct(

$this->setInputGroup(
$field_factory->group([
self::FNAME_OFFSET => $field_factory->hidden(),
self::FNAME_LIMIT => $field_factory->hidden(),
self::FNAME_OFFSET => $field_factory->hidden()->withDedicatedName(self::FNAME_OFFSET),
self::FNAME_LIMIT => $field_factory->hidden()->withDedicatedName(self::FNAME_LIMIT),
])
->withDedicatedName(self::FNAME_PAGINATION)
->withAdditionalTransformation($this->getRangeTransform())
->withAdditionalTransformation($this->getCorrectOffsetForPageSize())
);
Expand Down Expand Up @@ -87,12 +89,12 @@ protected function getCorrectOffsetForPageSize(): Transformation
return $this->refinery->custom()->transformation(
function ($v): Range {
list($offset, $limit) = $v->unpack();
if($limit === 0) {
if ($limit === 0) {
$limit = current($this->getLimitOptions());
}
$current_page = floor($offset / $limit);
$offset = $current_page * $limit;
return $this->data_factory->range((int)$offset, $limit);
return $this->data_factory->range((int) $offset, $limit);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
class Sortation extends ViewControlInput implements VCInterface\Sortation, HasInputGroup
{
use GroupDecorator;
private const FNAME_ASPECT = 'asp';
private const FNAME_DIRECTION = 'dir';
private const FNAME_SORTATION = 'sort';

protected Signal $internal_selection_signal;
protected string $aspect;
Expand Down Expand Up @@ -61,9 +64,11 @@ public function __construct(
$this->options = $options;

$this->setInputGroup($field_factory->group([
$field_factory->hidden(), //aspect
$field_factory->hidden(), //direction
])->withAdditionalTransformation($this->getOrderTransform()));
$field_factory->hidden()->withDedicatedName(self::FNAME_ASPECT), //aspect
$field_factory->hidden()->withDedicatedName(self::FNAME_DIRECTION), //direction
])
->withDedicatedName(self::FNAME_SORTATION)
->withAdditionalTransformation($this->getOrderTransform()));

$this->internal_selection_signal = $signal_generator->create();
}
Expand Down
25 changes: 16 additions & 9 deletions components/ILIAS/UI/src/Implementation/Component/Table/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class Data extends AbstractTable implements T\Data
public const STORAGE_ID_PREFIX = self::class . '_';
public const VIEWCONTROL_KEY_PAGINATION = 'range';
public const VIEWCONTROL_KEY_ORDERING = 'order';
public const VIEWCONTROL_KEY_FIELDSELECTION = 'selected_optional';
public const VIEWCONTROL_KEY_FIELDSELECTION = 'selopt';
public const VIEWCONTROL_KEY_ADDITIONAL = 'additional';

protected mixed $filter = null;
protected mixed $additional_parameters = null;
protected mixed $additional_viewcontrol_data = null;
protected array $additional_view_controls = [];
protected ?ViewControlContainer\ViewControlInput $additional_view_control = null;

/**
* @param array<string, Column> $columns
Expand Down Expand Up @@ -180,23 +181,29 @@ public function applyViewControls(
protected function getViewControls(?int $total_count = null): ViewControlContainer\ViewControl
{
$view_controls = [
self::VIEWCONTROL_KEY_PAGINATION => $this->getViewControlPagination($total_count),
self::VIEWCONTROL_KEY_ORDERING => $this->getViewControlOrdering($total_count),
self::VIEWCONTROL_KEY_FIELDSELECTION => $this->getViewControlFieldSelection(),
self::VIEWCONTROL_KEY_PAGINATION => $this->getViewControlPagination($total_count)
?->withDedicatedName(self::VIEWCONTROL_KEY_PAGINATION),
self::VIEWCONTROL_KEY_ORDERING => $this->getViewControlOrdering($total_count)
?->withDedicatedName(self::VIEWCONTROL_KEY_ORDERING),
self::VIEWCONTROL_KEY_FIELDSELECTION => $this->getViewControlFieldSelection()
?->withDedicatedName(self::VIEWCONTROL_KEY_FIELDSELECTION),
];
$view_controls = array_filter($view_controls);
$view_controls = array_merge($view_controls, $this->additional_view_controls);
if ($this->additional_view_control !== null) {
$view_controls[] = $this->additional_view_control;
}

return $this->view_control_container_factory->standard($view_controls);
return $this->view_control_container_factory->standard($view_controls)
->withDedicatedName('vc');
}


public function withAdditionalViewControl(
string $key,
ViewControlContainer\ViewControlInput $view_control
): self {
$clone = clone $this;
$clone->additional_view_controls[$key] = $view_control;
$clone->additional_view_control = $view_control
->withDedicatedName(self::VIEWCONTROL_KEY_ADDITIONAL);
return $clone;
}

Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/UI/src/examples/Table/Data/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function getRows(
}
$record['achieve'] = $icon;

if ($additional_viewcontrol_data['anon_mail'] === 'hide') {
if (in_array('hide', $additional_viewcontrol_data)) {
$record['email'] = '-';
}

Expand Down Expand Up @@ -246,7 +246,7 @@ protected function getRecords(Range $range = null, Order $order = null): array
->withOrder(new Order('achieve', Order::DESC))

->withAdditionalViewControl(
'anon_mail',
//'anon_mail',
$f->input()->viewControl()->mode([
'show' => 'show mails',
'hide' => 'anon mails'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public function testViewControlContainerWithRequest(): void
->method("getQueryParams")
->willReturn([
'view_control/input_0' => ['a1', 'a3'],
'view_control/input_1/input_2' => 'a2',
'view_control/input_1/input_3' => 'DESC'
'view_control/sort/asp' => 'a2',
'view_control/sort/dir' => 'DESC'
]);

$c_factory = $this->buildVCFactory();
Expand Down Expand Up @@ -190,8 +190,8 @@ public function testExtractCurrentValues(): void
$this->assertEquals(
[
'view_control/input_0' => ['a1', 'a3'],
'view_control/input_1/input_2' => 'a2',
'view_control/input_1/input_3' => 'DESC'
'view_control/sort/asp' => 'a2',
'view_control/sort/dir' => 'DESC'
],
$data
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ public function getNewName(): string
{
$name = "name_{$this->count}";
$this->count++;

return $name;
}
public function getNewDedicatedName($dedicated_name = 'dedicated_name'): string
{
$name = $dedicated_name . "_{$this->count}";
$this->count++;
return $name;
}
};
Expand Down
40 changes: 11 additions & 29 deletions components/ILIAS/UI/tests/Component/Table/DataViewControlsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,15 @@ public function testDataTableViewControlStorage(): void
->withId($table_id)
->withRequest(
$this->getRequestMock([
'view_control/input_0/input_1' => 0,
'view_control/input_0/input_2' => 10,
'view_control/input_3/input_4' => 'f2',
'view_control/input_3/input_5' => 'DESC',
'view_control/input_6' => ['f2']
'vc/pag_0/offset_1' => 0,
'vc/pag_0/limit_2' => 10,
'vc/sort_3/asp_4' => 'f2',
'vc/sort_3/dir_5' => 'DESC',
'vc/selopt_6' => ['f2']
])
);
list($table, $view_controls) = $table->applyViewControls([], []);

//applied values from viewcontrols
$this->assertEquals(new Range(0, 10), $table->getRange());
$this->assertEquals(new Order('f2', Order::DESC), $table->getOrder());
Expand Down Expand Up @@ -270,7 +271,6 @@ public function testDataTableHasNoFieldSelectionButAdditionalViewControl(): void
$total_count = 200;
$table = $factory->data('Table', $columns, $this->getDataRetrieval($total_count))
->withAdditionalViewControl(
'additional_control',
$this->getViewControlFactory()->mode([
'mode1' => 'a mode',
'mode2' => 'another mode'
Expand All @@ -279,42 +279,24 @@ public function testDataTableHasNoFieldSelectionButAdditionalViewControl(): void
->withId('testing_data_table_id')
->withRequest(
$this->getRequestMock([
'view_control/input_0/input_1' => 0,
'view_control/input_0/input_2' => 10,
'view_control/input_3/input_4' => 'f2',
'view_control/input_3/input_5' => 'DESC',
'view_control/input_6' => 'mode2'
'vc/additional_6' => 'mode2'
])
);

$additional_parameters = ['existing' => true];
list($table, $view_controls) = $table->applyViewControls([], $additional_parameters);
list($table, $view_controls) = $table->applyViewControls([], []);

$this->assertEquals(
[
C\Table\Data::VIEWCONTROL_KEY_PAGINATION,
C\Table\Data::VIEWCONTROL_KEY_ORDERING,
'additional_control'
0
],
array_keys($view_controls->getInputs())
);
$this->assertEquals(
[
'additional_control' => 'mode2',
'existing' => true,
],
$table->getAdditionalParameters()
);

//applied values from session with empty request
$table = $table->withRequest($this->getRequestMock([]));
list($table, $view_controls) = $table->applyViewControls([], $additional_parameters);
$this->assertEquals(
[
'additional_control' => 'mode2',
'existing' => true,
],
$table->getAdditionalParameters()
['mode2'],
$table->getAdditionalViewControlData()
);
}
}

0 comments on commit 3392e6e

Please sign in to comment.