Commit f5b07206 authored by David Surville's avatar David Surville
Browse files

Modification de l'affichage des périmètres par catégorie sur la page d'un...

Modification de l'affichage des périmètres par catégorie sur la page d'un utilsateur pour une meilleure lisibilité
parent 158c62e9
Loading
Loading
Loading
Loading
+4 −9
Original line number Diff line number Diff line
@@ -270,10 +270,6 @@ class UtilisateurController extends AbstractActionController

        return new JsonModel([
            "result" => $result ?: false,
            "url" => $this->url()->fromRoute('unicaen-utilisateur/supprimer-perimetre', [
                'utilisateur' => $utilisateur->getId(),
                'role' => $role->getId(),
                'perimetre' => $perimetre->getId(),], [], true),
            "message" => $result
                ? sprintf("Ajout du périmètre <strong>%s : %s</strong> à l'utilisateur <strong>%s</strong>.",
                    $perimetre->getCategorie()->getLibelle(), $perimetre->getLibelle(), $utilisateur->getDisplayName())
@@ -380,7 +376,10 @@ class UtilisateurController extends AbstractActionController
        /** @var RoleInterface $role */
        $role = $this->roleService->find($roleId);

        return compact('utilisateur', 'role');
        $view = new ViewModel();
        $view->setTerminal(true);

        return $view->setVariables(compact('utilisateur', 'role'));
    }

    public function modifierAction()
@@ -510,10 +509,6 @@ class UtilisateurController extends AbstractActionController

        return new JsonModel([
            "result" => $result ?: false,
            "url" => $this->url()->fromRoute('unicaen-utilisateur/ajouter-perimetre', [
                'utilisateur' => $utilisateur->getId(),
                'role' => $role->getId(),
                'perimetre' => $perimetre->getId(),], [], true),
            "message" => $result
                ? sprintf("Suppression du périmètre <strong>%s : %s</strong> de l'utilisateur <strong>%s</strong>.",
                    $perimetre->getCategorie()->getLibelle(), $perimetre->getLibelle(), $utilisateur->getDisplayName())
+30 −51
Original line number Diff line number Diff line
@@ -50,9 +50,7 @@ class UserRole extends AbstractHelper
            ? sprintf(
                '<a href="%s"
                   class="remove-role"
                   title="Suppression du rôle"
                   data-html="true"
                   data-content="<p>Voulez-vous supprimer le rôle ?</p>">
                   title="Suppression du rôle">
                    <i class="far fa-trash-alt text-danger" title="Supprimer le rôle"></i>
                </a>',
                $this->view->url('unicaen-utilisateur/supprimer-role', ['utilisateur' => $this->user->getId(), 'role' => $role->getId()], [], true)
@@ -67,61 +65,42 @@ class UserRole extends AbstractHelper
        return $this->view->render('unicaen-utilisateur/utilisateur/template/liste-perimetre', compact('user', 'role'));
    }

    /**
     * @param RoleInterface $role
     * @param PerimetreInterface $perimetre
     * @return string
     */
    public function renderPerimetreStatut(RoleInterface $role, PerimetreInterface $perimetre)
    {
        $statut = false;
        $categorie = $perimetre->getCategorie();
        $userRole = $this->user->getFullRole($role);

        if(null !== $userRole) { // rôle manuel
            $userRolePerimetres = $userRole->getPerimetres();
            $userPerimetres = $userRolePerimetres->filter(function ($p) use ($categorie) {
                return $p->getPerimetre()->getCategorie()->getCode() === $categorie->getCode();
            });
            $statut = $userPerimetres->exists(function ($k, $p) use ($perimetre) {
                return $p->getPerimetre()->getCode() === $perimetre->getCode();
            });
        }

        $html = sprintf('
            <div class="checkbox">
                <label>
                    <input title="%s" class="basculer-perimetre" href="%s" type="checkbox" %s> %s
                </label>
            </div>',
            $perimetre->getDescription() ?: '',
            $statut ? $this->renderLienSupprimerPerimetre($role, $perimetre) : $this->renderLienAjouterPerimetre($role, $perimetre),
            $statut ? 'checked' : '',
            $perimetre->getLibelle()
        );

        return $html;
    }

    public function renderLienAjouterPerimetre(RoleInterface $role, PerimetreInterface $perimetre)
    {
        return $this->view->isAllowed(UtilisateurPrivileges::getResourceId(UtilisateurPrivileges::UTILISATEUR_MODIFIERROLE))
            ? $this->view->url('unicaen-utilisateur/ajouter-perimetre', [
            ? sprintf(
                '<a href="%s" class="dropdown-item add-perimetre" title="%s">%s</a>',
                $this->view->url('unicaen-utilisateur/ajouter-perimetre', [
                    'utilisateur' => $this->user->getId(),
                    'role' => $role->getId(),
                'perimetre' => $perimetre->getId()], [], true
            )
            : '';
                    'perimetre' => $perimetre->getId()], [], true),
                $perimetre->getDescription(),
                $perimetre)
            : sprintf(
                '<a class="dropdown-item" title="%s">%s</a>',
                $perimetre->getDescription(),
                $perimetre);
    }

    public function renderLienSupprimerPerimetre(RoleInterface $role, PerimetreInterface $perimetre)
    {
        return $this->view->isAllowed(UtilisateurPrivileges::getResourceId(UtilisateurPrivileges::UTILISATEUR_MODIFIERROLE))
            ? $this->view->url('unicaen-utilisateur/supprimer-perimetre', [
            ? sprintf(
                '<a href="%s"
                    class="list-group-item list-group-item-action remove-perimetre"
                    title="%s">%s <i class="far fa-trash-alt text-danger float-end pt-1" title="Supprimer le périmètre"></i>
                 </a>',
                $this->view->url('unicaen-utilisateur/supprimer-perimetre', [
                    'utilisateur' => $this->user->getId(),
                    'role' => $role->getId(),
                'perimetre' => $perimetre->getId()], [], true
            )
            : '';
                    'perimetre' => $perimetre->getId()], [], true),
                $perimetre->getDescription(),
                $perimetre)
            : sprintf(
                '<a class="list-group-item list-group-item-action"
                    title="%s">%s
                 </a>',
                $perimetre->getDescription(),
                $perimetre);
    }
}
 No newline at end of file
+9 −2
Original line number Diff line number Diff line
@@ -22,8 +22,15 @@ div.unicaen-utilisateur table#utilisateur-liste > tbody > tr > td {
    cursor: pointer;
}

div.unicaen-utilisateur div#user-role-perimetres .checkbox label {
    font-weight: 200;
div.unicaen-utilisateur #user-role-perimetres .perimetre-categorie .dropdown-menu {
    overflow: hidden;
    overflow-y: auto;
    max-height: 200px;
}

