Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use ILIAS\GlobalScreen\GUI\I18n\MultiLanguage\TranslationWorkflowForm;
use ILIAS\GlobalScreen\GUI\Pons;
use ILIAS\Data\URI;
use ILIAS\UI\URLBuilder;

/**
* @author Fabian Schmid <fabian@sr.solutions>
Expand Down Expand Up @@ -115,7 +116,9 @@ private function index(): void
}

$prompt = $this->ui_factory->prompt()->standard(
$this->pons->flow()->getHereAsURI(self::CMD_LANGUAGE_SELECTION)
new URLBuilder(
$this->pons->flow()->getHereAsURI(self::CMD_LANGUAGE_SELECTION)
)
);

// Edit Button
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/UI/resources/js/Table/dist/table.min.js

Large diffs are not rendered by default.

25 changes: 18 additions & 7 deletions components/ILIAS/UI/resources/js/Table/src/datatable.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ export default class DataTable {
#jquery;

/**
* @type {actionId: string, rowId: string}
* @type {JQueryEventDispatcher}
*/
#eventDispatcher;

/**
* @type {actionId: string, rowId: string, async: string}
*/
#signalConstants;

Expand Down Expand Up @@ -70,18 +75,19 @@ export default class DataTable {
#table;

/**
* @type {array<string, {async: bool, urlBuilder: URLBuilder, urlTokens: Map}>}
* @type {array<string, {async: bool, signalId: string, urlBuilder: URLBuilder, urlTokens: Map}>}
*/
#actionsRegistry;

/**
* @param {jQuery} jquery
* @param {JQueryEventDispatcher} eventDispatcher
* @param {string} optActionId
* @param {string} optRowId
* @param {string} tableId
* @throws {Error} if DOM element is missing
*/
constructor(jquery, optActionId, optRowId, componentId) {
constructor(jquery, eventDispatcher, optActionId, optRowId, componentId) {
this.#component = document.getElementById(componentId);
if (this.#component === null) {
throw new Error(`Could not find a DataTable for id '${componentId}'.`);
Expand All @@ -95,6 +101,7 @@ export default class DataTable {
this.#responseContent = this.#responseContainer.getElementsByClassName('c-table-data__async_messageresponse').item(0);

this.#jquery = jquery;
this.#eventDispatcher = eventDispatcher;
this.#signalConstants = {
actionId: optActionId,
rowId: optRowId,
Expand All @@ -113,13 +120,15 @@ export default class DataTable {
/**
* @param {string} actionId
* @param {bool} async
* @param {string} signalId
* @param {URLBuilder} urlBuilder
* @param {Map} urlTokens
* @return {void}
*/
registerAction(actionId, async, urlBuilder, urlTokens) {
registerAction(actionId, async, signalId, urlBuilder, urlTokens) {
this.#actionsRegistry[actionId] = {
async,
signalId,
urlBuilder,
urlTokens,
};
Expand Down Expand Up @@ -251,7 +260,6 @@ export default class DataTable {
const k = this.#signalConstants.actionId;
const signalData = { options: {} };
signalData.options[k] = selectedAction;

modalClose.click();
this.doAction(signalData, ['ALL_OBJECTS']);
}
Expand All @@ -269,10 +277,13 @@ export default class DataTable {
action.urlBuilder.writeParameter(token, rowIds);
const target = decodeURI(action.urlBuilder.getUrl().toString());

if (!action.async) {
if (action.signalId === '') {
window.location.href = target;
} else {
} else if (action.async) {
this.asyncAction(target);
} else {
signalData.options.url = target;
this.#eventDispatcher.dispatch(this.#component, action.signalId, signalData);
}
}

Expand Down
10 changes: 9 additions & 1 deletion components/ILIAS/UI/resources/js/Table/src/datatable.factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,23 @@ export default class DataTableFactory {
*/
#jquery;

/**
* @type {JQueryEventDispatcher}
*/
#eventDispatcher;

/**
* @type {Array<string, DataTable>}
*/
#instances = [];

/**
* @param {jQuery} jquery
* @param {JQueryEventDispatcher} eventDispatcher
*/
constructor(jquery) {
constructor(jquery, eventDispatcher) {
this.#jquery = jquery;
this.#eventDispatcher = eventDispatcher;
}

/**
Expand All @@ -47,6 +54,7 @@ export default class DataTableFactory {

this.#instances[tableId] = new DataTable(
this.#jquery,
this.#eventDispatcher,
optActionId,
optRowId,
tableId,
Expand Down
11 changes: 7 additions & 4 deletions components/ILIAS/UI/resources/js/Table/src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@

import il from 'il';
import $ from 'jquery';
import DataTableFactory from './datatable.factory';
import PresentationTableFactory from './presentationtable.factory';
import OrderingTableFactory from './orderingtable.factory';
import DataTableFactory from './datatable.factory.js';
import PresentationTableFactory from './presentationtable.factory.js';
import OrderingTableFactory from './orderingtable.factory.js';
import JQueryEventDispatcher from '../../Core/src/jqueryeventdispatcher.js';

const eventDispatcher = new JQueryEventDispatcher($);

il.UI = il.UI || {};
il.UI.table = il.UI.table || {};
il.UI.table.data = new DataTableFactory($);
il.UI.table.data = new DataTableFactory($, eventDispatcher);
il.UI.table.presentation = new PresentationTableFactory();
il.UI.table.ordering = new OrderingTableFactory();
6 changes: 3 additions & 3 deletions components/ILIAS/UI/src/Component/Prompt/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
namespace ILIAS\UI\Component\Prompt;

use ILIAS\UI\Component;
use ILIAS\Data\URI;
use ILIAS\UI\URLBuilder;

interface Factory
{
Expand All @@ -47,11 +47,11 @@ interface Factory
* usage:
* 1: >
* The server MUST answer with an Prompt State Component
* to a request to the url provided to the Prompt.
* to a request to the url provided to the Prompt via the URLBuilder.
* ---
* @return \ILIAS\UI\Component\Prompt\Prompt
*/
public function standard(URI $async_url): Prompt;
public function standard(URLBuilder $url_builder): Prompt;

/**
* ---
Expand Down
7 changes: 7 additions & 0 deletions components/ILIAS/UI/src/Component/Prompt/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use ILIAS\UI\Component\JavaScriptBindable;
use ILIAS\UI\Component\Signal;
use ILIAS\Data\URI;
use ILIAS\UI\URLBuilderToken;

interface Prompt extends Component, JavaScriptBindable
{
Expand All @@ -36,4 +37,10 @@ public function getShowSignal(?URI $uri = null): Signal;
* Get the signal to close this Prompt.
*/
public function getCloseSignal(): Signal;

/**
* Consumers my modify the target url by altering the parameter
* identified by the respective token.
*/
public function withParameter(URLBuilderToken $token, string|array $value): self;
}
3 changes: 3 additions & 0 deletions components/ILIAS/UI/src/Component/Table/Action/Action.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@

interface Action extends \ILIAS\UI\Component\Component
{
/**
* @deprecated with ILIAS 11. Please use Prompt.
*/
public function withAsync(bool $async = true): self;
}
7 changes: 4 additions & 3 deletions components/ILIAS/UI/src/Component/Table/Action/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use ILIAS\UI\URLBuilder;
use ILIAS\UI\URLBuilderToken;
use ILIAS\UI\Component\Prompt\Prompt;

interface Factory
{
Expand All @@ -37,7 +38,7 @@ interface Factory
*/
public function standard(
string $label,
URLBuilder $url_builder,
Prompt | URLBuilder $target,
URLBuilderToken $row_id_parameter
): Standard;

Expand All @@ -53,7 +54,7 @@ public function standard(
*/
public function single(
string $label,
URLBuilder $url_builder,
Prompt | URLBuilder $target,
URLBuilderToken $row_id_parameter
): Single;

Expand All @@ -69,7 +70,7 @@ public function single(
*/
public function multi(
string $label,
URLBuilder $url_builder,
Prompt | URLBuilder $target,
URLBuilderToken $row_id_parameter
): Multi;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use ILIAS\UI\Component\Prompt as I;
use ILIAS\UI\Implementation\Component\SignalGeneratorInterface;
use ILIAS\Data\URI;
use ILIAS\UI\URLBuilder;

class Factory implements I\Factory
{
Expand All @@ -31,9 +31,9 @@ public function __construct(
) {
}

public function standard(URI $async_url): Standard
public function standard(URLBuilder $url_builder): Standard
{
return new Standard($this->signal_generator, $async_url);
return new Standard($this->signal_generator, $url_builder);
}

public function state(): State\Factory
Expand Down
21 changes: 17 additions & 4 deletions components/ILIAS/UI/src/Implementation/Component/Prompt/Prompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
use ILIAS\UI\Implementation\Component\ComponentHelper;
use ILIAS\UI\Implementation\Component\JavaScriptBindable;
use ILIAS\UI\Implementation\Component\SignalGenerator;

use ILIAS\Data\URI;
use ILIAS\UI\URLBuilder;
use ILIAS\UI\URLBuilderToken;

/**
*
Expand All @@ -41,20 +42,25 @@ abstract class Prompt implements I\Prompt

public function __construct(
SignalGenerator $signal_generator,
protected URI $async_url
protected URLBuilder $url_builder
) {
$this->show_signal = $signal_generator->create();
$this->close_signal = $signal_generator->create();
}

public function getAsyncUrl(): URI
{
return $this->async_url;
return $this->url_builder->buildURI();
}

public function getURLBuilder(): URLBuilder
{
return $this->url_builder;
}

public function getShowSignal(?URI $uri = null): Signal
{
$target = $uri ?? $this->async_url;
$target = $uri ?? $this->getAsyncUrl();
$signal = clone $this->show_signal;
$signal->addOption('url', $target->__toString());
return $signal;
Expand All @@ -64,4 +70,11 @@ public function getCloseSignal(): Signal
{
return $this->close_signal;
}

public function withParameter(URLBuilderToken $token, string|array $value): self
{
$clone = clone $this;
$clone->url_builder = $clone->url_builder->withParameter($token, $value);
return $clone;
}
}
Loading