handelled the requests

This commit is contained in:
Vaibhav Surve 2025-05-03 10:58:22 +05:30
parent 0ea2fbfa0c
commit bf003bac63
3 changed files with 45 additions and 33 deletions

View File

@ -51,20 +51,21 @@ class AttendanceController extends GetxController {
if (response != null && response.isNotEmpty) {
projects = response.map((json) => ProjectModel.fromJson(json)).toList();
selectedProjectId = projects.first.id.toString();
await _fetchProjectData(selectedProjectId);
await fetchProjectData(selectedProjectId);
update(['attendance_dashboard_controller']);
} else {
print("No projects data found or failed to fetch data.");
}
}
Future<void> _fetchProjectData(String? projectId) async {
Future<void> fetchProjectData(String? projectId) async {
if (projectId == null) return;
isLoading.value = true; // Set loading to true before API call
await Future.wait([
fetchEmployeesByProject(projectId),
fetchAttendanceLogs(projectId, dateFrom: startDateAttendance, dateTo: endDateAttendance),
fetchAttendanceLogs(projectId,
dateFrom: startDateAttendance, dateTo: endDateAttendance),
fetchRegularizationLogs(projectId),
]);
isLoading.value = false; // Set loading to false after data is fetched
@ -74,7 +75,8 @@ class AttendanceController extends GetxController {
if (projectId == null) return;
isLoading.value = true; // Set loading to true before API call
final response = await ApiService.getEmployeesByProject(int.parse(projectId));
final response =
await ApiService.getEmployeesByProject(int.parse(projectId));
isLoading.value = false; // Set loading to false after API call completes
if (response != null) {
@ -138,7 +140,8 @@ class AttendanceController extends GetxController {
firstDate: DateTime(2022),
lastDate: DateTime.now(),
initialDateRange: DateTimeRange(
start: startDateAttendance ?? DateTime.now().subtract(const Duration(days: 7)),
start: startDateAttendance ??
DateTime.now().subtract(const Duration(days: 7)),
end: endDateAttendance ?? DateTime.now(),
),
);
@ -171,7 +174,8 @@ class AttendanceController extends GetxController {
isLoading.value = false; // Set loading to false after API call completes
if (response != null) {
attendanceLogs = response.map((json) => AttendanceLogModel.fromJson(json)).toList();
attendanceLogs =
response.map((json) => AttendanceLogModel.fromJson(json)).toList();
print("Attendance logs fetched: ${response}");
update();
} else {
@ -186,15 +190,16 @@ class AttendanceController extends GetxController {
}) async {
if (projectId == null) return;
isLoading.value = true; // Set loading to true before API call
final response = await ApiService.getRegularizationLogs(int.parse(projectId));
isLoading.value = false; // Set loading to false after API call completes
isLoading.value = true;
final response =
await ApiService.getRegularizationLogs(int.parse(projectId));
isLoading.value = false;
if (response != null) {
regularizationLogs = response
.map((json) => RegularizationLogModel.fromJson(json))
.toList();
update();
update();
} else {
print("Failed to fetch regularization logs for project $projectId.");
}

View File

@ -82,7 +82,7 @@ class ApiService {
};
final response =
await _getRequest("/attendance/project/team", queryParams: query);
await _getRequest("/attendance/project/log", queryParams: query);
return response != null
? _parseResponse(response, label: 'Attendance Logs')
: null;

View File

@ -3,7 +3,8 @@ import 'package:flutter_lucide/flutter_lucide.dart';
import 'package:get/get.dart';
import 'package:marco/helpers/theme/app_theme.dart';
import 'package:marco/helpers/utils/mixins/ui_mixin.dart';
import 'package:marco/helpers/utils/my_shadow.dart';
import 'package:marco/helpers/utils/permission_constants.dart';
import 'package:marco/helpers/utils/attendance_actions.dart';
import 'package:marco/helpers/widgets/my_breadcrumb.dart';
import 'package:marco/helpers/widgets/my_breadcrumb_item.dart';
import 'package:marco/helpers/widgets/my_card.dart';
@ -11,17 +12,16 @@ import 'package:marco/helpers/widgets/my_container.dart';
import 'package:marco/helpers/widgets/my_flex.dart';
import 'package:marco/helpers/widgets/my_flex_item.dart';
import 'package:marco/helpers/widgets/my_list_extension.dart';
import 'package:marco/helpers/widgets/my_loading_component.dart';
import 'package:marco/helpers/widgets/my_refresh_wrapper.dart';
import 'package:marco/helpers/widgets/my_spacing.dart';
import 'package:marco/helpers/widgets/my_text.dart';
import 'package:marco/helpers/utils/my_shadow.dart';
import 'package:marco/model/my_paginated_table.dart';
import 'package:marco/view/layouts/layout.dart';
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
import 'package:intl/intl.dart';
import 'package:marco/controller/permission_controller.dart';
import 'package:marco/helpers/utils/permission_constants.dart';
import 'package:marco/helpers/utils/attendance_actions.dart';
import 'package:marco/helpers/widgets/my_refresh_wrapper.dart';
import 'package:marco/model/my_paginated_table.dart';
import 'package:marco/helpers/widgets/my_loading_component.dart';
class AttendanceScreen extends StatefulWidget {
const AttendanceScreen({super.key});
@ -31,8 +31,10 @@ class AttendanceScreen extends StatefulWidget {
}
class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
AttendanceController attendanceController = Get.put(AttendanceController());
PermissionController permissionController = Get.put(PermissionController());
final AttendanceController attendanceController =
Get.put(AttendanceController());
final PermissionController permissionController =
Get.put(PermissionController());
@override
Widget build(BuildContext context) {
@ -48,13 +50,13 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
await attendanceController.fetchProjects();
}
},
child: GetBuilder(
child: GetBuilder<AttendanceController>(
init: attendanceController,
tag: 'attendance_dashboard_controller',
builder: (controller) {
return LoadingComponent(
isLoading: controller.isLoading.value,
loadingText: 'Loading Attendance...',
loadingText: 'Loading Attendance...',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
@ -79,19 +81,22 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
padding: MySpacing.x(flexSpacing / 2),
child: MyFlex(
children: [
// Popup Menu for Project Selection
// Project Selection Dropdown
MyFlexItem(
sizes: 'lg-12',
child: MyContainer.bordered(
padding: MySpacing.xy(8, 8),
child: PopupMenuButton<String>(
onSelected: (value) {
setState(() {
onSelected: (value) async {
attendanceController.selectedProjectId = value;
attendanceController
.fetchEmployeesByProject(value);
attendanceController.fetchAttendanceLogs(value);
});
await attendanceController
.fetchEmployeesByProject(value);
await attendanceController
.fetchAttendanceLogs(value);
await attendanceController
.fetchRegularizationLogs(value);
await attendanceController.fetchProjectData(value);
attendanceController.update();
},
itemBuilder: (BuildContext context) {
if (attendanceController.projects.isEmpty) {
@ -118,10 +123,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
},
color: theme.cardTheme.color,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
MyText.labelSmall(
attendanceController.selectedProjectId != null
attendanceController.selectedProjectId !=
null
? attendanceController.projects
.firstWhereOrNull((proj) =>
proj.id.toString() ==
@ -141,7 +148,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
),
),
// Tabs for Employee List, Logs, and Regularization
// Tab Section
MyFlexItem(
sizes: 'lg-12',
child: Obx(() {
@ -167,8 +174,8 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
length: tabs.length,
child: MyCard.bordered(
borderRadiusAll: 4,
border:
Border.all(color: Colors.grey.withAlpha(50)),
border: Border.all(
color: Colors.grey.withAlpha(50)),
shadow: MyShadow(
elevation: 1,
position: MyShadowPosition.bottom),