handelled the requests
This commit is contained in:
parent
0ea2fbfa0c
commit
bf003bac63
@ -51,20 +51,21 @@ class AttendanceController extends GetxController {
|
|||||||
if (response != null && response.isNotEmpty) {
|
if (response != null && response.isNotEmpty) {
|
||||||
projects = response.map((json) => ProjectModel.fromJson(json)).toList();
|
projects = response.map((json) => ProjectModel.fromJson(json)).toList();
|
||||||
selectedProjectId = projects.first.id.toString();
|
selectedProjectId = projects.first.id.toString();
|
||||||
await _fetchProjectData(selectedProjectId);
|
await fetchProjectData(selectedProjectId);
|
||||||
update(['attendance_dashboard_controller']);
|
update(['attendance_dashboard_controller']);
|
||||||
} else {
|
} else {
|
||||||
print("No projects data found or failed to fetch data.");
|
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;
|
if (projectId == null) return;
|
||||||
|
|
||||||
isLoading.value = true; // Set loading to true before API call
|
isLoading.value = true; // Set loading to true before API call
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
fetchEmployeesByProject(projectId),
|
fetchEmployeesByProject(projectId),
|
||||||
fetchAttendanceLogs(projectId, dateFrom: startDateAttendance, dateTo: endDateAttendance),
|
fetchAttendanceLogs(projectId,
|
||||||
|
dateFrom: startDateAttendance, dateTo: endDateAttendance),
|
||||||
fetchRegularizationLogs(projectId),
|
fetchRegularizationLogs(projectId),
|
||||||
]);
|
]);
|
||||||
isLoading.value = false; // Set loading to false after data is fetched
|
isLoading.value = false; // Set loading to false after data is fetched
|
||||||
@ -74,7 +75,8 @@ class AttendanceController extends GetxController {
|
|||||||
if (projectId == null) return;
|
if (projectId == null) return;
|
||||||
|
|
||||||
isLoading.value = true; // Set loading to true before API call
|
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
|
isLoading.value = false; // Set loading to false after API call completes
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
@ -138,7 +140,8 @@ class AttendanceController extends GetxController {
|
|||||||
firstDate: DateTime(2022),
|
firstDate: DateTime(2022),
|
||||||
lastDate: DateTime.now(),
|
lastDate: DateTime.now(),
|
||||||
initialDateRange: DateTimeRange(
|
initialDateRange: DateTimeRange(
|
||||||
start: startDateAttendance ?? DateTime.now().subtract(const Duration(days: 7)),
|
start: startDateAttendance ??
|
||||||
|
DateTime.now().subtract(const Duration(days: 7)),
|
||||||
end: endDateAttendance ?? DateTime.now(),
|
end: endDateAttendance ?? DateTime.now(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -171,7 +174,8 @@ class AttendanceController extends GetxController {
|
|||||||
isLoading.value = false; // Set loading to false after API call completes
|
isLoading.value = false; // Set loading to false after API call completes
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
attendanceLogs = response.map((json) => AttendanceLogModel.fromJson(json)).toList();
|
attendanceLogs =
|
||||||
|
response.map((json) => AttendanceLogModel.fromJson(json)).toList();
|
||||||
print("Attendance logs fetched: ${response}");
|
print("Attendance logs fetched: ${response}");
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
@ -186,15 +190,16 @@ class AttendanceController extends GetxController {
|
|||||||
}) async {
|
}) async {
|
||||||
if (projectId == null) return;
|
if (projectId == null) return;
|
||||||
|
|
||||||
isLoading.value = true; // Set loading to true before API call
|
isLoading.value = true;
|
||||||
final response = await ApiService.getRegularizationLogs(int.parse(projectId));
|
final response =
|
||||||
isLoading.value = false; // Set loading to false after API call completes
|
await ApiService.getRegularizationLogs(int.parse(projectId));
|
||||||
|
isLoading.value = false;
|
||||||
|
|
||||||
if (response != null) {
|
if (response != null) {
|
||||||
regularizationLogs = response
|
regularizationLogs = response
|
||||||
.map((json) => RegularizationLogModel.fromJson(json))
|
.map((json) => RegularizationLogModel.fromJson(json))
|
||||||
.toList();
|
.toList();
|
||||||
update();
|
update();
|
||||||
} else {
|
} else {
|
||||||
print("Failed to fetch regularization logs for project $projectId.");
|
print("Failed to fetch regularization logs for project $projectId.");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -82,7 +82,7 @@ class ApiService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
final response =
|
final response =
|
||||||
await _getRequest("/attendance/project/team", queryParams: query);
|
await _getRequest("/attendance/project/log", queryParams: query);
|
||||||
return response != null
|
return response != null
|
||||||
? _parseResponse(response, label: 'Attendance Logs')
|
? _parseResponse(response, label: 'Attendance Logs')
|
||||||
: null;
|
: null;
|
||||||
|
|||||||
@ -3,7 +3,8 @@ import 'package:flutter_lucide/flutter_lucide.dart';
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:marco/helpers/theme/app_theme.dart';
|
import 'package:marco/helpers/theme/app_theme.dart';
|
||||||
import 'package:marco/helpers/utils/mixins/ui_mixin.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.dart';
|
||||||
import 'package:marco/helpers/widgets/my_breadcrumb_item.dart';
|
import 'package:marco/helpers/widgets/my_breadcrumb_item.dart';
|
||||||
import 'package:marco/helpers/widgets/my_card.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.dart';
|
||||||
import 'package:marco/helpers/widgets/my_flex_item.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_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_spacing.dart';
|
||||||
import 'package:marco/helpers/widgets/my_text.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/view/layouts/layout.dart';
|
||||||
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
|
import 'package:marco/controller/dashboard/attendance_screen_controller.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import 'package:marco/controller/permission_controller.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 {
|
class AttendanceScreen extends StatefulWidget {
|
||||||
const AttendanceScreen({super.key});
|
const AttendanceScreen({super.key});
|
||||||
@ -31,8 +31,10 @@ class AttendanceScreen extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
||||||
AttendanceController attendanceController = Get.put(AttendanceController());
|
final AttendanceController attendanceController =
|
||||||
PermissionController permissionController = Get.put(PermissionController());
|
Get.put(AttendanceController());
|
||||||
|
final PermissionController permissionController =
|
||||||
|
Get.put(PermissionController());
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -48,13 +50,13 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
await attendanceController.fetchProjects();
|
await attendanceController.fetchProjects();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: GetBuilder(
|
child: GetBuilder<AttendanceController>(
|
||||||
init: attendanceController,
|
init: attendanceController,
|
||||||
tag: 'attendance_dashboard_controller',
|
tag: 'attendance_dashboard_controller',
|
||||||
builder: (controller) {
|
builder: (controller) {
|
||||||
return LoadingComponent(
|
return LoadingComponent(
|
||||||
isLoading: controller.isLoading.value,
|
isLoading: controller.isLoading.value,
|
||||||
loadingText: 'Loading Attendance...',
|
loadingText: 'Loading Attendance...',
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@ -79,19 +81,22 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
padding: MySpacing.x(flexSpacing / 2),
|
padding: MySpacing.x(flexSpacing / 2),
|
||||||
child: MyFlex(
|
child: MyFlex(
|
||||||
children: [
|
children: [
|
||||||
// Popup Menu for Project Selection
|
// Project Selection Dropdown
|
||||||
MyFlexItem(
|
MyFlexItem(
|
||||||
sizes: 'lg-12',
|
sizes: 'lg-12',
|
||||||
child: MyContainer.bordered(
|
child: MyContainer.bordered(
|
||||||
padding: MySpacing.xy(8, 8),
|
padding: MySpacing.xy(8, 8),
|
||||||
child: PopupMenuButton<String>(
|
child: PopupMenuButton<String>(
|
||||||
onSelected: (value) {
|
onSelected: (value) async {
|
||||||
setState(() {
|
|
||||||
attendanceController.selectedProjectId = value;
|
attendanceController.selectedProjectId = value;
|
||||||
attendanceController
|
await attendanceController
|
||||||
.fetchEmployeesByProject(value);
|
.fetchEmployeesByProject(value);
|
||||||
attendanceController.fetchAttendanceLogs(value);
|
await attendanceController
|
||||||
});
|
.fetchAttendanceLogs(value);
|
||||||
|
await attendanceController
|
||||||
|
.fetchRegularizationLogs(value);
|
||||||
|
await attendanceController.fetchProjectData(value);
|
||||||
|
attendanceController.update();
|
||||||
},
|
},
|
||||||
itemBuilder: (BuildContext context) {
|
itemBuilder: (BuildContext context) {
|
||||||
if (attendanceController.projects.isEmpty) {
|
if (attendanceController.projects.isEmpty) {
|
||||||
@ -118,10 +123,12 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
},
|
},
|
||||||
color: theme.cardTheme.color,
|
color: theme.cardTheme.color,
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment:
|
||||||
|
MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
MyText.labelSmall(
|
MyText.labelSmall(
|
||||||
attendanceController.selectedProjectId != null
|
attendanceController.selectedProjectId !=
|
||||||
|
null
|
||||||
? attendanceController.projects
|
? attendanceController.projects
|
||||||
.firstWhereOrNull((proj) =>
|
.firstWhereOrNull((proj) =>
|
||||||
proj.id.toString() ==
|
proj.id.toString() ==
|
||||||
@ -141,7 +148,7 @@ class _AttendanceScreenState extends State<AttendanceScreen> with UIMixin {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
||||||
// Tabs for Employee List, Logs, and Regularization
|
// Tab Section
|
||||||
MyFlexItem(
|
MyFlexItem(
|
||||||
sizes: 'lg-12',
|
sizes: 'lg-12',
|
||||||
child: Obx(() {
|
child: Obx(() {
|
||||||
@ -167,8 +174,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: Border.all(
|
||||||
Border.all(color: Colors.grey.withAlpha(50)),
|
color: Colors.grey.withAlpha(50)),
|
||||||
shadow: MyShadow(
|
shadow: MyShadow(
|
||||||
elevation: 1,
|
elevation: 1,
|
||||||
position: MyShadowPosition.bottom),
|
position: MyShadowPosition.bottom),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user