- Updated import paths across multiple files to reflect the new package name. - Changed application name and identifiers in CMakeLists.txt, Runner.rc, and other configuration files. - Modified web index.html and manifest.json to update the app title and name. - Adjusted macOS and Windows project settings to align with the new application name. - Ensured consistency in naming across all relevant files and directories.
103 lines
2.9 KiB
Dart
103 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:on_field_work/helpers/services/api_service.dart';
|
|
import 'package:on_field_work/helpers/widgets/my_snackbar.dart';
|
|
import 'package:on_field_work/controller/service_project/service_project_details_screen_controller.dart';
|
|
import 'package:on_field_work/model/employees/employee_model.dart';
|
|
import 'package:on_field_work/model/service_project/service_project_branches_model.dart';
|
|
|
|
class AddServiceProjectJobController extends GetxController {
|
|
// FORM CONTROLLERS
|
|
final titleCtrl = TextEditingController();
|
|
final descCtrl = TextEditingController();
|
|
final tagCtrl = TextEditingController();
|
|
final searchFocusNode = FocusNode();
|
|
|
|
// OBSERVABLES
|
|
final startDate = Rx<DateTime?>(DateTime.now());
|
|
final dueDate = Rx<DateTime?>(DateTime.now().add(const Duration(days: 1)));
|
|
|
|
final enteredTags = <String>[].obs;
|
|
final selectedAssignees = <EmployeeModel>[].obs;
|
|
|
|
// Branches
|
|
final branches = <Branch>[].obs;
|
|
final selectedBranch = Rxn<Branch>();
|
|
final isBranchLoading = false.obs;
|
|
|
|
// Loading
|
|
final isLoading = false.obs;
|
|
|
|
@override
|
|
void onClose() {
|
|
titleCtrl.dispose();
|
|
descCtrl.dispose();
|
|
tagCtrl.dispose();
|
|
searchFocusNode.dispose();
|
|
super.onClose();
|
|
}
|
|
|
|
// FETCH BRANCHES
|
|
Future<void> fetchBranches(String projectId) async {
|
|
isBranchLoading.value = true;
|
|
|
|
final response = await ApiService.getServiceProjectBranchesFull(
|
|
projectId: projectId,
|
|
);
|
|
|
|
if (response != null && response.success) {
|
|
branches.assignAll(response.data?.data ?? []);
|
|
}
|
|
|
|
isBranchLoading.value = false;
|
|
}
|
|
|
|
// CREATE JOB
|
|
Future<void> createJob(String projectId) async {
|
|
if (titleCtrl.text.trim().isEmpty || descCtrl.text.trim().isEmpty) {
|
|
showAppSnackbar(
|
|
title: "Validation",
|
|
message: "Title and Description are required",
|
|
type: SnackbarType.warning,
|
|
);
|
|
return;
|
|
}
|
|
|
|
final assigneeIds = selectedAssignees.map((e) => e.id).toList();
|
|
|
|
isLoading.value = true;
|
|
|
|
final success = await ApiService.createServiceProjectJobApi(
|
|
title: titleCtrl.text.trim(),
|
|
description: descCtrl.text.trim(),
|
|
projectId: projectId,
|
|
branchId: selectedBranch.value?.id,
|
|
assignees: assigneeIds.map((id) => {"id": id}).toList(),
|
|
startDate: startDate.value!,
|
|
dueDate: dueDate.value!,
|
|
tags: enteredTags.map((tag) => {"name": tag}).toList(),
|
|
);
|
|
|
|
isLoading.value = false;
|
|
|
|
if (success) {
|
|
if (Get.isRegistered<ServiceProjectDetailsController>()) {
|
|
Get.find<ServiceProjectDetailsController>().refreshJobsAfterAdd();
|
|
}
|
|
|
|
Get.back();
|
|
showAppSnackbar(
|
|
title: "Success",
|
|
message: "Job created successfully",
|
|
type: SnackbarType.success,
|
|
);
|
|
} else {
|
|
showAppSnackbar(
|
|
title: "Error",
|
|
message: "Failed to create job",
|
|
type: SnackbarType.error,
|
|
);
|
|
}
|
|
}
|
|
}
|