From cc2f33e82550f9c07d6895e2e66e5ea234c8290f Mon Sep 17 00:00:00 2001
From: Myriam Delaruelle <myriam.delaruelle@univ-lorraine.fr>
Date: Tue, 1 Apr 2025 15:35:03 +0200
Subject: [PATCH] patch filters/activities that were not displaying proper
 results

---
 amd/build/suivi.js | 17 ++++++++++++++---
 suivi_unit.php     |  2 +-
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/amd/build/suivi.js b/amd/build/suivi.js
index a135926..c6e6a85 100644
--- a/amd/build/suivi.js
+++ b/amd/build/suivi.js
@@ -223,14 +223,23 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
     	if(groupsid.length==0){
     		groupsid.push(-2);
     	}
+
+    	// FAIRE EN JS ? 
+    	// OUI : sinon le cache va tout défoncer
+    	// NON : performances 
+    	// Pour les gros cours, on mettrait les paramas des activités à envoyer
+    	//var params=[];
+    	
     	$.ajax({ url: completeUrl,
         	data: {action: 'fetchgroups', groupsid:groupsid},
         	type: 'post',
         	success: function(request) { 
         		
-        		showHideActivities();
         		parsedrequest=JSON.parse(request);
-        		data=calcPercentage(parsedrequest);
+        		data=parsedrequest;
+        		showHideActivities();
+        		data=calcPercentage(data);
+        		
         		
         		showHideStudents();
         		if(data.countstudents<1500){
@@ -239,6 +248,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
         			localStorage.setItem("groups",JSON.stringify(parsedrequest["groups"]));
         			
         		}
+
         		reloadTable(data);
         		updateGroupsFilterLabel(false);
 			}
@@ -380,6 +390,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
         var arrayActivitiesID=[];
         var activitiesToStore=[];
         var activities = $('input[name="options[]"]');
+
         for(var i=0; i<activities.length;i++){
 
             prog=data.modules.find(element => element.id === activities[i].value);
@@ -400,7 +411,7 @@ define(['jquery', 'core/ajax', 'core/templates', 'core/str'],
         if(data.countstudents<1500){
         	localStorage.setItem("activities",JSON.stringify(activitiesToStore));
         }
-        
+       
        /* if(changefilter==true){
         	reloadTable(data);
         }*/
diff --git a/suivi_unit.php b/suivi_unit.php
index dee5e10..74c8d29 100644
--- a/suivi_unit.php
+++ b/suivi_unit.php
@@ -546,7 +546,7 @@ else if(isset($_POST['action']) && $_POST['action'] == 'search_student' && isset
 }
 // If a post is sent trought the page --> Si on change les filtres (de groupes), le template est appelé en JS
 else if (isset($_POST['action']) && !empty($_POST['action'])) {
-
+    
     $groups = groups_get_all_groups($COURSE->id, 0, 0, 'g.*', true);
     $data = [];
     $modules = get_activities($completion, $activesectionid);
-- 
GitLab