Skip to content

Commit

Permalink
fix release
Browse files Browse the repository at this point in the history
  • Loading branch information
forxer committed Aug 5, 2022
1 parent 3b58de3 commit 42072f2
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 38 deletions.
9 changes: 8 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

4.0.1 (2022-08-05)
------------------

- Fix stacks management
- Removed buggy `$errorsCount` in favor of `$flashErrorsCount` and `$nowErrorsCount`


4.0.0 (2022-08-04)
------------------

Expand All @@ -9,7 +16,7 @@ Changelog
- Added the ability to group messages of the same type in the same notification when viewing
- Added ability to group messages notifications based on their types when viewing
- Added the ability to set the display order of messages types
- Added `<x-notify />` Blade component
- Added `<x-notify />` Blade component with many attributs
- Added predefined views:
- `bootstrap-5`
- `bootstrap-5-toast`
Expand Down
11 changes: 6 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,8 @@ Dans votre nouvelle vue, vous aurez alors accès aux variables publiques du comp

- `$flashMessages` : la collection des messages flash
- `$nowMessages` : la collection des messages instantanés
- `$errorsCount` : le nombre d'erreurs (généralement celles liées à la validation)
- `$flashErrorsCount` : le nombre d'erreurs dans les messages flash
- `$nowErrorsCount` : le nombre d'erreurs dans les messages instantanés

Il conviendra alors de boucler sur les messages :

