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 @@ -
{TOASTS}
\ No newline at end of file +
+ {TOASTS} +
diff --git a/src/UI/templates/default/Toast/tpl.toast.html b/src/UI/templates/default/Toast/tpl.toast.html index 4ec287672710..2ef99a8b8291 100644 --- a/src/UI/templates/default/Toast/tpl.toast.html +++ b/src/UI/templates/default/Toast/tpl.toast.html @@ -1,4 +1,4 @@ -
id="{ID}" data-vanishurl="{VANISH_ASYNC}" data-vanish="{TOAST_VANISH}" data-delay="{TOAST_DELAY}"> +
id="{ID}" data-vanishurl="{VANISH_ASYNC}">
{ICON}
{TITLE}
@@ -12,4 +12,4 @@
-
\ No newline at end of file + diff --git a/src/UI/templates/js/Toast/toast.js b/src/UI/templates/js/Toast/toast.js index 7e56ab6b0994..1869e2e65a03 100644 --- a/src/UI/templates/js/Toast/toast.js +++ b/src/UI/templates/js/Toast/toast.js @@ -1,17 +1,9 @@ var il = il || {}; il.UI = il.UI || {}; il.UI.toast = ((UI) => { - let vanishTime = 5000; - let delayTime = 500; - - let setToastSettings = (element) => { - if (element.hasAttribute('data-vanish')) { - vanishTime = parseInt(element.dataset.vanish); - } - if (element.hasAttribute('data-delay')) { - delayTime = parseInt(element.dataset.delay); - } - } + let container = document.querySelector('.il-toast-container'); + let vanishTime = container.dataset.vanish; + let delayTime = container.dataset.delay; let showToast = (element) => { setTimeout(() => {appearToast(element);}, delayTime); @@ -40,6 +32,5 @@ il.UI.toast = ((UI) => { showToast: showToast, closeToast: closeToast, appearToast: appearToast, - setToastSettings: setToastSettings, } -})(il.UI) \ No newline at end of file +})(il.UI) diff --git a/tests/GlobalScreen/Toast/Collector/ToastCollectorTest.php b/tests/GlobalScreen/Toast/Collector/ToastCollectorTest.php index 03f2f07a8266..8bd7ddf8ed66 100644 --- a/tests/GlobalScreen/Toast/Collector/ToastCollectorTest.php +++ b/tests/GlobalScreen/Toast/Collector/ToastCollectorTest.php @@ -21,6 +21,7 @@ use ILIAS\GlobalScreen\Scope\Toast\Collector\ToastCollector; use ILIAS\GlobalScreen\Identification\IdentificationFactory; use ILIAS\GlobalScreen\Identification\IdentificationInterface; +use ILIAS\UI\Implementation\Component\Toast\Container; require_once(__DIR__ . "/../BaseToastSetUp.php"); @@ -29,14 +30,14 @@ class ToastCollectorTest extends BaseToastSetUp public function testConstruct(): void { $provider = $this->getDummyToastProviderWithToasts([]); - $collector = new ToastCollector([$provider]); + $collector = new ToastCollector([$provider], new Container()); $this->assertInstanceOf(ToastCollector::class, $collector); } public function testGetToasts(): void { $provider = $this->getDummyToastProviderWithToasts([]); - $collector = new ToastCollector([$provider]); + $collector = new ToastCollector([$provider], new Container()); $this->assertEquals([], $collector->getToasts()); $id_one = $this->createMock(IdentificationInterface::class); @@ -53,7 +54,7 @@ public function testGetToasts(): void ); $provider = $this->getDummyToastProviderWithToasts([$toast1, $toast2]); - $collector = new ToastCollector([$provider]); + $collector = new ToastCollector([$provider], new Container()); $this->assertEquals([$toast1, $toast2], $collector->getToasts()); } } diff --git a/tests/UI/Client/Toast/ToastTest.html b/tests/UI/Client/Toast/ToastTest.html index e6387fbd6462..976fafa68e14 100644 --- a/tests/UI/Client/Toast/ToastTest.html +++ b/tests/UI/Client/Toast/ToastTest.html @@ -4,8 +4,8 @@ -
-
+
+
Test diff --git a/tests/UI/Component/Toast/ToastClientHtmlTest.php b/tests/UI/Component/Toast/ToastClientHtmlTest.php index b68cf974a9f5..7a7f43ca0e4b 100644 --- a/tests/UI/Component/Toast/ToastClientHtmlTest.php +++ b/tests/UI/Component/Toast/ToastClientHtmlTest.php @@ -1,4 +1,5 @@ '; - $container = $this->getToastFactory()->container()->withAdditionalToast( - $this->getToastFactory()->standard( - 'Title', - $this->getIconFactory()->standard('mail', 'Test') - ) - ->withVanishTime(5000) - ->withDelayTime(500) - ->withDescription('Description') - ->withAction('https://www.ilias.de') - ); + $container = $this->getToastFactory()->container() + ->withVanishTime(5000) + ->withDelayTime(500) + ->withAdditionalToast( + $this->getToastFactory()->standard('Title', $this->getIconFactory()->standard('mail', 'Test')) + ->withDescription('Description') + ->withAction('https://www.ilias.de') + ); $rendered_html = str_replace('{CONTAINER}', $this->getDefaultRenderer()->render($container), $rendered_html); $rendered_html = preg_replace('/id=".*?"/', '', $rendered_html); diff --git a/tests/UI/Component/Toast/ToastTest.php b/tests/UI/Component/Toast/ToastTest.php index 4046ebaf8729..f338e674adb4 100644 --- a/tests/UI/Component/Toast/ToastTest.php +++ b/tests/UI/Component/Toast/ToastTest.php @@ -1,7 +1,5 @@ getToastFactory()->standard($title, $this->getIconFactory()->standard('', '')) ->withDescription($description) - ->withVanishTime($vanish_time) - ->withDelayTime($delay_time) ->withAction($action) ->withAdditionalLink($this->getLinkFactory()->standard('', '')); $this->assertNotNull($toast); $this->assertEquals($title, $toast->getTitle()); $this->assertEquals($description, $toast->getDescription()); - $this->assertEquals($vanish_time, $toast->getVanishTime()); - $this->assertEquals($delay_time, $toast->getDelayTime()); $this->assertEquals($action, $toast->getAction()); $this->assertCount(1, $toast->getLinks()); $this->assertInstanceOf(Link::class, $toast->getLinks()[0]); @@ -77,13 +73,14 @@ public function test_toast(string $title, string $description, int $vanish_time, } /** - * @dataProvider toast_provider + * @dataProvider toast_container_provider */ - public function test_toast_container(string $title, string $description, int $vanish_time): void + public function test_toast_container(int $vanish_time, int $delay_time): void { - $container = $this->getToastFactory()->container()->withAdditionalToast( - $this->getToastFactory()->standard('', $this->getIconFactory()->standard('', '')) - ); + $container = $this->getToastFactory()->container() + ->withAdditionalToast($this->getToastFactory()->standard('', $this->getIconFactory()->standard('', ''))) + ->withVanishTime($vanish_time) + ->withDelayTime($delay_time); $this->assertNotNull($container); $this->assertCount(1, $container->getToasts()); @@ -94,9 +91,18 @@ public function test_toast_container(string $title, string $description, int $va public function toast_provider(): array { return [ - ['title', 'description', 5000, 500, 'test.php'], - ['', '', -5000, -500, ''], - ['"/>', '"/>', PHP_INT_MAX, PHP_INT_MIN, 'test.php'] + ['title', 'description', 'test.php'], + ['', '', ''], + ['"/>', '"/>', 'test.php'] + ]; + } + + public function toast_container_provider(): array + { + return [ + [5000, 500, ], + [-5000, -500], + [PHP_INT_MAX, PHP_INT_MIN] ]; } }