Skip to content

Commit

Permalink
[FEATURE] ILIASObject: remove ilProgressBar usage in progress table.
Browse files Browse the repository at this point in the history
  • Loading branch information
thibsy committed Oct 28, 2024
1 parent 4e878b6 commit 9655d2a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 33 deletions.
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
Expand Up @@ -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
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

0 comments on commit 9655d2a

Please sign in to comment.