From 4404ef7470c64a0f974fafb13c1815dabcffdc3c Mon Sep 17 00:00:00 2001
From: Hamza HRAMCHI <hamza.hramchi@xelians.fr>
Date: Mon, 16 May 2022 16:34:15 +0200
Subject: [PATCH] FIX #20773 TIME 2:40 fixed infinite scrolling if the number
 of users associated with a group is very large

---
 lang/en.json                                         |  3 ++-
 lang/fr.json                                         |  3 ++-
 .../app/administration/group/group.component.html    | 11 +++++++++--
 .../app/administration/group/group.component.ts      | 12 +++++++++++-
 4 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/lang/en.json b/lang/en.json
index c9a9c11929..224002d631 100755
--- a/lang/en.json
+++ b/lang/en.json
@@ -649,6 +649,7 @@
 		"licence": "GNU GPLv3 license",
         "groupsToManage": "Choose the authorized assignment groups",
 		"unlinkGroup": "Unlink group",
-        "emptyGroups": "No groups available to associate"
+        "emptyGroups": "No groups available to associate",
+        "emptyGroupUsers": "No users associated with this group"
     }
 }
\ No newline at end of file
diff --git a/lang/fr.json b/lang/fr.json
index bfcad10f72..a02eb1fe02 100755
--- a/lang/fr.json
+++ b/lang/fr.json
@@ -648,6 +648,7 @@
 		"licence": "licence GNU GPLv3",
 		"groupsToManage": "Choisir les groupes d'affectations autorisés",
 		"unlinkGroup": "Dissocier le groupe",
-		"emptyGroups": "Aucun groupe disponible à associer"
+		"emptyGroups": "Aucun groupe disponible à associer",
+		"emptyGroupUsers": "Aucun utilisateur associé à ce groupe"
 	}
 }
diff --git a/src/frontend/app/administration/group/group.component.html b/src/frontend/app/administration/group/group.component.html
index 4643365fa6..c7febb6003 100644
--- a/src/frontend/app/administration/group/group.component.html
+++ b/src/frontend/app/administration/group/group.component.html
@@ -35,7 +35,7 @@
         <ion-searchbar [placeholder]="'lang.filter' | translate" style="margin-left: 4x; display: flex; width: 50%;"
             (ionChange)="applyFilter($event.detail.value)">
         </ion-searchbar>
-        <ion-card *ngIf="!creationMode" style="height: 400px; overflow-y: auto;">
+        <ion-content *ngIf="!creationMode" style="height: 400px; overflow-y: auto;">
             <ion-list>
                 <ion-item style="position: sticky;top:0px;z-index:1;">
                     <ng-container style="display: flex;align-items: center;justify-content: center;width: 100%;background: white;">
@@ -73,8 +73,15 @@
                         </ion-button>
                     </ion-item>
                 </ion-virtual-scroll>
+                <ion-infinite-scroll threshold="100px" (ionInfinite)="loadData($event)" *ngIf="group.users.length > 7">
+                    <ion-infinite-scroll-content loadingSpinner="bubbles" [loadingText]="'lang.loadingMoreData' | translate">
+                    </ion-infinite-scroll-content>
+                </ion-infinite-scroll>
             </ion-list>
-        </ion-card>
+            <ion-item lines="none" *ngIf="group.users.length === 0" style="text-align: center; font-size: 20px; color: gray; margin-top: 5px;">
+                <ion-label>{{ 'lang.emptyGroupUsers' | translate }}</ion-label>
+            </ion-item>
+        </ion-content>
         <ion-item text-center lines="none" style="position: sticky;bottom:0px;z-index:1;">
             <div style="display: flex;align-items: center;justify-content: center;width: 100%;background: white;">
                 <ion-button type="submit" shape="round" size="large" fill="outline" color="primary"
diff --git a/src/frontend/app/administration/group/group.component.ts b/src/frontend/app/administration/group/group.component.ts
index d17dee4409..010ca53112 100644
--- a/src/frontend/app/administration/group/group.component.ts
+++ b/src/frontend/app/administration/group/group.component.ts
@@ -84,7 +84,7 @@ export class GroupComponent implements OnInit {
                 this.creationMode = false;
                 this.usersList = [];
 
-                this.http.get('../rest/groups/' + params['id'])
+                this.http.get(`../rest/groups/${params['id']}`)
                     .pipe(
                         map((data: any) => data.group),
                         finalize(() => {
@@ -462,6 +462,16 @@ export class GroupComponent implements OnInit {
     canManage(privilege: any) {
         return privilege.id === 'manage_users' && privilege.checked;
     }
+
+    loadData(event: any) {
+        this.http.get(`../rest/groups/${this.group.id}`).pipe(
+            tap((data: any) => {
+                this.group.users = data.group.users;
+                event.target.complete();
+                event.target.disabled = true;
+            })
+        ).subscribe();
+    }
 }
 
 
-- 
GitLab