Skip to content

Commit

Permalink
Frontend changes added
Browse files Browse the repository at this point in the history
  • Loading branch information
lahirulakruwan committed Apr 2, 2024
1 parent 9336b4b commit 2cea81b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 146 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,129 +32,11 @@ class _DailyAttendanceSummaryReportScreenState extends State<DailyAttendanceSum
//calendar specific variables
DateTime? _selectedDay;


// void selectDateRange(DateTime today) async {
// // Update the variables to select the week
// final formatter = DateFormat('MMM d, yyyy');
// formattedStartDate = formatter.format(today);
// formattedEndDate = formatter.format(today);
// setState(() {
// _isFetching = false;
// });
// }

@override
void initState() {
super.initState();
//var today = DateTime.now();
// selectDateRange(today);
}

// void updateExcelState() {
// AttendanceSummaryExcelReportExport(
// fetchedDailyAttendanceSummaryData: _fetchedExcelReportData,
// columnNames: columnNames,
// updateExcelState: updateExcelState,
// isFetching: _isFetching,
// formattedStartDate: formattedStartDate,
// formattedEndDate: formattedEndDate,
// );
// }


// void updateSelected(int index, bool value, List<bool> selected) {
// setState(() {
// selected[index] = value;
// });
// }

// void updateDateRange(_rangeStart, _rangeEnd) async {

// int? parentOrgId =
// campusAppsPortalInstance.getUserPerson().organization!.id;
// if (parentOrgId != null) {
// setState(() {
// _isFetching = true; // Set _isFetching to true before starting the fetch
// });

// // _fetchedExcelReportData = await getDailyAttendanceSummaryReport(
// // parentOrgId,
// // DateFormat('yyyy-MM-dd')
// // .format(DateFormat('MMM d, yyyy').parse(this.formattedStartDate)),
// // DateFormat('yyyy-MM-dd')
// // .format(DateFormat('MMM d, yyyy').parse(this.formattedEndDate)));


// try {
// setState(() {
// final startDate = _rangeStart ?? _selectedDay;
// final endDate = _rangeEnd ?? _selectedDay;
// final formatter = DateFormat('MMM d, yyyy');
// final formattedStartDate = formatter.format(startDate!);
// final formattedEndDate = formatter.format(endDate!);
// this.formattedStartDate = formattedStartDate;
// this.formattedEndDate = formattedEndDate;
// this._fetchedExcelReportData = _fetchedExcelReportData;
// refreshState();
// });
// } catch (error) {
// // Handle any errors that occur during the fetch
// setState(() {
// _isFetching = false; // Set _isFetching to false in case of error
// });
// // Perform error handling, e.g., show an error message
// }
// }
// }

// void refreshState() async {
// setState(() {
// _isFetching = true; // Set _isFetching to true before starting the fetch
// });
// int? parentOrgId =
// campusAppsPortalInstance.getUserPerson().organization!.id;

// // _fetchedExcelReportData = await getDailyAttendanceSummaryReport(
// // parentOrgId!,
// // DateFormat('yyyy-MM-dd')
// // .format(DateFormat('MMM d, yyyy').parse(this.formattedStartDate)),
// // DateFormat('yyyy-MM-dd')
// // .format(DateFormat('MMM d, yyyy').parse(this.formattedEndDate)));


// setState(() {
// this._isFetching = false;
// _data = MyData(_fetchedDailyAttendanceSummaryData,updateSelected);
// });
// }

// List<DataColumn> _buildDataColumns() {

// List<DataColumn> ColumnNames = [];

// ColumnNames.add(DataColumn(
// label: Text('Date',
// style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold))));
// ColumnNames.add(DataColumn(
// label: Text('Daily Count',
// style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold))));
// ColumnNames.add(DataColumn(
// label: Text('Daily Attendance Percentage',
// style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold))));
// ColumnNames.add(DataColumn(
// label: Text('Late Count',
// style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold))));
// ColumnNames.add(DataColumn(
// label: Text('Late Attendance Percentage',
// style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold))));
// ColumnNames.add(DataColumn(
// label: Text('Total Count',
// style: TextStyle(fontSize: 14.0, fontWeight: FontWeight.bold))));

// return ColumnNames;
// }


@override
void dispose() {
super.dispose();
Expand All @@ -171,24 +53,11 @@ class _DailyAttendanceSummaryReportScreenState extends State<DailyAttendanceSum
child: Container(
child: Column(
children: [
AttendanceSummaryReport(
),
AttendanceSummaryReport(),
],
),
),
),
// floatingActionButton: this._isFetching
// ? null
// : AttendanceSummaryExcelReportExport(
// fetchedDailyAttendanceSummaryData: _fetchedExcelReportData,
// columnNames: columnNames,
// updateExcelState: updateExcelState,
// isFetching: _isFetching,
// formattedStartDate: formattedStartDate,
// formattedEndDate: formattedEndDate,
// ),
// floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,

);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import 'package:gallery/data/person.dart';
import 'package:gallery/data/campus_apps_portal.dart';
import 'package:intl/intl.dart';
import 'package:flutter_date_range_picker/flutter_date_range_picker.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';


