Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] ILIASObject: remove ilProgressBar usage #8270

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from
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
44 changes: 22 additions & 22 deletions components/ILIAS/ILIASObject/classes/class.ilObjectCopyGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use ILIAS\UI\Renderer as UIRenderer;
use ILIAS\UI\Component\Input\Container\Form\Standard;
use ILIAS\Object\ImplementsCreationCallback;
use ILIAS\HTTP\GlobalHttpState;

/**
* GUI class for the workflow of copying objects
Expand Down Expand Up @@ -73,6 +74,7 @@ class ilObjectCopyGUI
protected ServerRequestInterface $request;
protected UIFactory $ui_factory;
protected UIRenderer $ui_renderer;
protected GlobalHttpState $http;

protected ContainerDBRepository $container_repo;

Expand Down Expand Up @@ -112,6 +114,7 @@ public function __construct(ImplementsCreationCallback $parent_gui)
$this->ui_factory = $DIC['ui.factory'];
$this->ui_renderer = $DIC['ui.renderer'];
$this->retriever = new ilObjectRequestRetriever($DIC->http()->wrapper(), $this->refinery);
$this->http = $DIC->http();

$this->container_repo = new ContainerDBRepository($DIC['ilDB']);

Expand Down Expand Up @@ -1017,34 +1020,31 @@ protected function showCopyProgress(): void

protected function updateProgress(): void
{
$json = new stdClass();
$json->percentage = null;
$json->performed_steps = null;

$max_steps = $this->retriever->getMaybeInt('_max_steps');
$copy_id = $this->retriever->getMaybeInt('_copy_id');
$options = ilCopyWizardOptions::_getInstance($copy_id);
$node = $options->fetchFirstNode();
$json->current_node_id = 0;
$json->current_node_title = "";
$json->in_dependencies = false;
if (is_array($node)) {
$json->current_node_id = $node['obj_id'];
$json->current_node_title = $node['title'];
$required_steps = $options->getRequiredSteps();

if (0 === $required_steps) {
$state = $this->ui_factory->progress()->state()->bar()->success($this->lng->txt('copied'));
} else {
$node = $options->fetchFirstDependenciesNode();
if (is_array($node)) {
$json->current_node_id = $node['obj_id'];
$json->current_node_title = $node['title'];
$json->in_dependencies = true;
}
$completed_steps = $max_steps - $required_steps;
$percentage = floor(($completed_steps / $max_steps) * 100);
$percentage = min($percentage, 99); // cap value to 99
$percentage = (int) $percentage;

$state = $this->ui_factory->progress()->state()->bar()->determinate($percentage);
}
$json->required_steps = $options->getRequiredSteps();
$json->id = $copy_id;

$this->log->debug('Update copy progress: ' . json_encode($json));
$html = $this->ui_renderer->renderAsync($state);

echo json_encode($json);
exit;
$this->http->saveResponse(
$this->http->response()
->withHeader('Content-Type', 'text/html; charset=utf-8')
->withBody(\ILIAS\Filesystem\Stream\Streams::ofString($html))
);
$this->http->sendResponse();
$this->http->close();
}

protected function copyContainer(int $target_ref_id): array
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Table gui for copy progress
*
Expand All @@ -27,9 +27,17 @@ class ilObjectCopyProgressTableGUI extends ilTable2GUI
{
protected array $objects = [];

protected \ILIAS\Data\Factory $data_factory;
protected \ILIAS\UI\Renderer $ui_renderer;
protected \ILIAS\UI\Factory $ui_factory;

public function __construct(ilObjectCopyGUI $parent_obj, string $parent_cmd, int $id)
{
global $DIC;
$this->setId('obj_cp_prog_tbl_' . $id);
$this->ui_factory = $DIC->ui()->factory();
$this->ui_renderer = $DIC->ui()->renderer();
$this->data_factory = new \ILIAS\Data\Factory();
parent::__construct($parent_obj, $parent_cmd);
}

Expand Down Expand Up @@ -73,16 +81,11 @@ protected function fillRow(array $set): void
$this->tpl->setVariable('TYPE_IMG', ilObject::_getIcon($set['obj_id'], "small", $set['type']));
$this->tpl->setVariable('TYPE_STR', $this->lng->txt('obj_' . $set['type']));

$progress = ilProgressBar::getInstance();
$progress->setType(ilProgressBar::TYPE_SUCCESS);
$progress->setMin(0);
$progress->setMax($set['max_steps']);
$progress->setCurrent(0);
$progress->setAnimated(true);
$progress->setId((string) $set['copy_id']);

$this->ctrl->setParameter($this->getParentObject(), '_copy_id', $set['copy_id']);
$progress->setAsyncStatusUrl(
$this->ctrl->setParameter($this->getParentObject(), '_max_steps', $set['max_steps']);

$progress_endpoint = $this->data_factory->uri(
ILIAS_HTTP_PATH . '/' .
$this->ctrl->getLinkTarget(
$this->getParentObject(),
'updateProgress',
Expand All @@ -91,8 +94,15 @@ protected function fillRow(array $set): void
)
);

$progress->setAsynStatusTimeout(1);
$this->tpl->setVariable('PROGRESS_BAR', $progress->render());
$progress_bar = $this->ui_factory->progress()->bar(
$this->lng->txt('copy_of') . ' ' . $set['title'],
$progress_endpoint
);

$this->tpl->setVariable('PROGRESS_BAR', $this->ui_renderer->render($progress_bar));

// start pulling progress from $endpoint once as soon as the page has loaded.
$this->main_tpl->addOnLoadCode("il.UI.Progress.Bar.indeterminate('{$progress_bar->getUpdateSignal()}')");
}

public function parse(): void
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default class ProgressBarAsyncDecorator {
const state = await this.#asyncRenderer.loadContent(this.#asyncUrl);
this.#handleState(state);
} catch (error) {
this.#progressBar.failure(error.message);
this.failure(error.message);
} finally {
this.#isFetching = false;
}
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_de.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3837,6 +3837,7 @@ common#:#continue#:#Weiter
common#:#continue_work#:#Fortsetzen
common#:#contra#:#Contra
common#:#copa#:#Inhaltsseite
common#:#copied#:#Kopiert
common#:#copy#:#Kopieren
common#:#copyChapter#:#Kopieren
common#:#copyPage#:#Kopieren
Expand Down
1 change: 1 addition & 0 deletions lang/ilias_en.lang
Original file line number Diff line number Diff line change
Expand Up @@ -3837,6 +3837,7 @@ common#:#continue#:#Continue
common#:#continue_work#:#Continue
common#:#contra#:#Contra
common#:#copa#:#Content Page
common#:#copied#:#Copied
common#:#copy#:#Copy
common#:#copyChapter#:#Copy
common#:#copyPage#:#Copy
Expand Down
Loading