Commit 5de8788c6bf931d2536751817c0277c5239b5670

Authored by Etienne Pallier
1 parent f94cf6ea
Exists in master and in 2 other branches dev, dev-IRAP

(Enorme) Simplification des vues (toujours en cours)

README.md
... ... @@ -54,11 +54,11 @@ Logiciel testé et validé sur les configurations suivantes :
54 54 VERSION ACTUELLE
55 55  
56 56 Date: 21/05/2019
57   -Version: 2.12.18
  57 +Version: 2.12.19
58 58 Author: EP
59 59 Commentaire:
60 60 Bugfix affichage boutons vue matériel (parfois 2e ligne chevauchait 1ère ligne)
61   - Simplification des vues (toujours en cours)
  61 + (Enorme) Simplification des vues (toujours en cours)
62 62  
63 63  
64 64 IMPORTANT :
... ... @@ -95,7 +95,9 @@ La liste ci-dessous n'est plus à jour, elle est désormais en ligne ici : https
95 95  
96 96 -----------------------------------------------------------------------------------------------------------
97 97  
98   -21/05/2019 Version: 2.12.18 (EP)
  98 +21/05/2019 Version: 2.12.18-19 (EP)
  99 + Bugfix affichage boutons vue matériel (parfois 2e ligne chevauchait 1ère ligne)
  100 + (Enorme) Simplification des vues (toujours en cours)
99 101  
100 102  
101 103 17/05/2019 Version: 2.12.15-17 (EP)
... ...
src/Controller/AppController.php
... ... @@ -617,6 +617,7 @@ class AppController extends Controller
617 617  
618 618 $role = $this->getUserRole();
619 619 $profile = self::PROFILES["$role"];
  620 +
620 621  
621 622 // Set General CONSTANTS for all CONTROLLERS
622 623 // (Before, they used to be in beforeFilter())
... ... @@ -628,8 +629,16 @@ class AppController extends Controller
628 629 // (c'est à dire s'il n'est pas dans la table "utilisateurs")
629 630 $this->priviledgedUser = $this->getTablePriviledgedUserFromCurrentSessionUserIfExists();
630 631  
  632 + $this->USER_IS_UTILISATEUR = ($profile == self::PROFILE_USER);
  633 + $this->USER_IS_ADMIN = ($profile == self::PROFILE_ADMIN);
  634 + $this->USER_IS_ADMINPLUS = ($profile == self::PROFILE_ADMINPLUS);
  635 + $this->USER_IS_SUPERADMIN = ($profile == self::PROFILE_SUPERADMIN);
  636 + $this->USER_IS_RESPONSABLE_OR_MORE = ($profile >= self::PROFILE_RESPONSABLE);
631 637 $this->USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE);
632 638 $this->USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN);
  639 + $this->USER_IS_ADMINPLUS_OR_MORE = ($profile >= self::PROFILE_ADMINPLUS);
  640 +
  641 +
633 642 // - Misc constants
634 643 $this->idGmNa = TableRegistry::getTableLocator()->get('GroupesMetiers')->find()
635 644 ->where([
... ... @@ -643,13 +652,21 @@ class AppController extends Controller
643 652 ->first()['id'];
644 653  
645 654 // Now, set these constants for all VIEWS
  655 + $this->set('role', $role);
  656 + $this->set('profile', $profile);
646 657 $this->set('username', $this->userName);
647 658 $this->set('priviledgedUser', $this->priviledgedUser);
648 659 $this->set('idGmNa', $this->idGmNa);
649 660 $this->set('idGtNa', $this->idGtNa);
  661 + $this->set('USER_IS_UTILISATEUR', $this->USER_IS_UTILISATEUR);
  662 + $this->set('USER_IS_ADMIN', $this->USER_IS_ADMIN);
  663 + $this->set('USER_IS_ADMINPLUS', $this->USER_IS_ADMINPLUS);
  664 + $this->set('USER_IS_SUPERADMIN', $this->USER_IS_SUPERADMIN);
  665 + $this->set('USER_IS_RESPONSABLE_OR_MORE', $this->USER_IS_RESPONSABLE_OR_MORE);
650 666 $this->set('USER_IS_RESPONSABLE', $this->USER_IS_RESPONSABLE);
  667 + //$this->set(compact('USER_IS_ADMIN_OR_MORE'));
651 668 $this->set('USER_IS_ADMIN_OR_MORE', $this->USER_IS_ADMIN_OR_MORE);
652   -
  669 + $this->set('USER_IS_ADMINPLUS_OR_MORE', $this->USER_IS_ADMINPLUS_OR_MORE);
653 670  
654 671 $configuration = $this->confLabinvent;
655 672 if ($configuration->mode_install)
... ... @@ -702,9 +719,10 @@ class AppController extends Controller
702 719 ]))
703 720 $this->set('_serialize', true);
704 721  
705   - // moved to beforeFilter()
  722 + // (EP 21/5/19) moved to beforeFilter()
