- Added a floating action button to the Layout widget for better accessibility. - Updated the left bar navigation items for clarity and consistency. - Introduced Daily Progress Report and Daily Task Planning screens with comprehensive UI. - Implemented filtering and refreshing functionalities in task planning. - Improved user experience with better spacing and layout adjustments. - Updated pubspec.yaml to include new dependencies for image handling and path management.
128 lines
3.4 KiB
Dart
128 lines
3.4 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:logger/logger.dart';
|
|
import 'package:marco/helpers/services/api_service.dart';
|
|
import 'package:marco/model/project_model.dart';
|
|
import 'package:marco/model/daily_task_model.dart';
|
|
|
|
final Logger log = Logger();
|
|
|
|
class DailyTaskController extends GetxController {
|
|
List<ProjectModel> projects = [];
|
|
String? selectedProjectId;
|
|
|
|
DateTime? startDateTask;
|
|
DateTime? endDateTask;
|
|
|
|
List<TaskModel> dailyTasks = [];
|
|
final RxSet<String> expandedDates = <String>{}.obs;
|
|
|
|
void toggleDate(String dateKey) {
|
|
if (expandedDates.contains(dateKey)) {
|
|
expandedDates.remove(dateKey);
|
|
} else {
|
|
expandedDates.add(dateKey);
|
|
}
|
|
}
|
|
|
|
RxBool isLoading = false.obs;
|
|
Map<String, List<TaskModel>> groupedDailyTasks = {};
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
_initializeDefaults();
|
|
}
|
|
|
|
void _initializeDefaults() {
|
|
_setDefaultDateRange();
|
|
fetchProjects();
|
|
}
|
|
|
|
void _setDefaultDateRange() {
|
|
final today = DateTime.now();
|
|
startDateTask = today.subtract(const Duration(days: 7));
|
|
endDateTask = today;
|
|
log.i("Default date range set: $startDateTask to $endDateTask");
|
|
}
|
|
|
|
Future<void> fetchProjects() async {
|
|
isLoading.value = true;
|
|
|
|
final response = await ApiService.getProjects();
|
|
isLoading.value = false;
|
|
|
|
if (response?.isEmpty ?? true) {
|
|
log.w("No project data found or API call failed.");
|
|
return;
|
|
}
|
|
|
|
projects = response!.map((json) => ProjectModel.fromJson(json)).toList();
|
|
selectedProjectId = projects.first.id.toString();
|
|
log.i("Projects fetched: ${projects.length} projects loaded.");
|
|
update();
|
|
await fetchTaskData(selectedProjectId);
|
|
}
|
|
|
|
Future<void> fetchTaskData(String? projectId) async {
|
|
if (projectId == null) return;
|
|
|
|
isLoading.value = true;
|
|
final response = await ApiService.getDailyTasks(
|
|
projectId,
|
|
dateFrom: startDateTask,
|
|
dateTo: endDateTask,
|
|
);
|
|
isLoading.value = false;
|
|
|
|
if (response != null) {
|
|
groupedDailyTasks.clear();
|
|
|
|
for (var taskJson in response) {
|
|
TaskModel task = TaskModel.fromJson(taskJson);
|
|
String assignmentDateKey =
|
|
task.assignmentDate.toIso8601String().split('T')[0];
|
|
|
|
if (groupedDailyTasks.containsKey(assignmentDateKey)) {
|
|
groupedDailyTasks[assignmentDateKey]?.add(task);
|
|
} else {
|
|
groupedDailyTasks[assignmentDateKey] = [task];
|
|
}
|
|
}
|
|
|
|
// Flatten the grouped tasks into the existing dailyTasks list
|
|
dailyTasks = groupedDailyTasks.values.expand((list) => list).toList();
|
|
|
|
log.i("Daily tasks fetched and grouped: ${dailyTasks.length}");
|
|
|
|
update();
|
|
} else {
|
|
log.e("Failed to fetch daily tasks for project $projectId");
|
|
}
|
|
}
|
|
|
|
Future<void> selectDateRangeForTaskData(
|
|
BuildContext context,
|
|
DailyTaskController controller,
|
|
) async {
|
|
final picked = await showDateRangePicker(
|
|
context: context,
|
|
firstDate: DateTime(2022),
|
|
lastDate: DateTime.now(),
|
|
initialDateRange: DateTimeRange(
|
|
start:
|
|
startDateTask ?? DateTime.now().subtract(const Duration(days: 7)),
|
|
end: endDateTask ?? DateTime.now(),
|
|
),
|
|
);
|
|
|
|
if (picked == null) return;
|
|
|
|
startDateTask = picked.start;
|
|
endDateTask = picked.end;
|
|
|
|
log.i("Date range selected: $startDateTask to $endDateTask");
|
|
|
|
await controller.fetchTaskData(controller.selectedProjectId);
|
|
}
|
|
}
|