Refactor AttendanceScreen to improve project selection and refresh logic
This commit is contained in:
parent
2421233b9f
commit
501bec819f
@ -40,22 +40,6 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Layout(
|
return Layout(
|
||||||
child: MyRefreshableContent(
|
|
||||||
onRefresh: () async {
|
|
||||||
if (attendanceController.selectedProjectId != null) {
|
|
||||||
await attendanceController.fetchEmployeesByProject(
|
|
||||||
attendanceController.selectedProjectId!);
|
|
||||||
await attendanceController
|
|
||||||
.fetchAttendanceLogs(attendanceController.selectedProjectId!);
|
|
||||||
await attendanceController
|
|
||||||
.fetchProjectData(attendanceController.selectedProjectId!);
|
|
||||||
await attendanceController
|
|
||||||
.fetchProjectData(attendanceController.selectedProjectId!);
|
|
||||||
attendanceController.update();
|
|
||||||
} else {
|
|
||||||
await attendanceController.fetchProjects();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: GetBuilder<AttendanceController>(
|
child: GetBuilder<AttendanceController>(
|
||||||
init: attendanceController,
|
init: attendanceController,
|
||||||
tag: 'attendance_dashboard_controller',
|
tag: 'attendance_dashboard_controller',
|
||||||
@ -148,12 +132,10 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
},
|
},
|
||||||
color: theme.cardTheme.color,
|
color: theme.cardTheme.color,
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment:
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
children: [
|
||||||
MyText.labelSmall(
|
MyText.labelSmall(
|
||||||
attendanceController.selectedProjectId !=
|
attendanceController.selectedProjectId != null
|
||||||
null
|
|
||||||
? attendanceController.projects
|
? attendanceController.projects
|
||||||
.firstWhereOrNull((proj) =>
|
.firstWhereOrNull((proj) =>
|
||||||
proj.id ==
|
proj.id ==
|
||||||
@ -199,8 +181,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
length: tabs.length,
|
length: tabs.length,
|
||||||
child: MyCard.bordered(
|
child: MyCard.bordered(
|
||||||
borderRadiusAll: 4,
|
borderRadiusAll: 4,
|
||||||
border: Border.all(
|
border:
|
||||||
color: Colors.grey.withAlpha(50)),
|
Border.all(color: Colors.grey.withAlpha(50)),
|
||||||
shadow: MyShadow(
|
shadow: MyShadow(
|
||||||
elevation: 1,
|
elevation: 1,
|
||||||
position: MyShadowPosition.bottom),
|
position: MyShadowPosition.bottom),
|
||||||
@ -234,7 +216,6 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,15 +346,27 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(0.0),
|
padding: const EdgeInsets.all(0.0),
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
|
child: MyRefreshableContent(
|
||||||
|
onRefresh: () async {
|
||||||
|
if (attendanceController.selectedProjectId != null) {
|
||||||
|
await attendanceController.fetchEmployeesByProject(
|
||||||
|
attendanceController.selectedProjectId!);
|
||||||
|
await attendanceController
|
||||||
|
.fetchProjectData(attendanceController.selectedProjectId!);
|
||||||
|
attendanceController.update();
|
||||||
|
} else {
|
||||||
|
await attendanceController.fetchProjects();
|
||||||
|
}
|
||||||
|
},
|
||||||
child: MyPaginatedTable(
|
child: MyPaginatedTable(
|
||||||
columns: columns,
|
columns: columns,
|
||||||
rows: rows,
|
rows: rows,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -832,11 +825,28 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
children: [
|
children: [
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(8.0),
|
padding: const EdgeInsets.all(8.0),
|
||||||
child: TextButton.icon(
|
child: GetBuilder<AttendanceController>(
|
||||||
|
id: 'attendance_dashboard_controller',
|
||||||
|
builder: (controller) {
|
||||||
|
String labelText;
|
||||||
|
if (controller.startDateAttendance != null &&
|
||||||
|
controller.endDateAttendance != null) {
|
||||||
|
final start = DateFormat('dd MM yyyy')
|
||||||
|
.format(controller.startDateAttendance!);
|
||||||
|
final end = DateFormat('dd MM yyyy')
|
||||||
|
.format(controller.endDateAttendance!);
|
||||||
|
labelText = "$start - $end";
|
||||||
|
} else {
|
||||||
|
labelText = "Select Date Range for Attendance";
|
||||||
|
}
|
||||||
|
|
||||||
|
return TextButton.icon(
|
||||||
icon: const Icon(Icons.date_range),
|
icon: const Icon(Icons.date_range),
|
||||||
label: const Text("Select Date Range for Attendance"),
|
label: Text(labelText, overflow: TextOverflow.ellipsis),
|
||||||
onPressed: () => attendanceController
|
onPressed: () => controller.selectDateRangeForAttendance(
|
||||||
.selectDateRangeForAttendance(context, attendanceController),
|
Get.context!, controller),
|
||||||
|
);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (attendanceController.attendanceLogs.isEmpty)
|
if (attendanceController.attendanceLogs.isEmpty)
|
||||||
@ -851,12 +861,25 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
SingleChildScrollView(
|
MyRefreshableContent(
|
||||||
|
onRefresh: () async {
|
||||||
|
if (attendanceController.selectedProjectId != null) {
|
||||||
|
await attendanceController.fetchAttendanceLogs(
|
||||||
|
attendanceController.selectedProjectId!);
|
||||||
|
await attendanceController.fetchProjectData(
|
||||||
|
attendanceController.selectedProjectId!);
|
||||||
|
attendanceController.update();
|
||||||
|
} else {
|
||||||
|
await attendanceController.fetchProjects();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: SingleChildScrollView(
|
||||||
child: MyPaginatedTable(
|
child: MyPaginatedTable(
|
||||||
columns: columns,
|
columns: columns,
|
||||||
rows: rows,
|
rows: rows,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -1120,6 +1143,18 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
)
|
)
|
||||||
else
|
else
|
||||||
Expanded(
|
Expanded(
|
||||||
|
child: MyRefreshableContent(
|
||||||
|
onRefresh: () async {
|
||||||
|
if (attendanceController.selectedProjectId != null) {
|
||||||
|
await attendanceController.fetchProjectData(
|
||||||
|
attendanceController.selectedProjectId!);
|
||||||
|
await attendanceController.fetchRegularizationLogs(
|
||||||
|
attendanceController.selectedProjectId!);
|
||||||
|
attendanceController.update();
|
||||||
|
} else {
|
||||||
|
await attendanceController.fetchProjects();
|
||||||
|
}
|
||||||
|
},
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: MyPaginatedTable(
|
child: MyPaginatedTable(
|
||||||
columns: columns,
|
columns: columns,
|
||||||
@ -1128,6 +1163,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user