diff --git a/Services/Awareness/classes/Provider/AwarenessToastProvider.php b/Services/Awareness/classes/Provider/AwarenessToastProvider.php index 7c6c91c4485c..b6f1b977b516 100644 --- a/Services/Awareness/classes/Provider/AwarenessToastProvider.php +++ b/Services/Awareness/classes/Provider/AwarenessToastProvider.php @@ -79,15 +79,12 @@ public function getToasts(): array ); if ($new_users !== []) { - $setting = new ilSetting('notifications'); $toast = $this->toast_factory ->standard( $this->if->identifier(self::PROVIDER_KEY . '_' . $this->dic->user()->getId()), $this->dic->language()->txt('awareness_now_online') ) - ->withIcon($this->dic->ui()->factory()->symbol()->icon()->standard(Standard::USR, '')) - ->withVanishTime((int) $setting->get('osd_vanish', (string) Toast::DEFAULT_VANISH_TIME)) - ->withDelayTime((int) $setting->get('osd_delay', (string) Toast::DEFAULT_DELAY_TIME)); + ->withIcon($this->dic->ui()->factory()->symbol()->icon()->standard(Standard::USR, '')); $links = []; foreach ($new_users as $user) { $uname = "[" . $user['login'] . "]"; diff --git a/Services/GlobalScreen/classes/class.ilGSProviderFactory.php b/Services/GlobalScreen/classes/class.ilGSProviderFactory.php index 4dbbae533a1a..f3bce269b35c 100644 --- a/Services/GlobalScreen/classes/class.ilGSProviderFactory.php +++ b/Services/GlobalScreen/classes/class.ilGSProviderFactory.php @@ -29,6 +29,7 @@ use ILIAS\GlobalScreen\Scope\Notification\Provider\NotificationProvider; use ILIAS\GlobalScreen\Scope\Toast\Provider\ToastProvider; use ILIAS\GlobalScreen\Scope\Tool\Provider\DynamicToolProvider; +use ILIAS\UI\Component\Toast\Container as ToastContainer; /** * Class ilGSProviderFactory @@ -227,6 +228,24 @@ public function getToastsProvider(): array return $providers; } + /** + * @inheritDoc + */ + public function getToastContainer(): ToastContainer + { + $settings = new ilSetting('notifications'); + $container = $this->dic->ui()->factory()->toast()->container(); + + if ($vanish = $settings->get('osd_vanish')) { + $container = $container->withVanishTime((int) $vanish); + } + if ($delay = $settings->get('osd_delay')) { + $container = $container->withDelayTime((int) $delay); + } + + return $container; + } + /** * @param array $array_of_providers * @param string $interface diff --git a/Services/Notifications/classes/Provider/NotificationToastProvider.php b/Services/Notifications/classes/Provider/NotificationToastProvider.php index 4b664f32bc55..dbd25fac87e7 100644 --- a/Services/Notifications/classes/Provider/NotificationToastProvider.php +++ b/Services/Notifications/classes/Provider/NotificationToastProvider.php @@ -43,11 +43,9 @@ class NotificationToastProvider extends AbstractToastProvider */ public function getToasts(): array { - $settings = new ilSetting('notifications'); $toasts = []; if ( - $settings->get('enable_osd', '0') !== '1' || 0 === $this->dic->user()->getId() || $this->dic->user()->isAnonymous() ) { @@ -70,8 +68,6 @@ public function getToasts(): array ) ->withIcon($this->getIconByType($notification->getType())) ->withDescription($notification->getObject()->shortDescription) - ->withVanishTime((int) $settings->get('osd_vanish', (string) Toast::DEFAULT_VANISH_TIME)) - ->withDelayTime((int) $settings->get('osd_delay', (string) Toast::DEFAULT_DELAY_TIME)) ->withClosedCallable(static function () use ($osd_repository, $notification) { $osd_repository->deleteOSDNotificationById($notification->getId()); }); diff --git a/src/GlobalScreen/Collector/CollectorFactory.php b/src/GlobalScreen/Collector/CollectorFactory.php index 4edcba8ed020..39e96acbf9f0 100644 --- a/src/GlobalScreen/Collector/CollectorFactory.php +++ b/src/GlobalScreen/Collector/CollectorFactory.php @@ -1,6 +1,5 @@ getWithArgument(ToastCollector::class, $this->provider_factory->getToastsProvider()); + return $this->getWithMultipleArguments(ToastCollector::class, [$this->provider_factory->getToastsProvider(), $this->provider_factory->getToastContainer()]); } } diff --git a/src/GlobalScreen/Provider/NullProviderFactory.php b/src/GlobalScreen/Provider/NullProviderFactory.php index c3fc3aa989fc..9886f6028360 100644 --- a/src/GlobalScreen/Provider/NullProviderFactory.php +++ b/src/GlobalScreen/Provider/NullProviderFactory.php @@ -1,6 +1,5 @@ ui->factory()->toast()->container(); + $toast_container = $this->gs->collector()->toasts()->getContainer(); foreach ($this->gs->collector()->toasts()->getToasts() as $toast) { $renderer = $toast->getRenderer(); $toast_container = $toast_container->withAdditionalToast($renderer->getToastComponentForItem($toast)); } + $toast_container = $toast_container->withAdditionalToast( + $this->ui->factory()->toast()->standard( + 'Test', + $this->ui->factory()->symbol()->icon()->standard("nota", 'test') + ) + ); + return $toast_container; } } diff --git a/src/GlobalScreen/Scope/Toast/Collector/Renderer/StandardToastRenderer.php b/src/GlobalScreen/Scope/Toast/Collector/Renderer/StandardToastRenderer.php index 92bb833f1d9f..c29ea52b2b62 100644 --- a/src/GlobalScreen/Scope/Toast/Collector/Renderer/StandardToastRenderer.php +++ b/src/GlobalScreen/Scope/Toast/Collector/Renderer/StandardToastRenderer.php @@ -127,15 +127,6 @@ public function getToastComponentForItem(isItem $item): Component $toast = $toast->withAdditionalLink($link); } - // Times (currently disbaled since these methods are not on the Interface of a Toast - if ($item->getVanishTime() !== null) { - // $toast = $toast->withVanishTime($item->getVanishTime()); - } - - if ($item->getDelayTime() !== null) { - // $toast = $toast->withDelayTime($item->getDelayTime()); - } - return $toast; } diff --git a/src/GlobalScreen/Scope/Toast/Collector/ToastCollector.php b/src/GlobalScreen/Scope/Toast/Collector/ToastCollector.php index 27bf1384eb44..b34e1d99587c 100644 --- a/src/GlobalScreen/Scope/Toast/Collector/ToastCollector.php +++ b/src/GlobalScreen/Scope/Toast/Collector/ToastCollector.php @@ -1,4 +1,5 @@ providers = $providers; + $this->container = $container; $this->collectOnce(); } @@ -78,4 +82,9 @@ public function getToasts(): array { return $this->toasts; } + + public function getContainer(): Container + { + return $this->container; + } } diff --git a/src/GlobalScreen/Scope/Toast/Factory/StandardToastItem.php b/src/GlobalScreen/Scope/Toast/Factory/StandardToastItem.php index cb7312d6a6fd..cf95191ffc4a 100644 --- a/src/GlobalScreen/Scope/Toast/Factory/StandardToastItem.php +++ b/src/GlobalScreen/Scope/Toast/Factory/StandardToastItem.php @@ -227,30 +227,6 @@ public function hasVanishedAction(): bool return $this->handle_vanished !== null; } - public function withVanishTime(int $miliseconds): isStandardItem - { - $clone = clone $this; - $clone->vanish_time = $miliseconds; - return $clone; - } - - public function getVanishTime(): ?int - { - return $this->vanish_time; - } - - public function withDelayTime(int $miliseconds): isStandardItem - { - $clone = clone $this; - $clone->delay_time = $miliseconds; - return $clone; - } - - public function getDelayTime(): ?int - { - return $this->delay_time; - } - final public function getRenderer(): ToastRenderer { return $this->renderer; diff --git a/src/GlobalScreen/Scope/Toast/Factory/isStandardItem.php b/src/GlobalScreen/Scope/Toast/Factory/isStandardItem.php index e682abadfb45..e5914c30cec9 100644 --- a/src/GlobalScreen/Scope/Toast/Factory/isStandardItem.php +++ b/src/GlobalScreen/Scope/Toast/Factory/isStandardItem.php @@ -102,13 +102,5 @@ public function getVanishedAction(): ?ToastAction; */ public function hasVanishedAction(): bool; - public function withVanishTime(int $miliseconds): isStandardItem; - - public function getVanishTime(): ?int; - - public function withDelayTime(int $miliseconds): isStandardItem; - - public function getDelayTime(): ?int; - public function getRenderer(): ToastRenderer; } diff --git a/src/UI/Component/Toast/Container.php b/src/UI/Component/Toast/Container.php index 9076cdcc34e3..8f5208a3588c 100644 --- a/src/UI/Component/Toast/Container.php +++ b/src/UI/Component/Toast/Container.php @@ -1,7 +1,5 @@ toasts = []; return $clone; } + + public function withVanishTime(int $vanishTime): Container + { + $new = clone $this; + $new->vanishTime = $vanishTime; + return $new; + } + + public function getVanishTime(): int + { + return $this->vanishTime; + } + + public function withDelayTime(int $delayTime): Container + { + $new = clone $this; + $new->delayTime = $delayTime; + return $new; + } + + public function getDelayTime(): int + { + return $this->delayTime; + } } diff --git a/src/UI/Implementation/Component/Toast/Renderer.php b/src/UI/Implementation/Component/Toast/Renderer.php index 6efb96270cf0..bfcd8b582ab5 100644 --- a/src/UI/Implementation/Component/Toast/Renderer.php +++ b/src/UI/Implementation/Component/Toast/Renderer.php @@ -1,7 +1,5 @@ setVariable("TITLE", $title); - $tpl->setVariable("TOAST_DELAY", $component->getDelayTime()); - $tpl->setVariable("TOAST_VANISH", $component->getVanishTime()); $tpl->setVariable("VANISH_ASYNC", $component->getAction()); $desc = htmlentities($component->getDescription()); @@ -82,10 +80,7 @@ protected function renderToast(Component\Toast\Toast $component, RendererInterfa $tpl->setVariable("ICON", $default_renderer->render($component->getIcon())); $tpl->setVariable("CLOSE", $default_renderer->render($this->getUIFactory()->button()->close())); - $component = $component->withAdditionalOnLoadCode(fn ($id) => " - il.UI.toast.setToastSettings($id); - il.UI.toast.showToast($id); - "); + $component = $component->withAdditionalOnLoadCode(fn ($id) => "il.UI.toast.showToast($id);"); $tpl->setCurrentBlock("id"); $tpl->setVariable('ID', $this->bindJavaScript($component)); @@ -97,7 +92,12 @@ protected function renderToast(Component\Toast\Toast $component, RendererInterfa protected function renderContainer(Component\Toast\Container $component, RendererInterface $default_renderer): string { $tpl = $this->getTemplate("tpl.container.html", true, true); + + $tpl->setVariable("TOAST_DELAY", $component->getDelayTime()); + $tpl->setVariable("TOAST_VANISH", $component->getVanishTime()); + $tpl->setVariable("TOASTS", $default_renderer->render($component->getToasts())); + return $tpl->get(); } diff --git a/src/UI/Implementation/Component/Toast/Toast.php b/src/UI/Implementation/Component/Toast/Toast.php index 2e0d6fe21021..3144447497bc 100644 --- a/src/UI/Implementation/Component/Toast/Toast.php +++ b/src/UI/Implementation/Component/Toast/Toast.php @@ -1,7 +1,5 @@ signal; } - - public function withVanishTime(int $vanishTime): Toast - { - $new = clone $this; - $new->vanishTime = $vanishTime; - return $new; - } - - public function getVanishTime(): int - { - return $this->vanishTime; - } - - public function withDelayTime(int $delayTime): Toast - { - $new = clone $this; - $new->delayTime = $delayTime; - return $new; - } - - public function getDelayTime(): int - { - return $this->delayTime; - } } diff --git a/src/UI/templates/default/Toast/tpl.container.html b/src/UI/templates/default/Toast/tpl.container.html index 2335965a5a0f..0265a74b47fa 100644 --- a/src/UI/templates/default/Toast/tpl.container.html +++ b/src/UI/templates/default/Toast/tpl.container.html @@ -1 +1,3 @@ -