@@ -17,6 +17,13 @@ class AcademyViewModel extends ChangeNotifier {
1717 List <SubjectModel > _subjects = [];
1818 List <SubjectModel > _availableSubjectsForStudent = [];
1919
20+ // --- FIX: Add the abbreviation map here ---
21+ final Map <String , String > _subjectAbbreviationMap = {
22+ 'LABORATORIO DE ELECTRICIDAD Y CONTROL' : 'LAB. ELECT. Y CONTROL' ,
23+ 'ARQUITECTURA Y ORGANIZACIÓN DE LAS COMPUTADORAS' : 'ARQ. Y ORG. COMP.' ,
24+ 'APLICACIÓN DE SISTEMAS DIGITALES' : 'APLIC. SIST. DIGITALES' ,
25+ };
26+
2027 bool get isLoading => _isLoading;
2128 String ? get errorMessage => _errorMessage;
2229 List <UserModel > get pendingStudents => _pendingStudents;
@@ -30,18 +37,25 @@ class AcademyViewModel extends ChangeNotifier {
3037 loadInitialData ();
3138 }
3239
33- // --- FIX: Make subject filtering case-insensitive ---
40+ // --- FIX: Make filtering "bilingual" ---
3441 void filterSubjectsForStudent (UserModel student) {
3542 if (student.subjectsToTake.isEmpty) {
3643 _availableSubjectsForStudent = List .from (_subjects);
3744 } else {
38- // Normalize the subjects the student needs to take for reliable comparison
3945 final studentSubjectsNormalized = student.subjectsToTake.map ((s) => s.trim ().toLowerCase ()).toSet ();
4046
4147 _availableSubjectsForStudent = _subjects.where ((subject) {
42- // Normalize the name of the subject from the general list before checking for inclusion
4348 final subjectNameNormalized = subject.name.trim ().toLowerCase ();
44- return studentSubjectsNormalized.contains (subjectNameNormalized);
49+ // Direct match (e.g., "sistemas digitales" == "sistemas digitales")
50+ if (studentSubjectsNormalized.contains (subjectNameNormalized)) {
51+ return true ;
52+ }
53+ // Abbreviation match (e.g., "sistemas digitales" == value for key "APLIC. SIST. DIGITALES")
54+ final abbreviation = _subjectAbbreviationMap[subject.name.toUpperCase ()];
55+ if (abbreviation != null && studentSubjectsNormalized.contains (abbreviation.toLowerCase ())) {
56+ return true ;
57+ }
58+ return false ;
4559 }).toList ();
4660 }
4761 notifyListeners ();
@@ -68,7 +82,7 @@ class AcademyViewModel extends ChangeNotifier {
6882 }
6983 }
7084
71- Future <void > _loadStudents () async {
85+ Future <void > _loadStudents () async {
7286 final query1 = _db
7387 .collection ('users' )
7488 .where ('role' , isEqualTo: 'student' )
@@ -119,9 +133,23 @@ Future<void> _loadStudents() async {
119133 }
120134
121135 Future <void > _loadSubjects () async {
136+ final Set <String > searchTerms = {};
137+ for (var academy in myAcademies) {
138+ searchTerms.add (academy);
139+ if (_subjectAbbreviationMap.containsValue (academy)) {
140+ final originalName = _subjectAbbreviationMap.entries.firstWhere ((entry) => entry.value == academy).key;
141+ searchTerms.add (originalName);
142+ }
143+ }
144+
145+ if (searchTerms.isEmpty) {
146+ _subjects = [];
147+ return ;
148+ }
149+
122150 final snapshot = await _db
123151 .collection ('subjects' )
124- .where ('academy' , whereIn: myAcademies )
152+ .where ('academy' , whereIn: searchTerms. toList () )
125153 .get ();
126154
127155 _subjects = snapshot.docs.map ((doc) => SubjectModel .fromMap (doc.data (), doc.id)).toList ();
0 commit comments