feat: Add service selection functionality and integrate with task fetching logic
This commit is contained in:
parent
83a8abbb87
commit
68cfdf54d6
@ -131,7 +131,7 @@ class DailyTaskPlanningController extends GetxController {
|
||||
}
|
||||
|
||||
/// Fetch Infra details and then tasks per work area
|
||||
Future<void> fetchTaskData(String? projectId) async {
|
||||
Future<void> fetchTaskData(String? projectId, {String? serviceId}) async {
|
||||
if (projectId == null) {
|
||||
logSafe("Project ID is null", level: LogLevel.warning);
|
||||
return;
|
||||
@ -139,6 +139,7 @@ class DailyTaskPlanningController extends GetxController {
|
||||
|
||||
isLoading.value = true;
|
||||
try {
|
||||
// Fetch infra details
|
||||
final infraResponse = await ApiService.getInfraDetails(projectId);
|
||||
final infraData = infraResponse?['data'] as List<dynamic>?;
|
||||
|
||||
@ -159,11 +160,12 @@ class DailyTaskPlanningController extends GetxController {
|
||||
return Floor(
|
||||
id: floorJson['id'],
|
||||
floorName: floorJson['floorName'],
|
||||
workAreas: (floorJson['workAreas'] as List<dynamic>).map((areaJson) {
|
||||
workAreas:
|
||||
(floorJson['workAreas'] as List<dynamic>).map((areaJson) {
|
||||
return WorkArea(
|
||||
id: areaJson['id'],
|
||||
areaName: areaJson['areaName'],
|
||||
workItems: [], // Initially empty, will fill after tasks API
|
||||
workItems: [], // Will fill after tasks API
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
@ -182,13 +184,17 @@ class DailyTaskPlanningController extends GetxController {
|
||||
);
|
||||
}).toList();
|
||||
|
||||
// Fetch tasks for each work area
|
||||
await Future.wait(dailyTasks.expand((task) => task.buildings)
|
||||
// Fetch tasks for each work area, passing serviceId only if selected
|
||||
await Future.wait(dailyTasks
|
||||
.expand((task) => task.buildings)
|
||||
.expand((b) => b.floors)
|
||||
.expand((f) => f.workAreas)
|
||||
.map((area) async {
|
||||
try {
|
||||
final taskResponse = await ApiService.getWorkItemsByWorkArea(area.id);
|
||||
final taskResponse = await ApiService.getWorkItemsByWorkArea(
|
||||
area.id,
|
||||
// serviceId: serviceId, // <-- only pass if not null
|
||||
);
|
||||
final taskData = taskResponse?['data'] as List<dynamic>? ?? [];
|
||||
|
||||
area.workItems.addAll(taskData.map((taskJson) {
|
||||
@ -200,11 +206,13 @@ class DailyTaskPlanningController extends GetxController {
|
||||
? ActivityMaster.fromJson(taskJson['activityMaster'])
|
||||
: null,
|
||||
workCategoryMaster: taskJson['workCategoryMaster'] != null
|
||||
? WorkCategoryMaster.fromJson(taskJson['workCategoryMaster'])
|
||||
? WorkCategoryMaster.fromJson(
|
||||
taskJson['workCategoryMaster'])
|
||||
: null,
|
||||
plannedWork: (taskJson['plannedWork'] as num?)?.toDouble(),
|
||||
completedWork: (taskJson['completedWork'] as num?)?.toDouble(),
|
||||
todaysAssigned: (taskJson['todaysAssigned'] as num?)?.toDouble(),
|
||||
todaysAssigned:
|
||||
(taskJson['todaysAssigned'] as num?)?.toDouble(),
|
||||
description: taskJson['description'] as String?,
|
||||
taskDate: taskJson['taskDate'] != null
|
||||
? DateTime.tryParse(taskJson['taskDate'])
|
||||
@ -221,7 +229,8 @@ class DailyTaskPlanningController extends GetxController {
|
||||
logSafe("Fetched infra and tasks for project $projectId",
|
||||
level: LogLevel.info);
|
||||
} catch (e, stack) {
|
||||
logSafe("Error fetching daily task data", level: LogLevel.error, error: e, stackTrace: stack);
|
||||
logSafe("Error fetching daily task data",
|
||||
level: LogLevel.error, error: e, stackTrace: stack);
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
update();
|
||||
|
43
lib/controller/tenant/service_controller.dart
Normal file
43
lib/controller/tenant/service_controller.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/services/api_service.dart';
|
||||
import 'package:marco/helpers/services/app_logger.dart';
|
||||
import 'package:marco/model/tenant/tenant_services_model.dart';
|
||||
|
||||
class ServiceController extends GetxController {
|
||||
List<Service> services = [];
|
||||
Service? selectedService;
|
||||
final isLoadingServices = false.obs;
|
||||
|
||||
/// Fetch services assigned to a project
|
||||
Future<void> fetchServices(String projectId) async {
|
||||
try {
|
||||
isLoadingServices.value = true;
|
||||
final response = await ApiService.getAssignedServices(projectId);
|
||||
if (response != null) {
|
||||
services = response.data;
|
||||
logSafe("Services fetched: ${services.length}");
|
||||
} else {
|
||||
logSafe("Failed to fetch services for project $projectId",
|
||||
level: LogLevel.error);
|
||||
}
|
||||
} finally {
|
||||
isLoadingServices.value = false;
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
/// Select a service
|
||||
void selectService(Service? service) {
|
||||
selectedService = service;
|
||||
update();
|
||||
}
|
||||
|
||||
/// Clear selection
|
||||
void clearSelection() {
|
||||
selectedService = null;
|
||||
update();
|
||||
}
|
||||
|
||||
/// Current selected name
|
||||
String get currentSelection => selectedService?.name ?? "All Services";
|
||||
}
|
@ -93,4 +93,5 @@ class ApiEndpoints {
|
||||
|
||||
static const String getAssignedOrganizations =
|
||||
"/project/get/assigned/organization";
|
||||
static const String getAssignedServices = "/Project/get/assigned/services";
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import 'package:marco/model/document/master_document_type_model.dart';
|
||||
import 'package:marco/model/document/document_details_model.dart';
|
||||
import 'package:marco/model/document/document_version_model.dart';
|
||||
import 'package:marco/model/attendance/organization_per_project_list_model.dart';
|
||||
import 'package:marco/model/tenant/tenant_services_model.dart';
|
||||
|
||||
class ApiService {
|
||||
static const bool enableLogs = true;
|
||||
@ -278,6 +279,36 @@ class ApiService {
|
||||
return null;
|
||||
}
|
||||
|
||||
//// Get Services assigned to a Project
|
||||
static Future<ServiceListResponse?> getAssignedServices(
|
||||
String projectId) async {
|
||||
final endpoint = "${ApiEndpoints.getAssignedServices}/$projectId";
|
||||
logSafe("Fetching services assigned to projectId: $projectId");
|
||||
|
||||
try {
|
||||
final response = await _getRequest(endpoint);
|
||||
|
||||
if (response == null) {
|
||||
logSafe("Assigned Services request failed: null response",
|
||||
level: LogLevel.error);
|
||||
return null;
|
||||
}
|
||||
|
||||
final jsonResponse =
|
||||
_parseResponseForAllData(response, label: "Assigned Services");
|
||||
|
||||
if (jsonResponse != null) {
|
||||
return ServiceListResponse.fromJson(jsonResponse);
|
||||
}
|
||||
} catch (e, stack) {
|
||||
logSafe("Exception during getAssignedServices: $e",
|
||||
level: LogLevel.error);
|
||||
logSafe("StackTrace: $stack", level: LogLevel.debug);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static Future<bool> postLogsApi(List<Map<String, dynamic>> logs) async {
|
||||
const endpoint = "${ApiEndpoints.uploadLogs}";
|
||||
logSafe("Posting logs... count=${logs.length}");
|
||||
@ -1928,7 +1959,8 @@ class ApiService {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<List<dynamic>?> getAllEmployees({String? organizationId}) async {
|
||||
static Future<List<dynamic>?> getAllEmployees(
|
||||
{String? organizationId}) async {
|
||||
var endpoint = ApiEndpoints.getAllEmployees;
|
||||
|
||||
// Add organization filter if provided
|
||||
@ -1939,8 +1971,7 @@ static Future<List<dynamic>?> getAllEmployees({String? organizationId}) async {
|
||||
return _getRequest(endpoint).then(
|
||||
(res) => res != null ? _parseResponse(res, label: 'All Employees') : null,
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static Future<List<dynamic>?> getRoles() async =>
|
||||
_getRequest(ApiEndpoints.getRoles).then(
|
||||
|
114
lib/helpers/widgets/tenant/service_selector.dart
Normal file
114
lib/helpers/widgets/tenant/service_selector.dart
Normal file
@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:marco/helpers/widgets/my_text.dart';
|
||||
import 'package:marco/model/tenant/tenant_services_model.dart';
|
||||
import 'package:marco/controller/tenant/service_controller.dart';
|
||||
|
||||
class ServiceSelector extends StatelessWidget {
|
||||
final ServiceController controller;
|
||||
|
||||
/// Called whenever a new service is selected (including "All Services")
|
||||
final Future<void> Function(Service?)? onSelectionChanged;
|
||||
|
||||
/// Optional height for the selector
|
||||
final double? height;
|
||||
|
||||
const ServiceSelector({
|
||||
super.key,
|
||||
required this.controller,
|
||||
this.onSelectionChanged,
|
||||
this.height,
|
||||
});
|
||||
|
||||
Widget _popupSelector({
|
||||
required String currentValue,
|
||||
required List<String> items,
|
||||
}) {
|
||||
return PopupMenuButton<String>(
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
onSelected: items.isEmpty
|
||||
? null
|
||||
: (name) async {
|
||||
Service? service = name == "All Services"
|
||||
? null
|
||||
: controller.services.firstWhere((e) => e.name == name);
|
||||
|
||||
controller.selectService(service);
|
||||
|
||||
if (onSelectionChanged != null) {
|
||||
await onSelectionChanged!(service);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) {
|
||||
if (items.isEmpty || items.length == 1 && items[0] == "All Services") {
|
||||
return [
|
||||
const PopupMenuItem<String>(
|
||||
enabled: false,
|
||||
child: Center(
|
||||
child: Text(
|
||||
"No services found",
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
}
|
||||
return items
|
||||
.map((e) => PopupMenuItem<String>(value: e, child: MyText(e)))
|
||||
.toList();
|
||||
},
|
||||
child: Container(
|
||||
height: height,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade100,
|
||||
border: Border.all(color: Colors.grey.shade300),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
currentValue.isEmpty ? "No services found" : currentValue,
|
||||
style: const TextStyle(
|
||||
color: Colors.black87,
|
||||
fontSize: 13,
|
||||
height: 1.2,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(Icons.arrow_drop_down, color: Colors.grey, size: 18),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Obx(() {
|
||||
if (controller.isLoadingServices.value) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
final serviceNames = controller.services.isEmpty
|
||||
? <String>[]
|
||||
: <String>[
|
||||
"All Services",
|
||||
...controller.services.map((e) => e.name).toList(),
|
||||
];
|
||||
|
||||
final currentValue =
|
||||
controller.services.isEmpty ? "" : controller.currentSelection;
|
||||
|
||||
return _popupSelector(
|
||||
currentValue: currentValue,
|
||||
items: serviceNames,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
78
lib/model/tenant/tenant_services_model.dart
Normal file
78
lib/model/tenant/tenant_services_model.dart
Normal file
@ -0,0 +1,78 @@
|
||||
class ServiceListResponse {
|
||||
final bool success;
|
||||
final String message;
|
||||
final List<Service> data;
|
||||
final dynamic errors;
|
||||
final int statusCode;
|
||||
final String timestamp;
|
||||
|
||||
ServiceListResponse({
|
||||
required this.success,
|
||||
required this.message,
|
||||
required this.data,
|
||||
this.errors,
|
||||
required this.statusCode,
|
||||
required this.timestamp,
|
||||
});
|
||||
|
||||
factory ServiceListResponse.fromJson(Map<String, dynamic> json) {
|
||||
return ServiceListResponse(
|
||||
success: json['success'] ?? false,
|
||||
message: json['message'] ?? '',
|
||||
data: (json['data'] as List<dynamic>?)
|
||||
?.map((e) => Service.fromJson(e))
|
||||
.toList() ??
|
||||
[],
|
||||
errors: json['errors'],
|
||||
statusCode: json['statusCode'] ?? 0,
|
||||
timestamp: json['timestamp'] ?? '',
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'success': success,
|
||||
'message': message,
|
||||
'data': data.map((e) => e.toJson()).toList(),
|
||||
'errors': errors,
|
||||
'statusCode': statusCode,
|
||||
'timestamp': timestamp,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class Service {
|
||||
final String id;
|
||||
final String name;
|
||||
final String description;
|
||||
final bool isSystem;
|
||||
final bool isActive;
|
||||
|
||||
Service({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.description,
|
||||
required this.isSystem,
|
||||
required this.isActive,
|
||||
});
|
||||
|
||||
factory Service.fromJson(Map<String, dynamic> json) {
|
||||
return Service(
|
||||
id: json['id'] ?? '',
|
||||
name: json['name'] ?? '',
|
||||
description: json['description'] ?? '',
|
||||
isSystem: json['isSystem'] ?? false,
|
||||
isActive: json['isActive'] ?? false,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'description': description,
|
||||
'isSystem': isSystem,
|
||||
'isActive': isActive,
|
||||
};
|
||||
}
|
||||
}
|
@ -17,6 +17,8 @@ import 'package:marco/model/dailyTaskPlanning/task_action_buttons.dart';
|
||||
import 'package:marco/helpers/widgets/my_custom_skeleton.dart';
|
||||
import 'package:marco/helpers/utils/permission_constants.dart';
|
||||
import 'package:marco/helpers/widgets/my_refresh_indicator.dart';
|
||||
import 'package:marco/controller/tenant/service_controller.dart';
|
||||
import 'package:marco/helpers/widgets/tenant/service_selector.dart';
|
||||
|
||||
class DailyProgressReportScreen extends StatefulWidget {
|
||||
const DailyProgressReportScreen({super.key});
|
||||
@ -41,6 +43,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
||||
final PermissionController permissionController =
|
||||
Get.find<PermissionController>();
|
||||
final ProjectController projectController = Get.find<ProjectController>();
|
||||
final ServiceController serviceController = Get.put(ServiceController());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -131,8 +134,7 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
||||
child: MyRefreshIndicator(
|
||||
onRefresh: _refreshData,
|
||||
child: CustomScrollView(
|
||||
physics:
|
||||
const AlwaysScrollableScrollPhysics(),
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
slivers: [
|
||||
SliverToBoxAdapter(
|
||||
child: GetBuilder<DailyTaskController>(
|
||||
@ -143,6 +145,26 @@ class _DailyProgressReportScreenState extends State<DailyProgressReportScreen>
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
MySpacing.height(flexSpacing),
|
||||
|
||||
// --- ADD SERVICE SELECTOR HERE ---
|
||||
Padding(
|
||||
padding: MySpacing.x(10),
|
||||
child: ServiceSelector(
|
||||
controller: serviceController,
|
||||
height: 40,
|
||||
onSelectionChanged: (service) async {
|
||||
final projectId =
|
||||
dailyTaskController.selectedProjectId;
|
||||
if (projectId?.isNotEmpty ?? false) {
|
||||
await dailyTaskController.fetchTaskData(
|
||||
projectId!,
|
||||
// serviceId: service?.id,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
|
||||
_buildActionBar(),
|
||||
Padding(
|
||||
padding: MySpacing.x(8),
|
||||
|
@ -13,6 +13,8 @@ import 'package:marco/model/dailyTaskPlanning/assign_task_bottom_sheet .dart';
|
||||
import 'package:marco/helpers/widgets/my_custom_skeleton.dart';
|
||||
import 'package:marco/helpers/utils/permission_constants.dart';
|
||||
import 'package:marco/helpers/widgets/my_refresh_indicator.dart';
|
||||
import 'package:marco/controller/tenant/service_controller.dart';
|
||||
import 'package:marco/helpers/widgets/tenant/service_selector.dart';
|
||||
|
||||
class DailyTaskPlanningScreen extends StatefulWidget {
|
||||
DailyTaskPlanningScreen({super.key});
|
||||
@ -29,6 +31,7 @@ class _DailyTaskPlanningScreenState extends State<DailyTaskPlanningScreen>
|
||||
final PermissionController permissionController =
|
||||
Get.put(PermissionController());
|
||||
final ProjectController projectController = Get.find<ProjectController>();
|
||||
final ServiceController serviceController = Get.put(ServiceController());
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -143,6 +146,26 @@ class _DailyTaskPlanningScreenState extends State<DailyTaskPlanningScreen>
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
MySpacing.height(flexSpacing),
|
||||
Padding(
|
||||
padding: MySpacing.x(10),
|
||||
child: ServiceSelector(
|
||||
controller:
|
||||
serviceController,
|
||||
height: 40,
|
||||
onSelectionChanged: (service) async {
|
||||
final projectId =
|
||||
projectController.selectedProjectId.value;
|
||||
if (projectId.isNotEmpty) {
|
||||
await dailyTaskPlanningController.fetchTaskData(
|
||||
projectId,
|
||||
// serviceId: service
|
||||
// ?.id,
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
),
|
||||
MySpacing.height(flexSpacing),
|
||||
Padding(
|
||||
padding: MySpacing.x(8),
|
||||
|
Loading…
x
Reference in New Issue
Block a user