Procházet zdrojové kódy

Système de notifications

tags/0.1
Guillaume před 3 roky
rodič
revize
4239edaf6d
12 změnil soubory, kde provedl 152 přidání a 37 odebrání
  1. +19
    -8
      Controller/Admin/AbstractCrudController.php
  2. +3
    -2
      Controller/Admin/DashboardController.php
  3. +50
    -0
      EventSubscriber/EasyAdminEventSubscriber.php
  4. +1
    -0
      Resources/assets/app/adminlte/common/app.common.js
  5. +3
    -0
      Resources/assets/app/adminlte/common/common.js
  6. +24
    -13
      Resources/assets/app/adminlte/common/js/notification.js
  7. +30
    -12
      Resources/assets/app/adminlte/common/scss/_toastr.scss
  8. +2
    -2
      Resources/assets/app/adminlte/index/index.js
  9. +5
    -0
      Resources/translations/admin.fr.yaml
  10. +1
    -0
      Resources/views/adminlte/block/flash_messages.html.twig
  11. +1
    -0
      Resources/views/adminlte/crud/index.html.twig
  12. +13
    -0
      Resources/views/adminlte/layout.html.twig

+ 19
- 8
Controller/Admin/AbstractCrudController.php Zobrazit soubor

@@ -80,13 +80,13 @@ abstract class AbstractCrudController extends EaAbstractCrudController
Action::NEW => [
'icon' => 'plus',
'label' => 'Créer',
'add_class'=>'btn-sm'
'add_class' => 'btn-sm'
],
Action::EDIT => [
'class' => 'btn btn-sm btn-primary',
'icon' => 'edit',
'label' => false,
'html_attributes'=> array('data-toggle'=> 'tooltip', 'title'=> 'Éditer')
'html_attributes' => array('data-toggle' => 'tooltip', 'title' => 'Éditer')
],
Action::DELETE => [
'icon' => 'trash',
@@ -147,7 +147,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController
$indexChildAction = Action::new('index_children', 'Afficher les enfants', 'fa fa-list')
->linkToCrudAction(Action::INDEX)
->setLabel('')
->setHtmlAttributes(array('data-toggle'=> 'tooltip', 'title'=> 'Afficher les enfants'))
->setHtmlAttributes(array('data-toggle' => 'tooltip', 'title' => 'Afficher les enfants'))
->setTemplatePath('@LcSov/adminlte/crud/action/index_children.html.twig')
->setCssClass('btn btn-sm btn-success');

@@ -179,7 +179,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController
}

if (isset($button['icon'])) {
$action->setIcon('fa fa-'.$button['icon']);
$action->setIcon('fa fa-' . $button['icon']);
}

if (isset($button['label'])) {
@@ -191,7 +191,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController
}

if (isset($button['html_attributes']) && $button['html_attributes']) {
$action->setHtmlAttributes( $button['html_attributes']);
$action->setHtmlAttributes($button['html_attributes']);
}

return $action;
@@ -217,7 +217,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController
$crud = parent::configureCrud($crud);

$this->setMaxResults($crud);
if($this->isInstanceOf(SortableInterface::class)){
if ($this->isInstanceOf(SortableInterface::class)) {
$crud->setDefaultSort(['position' => 'ASC']);
}
return $crud;
@@ -227,7 +227,7 @@ abstract class AbstractCrudController extends EaAbstractCrudController
{
$entityClass = $this->getEntityFqcn();
$paramListMaxResults = 'listMaxResults';
$paramSessionListMaxResults = $entityClass.'-'.$paramListMaxResults;
$paramSessionListMaxResults = $entityClass . '-' . $paramListMaxResults;
$requestListMaxResults = $this->request->getCurrentRequest()->get($paramListMaxResults);

if ($requestListMaxResults) {
@@ -375,7 +375,6 @@ abstract class AbstractCrudController extends EaAbstractCrudController
$filters
);

dump(get_defined_vars());
if ($this->isInstanceOf(TreeInterface::class)) {
$entityId = $searchDto->getRequest()->get('entityId');
if ($entityId !== null) {
@@ -417,6 +416,18 @@ abstract class AbstractCrudController extends EaAbstractCrudController
return $queryBuilder;
}

public function edit(AdminContext $context)
{
$response = parent::edit($context); ;

// on vide le flash bag si édition en ajax (notification déjà affichée en Javascript)
if ($context->getRequest()->isXmlHttpRequest()) {
$this->session->getFlashBag()->clear() ;
}

return $response ;
}

public function isInstanceOf(string $interfaceName): bool
{
return in_array($interfaceName, class_implements($this->getEntityFqcn()));

+ 3
- 2
Controller/Admin/DashboardController.php Zobrazit soubor

@@ -82,7 +82,7 @@ class DashboardController extends AbstractDashboardController
'crud/paginator' => '@LcSov/adminlte/crud/paginator.html.twig',
'crud/edit' => '@LcSov/adminlte/crud/edit.html.twig',
'crud/new' => '@LcSov/adminlte/crud/new.html.twig',
//'crud/action' => '@LcSov/adminlte/crud/action/action.html.twig',
'flash_messages' => '@LcSov/adminlte/block/flash_messages.html.twig',
]
)
->setFormThemes(
@@ -90,7 +90,8 @@ class DashboardController extends AbstractDashboardController
'@LcSov/adminlte/crud/form_theme.html.twig',
'@FOSCKEditor/Form/ckeditor_widget.html.twig'
]
);
)
;
}

}