Expand Down Expand Up @@ -557,7 +558,7 @@ Et donc dans la vue du component :
'type' => $flashMessage['type'],
'message' => $flashMessage['message'],
'title' => $flashMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $flashErrorsCount,
])
@endforeach
@foreach ($nowMessages as $nowMessage)
Expand All @@ -566,7 +567,7 @@ Et donc dans la vue du component :
'type' => $nowMessage['type'],
'message' => $nowMessage['message'],
'title' => $nowMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $nowErrorsCount,
])
@endforeach
</div>
Expand All @@ -580,15 +581,15 @@ Si vous n'avez pas besoin de modifier le code ci-dessus vous pouvez utiliser la
])
```

Maintenant il ne vous reste "plus qu'à implémenter" la vue du message `components/partials/custom-notify-message.blade.php`.
Maintenant il ne vous reste "plus qu'à" implémenter la vue du message `components/partials/custom-notify-message.blade.php`.

Dans celle-ci vous aurez accès aux variables suivantes :

- `$id` : l'identifiant unique du message
- `$type` : le type du message ('info', 'success', 'warning' ou 'error')
- `$message` : le contenu du message
- `$title` : l'éventuel titre du message
- `$errorsCount` : le nombre d'erreurs (généralement celles liées à la validation)
- `$errorsCount` : le nombre de messages d'erreurs

Et là c'est à vous de jouer :)

Expand Down
4 changes: 2 additions & 2 deletions resources/views/bootstrap-4-toast.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'type' => $flashMessage['type'],
'message' => $flashMessage['message'],
'title' => $flashMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $flashErrorsCount,
])
@endforeach
@foreach ($nowMessages as $nowMessage)
Expand All @@ -15,7 +15,7 @@
'type' => $nowMessage['type'],
'message' => $nowMessage['message'],
'title' => $nowMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $nowErrorsCount,
])
@endforeach
</div>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/bootstrap-5-toast.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'type' => $flashMessage['type'],
'message' => $flashMessage['message'],
'title' => $flashMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $flashErrorsCount,
])
@endforeach
@foreach ($nowMessages as $nowMessage)
Expand All @@ -15,7 +15,7 @@
'type' => $nowMessage['type'],
'message' => $nowMessage['message'],
'title' => $nowMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $nowErrorsCount,
])
@endforeach
</div>
Expand Down
6 changes: 3 additions & 3 deletions resources/views/partials/a-generic-component.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'type' => $flashMessage['type'],
'message' => $flashMessage['message'],
'title' => $flashMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $flashErrorsCount,
])
@endforeach
@foreach ($nowMessages as $nowMessage)
Expand All @@ -14,7 +14,7 @@
'type' => $nowMessage['type'],
'message' => $nowMessage['message'],
'title' => $nowMessage['title'],
'errorsCount' => $errorsCount,
'errorsCount' => $nowErrorsCount,
])
@endforeach
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$aria = 'role="alert" aria-live="assertive" aria-atomic="true"';
break;
case 'error':
$delay = 15000;
$delay = $errorsCount ? 7500 * $errorsCount : 15000;
$aria = 'role="alert" aria-live="assertive" aria-atomic="true"';
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
$aria = 'role="alert" aria-live="assertive" aria-atomic="true"';
break;
case 'error':
$delay = 15000;
$delay = $errorsCount ? 7500 * $errorsCount : 15000;
$aria = 'role="alert" aria-live="assertive" aria-atomic="true"';
break;
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/partials/sweetalert2-message.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
@case ('error')
Toast.fire({
timer: {!! 10000 * $errors->count() !!}
timer: {!! $errorsCount ? 7500 * $errorsCount : 15000 !!}
})
@break
@endswitch
Expand Down
5 changes: 2 additions & 3 deletions src/Concerns/HasFlashMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ public function error(string $message, ?string $title = null): Notify
/**
* Retourne les messages pour la prochaine requête HTTP.
*
* @param string $stack
* @return Collection
*/
public function flashMessages(string $stack = Notify::DEFAULT_STACK): Collection
public function flashMessages(): Collection
{
return $this->stackMessages("notify_flash_$stack");
return $this->stackMessages("notify_flash_$this->stack");
}

/**
Expand Down
5 changes: 2 additions & 3 deletions src/Concerns/HasNowMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ public function nowError(string $message, ?string $title = null): Notify
/**
* Retourne les messages pour la requête HTTP courante.
*
* @param string $stack
* @return Collection
*/
public function nowMessages(string $stack = Notify::DEFAULT_STACK): Collection
public function nowMessages(): Collection
{
return $this->stackMessages("notify_now_$stack");
return $this->stackMessages("notify_now_$this->stack");
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class Notify
/**
* Le nom de la stack à utiliser.
*
* @var string
* @var string|null
*/
protected string $stack;
protected ?string $stack;

/**
* Constructeur.
Expand All @@ -57,9 +57,9 @@ public function __construct(Session $session)
* @param string|null $stack
* @return self
*/
public function stack(?string $stack): self
public function stack(?string $stack = null): self
{
$this->stack = $stack ?? self::DEFAULT_STACK;
$this->stack = $stack ?? Notify::DEFAULT_STACK;

return $this;
}
Expand Down
37 changes: 25 additions & 12 deletions src/View/Components/NotifyComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ class NotifyComponent extends Component

public Collection $nowMessages;

public int $errorsCount;
public int $flashErrorsCount;

public int $nowErrorsCount;

private Notify $notify;

private ?string $stack;
private string $stack;

private string $viewName;

Expand All @@ -29,18 +31,17 @@ class NotifyComponent extends Component
private bool $withoutNowMessages;

public function __construct(
Notify $notify,
?string $stack = null,
string $stack = null,
?string $viewName = null,
?bool $sortByType = true,
?bool $groupByType = false,
?bool $withoutFlashMessages = false,
?bool $withoutNowMessages = false,
bool $sortByType = true,
bool $groupByType = false,
bool $withoutFlashMessages = false,
bool $withoutNowMessages = false,
) {
$this->notify = $notify;

$this->stack = $stack ?? Notify::DEFAULT_STACK;

$this->notify = notify($this->stack);

$config = config('notifier');

$this->viewName = $viewName ?? $config['default_view'];
Expand Down Expand Up @@ -73,6 +74,8 @@ private function setParticularViewParams(): void
$this->groupByType = true;
}

// les vue 'notifier::bootstrap-5' et 'notifier::bootstrap-4'
// ne peuvent êtres groupées par type car cela casse leur affichage
if (in_array($this->viewName, ['notifier::bootstrap-5', 'notifier::bootstrap-4'])) {
$this->groupByType = false;
}
Expand All @@ -89,6 +92,12 @@ private function flashMessages(): Collection
return collect();
}

$this->flashErrorsCount = $this->notify->flashMessages($this->stack)
->filter(function ($value) {
return $value['type'] === Notify::ERROR;
})
->count();

return $this->notify->flashMessages($this->stack)
->when($this->groupByType, function ($messages) {
return $messages->groupMessagesByType();
Expand All @@ -111,6 +120,12 @@ private function nowMessages(): Collection
return collect();
}

$this->nowErrorsCount = $this->notify->nowMessages($this->stack)
->filter(function ($value) {
return $value['type'] === Notify::ERROR;
})
->count();

return $this->notify->nowMessages($this->stack)
->when($this->groupByType, function ($messages) {
return $messages->groupMessagesByType();
Expand All @@ -129,8 +144,6 @@ private function addErrorsToNowMessage(): void
{
$errors = app('view')->shared('errors');

$this->errorsCount = $errors->count();

if ($errors->any()) {
foreach ($errors->all() as $error) {
$this->notify->nowError($error);
Expand Down

0 comments on commit 42072f2

Please sign in to comment.