]> git.agnieray.net Git - galette.git/commitdiff
Fix accordion when groups contains " / "
authorJohan Cwiklinski <johan@x-tnd.be>
Fri, 29 Dec 2023 16:20:54 +0000 (17:20 +0100)
committerJohan Cwiklinski <johan@x-tnd.be>
Sat, 30 Dec 2023 04:54:08 +0000 (05:54 +0100)
Fixes #1764
Fix group header display

Reword variables
Rework groups icons
Fix colspan when non group member/manager

galette/lib/Galette/Entity/Group.php
galette/templates/default/elements/group.html.twig
galette/templates/default/elements/group_persons.html.twig
galette/templates/default/pages/groups_list.html.twig
tests/Galette/Entity/tests/units/Group.php

index 3e3d3553adb7302f4522167abf37d9ffb53246e7..41b1aa411a2b68ae91647e5149d49df74abe529e 100644 (file)
@@ -550,6 +550,22 @@ class Group
         return $this->group_name;
     }
 
+    /**
+     * Get parents as an array
+     *
+     * @return array
+     */
+    public function getParents(): array
+    {
+        $parents = [];
+        $group = $this;
+        while ($group = $group->getParentGroup()) {
+            $parents[] = $group->getName();
+        }
+        return $parents;
+    }
+
+
     /**
      * Get the indented short name of the group "  >> bar"
      *
@@ -615,7 +631,7 @@ class Group
     /**
      * Get parent group
      *
-     * @return Group
+     * @return Group|null
      */
     public function getParentGroup()
     {
@@ -689,7 +705,6 @@ class Group
             }
         } while ($group = $group->getParentGroup());
 
-        //@phpstan-ignore-next-line
         return true;
     }
 
index d29af3edd148508394916a28152463665ed04c45..3022bff613f49444b679bb12f7e6b34c826d3f3b 100644 (file)
@@ -5,12 +5,17 @@
 
 <div class="ui stackable pointing inverted menu tabbed">
     <div class="item header">
-        <i class="users cog icon" aria-hidden="true"></i>
-        {{ group.getFullName() }} :
+        <div class="ui breadcrumb">
+            {% for parent in group.parents %}
+                <span class="section">{{ parent }}</span>
+                <i class="right angle icon divider"></i>
+            {% endfor %}
+            <span class="section active">{{ group.getName() }}</span>
+        </div>
     </div>
     <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_information" class="item{{ tab == 'group_information' ? ' active' }}" data-tab="group_information">{{ _T("Information") }}</a>
-    <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_managers" class="item{{ tab == 'group_managers' ? ' active' }}" data-tab="group_managers">{{ _T("Managers") }} ({{ managers|length }})</a>
-    <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_members" class="item{{ tab == 'group_members' ? ' active' }}" data-tab="group_members">{{ _T("Members") }} ({{ members|length }})</a>
+    <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_managers" class="item{{ tab == 'group_managers' ? ' active' }}" data-tab="group_managers"><i class="user shield icon" aria-hidden="true"></i>{{ _T("Managers") }} ({{ managers|length }})</a>
+    <a href="{{ url_for('groups', {'id': group.getId()}) }}?tab=group_members" class="item{{ tab == 'group_members' ? ' active' }}" data-tab="group_members"><i class="user icon" aria-hidden="true"></i>{{ _T("Members") }} ({{ members|length }})</a>
 </div>
 <form class="ui form" action="{{ url_for("doEditGroup", {"id": group.getId()}) }}" method="post" enctype="multipart/form-data" id="group_form">
     <div class="ui{{ tab == 'group_information' ? ' active' }} tab segment" data-tab="group_information">
index 576233fcd3315109d6bd1bfdd9fbc8a14cdbcc27..5182cd75fffc179d27e4c2fbc737007802ad1401 100644 (file)
@@ -70,7 +70,7 @@
     {% endif %}
 {% else %}
                             <tr>
-                                <td colspan="2">
+                                <td colspan="{% if login.isSuperAdmin() %}3{% else %}2{% endif %}">
     {% if person_mode == 'members' %}
                                     {{ _T("No member attached") }}
     {% else %}
index 9ce0becdd3801e8a775e3101ce606e34482419f4..dfc092ef7feafd564e54befdd9149d8950508c32 100644 (file)
@@ -2,18 +2,18 @@
 
 {% set can_export = login.isGroupManager() and preferences.pref_bool_groupsmanagers_exports or login.isAdmin() or login.isStaff() %}
 
-{% macro group_item(login, group, opened, selected) %}
-    <div class="{% if group.getGroups()|length > 0 %}title{% if group.getName() in opened %} active{% endif %}{% else %}nochild{% endif %}">
+{% macro group_item(login, group, parents, selected) %}
+    <div class="{% if group.getGroups()|length > 0 %}title{% if group.getName() in parents %} active{% endif %}{% else %}nochild{% endif %}">
         <i class="{% if group.getGroups()|length > 0 %}dropdown{% else %}empty{% endif %} icon" aria-hidden="true"></i>
         <a class="ui{% if group.getName() == selected %} primary{% endif %}{% if not login.isGroupManager(group.getId()) %} disabled{% endif %} label" href="{% if login.isGroupManager(group.getId()) %}{{ url_for("groups", {"id": group.getId()}) }}{% else %}#{% endif %}">
             {{ group.getName() }}
         </a>
     </div>
     {% if group.getGroups()|length > 0 %}
-    <div class="content{% if group.getName() in opened %} active{% endif %}">
+    <div class="content{% if group.getName() in parents %} active{% endif %}">
         <div class="accordion">
         {% for child_group in group.getGroups() %}
-            {{ _self.group_item(login, child_group, opened, selected) }}
+            {{ _self.group_item(login, child_group, parents, selected) }}
         {% endfor %}
         </div>
     </div>
@@ -21,8 +21,8 @@
 {% endmacro %}
 
 {% block content %}
-    {% set opened = group.getFullName()|split(' / ') %}
-    {% set selected = opened|last %}
+    {% set parents = group.getParents() %}
+    {% set selected = group.getName() %}
     <div class="ui stackable grid">
         <div class="three wide column">
     {% if group.getId() %}
@@ -30,7 +30,7 @@
             <div class="ui attached accordion-styled scrolling segment loader_selector">
                 <div class="ui tree accordion">
                 {% for group in groups_root %}
-                    {{ _self.group_item(login, group, opened, selected) }}
+                    {{ _self.group_item(login, group, parents, selected) }}
                 {% endfor %}
                 </div>
             </div>
index 7dbffbe23f19b75a709bcd87c80d82e15732655b..0b2b78b1832ceb3cb47f713b59678f66edbb0279 100644 (file)
@@ -251,6 +251,20 @@ class Group extends GaletteTestCase
         $children = $group->getGroups();
         $this->assertCount(1, $children);
         $this->assertSame('Another child group', $children[0]->getName());
+
+        $group = new \Galette\Entity\Group($child_id_2);
+        $this->assertSame(['A parent group'], $group->getParents());
+
+        $group = new \Galette\Entity\Group();
+        $group->setName('A second level child group');
+        $group->setParentGroup($child_id_2);
+        $this->assertTrue($group->store());
+        $child_id_3 = $group->getId();
+        $this->assertSame($child_id_2, $group->getParentGroup()->getId());
+
+        $group = new \Galette\Entity\Group($child_id_3);
+        $this->assertSame(['Another child group', 'A parent group'], $group->getParents());
+        $this->assertTrue($group->detach());
     }
 
     /**