connect generate reports model and api to view

This commit is contained in:
ashrafzarkanisala
2024-08-27 20:34:41 +03:00
parent 5daf7228af
commit bd99049fe4
8 changed files with 89 additions and 71 deletions
@@ -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',
},
],
);
}
}
@@ -2,7 +2,7 @@ class DeviceReport {
final String? deviceUuid;
final int? startTime;
final int? endTime;
final List<dynamic>? data;
final List<DeviceEvent>? 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<dynamic>?)
?.map((e) => DeviceEvent.fromJson(e as Map<String, dynamic>))
.toList();
Map<String, dynamic> 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<String, dynamic> json)
: code = json['code'] as String?,
eventTime = json['eventTime'] as int?,
value = json['value'] as String?;
Map<String, dynamic> toJson() => {
'code': code,
'eventTime': eventTime,
'value': value,
};
}