diff --git a/lib/pages/device_managment/all_devices/models/device_space_model.dart b/lib/pages/device_managment/all_devices/models/device_space_model.dart new file mode 100644 index 00000000..29f80142 --- /dev/null +++ b/lib/pages/device_managment/all_devices/models/device_space_model.dart @@ -0,0 +1,18 @@ +class DeviceSpaceModel { + String? uuid; + String? spaceName; + + DeviceSpaceModel({this.uuid, this.spaceName}); + + DeviceSpaceModel.fromJson(Map json) { + uuid = json['uuid']?.toString(); + spaceName = json['spaceName']?.toString(); + } + + Map toJson() { + final data = {}; + data['uuid'] = uuid; + data['spaceName'] = spaceName; + return data; + } +} diff --git a/lib/pages/device_managment/all_devices/models/devices_model.dart b/lib/pages/device_managment/all_devices/models/devices_model.dart index b706dad3..f62c4cff 100644 --- a/lib/pages/device_managment/all_devices/models/devices_model.dart +++ b/lib/pages/device_managment/all_devices/models/devices_model.dart @@ -1,3 +1,4 @@ +import 'package:syncrow_web/pages/device_managment/all_devices/models/device_space_model.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/room.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/unit.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; @@ -64,6 +65,7 @@ class AllDevicesModel { String? uuid; int? batteryLevel; String? productName; + List? spaces; AllDevicesModel({ this.room, @@ -92,6 +94,7 @@ class AllDevicesModel { this.uuid, this.batteryLevel, this.productName, + this.spaces, }); AllDevicesModel.fromJson(Map json) { room = (json['room'] != null && (json['room'] is Map)) @@ -124,6 +127,11 @@ class AllDevicesModel { uuid = json['uuid']?.toString(); batteryLevel = int.tryParse(json['battery']?.toString() ?? ''); productName = json['productName']?.toString(); + if (json['spaces'] != null && json['spaces'] is List) { + spaces = (json['spaces'] as List) + .map((space) => DeviceSpaceModel.fromJson(space)) + .toList(); + } } String _getDefaultIcon(String? productType) { @@ -186,6 +194,9 @@ class AllDevicesModel { data['uuid'] = uuid; data['battery'] = batteryLevel; data['productName'] = productName; + if (spaces != null) { + data['spaces'] = spaces!.map((space) => space.toJson()).toList(); + } return data; } diff --git a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart index 2787c7b9..148d085f 100644 --- a/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart +++ b/lib/pages/device_managment/all_devices/widgets/device_managment_body.dart @@ -138,8 +138,8 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout { 'Device Name', 'Product Name', 'Device ID', - 'Unit Name', - 'Room', + 'Space Name', + 'location', 'Battery Level', 'Installation Date and Time', 'Status', diff --git a/lib/services/devices_mang_api.dart b/lib/services/devices_mang_api.dart index bb591b0d..c8f680d2 100644 --- a/lib/services/devices_mang_api.dart +++ b/lib/services/devices_mang_api.dart @@ -68,7 +68,8 @@ class DevicesManagementApi { } } - Future deviceBatchControl(List uuids, String code, dynamic value) async { + Future deviceBatchControl( + List uuids, String code, dynamic value) async { try { final body = { 'devicesUuid': uuids, @@ -92,7 +93,8 @@ class DevicesManagementApi { } } - static Future> getDevicesByGatewayId(String gatewayId) async { + static Future> getDevicesByGatewayId( + String gatewayId) async { final response = await HTTPService().get( path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId), showServerMessage: false, @@ -126,7 +128,9 @@ class DevicesManagementApi { String code, ) async { final response = await HTTPService().get( - path: ApiEndpoints.getDeviceLogs.replaceAll('{uuid}', uuid).replaceAll('{code}', code), + path: ApiEndpoints.getDeviceLogs + .replaceAll('{uuid}', uuid) + .replaceAll('{code}', code), showServerMessage: false, expectedResponseModel: (json) { return DeviceReport.fromJson(json); @@ -135,7 +139,8 @@ class DevicesManagementApi { return response; } - static Future getDeviceReportsByDate(String uuid, String code, [String? from, String? to]) async { + static Future getDeviceReportsByDate(String uuid, String code, + [String? from, String? to]) async { final response = await HTTPService().get( path: ApiEndpoints.getDeviceLogsByDate .replaceAll('{uuid}', uuid) @@ -174,7 +179,8 @@ class DevicesManagementApi { } } - Future addScheduleRecord(ScheduleEntry sendSchedule, String uuid) async { + Future addScheduleRecord( + ScheduleEntry sendSchedule, String uuid) async { try { final response = await HTTPService().post( path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid), @@ -191,10 +197,13 @@ class DevicesManagementApi { } } - Future> getDeviceSchedules(String uuid, String category) async { + Future> getDeviceSchedules( + String uuid, String category) async { try { final response = await HTTPService().get( - path: ApiEndpoints.getScheduleByDeviceId.replaceAll('{deviceUuid}', uuid).replaceAll('{category}', category), + path: ApiEndpoints.getScheduleByDeviceId + .replaceAll('{deviceUuid}', uuid) + .replaceAll('{category}', category), showServerMessage: true, expectedResponseModel: (json) { List schedules = []; @@ -211,7 +220,10 @@ class DevicesManagementApi { } } - Future updateScheduleRecord({required bool enable, required String uuid, required String scheduleId}) async { + Future updateScheduleRecord( + {required bool enable, + required String uuid, + required String scheduleId}) async { try { final response = await HTTPService().put( path: ApiEndpoints.updateScheduleByDeviceId @@ -232,7 +244,8 @@ class DevicesManagementApi { } } - Future editScheduleRecord(String uuid, ScheduleEntry newSchedule) async { + Future editScheduleRecord( + String uuid, ScheduleEntry newSchedule) async { try { final response = await HTTPService().put( path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),