div.unicaen-utilisateur #user-role-perimetres .perimetre-categorie .remove-perimetre:hover {
    color: #b02a37;
    background-color: #f8d7da;
}

div.unicaen-utilisateur span.temoin:before {
+1 −2
Original line number Diff line number Diff line
@@ -311,9 +311,8 @@ $canModifier = $canAjouter;
                </div>
            </div>
        <?php echo $this->form()->closeTag(); ?>
        <p></p>

        <div id="user-role-perimetres"></div>
        <div id="user-role-perimetres" data-url="" class="mt-4"></div>

        <script type="text/javascript">
            $(function() {
+111 −41
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@

use BjyAuthorize\Provider\Identity\ProviderInterface;
use UnicaenPrivilege\Entity\Db\PerimetreCategorieInterface;
use UnicaenPrivilege\Entity\Db\PerimetreUserRoleInterface;
use UnicaenUtilisateur\Controller\UtilisateurController;
use UnicaenUtilisateur\Entity\Db\UserInterface;
use UnicaenUtilisateur\Entity\Db\RoleInterface;
@@ -18,6 +19,8 @@ use UnicaenUtilisateur\View\Helper\UserRole;
$canRole = $this->isAllowed(UtilisateurPrivileges::getResourceId(UtilisateurPrivileges::UTILISATEUR_MODIFIERROLE));
$categories = $role->getPerimetreCategories();

$userRole = $user->getFullRole($role);

if($categories->isEmpty()):
?>

@@ -27,50 +30,117 @@ if($categories->isEmpty()):

<?php else: ?>

    <div class="row">

    <?php
    /** @var PerimetreCategorieInterface $categ */
    foreach($categories as $categ):
    foreach($categories as $categ) {
        if(null !== $userRole) {
            $userRolePerimetres = $userRole->getPerimetres();
            $userPerimetres =
                $userRolePerimetres->filter(function (PerimetreUserRoleInterface $up) use ($categ) {
                    return $up->getPerimetre()->getCategorie()->getCode() === $categ->getCode();
                })->map(function (PerimetreUserRoleInterface $up) {
                    return $up->getPerimetre();
                });
            $perimetres = $categ->getPerimetres()->filter(function($p) use ($userPerimetres) {
                return !$userPerimetres->contains($p);
            });
        } else {
            $perimetres = $categ->getPerimetres();
        }
    ?>
    <div class="perimetre-categorie col-md-3">
        <dl>
            <dt>
                <h4>
                    <strong><?php echo $categ->getLibelle(); ?></strong>

        <div class="perimetre-categorie col-sm-3">
            <div class="btn-group col-sm-12">
                <button type="button" class="btn btn-secondary col-sm-9 text-start">
                    <?php echo $categ->getLibelle(); ?>
                    <?php echo ($description = $categ->getDescription()) ? '<i class="fas fa-info-circle" title="'. $description .'"></i>' : ''; ?>
                </h4>
            </dt>
                </button>
                <button type="button" class="btn btn-secondary dropdown-toggle dropdown-toggle-split" type="button" id="<?php echo $categ->getCode(); ?>" data-bs-toggle="dropdown" aria-expanded="false">
                    <span class="visually-hidden"><?php echo $categ->getLibelle(); ?></span>
                </button>
                <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="<?php echo $categ->getCode(); ?>">
                    <li><h5 class="dropdown-header"><?php echo $categ->getLibelle(); ?></h5></li>
                    <?php
            $iterator = $categ->getPerimetres()->getIterator();
                    $iterator = $perimetres->getIterator();
                    $iterator->uasort(function ($a, $b) {
                        return ( $a->getOrdre() < $b->getOrdre() ) ? -1 : 1;
                    });
                    foreach($iterator as $perimetre): ?>
                <dd>
                    <?php echo $this->userRole($user)->renderPerimetreStatut($role, $perimetre); ?>
                </dd>
                        <li><?php echo $this->userRole($user)->renderLienAjouterPerimetre($role, $perimetre); ?></li>
                    <?php endforeach; ?>
        <dl>
                </ul>
            </div>
            <?php if(!$userPerimetres->isEmpty()): ?>
                <div class="list-group mt-3">
                    <?php
                    foreach($userPerimetres as $p) {
                        echo $this->userRole($user)->renderLienSupprimerPerimetre($role, $p);
                    }
                    ?>
                </div>
            <?php else: ?>
                <p class="mt-4 ml-2"><em>Aucun périmètre attribué</em></p>
            <?php endif; ?>
        </div>

    <?php }; ?>

    </div>
    <?php endforeach; ?>

    <script type="text/javascript">
        $(function () {
            $('body')
                .off('click', 'input.basculer-perimetre')
                .on('click', 'input.basculer-perimetre', function (e) {
                .on('click', '.add-perimetre', function (e) {
                    e.preventDefault();
                    that = $(this);
                    $.ajax({
                        type: "GET",
                        url: that.attr('href'),
                        dataType: "json",
                        success: function (data) {
                            if (data.result == true) {
                                $.ajax({
                                    type: "GET",
                                    url: '/utilisateur/lister-perimetre/' + <?php echo $user->getId(); ?> + '/' + <?php echo $role->getId(); ?>,
                                    dataType: "html",
                                    success: function (data) {
                                        $('#user-role-perimetres').html(data);
                                    }
                                });
                                $('#perimetre-message').addClass('alert-success')
                                    .html(data.message)
                                    .show();
                            } else {
                                $('#perimetre-message').addClass('alert-danger')
                                    .html(data.message)
                                    .show();
                            }
                        },
                    });
                })
                .on('click', '.remove-perimetre', function (e) {
                    e.preventDefault();
                    that = $(this);
                    $.ajax({
                        type: "GET",
                    url: $(this).attr('href'),
                        url: that.attr('href'),
                        dataType: "json",
                        success: function (data) {
                            if (data.result == true) {
                            that.attr('href', data.url);
                                $.ajax({
                                    type: "GET",
                                    url: '/utilisateur/lister-perimetre/' + <?php echo $user->getId(); ?> + '/' + <?php echo $role->getId(); ?>,
                                    dataType: "html",
                                    success: function (data) {
                                        $('#user-role-perimetres').html(data);
                                    }
                                });
                                $('#perimetre-message').addClass('alert-success')
                                    .html(data.message)
                                    .show();
                            } else {
                            that.prop('checked', !that.prop('checked'))
                                $('#perimetre-message').addClass('alert-danger')
                                    .html(data.message)
                                    .show();