+ 50
- 0
EventSubscriber/EasyAdminEventSubscriber.php Zobrazit soubor

@@ -0,0 +1,50 @@
<?php

namespace Lc\SovBundle\EventSubscriber;

use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityDeletedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityPersistedEvent;
use EasyCorp\Bundle\EasyAdminBundle\Event\AfterEntityUpdatedEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Translation\TranslatableMessage;

class EasyAdminEventSubscriber implements EventSubscriberInterface
{
protected $session ;

public function __construct(SessionInterface $session)
{
$this->session = $session ;
}

public static function getSubscribedEvents(): array
{
return [
AfterEntityPersistedEvent::class => ['flashMessageAfterPersist'],
AfterEntityUpdatedEvent::class => ['flashMessageAfterUpdate'],
AfterEntityDeletedEvent::class => ['flashMessageAfterDelete'],
];
}

public function flashMessageAfterPersist(AfterEntityPersistedEvent $event): void
{
$this->session->getFlashBag()->add('success', new TranslatableMessage('content_admin.flash_message.create', [
'%name%' => (string) $event->getEntityInstance(),
], 'admin'));
}

public function flashMessageAfterUpdate(AfterEntityUpdatedEvent $event): void
{
$this->session->getFlashBag()->add('success', new TranslatableMessage('content_admin.flash_message.update', [
'%name%' => (string) $event->getEntityInstance(),
], 'admin'));
}

public function flashMessageAfterDelete(AfterEntityDeletedEvent $event): void
{
$this->session->getFlashBag()->add('success', new TranslatableMessage('content_admin.flash_message.delete', [
'%name%' => (string) $event->getEntityInstance(),
], 'admin'));
}
}

+ 1
- 0
Resources/assets/app/adminlte/common/app.common.js Zobrazit soubor

@@ -26,6 +26,7 @@ global.Tools = Tools;

import { Notification } from './js/notification.js';
global.Notification = Notification;
Notification.init() ;

// Common
import './common.scss';

+ 3
- 0
Resources/assets/app/adminlte/common/common.js Zobrazit soubor

@@ -1,4 +1,7 @@

/* Notifications */
//Notification.init() ;

/* Tooltip */
$('[data-toggle="tooltip"]').tooltip();


+ 24
- 13
Resources/assets/app/adminlte/common/js/notification.js Zobrazit soubor

@@ -1,34 +1,45 @@