class AttendanceDashboardScreen extends StatefulWidget {
const AttendanceDashboardScreen({Key? key}) : super(key: key);
Expand Down Expand Up @@ -40,6 +42,8 @@ class _AttendanceDashboardScreenState extends State<AttendanceDashboardScreen> {
String startDate = "";
String endDate = "";
List cardData = [];
late Future<List<Organization>> _fetchBatchData;
Organization? _selectedOrganizationValue;

@override
void initState() {
Expand All @@ -49,13 +53,18 @@ class _AttendanceDashboardScreenState extends State<AttendanceDashboardScreen> {
formattedEndDate = DateFormat('MMM d, yyyy').format(today);
String formattedToday = DateFormat('yyyy-MM-dd').format(today);
refreshState(null, formattedToday, formattedToday);
_fetchBatchData = _loadBatchData();
}

@override
void dispose() {
super.dispose();
}

Future<List<Organization>> _loadBatchData() async{
return await fetchOrganizationsByAvinyaType(86);
}

DateRange? selectedDateRange;
void updateDateRange(_rangeStart, _rangeEnd) async {
int? parentOrgId =
Expand Down Expand Up @@ -327,6 +336,61 @@ class _AttendanceDashboardScreenState extends State<AttendanceDashboardScreen> {
),
child: Text(formattedStartDate + " - " + formattedEndDate),
),
SizedBox(
width: 30,
),
Text('Select a Batch :'),
SizedBox(
width: 10,
),
FutureBuilder<List<Organization>>(
future: _fetchBatchData,
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 batch found'),
);
}
final batchData = snapshot.data!;
return DropdownButton<Organization>(
value: _selectedOrganizationValue,
items: batchData.map((Organization batch){
return DropdownMenuItem(
value: batch,
child: Text(batch.name!.name_en??'')
);
}).toList(),
onChanged:(Organization? newValue) async{
if(newValue == null){
return;
}

if(newValue.organization_metadata.isEmpty){
return;
}

setState(() {
_selectedOrganizationValue = newValue;
});

}
);
},
),
Expanded(
child: Container(
margin: EdgeInsets.only(left: 8.0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@ class _AttendanceSummaryReportState extends State<AttendanceSummaryReport>{
isFetching: _isFetching,
formattedStartDate: _selectedValue!.organization_metadata[0].value!,
formattedEndDate: _selectedValue!.organization_metadata[1].value!,
);
);
}


@override
void didChangeDependencies() {
super.didChangeDependencies();
_data = MyData(_fetchedDailyAttendanceSummaryData,updateSelected);
// DateRangePicker(updateDateRange, formattedStartDate);
}

void updateSelected(int index, bool value, List<bool> selected) {
Expand Down Expand Up @@ -118,16 +117,6 @@ class _AttendanceSummaryReportState extends State<AttendanceSummaryReport>{
@override
Widget build(BuildContext context) {


// AttendanceSummaryExcelReportExport(
// fetchedDailyAttendanceSummaryData: _fetchedExcelReportData,
// columnNames: columnNames,
// updateExcelState: updateExcelState,
// isFetching: _isFetching,
// formattedStartDate: formattedStartDate,
// formattedEndDate: formattedEndDate,
// );

return SingleChildScrollView(
child: Column(
children: [
Expand Down Expand Up @@ -181,8 +170,6 @@ class _AttendanceSummaryReportState extends State<AttendanceSummaryReport>{
return;
}


//filteredAvinyaTypeIdValues =[];
if (DateTime.parse(newValue.organization_metadata[1].value.toString()).isBefore(DateTime.parse('2024-03-01'))) {
filteredAvinyaTypeIdValues = [AvinyaTypeId.Empower];
}else{
Expand Down
33 changes: 33 additions & 0 deletions campus/frontend/lib/data/person.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:developer';

import 'package:flutter/src/material/data_table.dart';
import 'package:gallery/avinya/attendance/lib/data.dart';
import 'package:gallery/avinya/attendance/lib/data/organization_meta_data.dart';
import 'package:gallery/data/address.dart';
import 'package:http/http.dart' as http;
import 'dart:convert';
Expand Down Expand Up @@ -43,6 +44,7 @@ class Organization {
var child_organizations = <Organization>[];
var parent_organizations = <Organization>[];
var people = <Person>[];
var organization_metadata = <OrganizationMetaData>[];

Organization({
this.id,
Expand All @@ -51,6 +53,7 @@ class Organization {
this.child_organizations = const [],
this.parent_organizations = const [],
this.people = const [],
this.organization_metadata = const[],
});

factory Organization.fromJson(Map<String, dynamic> json) {
Expand All @@ -69,6 +72,10 @@ class Organization {
people: json['people'] != null
? List<Person>.from(json['people'].map((x) => Person.fromJson(x)))
: [],
organization_metadata: json['organization_metadata'] != null
? List<OrganizationMetaData>.from(
json['organization_metadata'].map((x) => OrganizationMetaData.fromJson(x)))
: [],
);
}

Expand All @@ -83,6 +90,7 @@ class Organization {
'parent_organizations':
List<dynamic>.from(parent_organizations.map((x) => x.toJson())),
'people': List<dynamic>.from(people.map((x) => x.toJson())),
'organization_metadata':List<dynamic>.from(organization_metadata.map((x) => x.toJson()))
// if (employees != null) 'employees': List<dynamic>.from(employees!.map((x) => x.toJson())),
};
}
Expand Down Expand Up @@ -134,6 +142,31 @@ Future<List<Person>> fetchOrganizationForAll(int id) async {
throw Exception('Failed to load Person');
}
}
Future<List<Organization>> fetchOrganizationsByAvinyaType(int avinya_type) async {

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

if (response.statusCode > 199 && response.statusCode < 300) {

var resultsJson = json.decode(response.body).cast<Map<String, dynamic>>();

List<Organization> organization =
await resultsJson
.map<Organization>((json) => Organization.fromJson(json))
.toList();
return organization;
} else {
throw Exception('Failed to load organizations');
}
}

class Person {
int? id;
Expand Down

0 comments on commit 2cea81b

Please sign in to comment.