mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
push garage door records
This commit is contained in:
@ -32,6 +32,7 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
on<UpdateSelectedDayEvent>(_updateSelectedDay);
|
on<UpdateSelectedDayEvent>(_updateSelectedDay);
|
||||||
on<UpdateFunctionOnEvent>(_updateFunctionOn);
|
on<UpdateFunctionOnEvent>(_updateFunctionOn);
|
||||||
on<InitializeAddScheduleEvent>(_initializeAddSchedule);
|
on<InitializeAddScheduleEvent>(_initializeAddSchedule);
|
||||||
|
on<BackToGarageDoorGridViewEvent>(_backToGridView);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _fetchGarageDoorStatus(GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
|
void _fetchGarageDoorStatus(GarageDoorInitialEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
@ -167,13 +168,20 @@ class GarageDoorBloc extends Bloc<GarageDoorEvent, GarageDoorState> {
|
|||||||
Future<void> _fetchRecords(FetchGarageDoorRecordsEvent event, Emitter<GarageDoorState> emit) async {
|
Future<void> _fetchRecords(FetchGarageDoorRecordsEvent event, Emitter<GarageDoorState> emit) async {
|
||||||
emit(GarageDoorReportsLoadingState());
|
emit(GarageDoorReportsLoadingState());
|
||||||
try {
|
try {
|
||||||
final DeviceReport records = await DevicesManagementApi.getDeviceReports(event.deviceId, 'switch_1');
|
final from = DateTime.now().subtract(const Duration(days: 30)).millisecondsSinceEpoch;
|
||||||
|
final to = DateTime.now().millisecondsSinceEpoch;
|
||||||
|
final DeviceReport records =
|
||||||
|
await DevicesManagementApi.getDeviceReportsByDate(event.deviceId, 'switch_1', from.toString(), to.toString());
|
||||||
emit(GarageDoorReportsState(deviceReport: records));
|
emit(GarageDoorReportsState(deviceReport: records));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(GarageDoorReportsFailedState(error: e.toString()));
|
emit(GarageDoorReportsFailedState(error: e.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _backToGridView(BackToGarageDoorGridViewEvent event, Emitter<GarageDoorState> emit) {
|
||||||
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
|
}
|
||||||
|
|
||||||
void _handleUpdate(GarageDoorUpdatedEvent event, Emitter<GarageDoorState> emit) {
|
void _handleUpdate(GarageDoorUpdatedEvent event, Emitter<GarageDoorState> emit) {
|
||||||
emit(GarageDoorLoadedState(status: deviceStatus));
|
emit(GarageDoorLoadedState(status: deviceStatus));
|
||||||
}
|
}
|
||||||
|
@ -102,13 +102,16 @@ class DecreaseGarageDoorDelayEvent extends GarageDoorEvent {
|
|||||||
|
|
||||||
class FetchGarageDoorRecordsEvent extends GarageDoorEvent {
|
class FetchGarageDoorRecordsEvent extends GarageDoorEvent {
|
||||||
final String deviceId;
|
final String deviceId;
|
||||||
|
final String code;
|
||||||
|
|
||||||
const FetchGarageDoorRecordsEvent({required this.deviceId});
|
const FetchGarageDoorRecordsEvent({required this.deviceId, required this.code});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [deviceId];
|
List<Object?> get props => [deviceId, code];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BackToGarageDoorGridViewEvent extends GarageDoorEvent {}
|
||||||
|
|
||||||
class GarageDoorUpdatedEvent extends GarageDoorEvent {}
|
class GarageDoorUpdatedEvent extends GarageDoorEvent {}
|
||||||
|
|
||||||
class UpdateSelectedTimeEvent extends GarageDoorEvent {
|
class UpdateSelectedTimeEvent extends GarageDoorEvent {
|
||||||
|
@ -5,6 +5,7 @@ import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_
|
|||||||
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
import 'package:syncrow_web/pages/device_managment/garage_door/bloc/garage_door_state.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/garage_door/models/garage_door_model.dart';
|
import 'package:syncrow_web/pages/device_managment/garage_door/models/garage_door_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/garage_door/widgets/schedule_garage_view.dart';
|
import 'package:syncrow_web/pages/device_managment/garage_door/widgets/schedule_garage_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/shared/table/report_table.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/toggle_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
@ -26,6 +27,16 @@ class GarageDoorControlView extends StatelessWidget with HelperResponsiveLayout
|
|||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is GarageDoorLoadingState) {
|
if (state is GarageDoorLoadingState) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
} else if (state is GarageDoorReportsState) {
|
||||||
|
return ReportsTable(
|
||||||
|
report: state.deviceReport,
|
||||||
|
hideValueShowDescription: true,
|
||||||
|
garageDoorSensor: true,
|
||||||
|
onRowTap: (index) {},
|
||||||
|
onClose: () {
|
||||||
|
context.read<GarageDoorBloc>().add(BackToGarageDoorGridViewEvent());
|
||||||
|
},
|
||||||
|
);
|
||||||
} else if (state is GarageDoorLoadedState) {
|
} else if (state is GarageDoorLoadedState) {
|
||||||
return _buildControlView(context, state.status);
|
return _buildControlView(context, state.status);
|
||||||
} else if (state is GarageDoorErrorState) {
|
} else if (state is GarageDoorErrorState) {
|
||||||
@ -162,9 +173,7 @@ class GarageDoorControlView extends StatelessWidget with HelperResponsiveLayout
|
|||||||
name: 'Records',
|
name: 'Records',
|
||||||
icon: Assets.records,
|
icon: Assets.records,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
// context.read<GarageDoorBloc>().add(
|
context.read<GarageDoorBloc>().add(FetchGarageDoorRecordsEvent(code: 'switch_1', deviceId: status.uuid));
|
||||||
// (deviceId: status.uuid, isOpen: !status.isOpen, code: 'switch_1'),
|
|
||||||
// );
|
|
||||||
},
|
},
|
||||||
status: false,
|
status: false,
|
||||||
textColor: ColorsManager.blackColor,
|
textColor: ColorsManager.blackColor,
|
||||||
@ -174,11 +183,7 @@ class GarageDoorControlView extends StatelessWidget with HelperResponsiveLayout
|
|||||||
isFullIcon: false,
|
isFullIcon: false,
|
||||||
name: 'Preferences',
|
name: 'Preferences',
|
||||||
icon: Assets.preferences,
|
icon: Assets.preferences,
|
||||||
onTap: () {
|
onTap: () {},
|
||||||
// context.read<GarageDoorBloc>().add(
|
|
||||||
// (deviceId: status.uuid, isOpen: !status.isOpen, code: 'switch_1'),
|
|
||||||
// );
|
|
||||||
},
|
|
||||||
status: false,
|
status: false,
|
||||||
textColor: ColorsManager.blackColor,
|
textColor: ColorsManager.blackColor,
|
||||||
// paddingAmount: 6,
|
// paddingAmount: 6,
|
||||||
|
@ -13,6 +13,7 @@ class ReportsTable extends StatelessWidget {
|
|||||||
final VoidCallback onClose;
|
final VoidCallback onClose;
|
||||||
bool? hideValueShowDescription;
|
bool? hideValueShowDescription;
|
||||||
bool? mainDoorSensor;
|
bool? mainDoorSensor;
|
||||||
|
bool? garageDoorSensor;
|
||||||
|
|
||||||
ReportsTable({
|
ReportsTable({
|
||||||
super.key,
|
super.key,
|
||||||
@ -23,6 +24,7 @@ class ReportsTable extends StatelessWidget {
|
|||||||
this.thirdColumnDescription,
|
this.thirdColumnDescription,
|
||||||
this.hideValueShowDescription,
|
this.hideValueShowDescription,
|
||||||
this.mainDoorSensor,
|
this.mainDoorSensor,
|
||||||
|
this.garageDoorSensor,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -53,30 +55,31 @@ class ReportsTable extends StatelessWidget {
|
|||||||
DeviceEvent data = entry.value;
|
DeviceEvent data = entry.value;
|
||||||
|
|
||||||
// Parse eventTime into Date and Time
|
// Parse eventTime into Date and Time
|
||||||
DateTime eventDateTime =
|
DateTime eventDateTime = DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
|
||||||
DateTime.fromMillisecondsSinceEpoch(data.eventTime!);
|
|
||||||
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
|
String date = DateFormat('dd/MM/yyyy').format(eventDateTime);
|
||||||
String time = DateFormat('HH:mm').format(eventDateTime);
|
String time = DateFormat('HH:mm').format(eventDateTime);
|
||||||
|
|
||||||
|
String value;
|
||||||
|
if (hideValueShowDescription == true) {
|
||||||
|
if (mainDoorSensor != null && mainDoorSensor == true) {
|
||||||
|
value = data.value == 'true' ? 'Open' : 'Close';
|
||||||
|
} else if (garageDoorSensor != null && garageDoorSensor == true) {
|
||||||
|
value = data.value == 'true' ? 'Opened' : 'Closed';
|
||||||
|
} else {
|
||||||
|
value = '${data.value!} ${thirdColumnDescription ?? ''}';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
value = '${data.value!} ${thirdColumnDescription ?? ''}';
|
||||||
|
}
|
||||||
|
|
||||||
return TableRow(
|
return TableRow(
|
||||||
children: [
|
children: [
|
||||||
TableCellWidget(value: date),
|
TableCellWidget(value: date),
|
||||||
TableCellWidget(value: time),
|
TableCellWidget(value: time),
|
||||||
hideValueShowDescription == true
|
TableCellWidget(
|
||||||
? TableCellWidget(
|
value: value,
|
||||||
value: (mainDoorSensor != null &&
|
onTap: () => onRowTap(index),
|
||||||
mainDoorSensor == true)
|
),
|
||||||
? data.value == 'true'
|
|
||||||
? 'Open'
|
|
||||||
: 'Close'
|
|
||||||
: thirdColumnDescription ?? '',
|
|
||||||
onTap: () => onRowTap(index),
|
|
||||||
)
|
|
||||||
: TableCellWidget(
|
|
||||||
value:
|
|
||||||
'${data.value!} ${thirdColumnDescription ?? ''}',
|
|
||||||
onTap: () => onRowTap(index),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
|
Reference in New Issue
Block a user