Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/ILIAS/UI/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,9 @@ public function init(
$internal[UI\Implementation\Component\Table\Action\Factory::class] = static fn() =>
new UI\Implementation\Component\Table\Action\Factory();
$internal[UI\Implementation\Component\Table\DataRowBuilder::class] = static fn() =>
new UI\Implementation\Component\Table\DataRowBuilder();
new UI\Implementation\Component\Table\DataRowBuilder(
$pull[Data\Factory::class]
);
$internal[UI\Implementation\Component\Table\OrderingRowBuilder::class] = static fn() =>
new UI\Implementation\Component\Table\OrderingRowBuilder();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Component\Table;

use ILIAS\Data\Range;
use ILIAS\Data\Text\WordOnlyMarkdown;
use ILIAS\Data\Factory as DataFactory;

interface DataRetrievalWithHeaderSummary extends DataRetrieval
{
/**
* Add a summary to the Table's header for specified columns.
*
* @param string[] $visible_column_ids
* @return array<string, WordOnlyMarkdown>
*/
public function getHeaderSummary(
DataFactory $data_factory,
array $visible_column_ids,
mixed $filter_data,
mixed $additional_parameters
): array;
}
6 changes: 3 additions & 3 deletions components/ILIAS/UI/src/Component/Table/DataRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

namespace ILIAS\UI\Component\Table;

use ILIAS\UI\Component\Table\Column\Column;
use ILIAS\UI\Component\Table\Action\Action;
use ILIAS\UI\Component\Component;
use ILIAS\UI\Component\Table\Column\Column;
use ILIAS\UI\Component\Table\Action\Action;
use ILIAS\UI\Component\Component;

interface DataRow extends Component
{
Expand Down
5 changes: 5 additions & 0 deletions components/ILIAS/UI/src/Component/Table/DataRowBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ interface DataRowBuilder
* @param array<string, mixed> $record
*/
public function buildDataRow(string $id, array $record): DataRow;

/**
* @param array<string, mixed> $record
*/
public function buildSummaryRow(array $record): SummaryRow;
}
34 changes: 34 additions & 0 deletions components/ILIAS/UI/src/Component/Table/SummaryRow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
*
* ILIAS is licensed with the GPL-3.0,
* see https://www.gnu.org/licenses/gpl-3.0.en.html
* You should have received a copy of said license along with the
* source code, too.
*
* If this is not the case or you just want to try ILIAS, you'll find
* us at:
* https://www.ilias.de
* https://github.com/ILIAS-eLearning
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Component\Table;

use ILIAS\UI\Component\Component;
use ILIAS\Data\Text\WordOnlyMarkdown;

interface SummaryRow extends Component
{
/**
* @return array<string, Table\Column\Column>
*/
public function getColumns(): array;

public function getCellContent(string $col_id): ?WordOnlyMarkdown;
}
32 changes: 11 additions & 21 deletions components/ILIAS/UI/src/Implementation/Component/Table/DataRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
use ILIAS\UI\Component\Component;
use ILIAS\UI\Implementation\Component\ComponentHelper;

class DataRow implements T\DataRow
class DataRow extends Row implements T\DataRow
{
use ComponentHelper;

/**
* @var array<string, bool>
*/
Expand All @@ -42,13 +40,19 @@ class DataRow implements T\DataRow
* @param array<string, mixed> $record
*/
public function __construct(
protected bool $table_has_singleactions,
protected bool $table_has_multiactions,
protected array $columns,
bool $table_has_singleactions,
bool $table_has_multiactions,
array $columns,
protected array $actions,
protected string $id,
protected array $record
array $record
) {
parent::__construct(
$table_has_singleactions,
$table_has_multiactions,
$columns,
$record,
);
}

public function getId(): string
Expand All @@ -66,20 +70,6 @@ public function withDisabledAction(string $action_id, bool $disable = true): sta
return $clone;
}

public function getColumns(): array
{
return $this->columns;
}

public function tableHasSingleActions(): bool
{
return $this->table_has_singleactions;
}
public function tableHasMultiActions(): bool
{
return $this->table_has_multiactions;
}

public function getActions(): array
{
return array_filter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,19 @@
use ILIAS\UI\Component\Table as T;
use ILIAS\UI\Component\Table\Column\Column;
use ILIAS\UI\Component\Table\Action\Action;
use ILIAS\Data\Factory as DataFactory;

class DataRowBuilder extends RowBuilder implements T\DataRowBuilder
{
public function __construct(
protected DataFactory $data_factory
) {
}

/**
* @param array<string, mixed> $record
*/
public function buildDataRow(string $id, array $record): T\DataRow
public function buildDataRow(string $id, array $record): DataRow
{
return new DataRow(
$this->row_actions !== [],
Expand All @@ -40,4 +46,15 @@ public function buildDataRow(string $id, array $record): T\DataRow
$record
);
}

public function buildSummaryRow(array $record): SummaryRow
{
return new SummaryRow(
$this->row_actions !== [],
$this->table_has_multiactions,
$this->columns,
$this->data_factory,
$record
);
}
}
76 changes: 63 additions & 13 deletions components/ILIAS/UI/src/Implementation/Component/Table/Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use ILIAS\UI\Implementation\Component\Table\Action\Action;
use ILIAS\UI\Implementation\Component\Input\ViewControl\Pagination;
use ILIAS\UI\Implementation\Component\Input\NameSource;
use ILIAS\UI\Component\Table\DataRetrievalWithHeaderSummary;
use ILIAS\Data\Text\WordOnlyMarkdown;

class Renderer extends AbstractComponentRenderer
{
Expand All @@ -52,6 +54,9 @@ public function render(Component\Component $component, RendererInterface $defaul
) {
return $this->renderDataRow($component, $default_renderer);
}
if ($component instanceof Component\Table\SummaryRow) {
return $this->renderSummaryRow($component, $default_renderer);
}
if ($component instanceof Component\Table\Ordering) {
return $this->renderOrderingTable($component, $default_renderer);
}
Expand Down Expand Up @@ -208,7 +213,8 @@ public function renderDataTable(Component\Table\Data $component, RendererInterfa
$component->getAdditionalParameters()
);

$rows = $component->getDataRetrieval()->getRows(
$data_retrieval = $component->getDataRetrieval();
$rows = $data_retrieval->getRows(
$component->getRowBuilder(),
array_keys($component->getVisibleColumns()),
$component->getRange(),
Expand Down Expand Up @@ -271,7 +277,16 @@ public function renderDataTable(Component\Table\Data $component, RendererInterfa
}
}

$this->renderTableHeader($default_renderer, $component, $tpl, $sortation_signal, $compensate_col_index);
$header_summary = [];
if ($data_retrieval instanceof DataRetrievalWithHeaderSummary) {
$header_summary = $data_retrieval->getHeaderSummary(
$this->getDataFactory(),
array_keys($component->getVisibleColumns()),
$component->getFilter(),
$component->getAdditionalParameters()
);
}
$this->renderTableHeader($default_renderer, $component, $tpl, $sortation_signal, $compensate_col_index, $header_summary);
return $tpl->get();
}

Expand All @@ -281,6 +296,7 @@ protected function renderTableHeader(
Template $tpl,
?Component\Signal $sortation_signal,
int $compensate_col_index,
array $header_summary
): void {
$order = $component->getOrder();
$glyph_factory = $this->getUIFactory()->symbol()->glyph();
Expand Down Expand Up @@ -324,6 +340,15 @@ protected function renderTableHeader(
$tpl->setVariable('COL_TITLE', $col_title);
$tpl->setVariable('COL_TYPE', strtolower($col->getType()));
$tpl->parseCurrentBlock();

if ($header_summary !== []) {
$tpl->setCurrentBlock('header_summary_cell');
$tpl->setVariable(
'SUMMARY_CELL_CONTENT',
array_key_exists($col_id, $header_summary) ? $header_summary[$col_id]->toHTML() : ''
);
$tpl->parseCurrentBlock();
}
}
}

Expand All @@ -333,9 +358,14 @@ protected function renderActionsHeader(
Template $tpl,
int $compensate_col_count,
): void {
$has_summary = $component instanceof Data
&& $component->getDataRetrieval() instanceof DataRetrievalWithHeaderSummary;
if ($component->hasSingleActions()) {
$tpl->setVariable('COL_INDEX_ACTION', (string) $component->getColumnCount() + $compensate_col_count);
$tpl->setVariable('COL_TITLE_ACTION', $this->txt('actions'));
if ($has_summary) {
$tpl->touchBlock('header_summary_singleact');
}
}

if ($component->hasMultiActions()) {
Expand All @@ -348,6 +378,9 @@ protected function renderActionsHeader(
$select_none = $glyph_factory->close()->withOnClick($signal);
$tpl->setVariable('SELECTION_CONTROL_SELECT', $default_renderer->render($select_all));
$tpl->setVariable('SELECTION_CONTROL_DESELECT', $default_renderer->render($select_none));
if ($has_summary) {
$tpl->touchBlock('header_summary_multiact');
}
}

if ($component instanceof Component\Table\Ordering) {
Expand Down Expand Up @@ -549,16 +582,29 @@ public function renderDataRow(Component\Table\DataRow $component, RendererInterf
{
$cell_tpl = $this->getTemplate("tpl.datacell.html", true, true);
$this->fillCells($component, $cell_tpl, $default_renderer);
$this->fillActions($component, $cell_tpl, $default_renderer);
return $cell_tpl->get();
}


public function renderSummaryRow(Component\Table\SummaryRow $component, RendererInterface $default_renderer): string
{
$cell_tpl = $this->getTemplate("tpl.summarycell.html", true, true);
$this->fillCells($component, $cell_tpl, $default_renderer);
if ($component->tableHasMultiActions()) {
$cell_tpl->touchBlock('rowselection_cell');
}
if ($component->tableHasSingleActions()) {
$cell_tpl->touchBlock('rowaction_cell');
}
return $cell_tpl->get();
}


public function renderOrderingRow(Component\Table\OrderingRow $component, RendererInterface $default_renderer): string
{
$cell_tpl = $this->getTemplate("tpl.orderingcell.html", true, true);
$this->fillCells($component, $cell_tpl, $default_renderer);

$this->fillActions($component, $cell_tpl, $default_renderer);

if ($component->isOrderingDisabled()) {
return $cell_tpl->get();
Expand All @@ -582,12 +628,15 @@ public function getNewDedicatedName(string $dedicated_name): string
->withValue($component->getPosition() * 10);
$cell_tpl->setVariable('ORDER_INPUT', $default_renderer->render($input));

$drag_handle = $this->getUIFactory()->symbol()->glyph()->dragHandle();
$drag_handle = $default_renderer->render($drag_handle);
$cell_tpl->setVariable('DRAG_HANDLE', $drag_handle);
return $cell_tpl->get();
}


protected function fillCells(
Component\Table\DataRow $row,
Component\Table\DataRow|Component\Table\SummaryRow $row,
Template $cell_tpl,
RendererInterface $default_renderer
) {
Expand All @@ -602,11 +651,20 @@ protected function fillCells(
if ($cell_content instanceof Component\Component) {
$cell_content = $default_renderer->render($cell_content);
}
if ($cell_content instanceof WordOnlyMarkdown) {
$cell_content = $cell_content->toHTML();
}
$cell_tpl->setVariable('CELL_CONTENT', $cell_content);
$cell_tpl->setVariable('CELL_COL_TITLE', $row->getColumns()[$col_id]->getTitle());
$cell_tpl->parseCurrentBlock();
}
}

protected function fillActions(
Component\Table\DataRow|Component\Table\SummaryRow $row,
Template $cell_tpl,
RendererInterface $default_renderer
) {
if ($row->tableHasMultiActions()) {
$cell_tpl->setVariable('ROW_ID', $row->getId());
}
Expand All @@ -617,14 +675,6 @@ protected function fillCells(
);
$cell_tpl->setVariable('ACTION_CONTENT', $default_renderer->render($row_actions_dropdown));
}

if ($row instanceof Component\Table\OrderingRow) {
if (!$row->isOrderingDisabled()) {
$drag_handle = $this->getUIFactory()->symbol()->glyph()->dragHandle();
$drag_handle = $default_renderer->render($drag_handle);
$cell_tpl->setVariable('DRAG_HANDLE', $drag_handle);
}
}
}

/**
Expand Down
Loading