706 723 //$this->set('username', $this->LdapAuth->user('sn')[0] . ' ' . $this->LdapAuth->user('givenname')[0]);
707 724  
  725 + // TODO: (EP) A quoi ça sert ???
708 726 $configuration = $this->confLabinvent;
709 727 $this->set('configuration', $configuration);
710 728 $this->request->getSession()->write("authType", $configuration->ldap_authenticationType);
... ... @@ -722,26 +740,29 @@ class AppController extends Controller
722 740 * $role = 'Utilisateur';
723 741 */
724 742 // Role = 'Utilisateur', 'Responsable", ...
  743 + // (EP 21/5/19) moved to beforeFilter()
  744 + /*
725 745 $role = $this->getUserRole();
726 746 $this->set('role', $role);
  747 + */
727 748  
728 749 // Profile = PROFILE_USER (=1), PROFILE_RESPONSABLE (=2), ...
729 750 // $profile = $this->allProfiles["$role"];
  751 + // (EP 21/5/19) moved to beforeFilter()
  752 + /*
730 753 $profile = self::PROFILES["$role"];
731 754 $this->set('profile', $profile);
  755 + */
732 756  
  757 + // (EP 21/5/19) moved to beforeFilter()
  758 + /*
733 759 $USER_IS_UTILISATEUR = ($profile == self::PROFILE_USER);
734   -
735   -
736 760 $USER_IS_ADMIN = ($profile == self::PROFILE_ADMIN);
737 761 $USER_IS_ADMINPLUS = ($profile == self::PROFILE_ADMINPLUS);
738 762 $USER_IS_SUPERADMIN = ($profile == self::PROFILE_SUPERADMIN);
739 763 $USER_IS_RESPONSABLE_OR_MORE = ($profile >= self::PROFILE_RESPONSABLE);
740   -
741   - // moved to beforeFilter()
742   - //$USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE);
743   - //$USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN);
744   -
  764 + $USER_IS_RESPONSABLE = ($profile == self::PROFILE_RESPONSABLE);
  765 + $USER_IS_ADMIN_OR_MORE = ($profile >= self::PROFILE_ADMIN);
745 766 $USER_IS_ADMINPLUS_OR_MORE = ($profile >= self::PROFILE_ADMINPLUS);
746 767  
747 768 $this->set('USER_IS_UTILISATEUR', $USER_IS_UTILISATEUR);
... ... @@ -749,13 +770,12 @@ class AppController extends Controller
749 770 $this->set('USER_IS_ADMINPLUS', $USER_IS_ADMINPLUS);
750 771 $this->set('USER_IS_SUPERADMIN', $USER_IS_SUPERADMIN);
751 772 $this->set('USER_IS_RESPONSABLE_OR_MORE', $USER_IS_RESPONSABLE_OR_MORE);
752   - // moved to beforeFilter()
753   - //$this->set('USER_IS_RESPONSABLE', $USER_IS_RESPONSABLE);
754   - //$this->set(compact('USER_IS_ADMIN_OR_MORE'));
  773 + $this->set('USER_IS_RESPONSABLE', $USER_IS_RESPONSABLE);
  774 + $this->set(compact('USER_IS_ADMIN_OR_MORE'));
755 775 $this->set('USER_IS_ADMINPLUS_OR_MORE', $USER_IS_ADMINPLUS_OR_MORE);
756 776  
757   - // moved to beforeFilter()
758   - //$this->set('priviledgedUser', $priviledgedUser);
  777 + $this->set('priviledgedUser', $priviledgedUser);
  778 + */
