19 declare(strict_types=1);
47 $uri =
$http->request()->getUri();
48 $request =
$http->wrapper()->query();
49 $factory = $DIC->ui()->factory();
51 $data_factory = new \ILIAS\Data\Factory();
53 $endpoint_flag =
'progress_bar_example_endpoint';
54 $endpoint_url = $uri .
"&$endpoint_flag=1";
55 $endpoint_url = $data_factory->uri($endpoint_url);
57 $progress_bar = $factory->progress()->bar(
'waiting about 10 seconds', $endpoint_url);
59 $trigger = $factory->button()->standard(
'start making progress',
'#');
60 $trigger = $trigger->withAdditionalOnLoadCode(
61 static fn(
string $id) =>
" 62 document.getElementById('$id')?.addEventListener('click', (event) => { 63 // always 'kick off' async progress bars with an indeterminate state. 64 il.UI.Progress.Bar.indeterminate('{$progress_bar->getUpdateSignal()}', 'Estimating...'); 65 event.target.disabled = true; 70 if ($request->has($endpoint_flag)) {
74 return $renderer->render([$progress_bar, $trigger]);
83 $state = match ($task_progress) {
84 1 => $state = $factory->progress()->state()->bar()->determinate(10,
'Start processing...'),
85 2 => $state = $factory->progress()->state()->bar()->determinate(20),
86 3 => $state = $factory->progress()->state()->bar()->determinate(30),
87 4 => $state = $factory->progress()->state()->bar()->determinate(40),
88 5 => $state = $factory->progress()->state()->bar()->determinate(50,
'Still processing...'),
89 6 => $state = $factory->progress()->state()->bar()->determinate(60),
90 7 => $state = $factory->progress()->state()->bar()->determinate(70),
91 8 => $state = $factory->progress()->state()->bar()->determinate(80),
92 9 => $state = $factory->progress()->state()->bar()->determinate(90),
93 10 => $state = $factory->progress()->state()->bar()->success(
"All done!"),
94 default => $state = $factory->progress()->state()->bar()->failure(
"An error ocurred."),
97 if (10 > $task_progress) {
103 $html = $renderer->renderAsync($state);
107 ->withHeader(
'Content-Type',
'text/html; charset=utf-8')
108 ->withBody(Streams::ofString($html))
123 $previous_value =
\ilSession::get(__NAMESPACE__ .
'_example_task_progress');
124 \ilSession::set(__NAMESPACE__ .
'_example_task_progress', (
int) $previous_value + 1);
static get(string $a_var)
callArtificialTaskEndpoint(GlobalHttpState $http, UI\Factory $factory, UI\Renderer $renderer)
sendResponse()
Render the current response hold by ILIAS.
saveResponse(ResponseInterface $response)
Saves the given response for further use.
server()
description: > This example shows how a Progress Bar can be rendered and updated by the server...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
response()
Returns the current psr-7 response.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initialiseArtificialTaskOnce()
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.