export class Notification {

static setNotifications(notifications) {
static init() {
toastr.options.timeOut = 3000;
toastr.options.positionClass = 'toast-bottom-right';
toastr.options.onHidden = function () {
if ($('#toast-container .toast').length == 1) {
$('#toast-close-all').remove();
}
};
}

static set(notifications) {
var currentNotifications = new Array();
for (var type in notifications) {
for (var key in notifications[type]) {
if (!currentNotifications.includes(notifications[type][key])) {
currentNotifications.push(notifications[type][key]);
self.addNotification(type, notifications[type][key]);
self.add(type, notifications[type][key]);
}
}
}
}

static addNotification(type, text) {

toastr.options.timeOut = 3000;
toastr.options.onHidden = function () {
if ($('#toast-container .toast').length == 0) $('#toast-close-all').remove();
};
static add(type, text) {

toastr[type](text);

if ($('#toast-close-all').length == 0) {
$('#toast-container').prepend('<button id="toast-close-all"><i class="fa fa-times"></i></button>');
let $container = $('#toast-container') ;
let selectorButtonCloseAll = '#toast-close-all' ;
let countMessages = $container.find('.toast').length ;

if ($(selectorButtonCloseAll).length == 0 && countMessages > 2) {
$container.prepend('<button id="toast-close-all"><i class="fa fa-times"></i></button>');
}
$('#toast-close-all').off('click');
$('#toast-close-all').on('click', function () {
$(selectorButtonCloseAll).off('click').on('click', function () {
toastr.remove();
if ($('#toast-container .toast').length == 0) $('#toast-close-all').remove();
if (countMessages == 0) {
$('#toast-close-all').remove();
}
});
}


+ 30
- 12
Resources/assets/app/adminlte/common/scss/_toastr.scss Zobrazit soubor

@@ -1,10 +1,29 @@

#toast-container {
width: 350px;
width: 400px;
}

.toast {
float: right
#toast-container .toast {
float: right ;
width: 400px ;
opacity: 1 ;
box-shadow: none !important;
-moz-box-shadow: none !important;
-o-box-shadow: none !important;
-webkit-box-shadow: none !important;

&.success {
background-color: $success !important ;
}
&.danger, &.error {
background-color: $danger !important ;
}
&.info {
background-color: $info !important ;
}
&.warning {
background-color: $warning !important ;
}
}

#toast-container:before:hover {
@@ -15,22 +34,21 @@
#toast-close-all {
border: 0;
position: absolute;
bottom: 7px;
left: -15px;
pointer-events: auto;
z-index: 999999999999999999999;
z-index: 1000;
background: #BD362F;
border-radius: 3px;
color: #fff;
opacity: 0.8;
top: 2px;
width: 50px;
height: 50px;
font-size: 30px;
left: 0px;
font-size: 20px;
text-align: center;
-webkit-text-shadow: 0 1px 0 #fff;
text-shadow: 0 1px 0 #fff;
-moz-box-shadow: 0 0 12px #999;
-webkit-box-shadow: 0 0 12px #999;
box-shadow: 0 0 12px #999;

//@include text-shadow(0 1px 0 #999) ;

border-radius: 50px ;
}


+ 2
- 2
Resources/assets/app/adminlte/index/index.js Zobrazit soubor

@@ -17,14 +17,14 @@ function lcCrudIndexToggle() {
let toggleRequest = $.ajax({type: "POST", url: toggleUrl, data: {}, dataType: 'json'});

toggleRequest.done(function (response) {
Notification.addNotification('success', 'La propriété a bien été mise à jour.');
Notification.add('success', 'La propriété a bien été mise à jour.');
});

toggleRequest.fail(function () {
toggle.checked = oldValue;
toggle.disabled = true;
toggle.closest('.checkbox-switch').classList.add('disabled');
Notification.addNotification('error', 'Une erreur est survenue.');
Notification.add('error', 'Une erreur est survenue.');
});
});
}

+ 5
- 0
Resources/translations/admin.fr.yaml Zobrazit soubor

@@ -0,0 +1,5 @@
content_admin:
flash_message:
create: Le contenu "%name%" a été créé avec succès.
update: Le contenu "%name%" a été mis à jour avec succès.
delete: Le contenu "%name%" a été supprimé avec succès.

+ 1
- 0
Resources/views/adminlte/block/flash_messages.html.twig Zobrazit soubor

@@ -0,0 +1 @@
{# Gérés en Javascript dans layout.html.twig #}

+ 1
- 0
Resources/views/adminlte/crud/index.html.twig Zobrazit soubor

@@ -2,6 +2,7 @@
{# @var entities \EasyCorp\Bundle\EasyAdminBundle\Collection\EntityDtoCollection #}
{# @var paginator \EasyCorp\Bundle\EasyAdminBundle\Orm\EntityPaginator #}
{% extends ea.templatePath('layout') %}

{% trans_default_domain ea.i18n.translationDomain %}

{% block body_id entities|length > 0 ? 'ea-index-' ~ entities|first.name : '' %}

+ 13
- 0
Resources/views/adminlte/layout.html.twig Zobrazit soubor

@@ -179,6 +179,19 @@

{% include '@LcSov/adminlte/filemanager/file-manager-modal.html.twig' %}

{% if app.session is not null and app.session.started %}
{% set flash_messages = app.session.flashbag.all %}
{% if flash_messages|length > 0 %}
{% for label, messages in flash_messages %}
{% for message in messages %}
<script type="text/javascript">
Notification.add("{{ label }}", "{{ message|trans|raw|replace({'"': '\"'}) }}") ;
</script>
{% endfor %}
{% endfor %}
{% endif %}
{% endif %}

</body>
{% endblock body %}
</html>

Načítá se…
Zrušit
Uložit