759 779  
760 780 /*
761 781 * @todo EP 08/2017 Nouvelle organisation des ACL avec $easyACL
... ... @@ -857,28 +877,6 @@ class AppController extends Controller
857 877 ]
858 878 );
859 879 };
860   - /*
861   - $echoActionButton = function($html, $icon_class, $title, $action, $id, $controller='', $tip='', $confirmMessage='', $moreButtonStyle='', $mat=NULL, $photo=NULL) {
862   - if ($controller=='') $controller='materiels';
863   - echo $html->link(
864   - __("<i class=$icon_class></i> $title"),
865   - [
866   - 'controller' => $controller,
867   - 'action' => $action,
868   - $id,
869   - $mat,
870   - $photo
871   - ],
872   - [
873   - 'title' => $tip,
874   - 'escape' => false,
875   - 'onclick' => 'return true;',
876   - 'style' => 'margin-right: 10px'.$moreButtonStyle,
877   - 'confirm' => $confirmMessage
878   - ]
879   - );
880   - };
881   - */
882 880 $this->set(compact('echoActionButton'));
883 881  
884 882 } // beforeRender()
... ...
src/Controller/MaterielsController.php
... ... @@ -793,25 +793,51 @@ class MaterielsController extends AppController
793 793 $IS_TOBEARCHIVED = ($materiel->status == 'TOBEARCHIVED');
794 794 $IS_ARCHIVED = ($materiel->status == 'ARCHIVED');
795 795  
796   - // NEW TODO:
  796 +
  797 + // Current user is creator or owner of current materiel
797 798 $USER_IS_CREATOR_OR_OWNER = in_array($this->userName, [
798 799 $materiel->nom_createur,
799 800 $materiel->nom_responsable
800 801 ]);
  802 + $this->set(compact('USER_IS_CREATOR_OR_OWNER'));
  803 +
  804 + // Current user is same group as current materiel
801 805 $USER_IS_SAME_GROUP = (
802 806 ( isset($this->priviledgedUser->groupes_metier_id) && $this->priviledgedUser->groupes_metier_id != $this->idGmNa && $materiel->groupes_metier_id == $this->priviledgedUser->groupes_metier_id )
803 807 ||
804 808 ( isset($this->priviledgedUser->groupe_thematique_id) && $this->priviledgedUser->groupe_thematique_id != $this->idGtNa && $materiel->groupes_thematique_id == $this->priviledgedUser->groupe_thematique_id )
805 809 );
806   - $CAN_EDIT = $IS_CREATED && (
  810 + $this->set(compact('USER_IS_SAME_GROUP'));
  811 +
  812 +
  813 + $CAN_ATTACH_A_DOC =
807 814 $this->USER_IS_ADMIN_OR_MORE
808 815 ||
809 816 $USER_IS_CREATOR_OR_OWNER
810   - ||
811   - ( $this->USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP )
812   - );
  817 + ||
  818 + ($this->USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP);
  819 + $this->set(compact('CAN_ATTACH_A_DOC'));
  820 +
  821 + $CAN_MANAGE_SUIVIS = $CAN_ATTACH_A_DOC;
  822 + $this->set(compact('CAN_MANAGE_SUIVIS'));
  823 +
  824 + $CAN_MANAGE_EMPRUNTS = $CAN_ATTACH_A_DOC;
  825 + $this->set(compact('CAN_MANAGE_EMPRUNTS'));
  826 +
  827 + $CAN_MANAGE_FILES = $CAN_ATTACH_A_DOC;
  828 + $this->set(compact('CAN_MANAGE_FILES'));
  829 +
  830 + $CAN_EDIT = $IS_CREATED && $CAN_ATTACH_A_DOC;
813 831 $this->set(compact('CAN_EDIT'));
814   - // END TODO
  832 +
  833 + $CAN_COPY = $CAN_EDIT;
  834 + $this->set(compact('CAN_COPY'));
  835 +
  836 + $configuration = $this->confLabinvent;
  837 + $CAN_PRINT_LABEL = $IS_VALIDATED && $configuration->hasPrinter && $this->USER_IS_ADMIN_OR_MORE;
  838 + $this->set(compact('CAN_PRINT_LABEL'));
  839 +
  840 +
815 841  
816 842 // $status = $this->allStatus[$materiel->status];
817 843 $status = self::allStatus[$materiel->status];
... ...
src/Template/Materiels/view.ctp
... ... @@ -3,18 +3,27 @@ use Cake\I18n\Time;
3 3 use Cake\I18n\Date;
4 4 use Cake\ORM\TableRegistry;
5 5  
6   -// (EP 18/5/19) Elements set by Controller for this view:
  6 +// (EP 18/5/19)
  7 +// --- Elements set by Controller for this view ---
  8 +
7 9 // - Constants :
8 10 //$CAN_EDIT = $CAN_EDIT;
9 11 $PDF_ENGINE = $PDF_ENGINE;
  12 +
