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
19 changes: 17 additions & 2 deletions components/ILIAS/UI/UI.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,12 +466,17 @@ public function init(
$internal[UI\Implementation\Component\Entity\Factory::class] = static fn() =>
new UI\Implementation\Component\Entity\Factory();

$internal[UI\Implementation\Component\Prompt\State\Factory::class] = static fn() =>
new UI\Implementation\Component\Prompt\State\Factory(
$internal[UI\Implementation\Component\Listing\Entity\Factory::class],
$internal[UI\Implementation\Component\MessageBox\Factory::class],
$internal[UI\Implementation\Component\Input\Factory::class],
);
$internal[UI\Implementation\Component\Prompt\Factory::class] = static fn() =>
new UI\Implementation\Component\Prompt\Factory(
$internal[UI\Implementation\Component\SignalGeneratorInterface::class],
$internal[UI\Implementation\Component\Prompt\State\Factory::class],
);
$internal[UI\Implementation\Component\Prompt\State\Factory::class] = static fn() =>
new UI\Implementation\Component\Prompt\State\Factory();

$internal[UI\Implementation\Component\Navigation\Factory::class] = static fn() =>
new UI\Implementation\Component\Navigation\Factory(
Expand Down Expand Up @@ -551,6 +556,16 @@ public function init(
$use[UI\HelpTextRetriever::class],
$internal[UI\Implementation\Component\Input\UploadLimitResolver::class],
),
new UI\Implementation\Component\Entity\EntityRendererFactory(
$use[UI\Implementation\FactoryInternal::class],
$internal[UI\Implementation\Render\TemplateFactory::class],
$use[Language\Language::class],
$internal[UI\Implementation\Render\JavaScriptBinding::class],
$use[UI\Implementation\Render\ImagePathResolver::class],
$pull[Data\Factory::class],
$use[UI\HelpTextRetriever::class],
$internal[UI\Implementation\Component\Input\UploadLimitResolver::class],
)
)
)
);
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/UI/resources/js/Prompt/dist/prompt.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 26 additions & 15 deletions components/ILIAS/UI/resources/js/Prompt/src/prompt.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ export default class Prompt {
const buttons = doc.querySelector('section[data-section="il-prompt-state__buttons"]');
const command = doc.querySelector('section[data-section="il-prompt-state__command"]');
const parameters = doc.querySelector('section[data-section="il-prompt-state__parameters"]');
const scripts = doc.querySelector('script');
const scripts = doc.querySelector('script[data-replace-marker="script"]');
const dialogTitle = this.#prompt.querySelector('span.il-prompt__title');
const dialogContents = this.#prompt.querySelector('div.il-prompt__contents');
const dialogButtons = this.#prompt.querySelector('div.il-prompt__buttons');
dialogTitle.innerHTML = title.innerHTML;
dialogContents.innerHTML = contents.innerHTML;
dialogButtons.innerHTML = buttons.innerHTML;
if (title) {
dialogTitle.innerHTML = title.innerHTML;
}
if (contents) {
dialogContents.innerHTML = contents.innerHTML;
}
if (buttons) {
dialogButtons.innerHTML = buttons.innerHTML;
}

this.#captureForms(dialogContents);
this.#captureLinks(dialogContents);
Expand All @@ -85,14 +91,16 @@ export default class Prompt {
}

const params = [];
parameters.querySelectorAll('data').forEach(
(data) => {
params[data.innerHTML.trim()] = data.getAttribute('value');
},
);
if (parameters) {
parameters.querySelectorAll('data').forEach(
(data) => {
params[data.innerHTML.trim()] = data.getAttribute('value');
},
);
}

return {
cmd: command.innerHTML.trim(),
cmd: command ? command.innerHTML.trim() : '',
params,
};
})
Expand All @@ -117,7 +125,12 @@ export default class Prompt {
#appendScript(js) {
const dialogScript = this.#component.querySelector('section.il-prompt__scripts');
const script = document.createElement('script');
script.text = js;
script.text = js
.replace(/il\.UI\.prompt\.init\([^)]*\);?/g, '')
.replace(
/\$\(this\)\.trigger\('(il_signal_[^']+)'/g,
"$(document).trigger('$1'",
);
dialogScript.innerHTML = '';
dialogScript.appendChild(script);
}
Expand All @@ -127,8 +140,7 @@ export default class Prompt {
* @return {void}
*/
#captureForms(doc) {
const forms = doc.getElementsByTagName('form');
forms.forEach(
doc.querySelectorAll('form').forEach(
(form) => {
form.addEventListener('submit', (e) => {
e.preventDefault();
Expand All @@ -146,8 +158,7 @@ export default class Prompt {
* @return {void}
*/
#captureLinks(doc) {
const links = doc.getElementsByTagName('a');
links.forEach(
doc.querySelectorAll('a').forEach(
(lnk) => {
const { target } = lnk;
if (target !== '_blank') {
Expand Down
10 changes: 7 additions & 3 deletions components/ILIAS/UI/resources/js/Prompt/src/prompt.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* https://github.com/ILIAS-eLearning
*/

import Prompt from './prompt.class';
import Prompt from './prompt.class.js';

export default class PromptFactory {
/**
Expand All @@ -40,10 +40,14 @@ export default class PromptFactory {
*/
init(id) {
if (this.#instances[id] !== undefined) {
throw new Error(`Prompt with id '${id}' has already been initialized.`);
return;
}

this.#instances[id] = new Prompt(this.#DOMParser, id);
try {
this.#instances[id] = new Prompt(this.#DOMParser, id);
} catch (error) {
// Prompt element may not exist yet during async content replacement.
}
}

/**
Expand Down
5 changes: 5 additions & 0 deletions components/ILIAS/UI/src/Component/Entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
*/
interface Entity extends Component
{
/**
* Returns the technical identifier of this entity.
*/
public function getId(): string|int;

//Priority Areas

/**
Expand Down
61 changes: 61 additions & 0 deletions components/ILIAS/UI/src/Component/Entity/EntityRetrieval.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?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\Entity;

use Generator;
use ILIAS\Data\Order;
use ILIAS\Data\Range;

/**
* This describes how entities should be retrieved for different purposes.
*/
interface EntityRetrieval
{
/**
* This method is used by the Entity Listing to visualise all available entities.
*
* The signature mirrors {@see \ILIAS\UI\Component\Table\DataRetrieval::getRows()},
* so the UI framework can create expectations (order/range/grouping/etc.) globally
* and it allows future extension of additional (view/filter) controls.
*
* @return Generator<Entity>
*/
public function getEntities(
\ILIAS\UI\Factory $ui_factory,
Range $range,
Order $order,
mixed $additional_viewcontrol_data,
mixed $filter_data,
mixed $additional_parameters,
): Generator;

/**
* This method is used by the Prompt State to confirm a subset of entities.
*
* @param array<int|string> $entity_ids
* @return Generator<Entity>
*/
public function getEntitiesByIds(
\ILIAS\UI\Factory $ui_factory,
Order $order,
array $entity_ids,
): Generator;
}
8 changes: 6 additions & 2 deletions components/ILIAS/UI/src/Component/Entity/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ interface Factory
* The Standard Entity can (and should) be used to list system entities
* such as repository objects, users and similar.
* ---
* @param string|int $technical_identifier
* @param Symbol|Image|ShyButton|ShyLink|string $primary_visual_identifier
* @param Symbol|Image|ShyButton|ShyLink|string $secondary_visual_identifier
* @return \ILIAS\UI\Component\Entity\Standard
*/
public function standard(
Symbol | Image | ShyButton | ShyLink | string $primary_identifier,
Symbol | Image | ShyButton | ShyLink | string $secondary_identifier
string|int $technical_identifier,
Symbol|Image|ShyButton|ShyLink|string $primary_visual_identifier,
Symbol|Image|ShyButton|ShyLink|string $secondary_visual_identifier,
): Standard;
}
40 changes: 0 additions & 40 deletions components/ILIAS/UI/src/Component/Listing/Entity/DataRetrieval.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

namespace ILIAS\UI\Component\Listing\Entity;

use ILIAS\UI\Component\Entity\Entity;
use ILIAS\UI\Component\Component;

/**
* Hand a record over to RecordToEntity and factor an Entity
* This is what an EntityListings looks like
*/
interface Mapping
interface Entity extends Component
{
public function map(mixed $record): Entity;
}
36 changes: 0 additions & 36 deletions components/ILIAS/UI/src/Component/Listing/Entity/EntityListing.php

This file was deleted.

10 changes: 6 additions & 4 deletions components/ILIAS/UI/src/Component/Listing/Entity/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

namespace ILIAS\UI\Component\Listing\Entity;

use ILIAS\UI\Component\Entity\EntityRetrieval;

/**
* This is what a factory for EntityListings looks like
*/
Expand All @@ -36,10 +38,10 @@ interface Factory
* the space optimally. The design of the entity is one that favors a more horizontal representation.
*
* ---
* @param \ILIAS\UI\Component\Listing\Entity\RecordToEntity $entity_mapping
* @param \ILIAS\UI\Component\Entity\EntityRetrieval $entity_retrieval
* @return \ILIAS\UI\Component\Listing\Entity\Standard
*/
public function standard(RecordToEntity $entity_mapping): Standard;
public function standard(EntityRetrieval $entity_retrieval): Standard;

/**
* ---
Expand All @@ -57,8 +59,8 @@ public function standard(RecordToEntity $entity_mapping): Standard;
* with the same height.
*
* ---
* @param \ILIAS\UI\Component\Listing\Entity\RecordToEntity $entity_mapping
* @param \ILIAS\UI\Component\Entity\EntityRetrieval $entity_retrieval
* @return \ILIAS\UI\Component\Listing\Entity\Grid
*/
public function grid(RecordToEntity $entity_mapping): Grid;
public function grid(EntityRetrieval $entity_retrieval): Grid;
}
2 changes: 1 addition & 1 deletion components/ILIAS/UI/src/Component/Listing/Entity/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@

namespace ILIAS\UI\Component\Listing\Entity;

interface Grid extends EntityListing
interface Grid extends Entity
{
}
Loading
Loading