Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirulakruwan committed Oct 3, 2024
2 parents f9f6d85 + 4d4e2d1 commit fabd687
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main_avinyawebapp-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
npm run test --if-present
- name: Upload artifact for node app
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: node-app
path: campus/deployment/node-app
Expand All @@ -76,7 +76,7 @@ jobs:

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: node-app

Expand Down
36 changes: 35 additions & 1 deletion campus/frontend/lib/avinya/enrollment/lib/data/person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class MainOrganization {
AvinyaType? avinya_type;
Name? name;
String? phone;
List<ParentOrganization>? parent_organizations;

MainOrganization(
{this.id,
Expand All @@ -22,7 +23,8 @@ class MainOrganization {
this.address,
this.avinya_type,
this.name,
this.phone});
this.phone,
this.parent_organizations});

factory MainOrganization.fromJson(Map<String, dynamic> json) {
return MainOrganization(
Expand All @@ -36,6 +38,12 @@ class MainOrganization {
: null,
name: json['name'] != null ? Name.fromJson(json['name']) : null,
phone: json['phone'],
// Safely handle 'parent_organizations' being null
parent_organizations: json['parent_organizations'] != null
? (json['parent_organizations'] as List)
.map((item) => ParentOrganization.fromJson(item))
.toList()
: [],
);
}

Expand All @@ -47,6 +55,11 @@ class MainOrganization {
if (avinya_type != null) 'avinya_type': avinya_type!.toJson(),
if (name != null) 'name': name!.toJson(),
if (phone != null) 'phone': phone,
// Correctly handling 'parent_organizations' as a list
if (parent_organizations != null)
'parent_organizations': parent_organizations!
.map((parentOrg) => parentOrg.toJson())
.toList(),
};
}

Expand Down Expand Up @@ -108,6 +121,27 @@ class Name {
};
}

class ParentOrganization {
int? id;
Name? name;

ParentOrganization({this.id, this.name});

factory ParentOrganization.fromJson(Map<String, dynamic> json) {
return ParentOrganization(
id: json['id'],
name: json['name'] is Map<String, dynamic>
? Name.fromJson(json['name'])
: null, // Handle cases where 'name' is not a Map
);
}

Map<String, dynamic> toJson() => {
if (id != null) 'id': id,
if (name != null) 'name': name?.toJson(),
};
}

class City {
int? id;
Name? name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ class _StudentUpdateState extends State<StudentUpdate> {

Future<void> getUserPerson() async {
Person user = await fetchPerson(widget.id);
classes = await fetchClasses(user.organization?.id);
classes = await fetchClasses(
(user.organization?.parent_organizations?.isNotEmpty ?? false)
? user.organization?.parent_organizations?.first.id
: null);

setState(() {
classes = classes;
userPerson = user;
Expand Down Expand Up @@ -454,18 +458,11 @@ class _StudentUpdateState extends State<StudentUpdate> {
}

List<DropdownMenuItem<int>> _getClassOptions() {
List<Map<String, dynamic>> classes = [
{'id': 18, 'description': 'Leopards'},
{'id': 2, 'description': 'Dolphine'},
{'id': 3, 'description': 'Bees'},
{'id': 4, 'description': 'Elephents'},
];

return classes
.map((classe) => DropdownMenuItem<int>(
value: classe['id'] as int, // Explicitly cast to int
child: Text(
classe['description'] as String), // Explicitly cast to String
value: classe.id, // Access id directly from MainOrganization
child: Text(classe.description ??
'No description'), // Handle null description
))
.toList();
}
Expand Down

0 comments on commit fabd687

Please sign in to comment.