10 13 // - User status:
11 14 $username = $username;
12 15 $priviledgedUser = $priviledgedUser;
13 16 $USER_IS_UTILISATEUR = $USER_IS_UTILISATEUR;
14 17 $USER_IS_RESPONSABLE = $USER_IS_RESPONSABLE;
  18 +$USER_IS_RESPONSABLE_OR_MORE = $USER_IS_RESPONSABLE_OR_MORE;
15 19 $USER_IS_ADMIN = $USER_IS_ADMIN;
16 20 $USER_IS_ADMIN_OR_MORE = $USER_IS_ADMIN_OR_MORE;
  21 +$USER_IS_ADMINPLUS = $USER_IS_ADMINPLUS;
  22 +$USER_IS_ADMINPLUS_OR_MORE = $USER_IS_ADMINPLUS_OR_MORE;
17 23 $USER_IS_SUPERADMIN = $USER_IS_SUPERADMIN;
  24 +$USER_IS_CREATOR_OR_OWNER = $USER_IS_CREATOR_OR_OWNER;
  25 +$USER_IS_SAME_GROUP = $USER_IS_SAME_GROUP;
  26 +
18 27 // - Materiel status:
19 28 $idGmNa = $idGmNa;
20 29 $idGtNa = $idGtNa;
... ... @@ -22,11 +31,19 @@ $IS_CREATED = $IS_CREATED;
22 31 $IS_VALIDATED = $IS_VALIDATED;
23 32 $IS_TOBEARCHIVED = $IS_TOBEARCHIVED;
24 33 $IS_ARCHIVED = $IS_ARCHIVED;
  34 +
25 35 // - User capabilities on materiel:
26 36 $CAN_EDIT = $CAN_EDIT;
  37 +$CAN_ATTACH_A_DOC = $CAN_ATTACH_A_DOC;
  38 +$CAN_COPY = $CAN_COPY;
  39 +$CAN_PRINT_LABEL = $CAN_PRINT_LABEL;
  40 +$CAN_MANAGE_SUIVIS = $CAN_MANAGE_SUIVIS;
  41 +$CAN_MANAGE_EMPRUNTS = $CAN_MANAGE_EMPRUNTS;
  42 +$CAN_MANAGE_FILES = $CAN_MANAGE_FILES;
27 43 // Autres
28 44 // TODO: yena plein d'autres
29 45 // ...
  46 +
