Skip to content

Commit

Permalink
UI/Navigation: add storage for viewcontrols
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen committed Nov 15, 2024
1 parent b0972c6 commit af503ef
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,12 @@ public function getRefreshIntervalInMs(): int
$c["ui.factory.prompt"] = function ($c) {
return new ILIAS\UI\Implementation\Component\Prompt\Factory($c["ui.signal_generator"]);
};

$c["ui.factory.navigation"] = function ($c) {
return new ILIAS\UI\Implementation\Component\Navigation\Factory(
$c["ui.data_factory"],
$c["refinery"],
$c["ui.storage"],
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function withViewControls(ViewControlContainer $viewcontrols): static;
public function withActions(...$actions): static;

/**
* The Sequence comes with a storage to keep e.g. ViewControl-settings throughout requests.
* The Sequence comes with a storage to keep ViewControl-settings throughout requests.
* Set an Id to enable the storage and identify the distinct sequence.
*/
//public function withId(string $id): static;
public function withId(string $id): static;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Factory implements INavigation\Factory
public function __construct(
protected DataFactory $data_factory,
protected Refinery $refinery,
protected \ArrayAccess $storage,
) {
}

Expand All @@ -42,6 +43,7 @@ public function sequence(
new Sequence\SegmentBuilder(),
$this->data_factory,
$this->refinery,
$this->storage,
$binding
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function renderLinear(

$binding = $component->getBinding();
$vc_data = $component->getViewControls()?->getData() ?? [];
$filter_data = $component->getFilter()?->getData() ?? [];
$filter_data = [];
$positions = $binding->getSequencePositions(
$vc_data,
$filter_data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,23 @@
class Sequence implements ISequence\Sequence
{
use ComponentHelper;

private const PARAM_POSITION = 'p';
public const STORAGE_ID_PREFIX = self::class . '_';

protected ?ServerRequestInterface $request = null;
protected ?URLBuilder $url_builder = null;
protected ?URLBuilderToken $token_position = null;
protected ?ViewControlContainer $viewcontrols = null;
protected $filter = null;
protected ?array $actions = null;
protected int $position = 0;
protected ?string $id = null;

public function __construct(
protected ISequence\SegmentBuilder $segment_builder,
protected DataFactory $data_factory,
protected Refinery $refinery,
//protected \ArrayAccess $storage,
protected \ArrayAccess $storage,
protected ISequence\Binding $binding
) {
}
Expand Down Expand Up @@ -90,18 +91,6 @@ public function getViewControls(): ?ViewControlContainer
return $this->viewcontrols;
}

public function withFilter($filter): static
{
$clone = clone $this;
$clone->filter = $filter;
return $clone;
}

public function getFilter() //: ?ViewControlContainer
{
return $this->filter;
}

public function withActions(...$actions): static
{
$clone = clone $this;
Expand All @@ -114,9 +103,6 @@ public function getActions(): ?array
return $this->actions;
}




protected function checkRequest(): void
{
if (! $this->request) {
Expand Down Expand Up @@ -155,7 +141,11 @@ protected function initFromRequest(): void
);


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

public function getNext(int $direction): URI
Expand All @@ -166,51 +156,51 @@ public function getNext(int $direction): URI
->buildURI();
}

/*
protected function getStorageData(): ?array
{
if (null !== ($storage_id = $this->getStorageId())) {
return $this->storage[$storage_id] ?? null;
}
return null;
protected function getStorageData(): ?array
{
if (null !== ($storage_id = $this->getStorageId())) {
return $this->storage[$storage_id] ?? null;
}
return null;
}

protected function setStorageData(array $data): void
{
if (null !== ($storage_id = $this->getStorageId())) {
$this->storage[$storage_id] = $data;
}
protected function setStorageData(array $data): void
{
if (null !== ($storage_id = $this->getStorageId())) {
$this->storage[$storage_id] = $data;
}
}

protected function getStorageId(): ?string
{
if (null !== ($id = $this->getId())) {
return static::STORAGE_ID_PREFIX . $id;
}
return null;
protected function getStorageId(): ?string
{
if (null !== ($id = $this->getId())) {
return static::STORAGE_ID_PREFIX . $id;
}
return null;
}

public function withId(string $id): static
{
$clone = clone $this;
$clone->id = $id;
return $clone;
}
public function withId(string $id): static
{
$clone = clone $this;
$clone->id = $id;
return $clone;
}

protected function getId(): ?string
{
return $this->id;
}

protected function applyValuesToViewcontrols(
ViewControlContainer $view_controls,
ServerRequestInterface $request
): ViewControlContainer {
$stored_values = new ArrayInputData($this->getStorageData() ?? []);
$view_controls = $view_controls
->withStoredInput($stored_values)
->withRequest($request);
$this->setStorageData($view_controls->getComponentInternalValues());
return $view_controls;
}

protected function getId(): ?string
{
return $this->id;
}
protected function applyValuesToViewcontrols(
ViewControlContainer\ViewControl $view_controls,
ServerRequestInterface $request
): ViewControlContainer\ViewControl {
$stored_values = new ArrayInputData($this->getStorageData() ?? []);
$view_controls = $view_controls
->withStoredInput($stored_values)
->withRequest($request);
$this->setStorageData($view_controls->getComponentInternalValues());
return $view_controls;
}
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@ public function __construct(
];
}


public function getSequencePositions(
array $viewcontrol_values,
array $filter_values
): array {
//this is actually a filter, not a vc!
$chunks = $viewcontrol_values['chunks'] ?? [];
$chunks[] = 'c0';
return array_values(
Expand Down Expand Up @@ -84,16 +82,13 @@ public function getSegment(
))
]);

//$filter = $f->input()->container()->filter()->standard();

$global_actions = [
$f->button()->standard('a global action', '#')
];


$sequence = $f->navigation()->sequence($binding)
->withViewControls($viewcontrols)
//->withFilter($filter),
->withId('example')
->withActions($global_actions)
->withRequest($request);

Expand Down

0 comments on commit af503ef

Please sign in to comment.