- Replaced instances of the Logger package with a custom appLogger for consistent logging. - Introduced app_logger.dart to manage logging with file output and storage permissions. - Updated all controllers (e.g., DashboardController, EmployeesScreenController, etc.) to use appLogger for logging messages. - Ensured that logging messages are appropriately categorized (info, warning, error) throughout the application. - Implemented a file logging mechanism to store logs in a designated directory. - Cleaned up old log files to maintain only the most recent logs.
159 lines
4.5 KiB
Dart
159 lines
4.5 KiB
Dart
import 'package:get/get.dart';
|
|
import 'package:marco/helpers/services/app_logger.dart';
|
|
import 'package:marco/helpers/services/api_service.dart';
|
|
import 'package:marco/helpers/widgets/my_form_validator.dart';
|
|
import 'package:marco/helpers/widgets/my_snackbar.dart';
|
|
import 'package:marco/model/dailyTaskPlaning/master_work_category_model.dart';
|
|
|
|
|
|
class AddTaskController extends GetxController {
|
|
RxMap<String, RxBool> uploadingStates = <String, RxBool>{}.obs;
|
|
MyFormValidator basicValidator = MyFormValidator();
|
|
RxnString selectedCategoryId = RxnString();
|
|
RxnString selectedCategoryName = RxnString();
|
|
var categoryIdNameMap = <String, String>{}.obs;
|
|
|
|
List<Map<String, dynamic>> roles = [];
|
|
RxnString selectedRoleId = RxnString();
|
|
RxBool isLoadingWorkMasterCategories = false.obs;
|
|
RxList<WorkCategoryModel> workMasterCategories = <WorkCategoryModel>[].obs;
|
|
|
|
RxBool isLoading = false.obs;
|
|
@override
|
|
void onInit() {
|
|
super.onInit();
|
|
fetchWorkMasterCategories();
|
|
}
|
|
|
|
String? formFieldValidator(String? value, {required String fieldType}) {
|
|
if (value == null || value.trim().isEmpty) {
|
|
return 'This field is required';
|
|
}
|
|
if (fieldType == "target") {
|
|
if (int.tryParse(value.trim()) == null) {
|
|
return 'Please enter a valid number';
|
|
}
|
|
}
|
|
if (fieldType == "description") {
|
|
if (value.trim().length < 5) {
|
|
return 'Description must be at least 5 characters';
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
Future<bool> assignDailyTask({
|
|
required String workItemId,
|
|
required int plannedTask,
|
|
required String description,
|
|
required List<String> taskTeam,
|
|
DateTime? assignmentDate,
|
|
}) async {
|
|
appLogger.i("Starting assign task...");
|
|
|
|
final response = await ApiService.assignDailyTask(
|
|
workItemId: workItemId,
|
|
plannedTask: plannedTask,
|
|
description: description,
|
|
taskTeam: taskTeam,
|
|
assignmentDate: assignmentDate,
|
|
);
|
|
|
|
if (response == true) {
|
|
appLogger.i("Task assigned successfully.");
|
|
showAppSnackbar(
|
|
title: "Success",
|
|
message: "Task assigned successfully!",
|
|
type: SnackbarType.success,
|
|
);
|
|
return true;
|
|
} else {
|
|
appLogger.e("Failed to assign task.");
|
|
showAppSnackbar(
|
|
title: "Error",
|
|
message: "Failed to assign task.",
|
|
type: SnackbarType.error,
|
|
);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<bool> createTask({
|
|
required String parentTaskId,
|
|
required String workAreaId,
|
|
required String activityId,
|
|
required int plannedTask,
|
|
required String comment,
|
|
required String categoryId,
|
|
DateTime? assignmentDate,
|
|
}) async {
|
|
appLogger.i("Creating new task...");
|
|
|
|
final response = await ApiService.createTask(
|
|
parentTaskId: parentTaskId,
|
|
plannedTask: plannedTask,
|
|
comment: comment,
|
|
workAreaId: workAreaId,
|
|
activityId: activityId,
|
|
assignmentDate: assignmentDate,
|
|
categoryId: categoryId,
|
|
|
|
);
|
|
|
|
if (response == true) {
|
|
appLogger.i("Task created successfully.");
|
|
showAppSnackbar(
|
|
title: "Success",
|
|
message: "Task created successfully!",
|
|
type: SnackbarType.success,
|
|
);
|
|
return true;
|
|
} else {
|
|
appLogger.e("Failed to create task.");
|
|
showAppSnackbar(
|
|
title: "Error",
|
|
message: "Failed to create task.",
|
|
type: SnackbarType.error,
|
|
);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
Future<void> fetchWorkMasterCategories() async {
|
|
isLoadingWorkMasterCategories.value = true;
|
|
|
|
final response = await ApiService.getMasterWorkCategories();
|
|
if (response != null) {
|
|
try {
|
|
final dataList = response['data'] ?? [];
|
|
|
|
final parsedList = List<WorkCategoryModel>.from(
|
|
dataList.map((e) => WorkCategoryModel.fromJson(e)),
|
|
);
|
|
|
|
workMasterCategories.assignAll(parsedList);
|
|
final Map<String, String> mapped = {
|
|
for (var item in parsedList) item.id: item.name,
|
|
};
|
|
categoryIdNameMap.assignAll(mapped);
|
|
|
|
appLogger.i("Work categories fetched: ${dataList.length}");
|
|
} catch (e) {
|
|
appLogger.e("Error parsing work categories: $e");
|
|
workMasterCategories.clear();
|
|
categoryIdNameMap.clear();
|
|
}
|
|
} else {
|
|
appLogger.w("No work categories found or API call failed.");
|
|
}
|
|
|
|
isLoadingWorkMasterCategories.value = false;
|
|
update();
|
|
}
|
|
|
|
void selectCategory(String id) {
|
|
selectedCategoryId.value = id;
|
|
selectedCategoryName.value = categoryIdNameMap[id];
|
|
}
|
|
}
|