30 47 // - Fonctions :
31 48 $displayElement = $displayElement;
32 49 $dateProchainControleVerif = $dateProchainControleVerif;
... ... @@ -123,6 +140,7 @@ function $echoActionButton($html, $icon_class, $title, $action, $id, $tip=&#39;&#39;, $c
123 140 // debug("user=".$priviledgedUser);
124 141 // debug("user name = ".$username);
125 142  
  143 +/*
126 144 $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER = $USER_IS_UTILISATEUR && in_array($username, [
127 145 $materiel->nom_createur,
128 146 $materiel->nom_responsable
... ... @@ -134,13 +152,15 @@ $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER = $USER_IS_RESPONSABLE &amp;&amp; in_array($us
134 152 ]);
135 153  
136 154 $USER_IS_RESPONSABLE_AND_SAME_GROUP = $USER_IS_RESPONSABLE && ((isset($priviledgedUser->groupes_metier_id) && $priviledgedUser->groupes_metier_id != $idGmNa && $materiel->groupes_metier_id == $priviledgedUser->groupes_metier_id) || (isset($priviledgedUser->groupe_thematique_id) && $priviledgedUser->groupe_thematique_id != $idGtNa && $materiel->groupes_thematique_id == $priviledgedUser->groupe_thematique_id));
137   -
  155 +*/
138 156  
139 157 // TODO: to be set by controller
140   -//$CAN_EDIT = $IS_CREATED && ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER);
  158 +/*
  159 +$CAN_EDIT = $IS_CREATED && ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER);
141 160 $CAN_ATTACH_A_DOC = $USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER;
142 161 $CAN_COPY = $IS_CREATED and ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER);
143 162 $CAN_PRINT_LABEL = $IS_VALIDATED && $configuration->hasPrinter && $USER_IS_ADMIN_OR_MORE;
  163 +*/
144 164  
145 165 ?>
146 166  
... ... @@ -289,7 +309,7 @@ $CAN_PRINT_LABEL = $IS_VALIDATED &amp;&amp; $configuration-&gt;hasPrinter &amp;&amp; $USER_IS_ADMIN
289 309 $moreButtonStyle = '; margin-top:10px; display:inline-block';
290 310 $moreButtonStyleRed = $moreButtonStyle . '; color:red';
291 311 // BOUTON de changement de statut : Valider, Invalider, Demander archivage, ou Archiver
292   - if ($USER_IS_ADMIN_OR_MORE || $USER_IS_RESPONSABLE_AND_SAME_GROUP) {
  312 + if ($USER_IS_ADMIN_OR_MORE || ($USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP)) {
293 313 // CREATED
294 314 if ($IS_CREATED)
295 315 // Bouton VALIDER
... ... @@ -512,7 +532,14 @@ if ($USER_IS_ADMIN_OR_MORE) {
512 532 <tr>
513 533 <td class="actions" style="padding: 6px 0; text-align: left;">
514 534 <?php
515   - if ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER) {
  535 + //if ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER) {
  536 + /*
  537 + if ($USER_IS_ADMIN_OR_MORE
  538 + || $USER_IS_CREATOR_OR_OWNER
  539 + || ($USER_IS_RESPONSABLE && $USER_IS_SAME_GROUP)) {
  540 + */
  541 + if ($CAN_MANAGE_SUIVIS) {
  542 + // Edit Suivis
516 543 echo $this->Html->link(__('<i class="icon-pencil"></i>'), [
517 544 'controller' => 'Suivis',
518 545 'action' => 'edit',
... ... @@ -521,6 +548,7 @@ if ($USER_IS_ADMIN_OR_MORE) {
521 548 'escape' => false,
522 549 'style' => 'margin:0'
523 550 ]);
  551 + // Delete Suivis
524 552 echo $this->Form->postLink(__('<i class="icon-trash"></i>'), [
525 553 'controller' => 'Suivis',
526 554 'action' => 'delete',
... ... @@ -591,8 +619,10 @@ if ($USER_IS_ADMIN_OR_MORE) {
591 619 ?>
592 620 <tr>
593 621 <td class="actions" style="padding: 6px 0; text-align: left;">
594   - <?php
595   - if ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER ) {
  622 + <?php
  623 + //if ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER ) {
  624 + if ($CAN_MANAGE_EMPRUNTS) {
  625 + // Edit Emprunt
596 626 echo $this->Html->link(__('<i class="icon-pencil"></i>'), [
597 627 'controller' => 'Emprunts',
598 628 'action' => 'edit',
... ... @@ -601,6 +631,7 @@ if ($USER_IS_ADMIN_OR_MORE) {
601 631 'escape' => false,
602 632 'style' => 'margin:0'
603 633 ]);
  634 + // Delete Emprunt
604 635 echo $this->Form->postLink(__('<i class="icon-trash"></i>'), [
605 636 'controller' => 'Emprunts',
606 637 'action' => 'delete',
... ... @@ -672,7 +703,9 @@ if ($USER_IS_ADMIN_OR_MORE) {
672 703 'escape' => false
673 704 ]);
674 705 }
675   - if ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER) {
  706 + //if ($USER_IS_ADMIN_OR_MORE || $USER_IS_UTILISATEUR_AND_CREATOR_OR_OWNER || $USER_IS_RESPONSABLE_AND_SAME_GROUP || $USER_IS_RESPONSABLE_AND_CREATOR_OR_OWNER) {
  707 + if ($CAN_MANAGE_FILES) {
  708 + // Edit doc
676 709 echo $this->Html->link(__('<i class="icon-pencil"></i>'), [
677 710 'controller' => 'Documents',
678 711 'action' => 'edit',
... ... @@ -681,6 +714,7 @@ if ($USER_IS_ADMIN_OR_MORE) {
681 714 'escape' => false,
682 715 'style' => 'margin:0'
683 716 ]);
  717 + // Delete doc
684 718 echo $this->Form->postLink(__('<i class="icon-trash"></i>'), [
685 719 'controller' => 'Documents',
686 720 'action' => 'delete',
... ... @@ -690,7 +724,7 @@ if ($USER_IS_ADMIN_OR_MORE) {
690 724 'style' => 'margin:0',
691 725 'confirm' => __('Êtes-vous sur de vouloir supprimer # {0}?', $documents->id)
692 726 ]);
693   - //rajout d'un lien pour envoyer des mails avec les documents en pj
  727 + // Envoyer devis par mail (envoyer des mails avec les documents en pj)
694 728 echo $this->Form->postLink(__('<i class="icon-envelope"></i>'), [
695 729 'controller' => 'Documents',
696 730 'action' => __('mailDevis' ,$documents->id),
... ...