Skip to content

Commit

Permalink
Merge pull request #411 from YujithIsura/main
Browse files Browse the repository at this point in the history
lint
  • Loading branch information
YujithIsura authored Oct 1, 2024
2 parents 83a9020 + 25b45f4 commit fcddc04
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main_avinyawebapp-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
flutter config --enable-web
- name: Upload Flutter build artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: flutter-build
path: campus/frontend/build/web
Expand Down
2 changes: 1 addition & 1 deletion campus/bffs/enrollment/api/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ distribution-version = "2201.8.7"
[[package]]
org = "avinyafoundation"
name = "enrollment_bff"
version = "1.1.0"
version = "2.1.0"
dependencies = [
{org = "ballerina", name = "graphql"},
{org = "ballerina", name = "http"},
Expand Down
29 changes: 29 additions & 0 deletions campus/frontend/lib/avinya/enrollment/lib/data/person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,35 @@ Future<List<AvinyaType>> fetchAvinyaTypes() async {
}
}

Future<List<MainOrganization>> fetchClasses(int? id) async {
final uri = Uri.parse(AppConfig.campusProfileBffApiUrl + '/organization')
.replace(queryParameters: {'id': id.toString()});

final response = await http.get(
uri,
headers: <String, String>{
'Content-Type': 'application/json; charset=UTF-8',
'accept': 'application/json',
'Authorization': 'Bearer ' + AppConfig.campusBffApiKey,
},
);

if (response.statusCode == 200) {
// Parse the response body as JSON
final Map<String, dynamic> jsonResponse = json.decode(response.body);

// Extract the child_organizations_for_dashboard field
final List<MainOrganization> classes =
(jsonResponse['child_organizations_for_dashboard'] as List)
.map((data) => MainOrganization.fromJson(data))
.toList();

return classes;
} else {
throw Exception('Failed to load Classes');
}
}

