Skip to content

Commit

Permalink
Remove timing on toast and apply timing on container
Browse files Browse the repository at this point in the history
  • Loading branch information
iszmais committed Jun 13, 2024
1 parent 0053a12 commit af18c25
Show file tree
Hide file tree
Showing 24 changed files with 182 additions and 157 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'] . "]";
Expand Down
19 changes: 19 additions & 0 deletions Services/GlobalScreen/classes/class.ilGSProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
) {
Expand All @@ -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());
});
Expand Down
5 changes: 3 additions & 2 deletions src/GlobalScreen/Collector/CollectorFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +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 @@ -17,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/** @noinspection PhpIncompatibleReturnTypeInspection */

namespace ILIAS\GlobalScreen\Collector;
Expand Down Expand Up @@ -104,6 +105,6 @@ public function notifications(): MainNotificationCollector

public function toasts(): ToastCollector
{
return $this->getWithArgument(ToastCollector::class, $this->provider_factory->getToastsProvider());
return $this->getWithMultipleArguments(ToastCollector::class, [$this->provider_factory->getToastsProvider(), $this->provider_factory->getToastContainer()]);
}
}
15 changes: 14 additions & 1 deletion src/GlobalScreen/Provider/NullProviderFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +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 @@ -17,10 +16,14 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\GlobalScreen\Provider;

use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Information\ItemInformation;
use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Information\NullItemInformation;
use ILIAS\UI\Implementation\Component\Toast\Container;
use ILIAS\UI\NotImplementedException;

/**
* Class NullProviderFactory
Expand Down Expand Up @@ -76,6 +79,16 @@ public function getNotificationsProvider(): array
return [];
}

public function getToastsProvider(): array
{
return [];
}

public function getToastContainer(): \ILIAS\UI\Component\Toast\Container
{
return new Container();
}

/**
* @inheritDoc
*/
Expand Down
12 changes: 11 additions & 1 deletion src/GlobalScreen/Provider/ProviderFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +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 @@ -17,14 +16,18 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\GlobalScreen\Provider;

use ILIAS\GlobalScreen\Scope\Layout\Provider\ModificationProvider;
use ILIAS\GlobalScreen\Scope\MainMenu\Collector\Information\ItemInformation;
use ILIAS\GlobalScreen\Scope\MainMenu\Provider\StaticMainMenuProvider;
use ILIAS\GlobalScreen\Scope\MetaBar\Provider\StaticMetaBarProvider;
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;

/**
* Interface ProviderFactory
Expand Down Expand Up @@ -62,6 +65,13 @@ public function getMetaBarProvider(): array;
*/
public function getNotificationsProvider(): array;

/**
* @return ToastProvider[]
*/
public function getToastsProvider(): array;

public function getToastContainer(): Container;

/**
* @param string $class_name
* @return Provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,20 @@ public function getViewTitle(): string
*/
public function getToastContainer(): TContainer
{
$toast_container = $this->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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
11 changes: 10 additions & 1 deletion src/GlobalScreen/Scope/Toast/Collector/ToastCollector.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -21,22 +22,25 @@

use ILIAS\GlobalScreen\Collector\AbstractBaseCollector;
use ILIAS\GlobalScreen\Scope\Toast\Provider\ToastProvider;
use ILIAS\UI\Component\Toast\Container;
use Iterator;
use ILIAS\GlobalScreen\Scope\Toast\Factory\isStandardItem;

class ToastCollector extends AbstractBaseCollector
{
/** @var ToastProvider[] */
private array $providers;
private Container $container;
/** @var isStandardItem[] */
private array $toasts = [];

/**
* @param ToastProvider[] $providers
*/
public function __construct(array $providers)
public function __construct(array $providers, Container $container)
{
$this->providers = $providers;
$this->container = $container;
$this->collectOnce();
}

Expand Down Expand Up @@ -78,4 +82,9 @@ public function getToasts(): array
{
return $this->toasts;
}

public function getContainer(): Container
{
return $this->container;
}
}
24 changes: 0 additions & 24 deletions src/GlobalScreen/Scope/Toast/Factory/StandardToastItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 0 additions & 8 deletions src/GlobalScreen/Scope/Toast/Factory/isStandardItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
24 changes: 18 additions & 6 deletions src/UI/Component/Toast/Container.php
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,14 +16,12 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Component\Toast;

use ILIAS\UI\Component\Component;

/**
* Interface Container
* @package ILIAS\UI\Component\Toast
*/
interface Container extends Component
{
/**
Expand All @@ -36,4 +32,20 @@ public function getToasts(): array;
public function withAdditionalToast(Toast $toast): Container;

public function withoutToasts(): Container;

/**
* Create a copy of this container with a vanish time in miliseconds.
* The vanish time defines the time after which the toasts vanish.
*/
public function withVanishTime(int $vanishTime): Container;

public function getVanishTime(): int;

/**
* Create a copy of this container with a delay time in miliseconds.
* The delay time defines the time when the toasts are shown after a page refresh or an asyncronous update.
*/
public function withDelayTime(int $delayTime): Container;

public function getDelayTime(): int;
}
7 changes: 2 additions & 5 deletions src/UI/Component/Toast/Factory.php
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,13 +16,12 @@
*
*********************************************************************/

declare(strict_types=1);

namespace ILIAS\UI\Component\Toast;

use ILIAS\UI\Component\Symbol\Icon\Icon;

/**
* This is how a factory for Toast looks like.
*/
interface Factory
{
/**
Expand Down
Loading

0 comments on commit af18c25

Please sign in to comment.