Skip to content

Commit

Permalink
MD: data table in LOM editor, part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Jan 28, 2025
1 parent 446fcaf commit cef9354
Show file tree
Hide file tree
Showing 25 changed files with 425 additions and 202 deletions.
11 changes: 11 additions & 0 deletions components/ILIAS/MetaData/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ into `MetaData` (and `Services` reserved for things used across

Further, `Settings` should also be refactored to use `Services` properly.

### Clean up Control Flow in the Editor GUI

The control flow in `ilMDEditorGUI` is not really apparent from just that
class, since form actions and similar links are generated elsewhere. It
would be nice if one could see at a glance how stuff works.

Further, it might be possible to simplify the control flow itself: Is
it possible to merge `update` and `create` into a single `edit`, and
derive all the needed information from the action path? Is there a way
to organize the async calls a bit more neatly?

### Improve Unit Test Coverage

The following classes are not yet covered by unit tests:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function get(
}
$sections[self::TYPICAL_LEARNING_TIME] = $this->getTypicalLearningTimeSection($set);
$form = $this->ui_factory->input()->container()->form()->standard(
(string) $this->link_factory->custom(Command::UPDATE_DIGEST)->get(),
(string) $this->link_factory->standard(Command::UPDATE_DIGEST)->get(),
$sections
);

Expand Down Expand Up @@ -270,7 +270,7 @@ protected function getChangeCopyrightModal(bool $with_oer_warning): Interruptive
$modal = $this->ui_factory->modal()->interruptive(
$this->presenter->utilities()->txt("meta_copyright_change_warning_title"),
$message,
(string) $this->link_factory->custom(Command::UPDATE_DIGEST)->get()
(string) $this->link_factory->standard(Command::UPDATE_DIGEST)->get()
);

return $modal;
Expand Down
65 changes: 65 additions & 0 deletions components/ILIAS/MetaData/classes/Editor/Full/AsyncContent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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\MetaData\Editor\Full;

use ILIAS\UI\Component\Prompt\State\State;
use ILIAS\MetaData\Paths\PathInterface;
use ILIAS\MetaData\Elements\ElementInterface;
use ILIAS\MetaData\Editor\Full\Services\Services as FullEditorServices;
use ILIAS\MetaData\Editor\Full\Services\Actions\FlexibleModal;
use ILIAS\MetaData\Editor\Http\RequestInterface;

class AsyncContent
{
protected FullEditorServices $services;

public function __construct(
FullEditorServices $services
) {
$this->services = $services;
}

public function contentForEdit(
PathInterface $base_path,
ElementInterface $element,
RequestInterface $request
): State {
if ($element->isScaffold()) {
return $this->services->actions()->getModal()->createContent(
$base_path,
$element,
$request
);
}
return $this->services->actions()->getModal()->updateContent(
$base_path,
$element,
$request
);
}

public function contentForDelete(
PathInterface $base_path,
ElementInterface $element
): FlexibleModal {
return $this->services->actions()->getModal()->deleteContent($base_path, $element);
}
}
8 changes: 4 additions & 4 deletions components/ILIAS/MetaData/classes/Editor/Full/FormContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ public function content(
ElementInterface $element,
RequestInterface $request
): \Generator {
$delete_modal = $this->services->actions()->getModal()->delete(
$delete_modal = $this->services->actions()->getModal()->deletePlaceholder(
$base_path,
$element,
true
$element
);
if ($delete_modal) {
$button = $this->services->actions()->getButton()->delete(
Expand All @@ -62,7 +61,8 @@ public function content(
}
$form = $this->services->formFactory()->getUpdateForm(
$base_path,
$element
$element,
false
);
if ($request->shouldBeAppliedToForms()) {
$form = $request->applyRequestToForm($form);
Expand Down
31 changes: 26 additions & 5 deletions components/ILIAS/MetaData/classes/Editor/Full/FullEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use ILIAS\MetaData\Editor\Full\Services\Actions\FlexibleModal;
use ILIAS\MetaData\Editor\Http\RequestInterface;
use ILIAS\UI\Component\Table\Data as DataTable;
use ILIAS\UI\Component\Prompt\State\State;

class FullEditor
{
Expand All @@ -49,6 +50,7 @@ class FullEditor
protected TableContent $table_content;
protected PanelContent $panel_content;
protected RootContent $root_content;
protected AsyncContent $async_content;

public function __construct(
EditorDictionaryInterface $editor_dictionary,
Expand All @@ -57,7 +59,8 @@ public function __construct(
FormContent $form_content,
TableContent $table_content,
PanelContent $panel_content,
RootContent $root_content
RootContent $root_content,
AsyncContent $async_content
) {
$this->editor_dictionary = $editor_dictionary;
$this->navigator_factory = $navigator_factory;
Expand All @@ -66,13 +69,33 @@ public function __construct(
$this->table_content = $table_content;
$this->panel_content = $panel_content;
$this->root_content = $root_content;
$this->async_content = $async_content;
}

public function manipulateMD(): ManipulatorAdapter
{
return $this->services->manipulatorAdapter();
}

public function getAsyncContentForEdit(
SetInterface $set,
PathInterface $base_path,
PathInterface $action_path,
RequestInterface $request
): State {
$element = $this->getElements($set, $action_path)[0];
return $this->async_content->contentForEdit($base_path, $element, $request);
}

public function getAsyncContentForDelete(
SetInterface $set,
PathInterface $base_path,
PathInterface $action_path
): FlexibleModal {
$element = $this->getElements($set, $action_path)[0];
return $this->async_content->contentForDelete($base_path, $element);
}

/**
* @return DataTable[]|StandardForm[]|Panel[]|FlexibleModal[]|Button[]|StandardDropdown[]
*/
Expand Down Expand Up @@ -103,16 +126,14 @@ public function getContent(
yield from $this->panel_content->content(
$base_path,
$elements[0],
false,
$request,
false
);
return;

case self::ROOT:
yield from $this->root_content->content(
$base_path,
$elements[0],
$request
$elements[0]
);
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function init(): FullEditor
$presenter,
$panel_content
),
new AsyncContent($services)
);
}
}
14 changes: 5 additions & 9 deletions components/ILIAS/MetaData/classes/Editor/Full/PanelContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Implementation\Component\Listing\CharacteristicValue\Text as Listing;
use ILIAS\MetaData\Editor\Presenter\PresenterInterface;
use ILIAS\MetaData\Editor\Http\RequestInterface;

class PanelContent
{
Expand All @@ -52,14 +51,12 @@ public function __construct(
public function content(
PathInterface $base_path,
ElementInterface $element,
bool $is_subpanel,
RequestInterface $request
bool $is_subpanel
): \Generator {
$buttons = [];
$delete_modal = $this->services->actions()->getModal()->delete(
$delete_modal = $this->services->actions()->getModal()->deletePlaceholder(
$base_path,
$element,
true
$element
);
if ($delete_modal) {
$buttons[] = $this->services->actions()->getButton()->delete(
Expand All @@ -73,10 +70,9 @@ public function content(
if (!$sub->isScaffold()) {
continue;
}
$create_modal = $this->services->actions()->getModal()->create(
$create_modal = $this->services->actions()->getModal()->createPlaceholder(
$base_path,
$sub,
$request
$sub
);
$buttons[] = $this->services->actions()->getButton()->create(
$create_modal->getFlexibleSignal(),
Expand Down
17 changes: 6 additions & 11 deletions components/ILIAS/MetaData/classes/Editor/Full/RootContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@ public function __construct(
*/
public function content(
PathInterface $base_path,
ElementInterface $element,
RequestInterface $request
ElementInterface $element
): \Generator {
yield from $this->createModalsAndDropdown(
$base_path,
$element,
$request
$element
);

$content = [];
Expand All @@ -74,8 +72,7 @@ public function content(
$sub_content = $this->panel_content->content(
$base_path,
$sub,
true,
$request
true
);
foreach ($sub_content as $type => $entity) {
if ($type === ContentType::MAIN) {
Expand All @@ -98,18 +95,16 @@ public function content(
*/
protected function createModalsAndDropdown(
PathInterface $base_path,
ElementInterface $element,
RequestInterface $request
ElementInterface $element
): \Generator {
$buttons = [];
foreach ($element->getSubElements() as $sub) {
if (!$sub->isScaffold()) {
continue;
}
$create_modal = $this->services->actions()->getModal()->create(
$create_modal = $this->services->actions()->getModal()->createPlaceholder(
$base_path,
$sub,
$request
$sub
);
$buttons[] = $this->services->actions()->getButton()->create(
$create_modal->getFlexibleSignal(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,32 @@

namespace ILIAS\MetaData\Editor\Full\Services\Actions;

use ILIAS\UI\Component\Prompt\Prompt;
use ILIAS\UI\Component\Modal\Modal;
use ILIAS\UI\Component\Signal as Signal;

class FlexibleModal
{
protected ?Modal $modal = null;
protected Modal|Prompt|null $component = null;
protected FlexibleSignal $flexible_signal;

public function __construct(Modal|string $modal_or_link)
public function __construct(Modal|Prompt|string $component_or_link)
{
if (is_string($modal_or_link)) {
if (is_string($component_or_link)) {
$this->flexible_signal = new FlexibleSignal(
$modal_or_link
$component_or_link
);
} else {
$this->modal = $modal_or_link;
$this->component = $component_or_link;
$this->flexible_signal = new FlexibleSignal(
$this->modal->getShowSignal()
$this->component->getShowSignal()
);
}
}

public function getModal(): ?Modal
public function getComponent(): Modal|Prompt|null
{
return $this->modal;
return $this->component;
}

public function getFlexibleSignal(): FlexibleSignal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,27 @@ public function __construct(
$this->path_factory = $path_factory;
}

public function create(
public function standard(
PathInterface $base_path,
ElementInterface $to_be_created
): URI {
return $this->getLink(
$base_path,
$this->path_factory->toElement($to_be_created, true),
Command::CREATE_FULL
);
}

public function update(
PathInterface $base_path,
ElementInterface $to_be_updated
): URI {
return $this->getLink(
$base_path,
$this->path_factory->toElement($to_be_updated, true),
Command::UPDATE_FULL
);
}

public function delete(
PathInterface $base_path,
ElementInterface $to_be_deleted
ElementInterface $action_element,
Command $action_cmd
): URI {
return $this->getLink(
$base_path,
$this->path_factory->toElement($to_be_deleted, true),
Command::DELETE_FULL
);
$action_path = $this->path_factory->toElement($action_element, true);
return $this->link_factory
->standard($action_cmd)
->withParameter(Parameter::BASE_PATH, $base_path->toString())
->withParameter(Parameter::ACTION_PATH, $action_path->toString())
->get();
}

protected function getLink(
public function async(
PathInterface $base_path,
PathInterface $action_path,
ElementInterface $action_element,
Command $action_cmd
): URI {
$action_path = $this->path_factory->toElement($action_element, true);
return $this->link_factory
->custom($action_cmd)
->async($action_cmd)
->withParameter(Parameter::BASE_PATH, $base_path->toString())
->withParameter(Parameter::ACTION_PATH, $action_path->toString())
->get();
Expand Down
Loading

0 comments on commit cef9354

Please sign in to comment.