Future<List<MainOrganization>> fetchOrganizations() async {
final response = await http.get(
Uri.parse('${AppConfig.campusEnrollmentsBffApiUrl}/all_organizations'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class _PersonDataExcelReportState extends State<PersonDataExcelReport> {
if (_fetchedPersonData.length > 0) {
if (columnNamesWithoutDates.isEmpty) {
columnNamesWithoutDates.addAll([
"Date",
"Daily Count",
"Daily Attendance Percentage",
"Late Count",
"Late Attendance Percentage",
"Total Count"
"Preferred Name",
"NIC Number",
"Mobile Number",
"Digital ID",
"Date of Birth",
"Class"
]);
}

Expand Down Expand Up @@ -104,14 +104,15 @@ class _PersonDataExcelReportState extends State<PersonDataExcelReport> {
sheet
.cell(CellIndex.indexByColumnRow(columnIndex: 0, rowIndex: 0))
.value =
"Avinya Foundation Daily Attendance Summary Report From ${widget.formattedStartDate} to ${widget.formattedEndDate}";
"Avinya Foundation Student Enrollment Records for ${widget.formattedEndDate}";
sheet
.cell(CellIndex.indexByColumnRow(columnIndex: 0, rowIndex: 0))
.cellStyle = organizationHeaderStyle;

if (_fetchedPersonData.isNotEmpty) {
for (var index = 0; index < _fetchedPersonData.length; index++) {
var personData = _fetchedPersonData[index];
var org = personData.organization?.avinya_type?.name;

sheet
.cell(CellIndex.indexByColumnRow(
Expand Down Expand Up @@ -143,13 +144,13 @@ class _PersonDataExcelReportState extends State<PersonDataExcelReport> {
sheet
.cell(CellIndex.indexByColumnRow(
columnIndex: 5, rowIndex: index + 2))
.value = personData.organization_id?.toString() ?? '';
.value = personData.organization?.description?.toString() ?? '';
}
}

excel.save(
fileName:
"DailyAttendanceSummaryReport_${widget.formattedStartDate}_to_${widget.formattedEndDate}.xlsx");
"Student Enrollment Records for ${widget.formattedEndDate}.xlsx");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class _StudentUpdateState extends State<StudentUpdate> {
List<District> districts = [];
List<MainOrganization> organizations = [];
List<AvinyaType> avinyaTypes = [];
List<MainOrganization> classes = [];
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();

String? selectedSex;
Expand All @@ -39,7 +40,9 @@ class _StudentUpdateState extends State<StudentUpdate> {

Future<void> getUserPerson() async {
Person user = await fetchPerson(widget.id);
classes = await fetchClasses(user.organization?.id);
setState(() {
classes = classes;
userPerson = user;
selectedSex = userPerson.sex;
selectedCityId = userPerson.mailing_address?.city?.id;
Expand Down
128 changes: 89 additions & 39 deletions campus/frontend/lib/avinya/enrollment/lib/widgets/students.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,32 @@ class _StudentsState extends State<Students> {
return await fetchOrganizationsByAvinyaType(86);
}

Future<List<AvinyaTypeId>> fetchAvinyaTypes(newValue) async {
if (newValue != null) {
if (DateTime.parse(newValue.organization_metadata[1].value.toString())
.isBefore(DateTime.parse('2024-03-01'))) {
filteredAvinyaTypeIdValues = [
AvinyaTypeId.Empower,
AvinyaTypeId.IT,
AvinyaTypeId.CS,
AvinyaTypeId.FutureEnrollees
];
} else {
filteredAvinyaTypeIdValues = [
AvinyaTypeId.Empower,
AvinyaTypeId.FutureEnrollees
];
}
} else {
filteredAvinyaTypeIdValues = [
AvinyaTypeId.Empower,
AvinyaTypeId.FutureEnrollees
];
}

return filteredAvinyaTypeIdValues;
}

void updateExcelState() {
PersonDataExcelReport(
fetchedPersonData: _fetchedPersonData,
Expand Down Expand Up @@ -265,46 +291,70 @@ class _StudentsState extends State<Students> {
SizedBox(
width: 10,
),
DropdownButton(
value: _selectedAvinyaTypeId,
items: filteredAvinyaTypeIdValues
.map(
(typeId) => DropdownMenuItem(
value: typeId,
child: Text(
typeId.name == 'FutureEnrollees'
? 'FUTURE ENROLLEES'
: typeId.name.toUpperCase(),
),
FutureBuilder<List<AvinyaTypeId>>(
future: fetchAvinyaTypes(_selectedValue),
builder: (context, snapshot) {
if (snapshot.connectionState ==
ConnectionState.waiting) {
return Container(
margin: EdgeInsets.only(top: 10),
child: SpinKitCircle(
color: Colors.deepPurpleAccent,
size: 70,
),
);
} else if (snapshot.hasError) {
return const Center(
child: Text('Something went wrong...'),
);
} else if (!snapshot.hasData) {
return const Center(
child: Text('No Avinya Type found'),
);
}

final avinyaTypeData = snapshot.data!;
return DropdownButton<AvinyaTypeId>(
value: _selectedAvinyaTypeId,
items: avinyaTypeData.map((typeId) {
return DropdownMenuItem<AvinyaTypeId>(
value: typeId,
child: Text(
typeId.name == 'FutureEnrollees'
? 'FUTURE ENROLLEES'
: typeId.name.toUpperCase(),
),
)
.toList(),
onChanged: (AvinyaTypeId? value) async {
if (value == null) {
return;
}

if (_selectedValue == null ||
_selectedValue!.organization_metadata.length ==
0) {
return;
}

setState(() {
this._isFetching = true;
});

_fetchedPersonData = await fetchPersons(
_selectedValue!.id!, avinyaTypeId[value]!);

setState(() {
_selectedAvinyaTypeId = value;
this._isFetching = false;
_data = MyData(
_fetchedPersonData, updateSelected, context);
filteredStudents = _fetchedPersonData;
});
}),
);
}).toList(),
onChanged: (AvinyaTypeId? value) async {
if (value == null) {
return;
}

setState(() {
_selectedAvinyaTypeId = value;
_isFetching = true;
});

if (avinyaTypeId[value] == 103 ||
_selectedValue == null) {
_fetchedPersonData =
await fetchPersons(-1, avinyaTypeId[value]!);
} else {
_fetchedPersonData = await fetchPersons(
_selectedValue!.id!, avinyaTypeId[value]!);
}

setState(() {
_isFetching = false;
_data = MyData(
_fetchedPersonData, updateSelected, context);
filteredStudents = _fetchedPersonData;
});
},
);
},
),
SizedBox(
width: 30,
),
Expand Down

0 comments on commit fcddc04

Please sign in to comment.