-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
|![School](https://github.com/user-attachments/assets/be50f885-9ed6-4f13-9197-ae794a77a1fc) |![Admin](https://github.com/user-attachments/assets/91f1e454-4ea4-4f51-a07f-87a70e141156) | |--|--| |![Visibility](https://github.com/user-attachments/assets/c42ae561-c822-40e2-894a-2e4a5cdcbfae)|![Groups](https://github.com/user-attachments/assets/c0401da2-24f0-4d38-9f9a-8b71ef1049ee)|
- Loading branch information
Showing
26 changed files
with
1,044 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import 'package:myecl/admin/tools/function.dart'; | ||
|
||
class School { | ||
School({ | ||
required this.name, | ||
required this.id, | ||
required this.emailRegex, | ||
}); | ||
late final String name; | ||
late final String id; | ||
late final String emailRegex; | ||
|
||
School.fromJson(Map<String, dynamic> json) { | ||
name = getSchoolNameFromId(json['id'], json['name']); | ||
id = json['id']; | ||
emailRegex = json['email_regex']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final data = <String, dynamic>{}; | ||
data['name'] = name; | ||
data['id'] = id; | ||
data['email_regex'] = emailRegex; | ||
return data; | ||
} | ||
|
||
School copyWith({ | ||
String? name, | ||
String? id, | ||
String? emailRegex, | ||
}) => | ||
School( | ||
name: name ?? this.name, | ||
id: id ?? this.id, | ||
emailRegex: emailRegex ?? this.emailRegex, | ||
); | ||
|
||
School.empty() { | ||
name = 'Nom'; | ||
id = ''; | ||
emailRegex = ''; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'School(id: $id, name: $name, emailRegex: $emailRegex)'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
|
||
class SchoolIdNotifier extends StateNotifier<String> { | ||
SchoolIdNotifier() : super(""); | ||
|
||
void setId(String id) { | ||
state = id; | ||
} | ||
} | ||
|
||
final schoolIdProvider = StateNotifierProvider<SchoolIdNotifier, String>( | ||
(ref) => SchoolIdNotifier(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:myecl/admin/class/school.dart'; | ||
import 'package:myecl/admin/repositories/school_repository.dart'; | ||
import 'package:myecl/tools/providers/list_notifier.dart'; | ||
import 'package:myecl/tools/token_expire_wrapper.dart'; | ||
|
||
class SchoolListNotifier extends ListNotifier<School> { | ||
final SchoolRepository schoolRepository; | ||
SchoolListNotifier({required this.schoolRepository}) | ||
: super(const AsyncValue.loading()); | ||
|
||
Future<AsyncValue<List<School>>> loadSchools() async { | ||
return await loadList(schoolRepository.getSchoolList); | ||
} | ||
|
||
Future<bool> createSchool(School school) async { | ||
return await add(schoolRepository.createSchool, school); | ||
} | ||
|
||
Future<bool> updateSchool(School school) async { | ||
return await update( | ||
schoolRepository.updateSchool, | ||
(schools, school) => | ||
schools..[schools.indexWhere((g) => g.id == school.id)] = school, | ||
school, | ||
); | ||
} | ||
|
||
Future<bool> deleteSchool(School school) async { | ||
return await delete( | ||
schoolRepository.deleteSchool, | ||
(schools, school) => schools..removeWhere((i) => i.id == school.id), | ||
school.id, | ||
school, | ||
); | ||
} | ||
|
||
void setSchool(School school) { | ||
state.whenData( | ||
(d) { | ||
if (d.indexWhere((g) => g.id == school.id) == -1) return; | ||
state = AsyncValue.data( | ||
d..[d.indexWhere((g) => g.id == school.id)] = school, | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
final allSchoolListProvider = | ||
StateNotifierProvider<SchoolListNotifier, AsyncValue<List<School>>>((ref) { | ||
final schoolRepository = ref.watch(schoolRepositoryProvider); | ||
SchoolListNotifier provider = | ||
SchoolListNotifier(schoolRepository: schoolRepository); | ||
tokenExpireWrapperAuth(ref, () async { | ||
await provider.loadSchools(); | ||
}); | ||
return provider; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import 'package:hooks_riverpod/hooks_riverpod.dart'; | ||
import 'package:myecl/admin/class/school.dart'; | ||
import 'package:myecl/admin/repositories/school_repository.dart'; | ||
|
||
class SchoolNotifier extends StateNotifier<School> { | ||
final SchoolRepository schoolRepository; | ||
SchoolNotifier({required this.schoolRepository}) : super(School.empty()); | ||
|
||
void setSchool(School school) { | ||
state = school; | ||
} | ||
} | ||
|
||
final schoolProvider = StateNotifierProvider<SchoolNotifier, School>((ref) { | ||
final schoolRepository = ref.watch(schoolRepositoryProvider); | ||
return SchoolNotifier(schoolRepository: schoolRepository); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:myecl/admin/class/school.dart'; | ||
import 'package:myecl/auth/providers/openid_provider.dart'; | ||
import 'package:myecl/tools/repository/repository.dart'; | ||
|
||
class SchoolRepository extends Repository { | ||
@override | ||
// ignore: overridden_fields | ||
final ext = "schools/"; | ||
|
||
Future<List<School>> getSchoolList() async { | ||
return List<School>.from( | ||
(await getList()).map((x) => School.fromJson(x)), | ||
); | ||
} | ||
|
||
Future<School> getSchool(String schoolId) async { | ||
return School.fromJson(await getOne(schoolId)); | ||
} | ||
|
||
Future<bool> deleteSchool(String schoolId) async { | ||
return await delete(schoolId); | ||
} | ||
|
||
Future<bool> updateSchool(School school) async { | ||
return await update(school.toJson(), school.id); | ||
} | ||
|
||
Future<School> createSchool(School school) async { | ||
return School.fromJson(await create(school.toJson())); | ||
} | ||
} | ||
|
||
final schoolRepositoryProvider = Provider((ref) { | ||
final token = ref.watch(tokenProvider); | ||
return SchoolRepository()..setToken(token); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,49 @@ | ||
class AdminTextConstants { | ||
static const String accountTypes = "Types de compte"; | ||
static const String add = "Ajouter"; | ||
static const String addAssociation = "Ajouter une association"; | ||
static const String addedAssociation = "Association ajoutée"; | ||
static const String addGroup = "Ajouter un groupe"; | ||
static const String addedGroup = "Groupe créé"; | ||
static const String addedLoaner = "Préteur ajouté"; | ||
static const String addedMember = "Membre ajouté"; | ||
static const String addingError = "Erreur lors de l'ajout"; | ||
static const String addingMember = "Ajout d'un membre"; | ||
static const String addLoaningAssociation = "Ajouter une association de prêt"; | ||
static const String addLoaningGroup = "Ajouter un groupe de prêt"; | ||
static const String addSchool = "Ajouter une école"; | ||
static const String addedSchool = "École créée"; | ||
static const String administration = "Administration"; | ||
static const String association = "Association"; | ||
static const String group = "Groupe"; | ||
static const String groups = "Groupes"; | ||
static const String delete = "Supprimer"; | ||
static const String deleteAssociation = "Supprimer l'association ?"; | ||
static const String deletedAssociation = "Association supprimée"; | ||
static const String deleteGroup = "Supprimer le groupe ?"; | ||
static const String deletedGroup = "Groupe supprimé"; | ||
static const String deleteSchool = "Supprimer l'école ?"; | ||
static const String deletedSchool = "École supprimée"; | ||
static const String deleting = "Suppression"; | ||
static const String deletingError = "Erreur lors de la suppression"; | ||
static const String description = "Description"; | ||
static const String eclSchool = "Centrale Lyon"; | ||
static const String edit = "Modifier"; | ||
static const String emailRegex = "Email Regex"; | ||
static const String emptyFieldError = "Le nom ne peut pas être vide"; | ||
static const String error = "Erreur"; | ||
static const String loaningAssociation = "Association de prêt"; | ||
static const String loaningGroup = "Groupe de prêt"; | ||
static const String looking = "Recherche"; | ||
static const String members = "Membres"; | ||
static const String modifyModuleVisibility = | ||
"Modifier la visibilité des modules"; | ||
static const String modifyModuleVisibility = "Visibilité des modules"; | ||
static const String name = "Nom"; | ||
static const String noMoreLoaner = "Aucun prêteur n'est disponible"; | ||
static const String removeAssociationMember = | ||
"Supprimer le membre de l'association ?"; | ||
static const String updatedAssociation = "Association modifiée"; | ||
static const String noSchool = "Sans école"; | ||
static const String removeGroupMember = "Supprimer le membre du groupe ?"; | ||
static const String schools = "Écoles"; | ||
static const String updatedGroup = "Groupe modifié"; | ||
static const String updatingError = "Erreur lors de la modification"; | ||
static const String visibilities = "Visibilités"; | ||
} | ||
|
||
static const String accountTypes = "Types de compte"; | ||
enum SchoolIdConstant { | ||
noSchool("dce19aa2-8863-4c93-861e-fb7be8f610ed"), | ||
eclSchool("d9772da7-1142-4002-8b86-b694b431dfed"); | ||
|
||
static const String groups = "Groupes"; | ||
const SchoolIdConstant(this.value); | ||
final String value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import 'package:myecl/admin/tools/constants.dart'; | ||
|
||
String getSchoolNameFromId(String id, String name) { | ||
if (id == SchoolIdConstant.noSchool.value) { | ||
return AdminTextConstants.noSchool; | ||
} | ||
if (id == SchoolIdConstant.eclSchool.value) { | ||
return AdminTextConstants.eclSchool; | ||
} | ||
return name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.