-
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.
Merge pull request #41 from aeecleclair/phonebook
Module Phonebook
- Loading branch information
Showing
63 changed files
with
3,661 additions
and
0 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,67 @@ | ||
class Association { | ||
Association({ | ||
required this.id, | ||
required this.name, | ||
required this.description, | ||
required this.kind, | ||
required this.mandateYear, | ||
}); | ||
|
||
late final String id; | ||
late final String name; | ||
late final String description; | ||
late final String kind; | ||
late final int mandateYear; | ||
|
||
Association.fromJson(Map<String, dynamic> json) { | ||
id = json['id']; | ||
name = json['name']; | ||
description = json['description']; | ||
kind = json['kind']; | ||
mandateYear = json['mandate_year']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final data = <String, dynamic>{ | ||
'id': id, | ||
'name': name, | ||
'description': description, | ||
'kind': kind, | ||
'mandate_year': mandateYear, | ||
}; | ||
return data; | ||
} | ||
|
||
Association copyWith({ | ||
String? id, | ||
String? name, | ||
String? description, | ||
String? kind, | ||
int? mandateYear, | ||
}) { | ||
return Association( | ||
id: id ?? this.id, | ||
name: name ?? this.name, | ||
description: description ?? this.description, | ||
kind: kind ?? this.kind, | ||
mandateYear: mandateYear ?? this.mandateYear, | ||
); | ||
} | ||
|
||
Association.empty() { | ||
id = ""; | ||
name = ""; | ||
description = ""; | ||
kind = ""; | ||
mandateYear = 0; | ||
} | ||
|
||
void newMandate() { | ||
mandateYear = mandateYear + 1; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return "Association(Nom : $name, id : $id, description : $description, kind : $kind, mandate_year : $mandateYear)"; | ||
} | ||
} |
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,27 @@ | ||
class AssociationKinds { | ||
AssociationKinds({ | ||
required this.kinds, | ||
}); | ||
|
||
late final List<String> kinds; | ||
|
||
AssociationKinds.fromJson(Map<String, dynamic> json) { | ||
kinds = json['kinds'].map<String>((dynamic tag) => tag.toString()).toList(); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final data = <String, dynamic>{ | ||
'kinds': kinds, | ||
}; | ||
return data; | ||
} | ||
|
||
AssociationKinds empty() { | ||
return AssociationKinds(kinds: []); | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'AssociationKinds(kinds: $kinds)'; | ||
} | ||
} |
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,66 @@ | ||
import 'package:myecl/phonebook/class/membership.dart'; | ||
import 'member.dart'; | ||
|
||
class CompleteMember { | ||
CompleteMember({ | ||
required this.member, | ||
required this.memberships, | ||
}); | ||
|
||
late final Member member; | ||
late final List<Membership> memberships; | ||
|
||
CompleteMember.fromJson(Map<String, dynamic> json) { | ||
member = Member( | ||
name: json['name'], | ||
firstname: json['firstname'], | ||
nickname: json['nickname'] ?? "", | ||
id: json['id'], | ||
email: json['email'], | ||
phone: json['phone'], | ||
promotion: json['promo'] ?? 0); | ||
memberships = List<Membership>.from( | ||
json['memberships'].map((membership) { | ||
return Membership.fromJson(membership); | ||
}), | ||
); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final data = <String, dynamic>{ | ||
'member': member.id, | ||
'memberships': memberships.map((e) => e.toJson()).toList(), | ||
}; | ||
return data; | ||
} | ||
|
||
CompleteMember copyWith({ | ||
Member? member, | ||
List<Membership>? membership, | ||
}) { | ||
return CompleteMember( | ||
member: member ?? this.member, | ||
memberships: membership ?? memberships, | ||
); | ||
} | ||
|
||
CompleteMember.empty() { | ||
member = Member.empty(); | ||
memberships = []; | ||
} | ||
|
||
Member toMember() { | ||
return member; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'CompleteMember(member: $member, memberships: $memberships)'; | ||
} | ||
|
||
List<String> getRolesTags(String associationId) { | ||
return memberships | ||
.firstWhere((element) => element.associationId == associationId) | ||
.rolesTags; | ||
} | ||
} |
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,74 @@ | ||
import 'package:myecl/user/class/list_users.dart'; | ||
|
||
class Member extends SimpleUser { | ||
Member({ | ||
required super.name, | ||
required super.firstname, | ||
required super.nickname, | ||
required super.id, | ||
required this.email, | ||
required this.phone, | ||
required this.promotion, | ||
}); | ||
late final String email; | ||
late final String? phone; | ||
late final int promotion; | ||
|
||
Member.fromJson(Map<String, dynamic> json) : super.fromJson(json) { | ||
email = json['email']; | ||
phone = json['phone']; | ||
promotion = json['promo'] ?? 0; | ||
} | ||
|
||
@override | ||
Map<String, dynamic> toJson() { | ||
final Map<String, dynamic> data = super.toJson(); | ||
data['email'] = email; | ||
data['phone'] = phone; | ||
data['promotion'] = promotion; | ||
return data; | ||
} | ||
|
||
@override | ||
Member copyWith({ | ||
String? name, | ||
String? firstname, | ||
String? nickname, | ||
String? id, | ||
String? email, | ||
String? phone, | ||
int? promotion, | ||
}) { | ||
return Member( | ||
name: name ?? this.name, | ||
firstname: firstname ?? this.firstname, | ||
nickname: nickname, | ||
id: id ?? this.id, | ||
email: email ?? this.email, | ||
phone: phone ?? this.phone, | ||
promotion: promotion ?? this.promotion, | ||
); | ||
} | ||
|
||
Member.empty() : super.empty() { | ||
email = "email.test@empty.useless"; | ||
phone = "00 00 00 00 00"; | ||
promotion = 0; | ||
} | ||
|
||
Member.fromUser(SimpleUser user) | ||
: super( | ||
name: user.name, | ||
firstname: user.firstname, | ||
nickname: user.nickname, | ||
id: user.id) { | ||
email = ""; | ||
phone = ""; | ||
promotion = 0; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'Member(name: $name, firstname: $firstname, nickname: $nickname, id: $id, email: $email, phone: $phone, promotion: $promotion)'; | ||
} | ||
} |
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,68 @@ | ||
class Membership { | ||
Membership( | ||
{required this.id, | ||
required this.associationId, | ||
required this.memberId, | ||
required this.rolesTags, | ||
required this.apparentName, | ||
required this.mandateYear}); | ||
|
||
late final String id; | ||
late final String associationId; | ||
late final String memberId; | ||
late final List<String> rolesTags; | ||
late final String apparentName; | ||
late final int mandateYear; | ||
|
||
Membership.fromJson(Map<String, dynamic> json) { | ||
id = json['id']; | ||
associationId = json['association_id']; | ||
memberId = json['user_id']; | ||
rolesTags = json['role_tags'].split(";"); | ||
apparentName = json['role_name']; | ||
mandateYear = json['mandate_year']; | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final data = <String, dynamic>{ | ||
'id': id, | ||
'association_id': associationId, | ||
'user_id': memberId, | ||
'role_tags': rolesTags.join(";"), | ||
'role_name': apparentName, | ||
'mandate_year': mandateYear | ||
}; | ||
return data; | ||
} | ||
|
||
Membership copyWith({ | ||
String? id, | ||
String? associationId, | ||
String? memberId, | ||
List<String>? rolesTags, | ||
String? apparentName, | ||
int? mandateYear, | ||
}) { | ||
return Membership( | ||
id: id ?? this.id, | ||
associationId: associationId ?? this.associationId, | ||
memberId: memberId ?? this.memberId, | ||
rolesTags: rolesTags ?? this.rolesTags, | ||
apparentName: apparentName ?? this.apparentName, | ||
mandateYear: mandateYear ?? this.mandateYear); | ||
} | ||
|
||
Membership.empty() { | ||
id = ""; | ||
associationId = ""; | ||
memberId = ""; | ||
rolesTags = []; | ||
apparentName = ""; | ||
mandateYear = 0; | ||
} | ||
|
||
@override | ||
String toString() { | ||
return 'Membership(id: $id, associationId: $associationId, memberId: $memberId, rolesTags: ${rolesTags.join(";")}, apparentName: $apparentName,mandateYear: $mandateYear)'; | ||
} | ||
} |
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,22 @@ | ||
class RolesTags { | ||
RolesTags({ | ||
required this.tags, | ||
}); | ||
|
||
late final List<String> tags; | ||
|
||
RolesTags.fromJson(Map<String, dynamic> json) { | ||
tags = json['tags'].map<String>((dynamic tag) => tag.toString()).toList(); | ||
} | ||
|
||
Map<String, dynamic> toJson() { | ||
final data = <String, dynamic>{ | ||
'tags': tags, | ||
}; | ||
return data; | ||
} | ||
|
||
RolesTags empty() { | ||
return RolesTags(tags: []); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
lib/phonebook/providers/association_filtered_list_provider.dart
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,33 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:myecl/phonebook/class/association.dart'; | ||
import 'package:myecl/phonebook/providers/association_kind_provider.dart'; | ||
import 'package:myecl/phonebook/providers/association_kinds_provider.dart'; | ||
import 'package:myecl/phonebook/providers/association_list_provider.dart'; | ||
import 'package:myecl/phonebook/providers/research_filter_provider.dart'; | ||
import 'package:myecl/phonebook/tools/function.dart'; | ||
import 'package:diacritic/diacritic.dart'; | ||
|
||
final associationFilteredListProvider = Provider<List<Association>>((ref) { | ||
final associationsProvider = ref.watch(associationListProvider); | ||
final associationKinds = ref.watch(associationKindsProvider); | ||
final kindFilter = ref.watch(associationKindProvider); | ||
final searchFilter = ref.watch(filterProvider); | ||
return associationsProvider.maybeWhen( | ||
data: (associations) { | ||
List<Association> filteredAssociations = associations | ||
.where((association) => | ||
removeDiacritics(association.name.toLowerCase()) | ||
.contains(removeDiacritics(searchFilter.toLowerCase()))) | ||
.toList(); | ||
if (kindFilter != "") { | ||
filteredAssociations = filteredAssociations | ||
.where((association) => association.kind == kindFilter) | ||
.toList(); | ||
} | ||
return associationKinds.maybeWhen( | ||
data: (kinds) => | ||
sortedAssociationByKind(filteredAssociations, kinds), | ||
orElse: () => filteredAssociations); | ||
}, | ||
orElse: () => []); | ||
}); |
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,14 @@ | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
|
||
final associationKindProvider = | ||
StateNotifierProvider<AssociationKindNotifier, String>((ref) { | ||
return AssociationKindNotifier(); | ||
}); | ||
|
||
class AssociationKindNotifier extends StateNotifier<String> { | ||
AssociationKindNotifier() : super(""); | ||
|
||
void setKind(String i) { | ||
state = i; | ||
} | ||
} |
Oops, something went wrong.