diff --git a/lib/pages/device_managment/all_devices/helper/fake_report_data.dart b/lib/pages/device_managment/all_devices/helper/fake_report_data.dart deleted file mode 100644 index 0ffd8a1f..00000000 --- a/lib/pages/device_managment/all_devices/helper/fake_report_data.dart +++ /dev/null @@ -1,31 +0,0 @@ -import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart'; - -class FakeDeviceReport { - static DeviceReport generateFakeReport() { - return DeviceReport( - deviceUuid: 'fake-uuid-12345', - startTime: DateTime.now().millisecondsSinceEpoch, - endTime: DateTime.now().add(Duration(hours: 1)).millisecondsSinceEpoch, - data: [ - { - 'date': '13/08/2024', - 'time': '13:05', - 'status': 'Presence', - 'description': 'Description for Presence at 13:05 on 13/08/2024', - }, - { - 'date': '13/08/2024', - 'time': '14:10', - 'status': 'No Presence', - 'description': 'Description for No Presence at 14:10 on 13/08/2024', - }, - { - 'date': '14/08/2024', - 'time': '15:30', - 'status': 'Presence', - 'description': 'Description for Presence at 15:30 on 14/08/2024', - }, - ], - ); - } -} diff --git a/lib/pages/device_managment/all_devices/models/device_reports.dart b/lib/pages/device_managment/all_devices/models/device_reports.dart index 7d83052d..05604b25 100644 --- a/lib/pages/device_managment/all_devices/models/device_reports.dart +++ b/lib/pages/device_managment/all_devices/models/device_reports.dart @@ -2,7 +2,7 @@ class DeviceReport { final String? deviceUuid; final int? startTime; final int? endTime; - final List? data; + final List? data; DeviceReport({ this.deviceUuid, @@ -15,12 +15,37 @@ class DeviceReport { : deviceUuid = json['deviceUuid'] as String?, startTime = json['startTime'] as int?, endTime = json['endTime'] as int?, - data = json['data'] as List?; + data = (json['data'] as List?) + ?.map((e) => DeviceEvent.fromJson(e as Map)) + .toList(); Map toJson() => { 'deviceUuid': deviceUuid, 'startTime': startTime, 'endTime': endTime, - 'data': data + 'data': data?.map((e) => e.toJson()).toList(), + }; +} + +class DeviceEvent { + final String? code; + final int? eventTime; + final String? value; + + DeviceEvent({ + this.code, + this.eventTime, + this.value, + }); + + DeviceEvent.fromJson(Map json) + : code = json['code'] as String?, + eventTime = json['eventTime'] as int?, + value = json['value'] as String?; + + Map toJson() => { + 'code': code, + 'eventTime': eventTime, + 'value': value, }; } diff --git a/lib/pages/device_managment/ceiling_sensor/bloc/bloc.dart b/lib/pages/device_managment/ceiling_sensor/bloc/bloc.dart index 1ccf849b..fe928c94 100644 --- a/lib/pages/device_managment/ceiling_sensor/bloc/bloc.dart +++ b/lib/pages/device_managment/ceiling_sensor/bloc/bloc.dart @@ -1,10 +1,10 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/device_managment/all_devices/helper/fake_report_data.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/event.dart'; import 'package:syncrow_web/pages/device_managment/ceiling_sensor/bloc/state.dart'; import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/ceiling_sensor_model.dart'; +import 'package:syncrow_web/pages/device_managment/ceiling_sensor/model/help_description.dart'; import 'package:syncrow_web/services/devices_mang_api.dart'; class CeilingSensorBloc extends Bloc { @@ -93,17 +93,21 @@ class CeilingSensorBloc extends Bloc { FutureOr _getDeviceReports(GetCeilingDeviceReportsEvent event, Emitter emit) async { - emit(CeilingReportsLoadingState()); - - try { - //await DevicesManagementApi.getDeviceReports(deviceId, event.code) - // .then((value) { - final fakeReport = FakeDeviceReport.generateFakeReport(); - emit(CeilingReportsState(deviceReport: fakeReport)); - // }); - } catch (e) { - emit(CeilingReportsFailedState(error: e.toString())); + if (event.code.isEmpty) { + emit(ShowCeilingDescriptionState(description: reportString)); return; + } else { + emit(CeilingReportsLoadingState()); + + try { + await DevicesManagementApi.getDeviceReports(deviceId, event.code) + .then((value) { + emit(CeilingReportsState(deviceReport: value)); + }); + } catch (e) { + emit(CeilingReportsFailedState(error: e.toString())); + return; + } } } diff --git a/lib/pages/device_managment/ceiling_sensor/model/help_description.dart b/lib/pages/device_managment/ceiling_sensor/model/help_description.dart new file mode 100644 index 00000000..efcf7ce1 --- /dev/null +++ b/lib/pages/device_managment/ceiling_sensor/model/help_description.dart @@ -0,0 +1,17 @@ +String reportString = ''' +1. Nobody, the report to someone +Instruction: The propagation and processing of electromagnetic waves are complicated. There will be false alarms in the actual use of radar, and there will be some influencing factors in the environment, including: + +A. Physical disturbance: including air conditioning, fan, motor and other facilities vibration, cats, dogs, mice, birds and other animals passing through, may cause radar misjudgement of the environment. + +B. Space electromagnetic wave disturbance, including the possible existence of high-power electrical equipment around the radar, electromagnetic wave intensive places, the simultaneous coexistence of multiple radars and other environmental factors, may also cause radar misjudgement. Such interference items are few in home and office scenes, but more in factories and industrial environments. + +C. Power supply disturbance is mainly caused by power supply radar crosstalk caused by associated facilities and equipment in the mains environment, resulting in unstable power supply of radar and resulting in output misjudgement. + +2. In the case of human misreporting no one: +A. The presence of a human body beyond the radar test range. + +B. The human body is covered by metal, or by extremely thick office desks and chairs. + +C. When sleeping, the body cannot detect breathing micro-movements on the side, and may misjudge as nobody for a short time. +'''; diff --git a/lib/pages/device_managment/ceiling_sensor/view/ceiling_sensor_controls.dart b/lib/pages/device_managment/ceiling_sensor/view/ceiling_sensor_controls.dart index 72ade530..3b79303b 100644 --- a/lib/pages/device_managment/ceiling_sensor/view/ceiling_sensor_controls.dart +++ b/lib/pages/device_managment/ceiling_sensor/view/ceiling_sensor_controls.dart @@ -30,7 +30,8 @@ class CeilingSensorControls extends StatelessWidget ..add(CeilingInitialEvent()), child: BlocBuilder( builder: (context, state) { - if (state is CeilingLoadingInitialState) { + if (state is CeilingLoadingInitialState || + state is CeilingReportsLoadingState) { return const Center(child: CircularProgressIndicator()); } else if (state is CeilingUpdateState) { return _buildGridView( @@ -39,11 +40,11 @@ class CeilingSensorControls extends StatelessWidget return ReportsTable( report: state.deviceReport, onRowTap: (index) { - final entry = state.deviceReport.data![index]; - context.read().add( - ShowCeilingDescriptionEvent( - description: entry['description']), - ); + // final entry = state.deviceReport.data![index]; + // context.read().add( + // ShowCeilingDescriptionEvent( + // description: entry['description']), + // ); }, onClose: () { context @@ -154,7 +155,7 @@ class CeilingSensorControls extends StatelessWidget GestureDetector( onTap: () { context.read().add(GetCeilingDeviceReportsEvent( - code: 'illuminance_record', deviceUuid: device.uuid!)); + code: 'presence_state', deviceUuid: device.uuid!)); }, child: const PresenceStaticWidget( icon: Assets.illuminanceRecordIcon, diff --git a/lib/pages/device_managment/shared/table/report_table.dart b/lib/pages/device_managment/shared/table/report_table.dart index d4804397..619df168 100644 --- a/lib/pages/device_managment/shared/table/report_table.dart +++ b/lib/pages/device_managment/shared/table/report_table.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:intl/intl.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/device_reports.dart'; import 'package:syncrow_web/pages/device_managment/shared/table/table_cell_widget.dart'; import 'package:syncrow_web/pages/device_managment/shared/table/table_header.dart'; @@ -39,13 +40,20 @@ class ReportsTable extends StatelessWidget { ), ...report.data!.asMap().entries.map((entry) { int index = entry.key; - var data = entry.value; + DeviceEvent data = entry.value; + + // Parse eventTime into Date and Time + DateTime eventDateTime = + DateTime.fromMillisecondsSinceEpoch(data.eventTime!); + String date = DateFormat('dd/MM/yyyy').format(eventDateTime); + String time = DateFormat('HH:mm').format(eventDateTime); + return TableRow( children: [ - TableCellWidget(value: data['date']), - TableCellWidget(value: data['time']), + TableCellWidget(value: date), + TableCellWidget(value: time), TableCellWidget( - value: data['status'], + value: data.value!, onTap: () => onRowTap(index), ), ], diff --git a/lib/pages/device_managment/wall_sensor/bloc/bloc.dart b/lib/pages/device_managment/wall_sensor/bloc/bloc.dart index cd5c84b1..a2697cd3 100644 --- a/lib/pages/device_managment/wall_sensor/bloc/bloc.dart +++ b/lib/pages/device_managment/wall_sensor/bloc/bloc.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:syncrow_web/pages/device_managment/all_devices/helper/fake_report_data.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart'; import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/event.dart'; import 'package:syncrow_web/pages/device_managment/wall_sensor/bloc/state.dart'; @@ -98,11 +97,10 @@ class WallSensorBloc extends Bloc { emit(DeviceReportsLoadingState()); try { - //await DevicesManagementApi.getDeviceReports(deviceId, event.code) - // .then((value) { - final fakeReport = FakeDeviceReport.generateFakeReport(); - emit(DeviceReportsState(deviceReport: fakeReport)); - // }); + await DevicesManagementApi.getDeviceReports(deviceId, event.code) + .then((value) { + emit(DeviceReportsState(deviceReport: value)); + }); } catch (e) { emit(DeviceReportsFailedState(error: e.toString())); return; diff --git a/lib/pages/device_managment/wall_sensor/view/wall_sensor_conrtols.dart b/lib/pages/device_managment/wall_sensor/view/wall_sensor_conrtols.dart index e8117bcb..c83b4768 100644 --- a/lib/pages/device_managment/wall_sensor/view/wall_sensor_conrtols.dart +++ b/lib/pages/device_managment/wall_sensor/view/wall_sensor_conrtols.dart @@ -28,7 +28,8 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout { WallSensorBloc(deviceId: device.uuid!)..add(WallSensorInitialEvent()), child: BlocBuilder( builder: (context, state) { - if (state is WallSensorLoadingInitialState) { + if (state is WallSensorLoadingInitialState || + state is DeviceReportsLoadingState) { return const Center(child: CircularProgressIndicator()); } else if (state is WallSensorUpdateState) { return _buildGridView( @@ -36,12 +37,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout { } else if (state is DeviceReportsState) { return ReportsTable( report: state.deviceReport, - onRowTap: (index) { - final entry = state.deviceReport.data![index]; - context.read().add( - ShowDescriptionEvent(description: entry['description']), - ); - }, + onRowTap: (index) {}, onClose: () { context.read().add(BackToGridViewEvent()); }, @@ -155,7 +151,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout { GestureDetector( onTap: () { context.read().add(GetDeviceReportsEvent( - code: 'illuminance_record', deviceUuid: device.uuid!)); + code: 'illuminance_value', deviceUuid: device.uuid!)); }, child: const PresenceStaticWidget( icon: Assets.illuminanceRecordIcon, @@ -165,7 +161,7 @@ class WallSensorControls extends StatelessWidget with HelperResponsiveLayout { GestureDetector( onTap: () { context.read().add(GetDeviceReportsEvent( - code: 'presence_record', deviceUuid: device.uuid!)); + code: 'presence_state', deviceUuid: device.uuid!)); }, child: const PresenceStaticWidget( icon: Assets.presenceRecordIcon,