Skip to content

Commit

Permalink
UI/Navigation: add some Components to SegmentContent, expand example
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Nov 15, 2024
1 parent af503ef commit 20478c0
Show file tree
Hide file tree
Showing 17 changed files with 76 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,6 @@ public function getRefreshIntervalInMs(): int
);
};



// currently this is will be a session storage because we cannot store
// data on the client, see https://mantis.ilias.de/view.php?id=38503.
$c["ui.storage"] = function ($c): ArrayAccess {
Expand Down
4 changes: 2 additions & 2 deletions components/ILIAS/UI/src/Component/Image/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
use ILIAS\UI\Component\Signal;
use ILIAS\UI\Component\Component;
use ILIAS\UI\Component\Layout\Alignment\Block;
use ILIAS\UI\Component\Navigation\Sequence\SegmentContent;
use ILIAS\UI\Component\Navigation\Sequence\IsSegmentContent;

/**
* This describes how a glyph could be modified during construction of UI.
*
* Interface Image
* @package ILIAS\UI\Component\Image
*/
interface Image extends Component, JavaScriptBindable, Clickable, Block, SegmentContent
interface Image extends Component, JavaScriptBindable, Clickable, Block, IsSegmentContent
{
/**
* Types of images
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
namespace ILIAS\UI\Component\Input\Container\Form;

use ILIAS\UI\Component\Prompt\IsPromptContent;
use ILIAS\UI\Component\Navigation\Sequence\IsSegmentContent;

/**
* This describes a standard form.
*/
interface Standard extends FormWithPostURL, IsPromptContent
interface Standard extends FormWithPostURL, IsPromptContent, IsSegmentContent
{
/**
* Sets the label of the submit button of the form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@

use ILIAS\UI\Component\Component;
use ILIAS\UI\Component\Layout\Alignment\Block;
use ILIAS\UI\Component\Navigation\Sequence\SegmentContent;
use ILIAS\UI\Component\Navigation\Sequence\IsSegmentContent;

/**
* Interface Text
*/
interface Text extends Component, Block, SegmentContent
interface Text extends Component, Block, IsSegmentContent
{
/**
* Gets the items as array of key value pairs for the list.
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/UI/src/Component/Navigation/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ interface Factory
* usage:
* 1: >
* Use a sequence when the order of presentation is crucial or the
* sequencial presentation aids focus. The sequence is not more of
* sequencial presentation aids focus. The sequence is not of an
* explorative nature but rather instructional.
* interaction:
* 1: >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
namespace ILIAS\UI\Component\Navigation\Sequence;

/**
* SegmentContent is allowed in Segments.
* IsSegmentContent is allowed in Segments.
* Any actions included/provided by (parts of) a Segment MUST NOT leave
* the context of the sequence.
*/
interface SegmentContent
interface IsSegmentContent
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ interface Segment
public function getTitle(): string;

/**
* The actual "contents" of the view displayed when operating a sequence.
* Valid Components are flagged with the SegmentContent interface.
* @return SegmentContent[]
* The actual "contents" of the displayed view when operating a sequence.
* Valid Components are flagged with the IsSegmentContent interface.
* @return IsSegmentContent[]
*/
public function getContents(): array;

/**
* Segments may add actions to the sequence.
* Segments MAY add actions to the sequence.
* Those actions MUST target the actually displayed contents rather
* than changing context entirely (i.e. breaking the sequence).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@

interface SegmentBuilder
{
public function build(string $title, SegmentContent ...$contents): Segment;
public function build(string $title, IsSegmentContent ...$contents): Segment;
}
3 changes: 1 addition & 2 deletions components/ILIAS/UI/src/Component/Table/Presentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@
use Closure;
use ILIAS\UI\Implementation\Component\Signal;
use ILIAS\UI\Component\JavaScriptBindable;
use ILIAS\UI\Component\Navigation\Sequence\SegmentContent;

/**
* This describes a Presentation Table
*/
interface Presentation extends Table, HasViewControls, JavaScriptBindable, SegmentContent
interface Presentation extends Table, HasViewControls, JavaScriptBindable
{
/**
* Get a table like this with the closure $row_mapping.
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/UI/src/Component/Table/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
namespace ILIAS\UI\Component\Table;

use ILIAS\UI\Component\Component;
use ILIAS\UI\Component\Navigation\Sequence\IsSegmentContent;

interface Table extends Component
interface Table extends Component, IsSegmentContent
{
public function withTitle(string $title): self;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class Renderer extends AbstractComponentRenderer
public function render(Component\Component $component, RendererInterface $default_renderer): string
{
if ($component instanceof Component\Navigation\Sequence\Sequence) {
return $this->renderLinear($component, $default_renderer);
return $this->renderSequence($component, $default_renderer);
}

$this->cannotHandleComponent($component);
}

protected function renderLinear(
protected function renderSequence(
Component\Navigation\Sequence\Sequence $component,
RendererInterface $default_renderer
): string {
Expand Down Expand Up @@ -67,28 +67,30 @@ protected function renderLinear(
);

$ui_factory = $this->getUIFactory();
$back = $ui_factory->button()->standard('back', $component->getNext(-1)->__toString())
$back = $ui_factory->button()->standard($this->txt('back'), $component->getNext(-1)->__toString())
->withSymbol($ui_factory->symbol()->glyph()->back())
->withUnavailableAction($position - 1 < 0);

$next = $ui_factory->button()->standard('next', $component->getNext(1)->__toString())
$next = $ui_factory->button()->standard($this->txt('next'), $component->getNext(1)->__toString())
->withSymbol($ui_factory->symbol()->glyph()->next())
->withUnavailableAction($position + 1 === count($positions));

$tpl->setVariable('BACK', $default_renderer->render($back));
$tpl->setVariable('NEXT', $default_renderer->render($next));

$tpl->setVariable('VIEWCONTROLS', $default_renderer->render($component->getViewControls()));

$tpl->setVariable('SEGMENT_TITLLE', $segment->getTitle());
$tpl->setVariable('SEGMENT_CONTENTS', $default_renderer->render($segment->getContents()));
if ($viewcontrols = $component->getViewControls()) {
$tpl->setVariable('VIEWCONTROLS', $default_renderer->render($viewcontrols));
}

if ($actions = $segment->getActions()) {
$tpl->setVariable('ACTIONS_SEGMENT', $default_renderer->render($actions));
}
if ($actions = $component->getActions()) {
$tpl->setVariable('ACTIONS_GLOBAL', $default_renderer->render($actions));
}

$tpl->setVariable('SEGMENT_TITLLE', $segment->getTitle());
$tpl->setVariable('SEGMENT_CONTENTS', $default_renderer->render($segment->getContents()));
return $tpl->get();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class Segment implements ISequence\Segment
protected ?array $actions = null;

/**
* @var ISequence\SegmentContent[]
* @var ISequence\IsSegmentContent[]
*/
protected array $contents;

public function __construct(
protected string $title,
ISequence\SegmentContent ...$contents,
ISequence\IsSegmentContent ...$contents,
) {
$this->contents = $contents;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SegmentBuilder implements ISequence\SegmentBuilder
{
public function build(
string $title,
ISequence\SegmentContent ...$contents
ISequence\IsSegmentContent ...$contents
): ISequence\Segment {
return new Segment($title, ...$contents);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function withRequest(ServerRequestInterface $request): static
protected function initFromRequest(): void
{
$base_uri = $this->data_factory->uri($this->request->getUri()->__toString());
$namespace = ['sequence']; // add id
$namespace = ['sequence' . $this->getId() ?? ''];
$url_builder = new URLBuilder($base_uri);
list(
$this->url_builder,
Expand All @@ -140,12 +140,12 @@ protected function initFromRequest(): void
])
);


$this->viewcontrols = $this->applyValuesToViewcontrols(
$this->viewcontrols,
$this->request
);
//$this->viewcontrols = $this->viewcontrols->withRequest($this->request);
if ($this->viewcontrols) {
$this->viewcontrols = $this->applyValuesToViewcontrols(
$this->viewcontrols,
$this->request
);
}
}

public function getNext(int $direction): URI
Expand Down
31 changes: 29 additions & 2 deletions components/ILIAS/UI/src/examples/Navigation/Sequence/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@
use ILIAS\UI\URLBuilder;
use Psr\Http\Message\ServerRequestInterface;

/**
* ---
* description: >
* Base example for rendering a sequence navigation.
*
* expected output: >
* ILIAS shows a group of buttons and a characteristic value listing.
* Buttons are "back" and "next", of which the back button is inactive until
* the next button was clicked.
* A vieww control allows the user to select chunks of data, and an additional
* button (without real function) is labeled "a global action".
* ---
*/
function base()
{
global $DIC;
Expand All @@ -28,10 +41,13 @@ public function __construct(
) {
$this->seq_data = [
['c0', 'pos 1', [getListing($f)]],
['c0', 'pos 2', [$f->legacy('some legacy content')]],
['c0', 'pos 2', [
$f->legacy('some legacy content'),
$f->legacy('some more legacy content'),
]],
['c1', 'pos 3', [getImage($f)]],
['c2', 'pos 4', [getTable($f)]],
['c1', 'pos 5', [$f->legacy('some more legacy content')]],
['c1', 'pos 5', [getForm($f)]],
];
}

Expand Down Expand Up @@ -200,3 +216,14 @@ function ($row, $record, $ui_factory, $environment) { //mapping-closure
]
);
}

function getForm(UIFactory $ui_factory): \ILIAS\UI\Component\Input\Container\Form\Standard
{
return $ui_factory->input()->container()->form()->standard(
'#',
[
$ui_factory->input()->field()->text('a text field'),
$ui_factory->input()->field()->numeric('a number field'),
]
);
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
<div class="c-sequence c-sequence--linear" id="{ID}">

<div class="c-sequence__navigation l-bar__space-keeper">

<div class="c-sequence__navigation--primary l-bar__element">
{BACK}
{NEXT}
</div>
<!-- BEGIN viewcontrols -->
<div class="c-sequence__navigation--viewcontrols l-bar__element">
{VIEWCONTROLS}
</div>
<!-- END viewcontrols -->

<!-- BEGIN segmentactgions -->
<div class="c-sequence__navigation--actions_segment l-bar__element">
{ACTIONS_SEGMENT}
</div>
<!-- END segmentactgions -->

<!-- BEGIN globalactions -->
<div class="c-sequence__navigation--actions_external l-bar__element">
{ACTIONS_GLOBAL}
</div>

<!-- END globalactions -->
</div>


<div class="c-sequence__segment">
<div class="c-sequence__segment--title">
{SEGMENT_TITLLE}
</div>
<div class="c-sequence__segment--contents">
{SEGMENT_CONTENTS}
</div>
</div>

</div>
3 changes: 2 additions & 1 deletion components/ILIAS/UI/tests/MainFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class MainFactoryTest extends AbstractFactoryTestCase
"layout" => ["rules" => false],
"menu" => ["rules" => false],
"symbol" => ["rules" => false],
"entity" => ["context" => true]
"entity" => ["context" => true],
"navigation" => ["rules" => false],
];

public static string $factory_title = 'ILIAS\\UI\\Factory';
Expand Down

0 comments on commit 20478c0

Please sign in to comment.