mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
now batch is working
This commit is contained in:
@ -45,7 +45,8 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
) async {
|
) async {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
final status =
|
||||||
|
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||||
deviceStatus = AcStatusModel.fromJson(event.deviceId, status.status);
|
deviceStatus = AcStatusModel.fromJson(event.deviceId, status.status);
|
||||||
if (deviceStatus.countdown1 != 0) {
|
if (deviceStatus.countdown1 != 0) {
|
||||||
final totalMinutes = deviceStatus.countdown1 * 6;
|
final totalMinutes = deviceStatus.countdown1 * 6;
|
||||||
@ -82,10 +83,12 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
List<Status> statusList = [];
|
List<Status> statusList = [];
|
||||||
|
|
||||||
usersMap['status'].forEach((element) {
|
usersMap['status'].forEach((element) {
|
||||||
statusList.add(Status(code: element['code'], value: element['value']));
|
statusList
|
||||||
|
.add(Status(code: element['code'], value: element['value']));
|
||||||
});
|
});
|
||||||
|
|
||||||
deviceStatus = AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
deviceStatus =
|
||||||
|
AcStatusModel.fromJson(usersMap['productUuid'], statusList);
|
||||||
if (!isClosed) {
|
if (!isClosed) {
|
||||||
add(AcStatusUpdated(deviceStatus));
|
add(AcStatusUpdated(deviceStatus));
|
||||||
}
|
}
|
||||||
@ -129,8 +132,10 @@ class AcBloc extends Bloc<AcsEvent, AcsState> {
|
|||||||
) async {
|
) async {
|
||||||
emit(AcsLoadingState());
|
emit(AcsLoadingState());
|
||||||
try {
|
try {
|
||||||
final status = await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
final status =
|
||||||
deviceStatus = AcStatusModel.fromJson(event.devicesIds.first, status.status);
|
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||||
|
deviceStatus =
|
||||||
|
AcStatusModel.fromJson(event.devicesIds.first, status.status);
|
||||||
emit(ACStatusLoaded(status: deviceStatus));
|
emit(ACStatusLoaded(status: deviceStatus));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(AcsFailedState(error: e.toString()));
|
emit(AcsFailedState(error: e.toString()));
|
||||||
|
@ -213,7 +213,7 @@ mixin RouteControlsBasedCode {
|
|||||||
case 'CUR_2':
|
case 'CUR_2':
|
||||||
return CurtainModuleBatchView(
|
return CurtainModuleBatchView(
|
||||||
devicesIds: devices
|
devicesIds: devices
|
||||||
.where((e) => e.productType == 'AC')
|
.where((e) => e.productType == 'CUR_2')
|
||||||
.map((e) => e.uuid!)
|
.map((e) => e.uuid!)
|
||||||
.toList(),
|
.toList(),
|
||||||
);
|
);
|
||||||
|
@ -1,45 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:bloc/bloc.dart';
|
|
||||||
import 'package:equatable/equatable.dart';
|
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain_module/models/curtain_module_model.dart';
|
|
||||||
import 'package:syncrow_web/services/control_device_service.dart';
|
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
|
||||||
|
|
||||||
part 'curtain_module_batch_event.dart';
|
|
||||||
part 'curtain_module_batch_state.dart';
|
|
||||||
|
|
||||||
class CurtainModuleBatchBloc
|
|
||||||
extends Bloc<CurtainModuleBatchEvent, CurtainModuleBatchState> {
|
|
||||||
final ControlDeviceService controlDeviceService;
|
|
||||||
StreamSubscription<DatabaseEvent>? _firebaseSubscription;
|
|
||||||
|
|
||||||
CurtainModuleBatchBloc(this.controlDeviceService)
|
|
||||||
: super(CurtainModuleBatchInitial()) {
|
|
||||||
on<CutrainModuleFetchBatchStatusEvent>(_onFetchAcBatchStatus);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _onFetchAcBatchStatus(
|
|
||||||
CutrainModuleFetchBatchStatusEvent event,
|
|
||||||
Emitter<CurtainModuleBatchState> emit,
|
|
||||||
) async {
|
|
||||||
emit(CurtainModuleBatchLoadingState());
|
|
||||||
try {
|
|
||||||
final status =
|
|
||||||
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
|
||||||
status.status.forEach(
|
|
||||||
(element) => print(
|
|
||||||
'this is code ${element.code} - this is value ${element.value}'),
|
|
||||||
);
|
|
||||||
|
|
||||||
emit(
|
|
||||||
CurtainModuleBatchLoadedState(
|
|
||||||
curtainModuleStatusModel: CurtainModuleStatusModel.fromJson({}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
emit(CurtainModuleBatchFailedState(error: e.toString()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
part of 'curtain_module_batch_bloc.dart';
|
|
||||||
|
|
||||||
sealed class CurtainModuleBatchEvent extends Equatable {
|
|
||||||
const CurtainModuleBatchEvent();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
class CutrainModuleFetchBatchStatusEvent extends CurtainModuleBatchEvent {
|
|
||||||
final List<String> devicesIds;
|
|
||||||
|
|
||||||
const CutrainModuleFetchBatchStatusEvent({
|
|
||||||
required this.devicesIds,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [devicesIds];
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
part of 'curtain_module_batch_bloc.dart';
|
|
||||||
|
|
||||||
sealed class CurtainModuleBatchState extends Equatable {
|
|
||||||
const CurtainModuleBatchState();
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [];
|
|
||||||
}
|
|
||||||
|
|
||||||
final class CurtainModuleBatchInitial extends CurtainModuleBatchState {}
|
|
||||||
|
|
||||||
final class CurtainModuleBatchLoadingState extends CurtainModuleBatchState {}
|
|
||||||
|
|
||||||
final class CurtainModuleBatchLoadedState extends CurtainModuleBatchState {
|
|
||||||
final CurtainModuleStatusModel curtainModuleStatusModel;
|
|
||||||
const CurtainModuleBatchLoadedState({
|
|
||||||
required this.curtainModuleStatusModel,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
final class CurtainModuleBatchFailedState extends CurtainModuleBatchState {
|
|
||||||
final String error;
|
|
||||||
|
|
||||||
const CurtainModuleBatchFailedState({required this.error});
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [error];
|
|
||||||
}
|
|
@ -3,7 +3,9 @@ import 'package:bloc/bloc.dart';
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:firebase_database/firebase_database.dart';
|
import 'package:firebase_database/firebase_database.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain_module/models/curtain_module_model.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain_module/models/curtain_module_model.dart';
|
||||||
|
import 'package:syncrow_web/services/batch_control_devices_service.dart';
|
||||||
import 'package:syncrow_web/services/control_device_service.dart';
|
import 'package:syncrow_web/services/control_device_service.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
|
|
||||||
@ -12,9 +14,13 @@ part 'curtain_module_state.dart';
|
|||||||
|
|
||||||
class CurtainModuleBloc extends Bloc<CurtainModuleEvent, CurtainModuleState> {
|
class CurtainModuleBloc extends Bloc<CurtainModuleEvent, CurtainModuleState> {
|
||||||
final ControlDeviceService controlDeviceService;
|
final ControlDeviceService controlDeviceService;
|
||||||
|
final BatchControlDevicesService batchControlDevicesService;
|
||||||
StreamSubscription<DatabaseEvent>? _firebaseSubscription;
|
StreamSubscription<DatabaseEvent>? _firebaseSubscription;
|
||||||
|
|
||||||
CurtainModuleBloc(this.controlDeviceService) : super(CurtainModuleInitial()) {
|
CurtainModuleBloc({
|
||||||
|
required this.controlDeviceService,
|
||||||
|
required this.batchControlDevicesService,
|
||||||
|
}) : super(CurtainModuleInitial()) {
|
||||||
on<FetchCurtainModuleStatusEvent>(_onFetchCurtainModuleStatusEvent);
|
on<FetchCurtainModuleStatusEvent>(_onFetchCurtainModuleStatusEvent);
|
||||||
on<SendCurtainPercentToApiEvent>(_onSendCurtainPercentToApiEvent);
|
on<SendCurtainPercentToApiEvent>(_onSendCurtainPercentToApiEvent);
|
||||||
on<OpenCurtainEvent>(_onOpenCurtainEvent);
|
on<OpenCurtainEvent>(_onOpenCurtainEvent);
|
||||||
@ -26,6 +32,13 @@ class CurtainModuleBloc extends Bloc<CurtainModuleEvent, CurtainModuleState> {
|
|||||||
on<ChangeControlBackEvent>(_onChangeControlBackEvent);
|
on<ChangeControlBackEvent>(_onChangeControlBackEvent);
|
||||||
on<ChangeControlBackModeEvent>(_onChangeControlBackModeEvent);
|
on<ChangeControlBackModeEvent>(_onChangeControlBackModeEvent);
|
||||||
on<ChangeCurtainModuleStatusEvent>(_onChangeCurtainModuleStatusEvent);
|
on<ChangeCurtainModuleStatusEvent>(_onChangeCurtainModuleStatusEvent);
|
||||||
|
//batch
|
||||||
|
on<CurtainModuleFetchBatchStatusEvent>(_onFetchCurtainModuleBatchStatus);
|
||||||
|
on<SendCurtainBatchPercentToApiEvent>(_onSendCurtainBatchPercentToApiEvent);
|
||||||
|
on<OpenCurtainBatchEvent>(_onOpenCurtainBatchEvent);
|
||||||
|
on<CloseCurtainBatchEvent>(_onCloseCurtainBatchEvent);
|
||||||
|
on<StopCurtainBatchEvent>(_onStopCurtainBatchEvent);
|
||||||
|
on<CurtainModuleFactoryReset>(_onFactoryReset);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onFetchCurtainModuleStatusEvent(
|
Future<void> _onFetchCurtainModuleStatusEvent(
|
||||||
@ -224,6 +237,109 @@ class CurtainModuleBloc extends Bloc<CurtainModuleEvent, CurtainModuleState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onFetchCurtainModuleBatchStatus(
|
||||||
|
CurtainModuleFetchBatchStatusEvent event,
|
||||||
|
Emitter<CurtainModuleState> emit,
|
||||||
|
) async {
|
||||||
|
emit(CurtainModuleLoading());
|
||||||
|
try {
|
||||||
|
final status =
|
||||||
|
await DevicesManagementApi().getBatchStatus(event.devicesIds);
|
||||||
|
|
||||||
|
final result = Map.fromEntries(
|
||||||
|
status.status.map((element) => MapEntry(element.code, element.value)),
|
||||||
|
);
|
||||||
|
|
||||||
|
emit(CurtainModuleStatusLoaded(
|
||||||
|
curtainModuleStatus: CurtainModuleStatusModel.fromJson(result),
|
||||||
|
));
|
||||||
|
} catch (e) {
|
||||||
|
emit(CurtainModuleError(message: e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onSendCurtainBatchPercentToApiEvent(
|
||||||
|
SendCurtainBatchPercentToApiEvent event,
|
||||||
|
Emitter<CurtainModuleState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
await batchControlDevicesService.batchControlDevices(
|
||||||
|
uuids: event.devicesId,
|
||||||
|
code: event.status.code,
|
||||||
|
value: event.status.value,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(CurtainModuleError(message: 'Failed to send control command: $e'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onOpenCurtainBatchEvent(
|
||||||
|
OpenCurtainBatchEvent event,
|
||||||
|
Emitter<CurtainModuleState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
await batchControlDevicesService.batchControlDevices(
|
||||||
|
uuids: event.devicesId,
|
||||||
|
code: 'control',
|
||||||
|
value: 'open',
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(CurtainModuleError(message: 'Failed to open curtain: $e'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onCloseCurtainBatchEvent(
|
||||||
|
CloseCurtainBatchEvent event,
|
||||||
|
Emitter<CurtainModuleState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
await batchControlDevicesService.batchControlDevices(
|
||||||
|
uuids: event.devicesId,
|
||||||
|
code: 'control',
|
||||||
|
value: 'close',
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(CurtainModuleError(message: 'Failed to close curtain: $e'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onStopCurtainBatchEvent(
|
||||||
|
StopCurtainBatchEvent event,
|
||||||
|
Emitter<CurtainModuleState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
await batchControlDevicesService.batchControlDevices(
|
||||||
|
uuids: event.devicesId,
|
||||||
|
code: 'control',
|
||||||
|
value: 'stop',
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(CurtainModuleError(message: 'Failed to stop curtain: $e'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onFactoryReset(
|
||||||
|
CurtainModuleFactoryReset event,
|
||||||
|
Emitter<CurtainModuleState> emit,
|
||||||
|
) async {
|
||||||
|
emit(CurtainModuleLoading());
|
||||||
|
try {
|
||||||
|
final response = await DevicesManagementApi().factoryReset(
|
||||||
|
event.factoryReset,
|
||||||
|
event.deviceId,
|
||||||
|
);
|
||||||
|
if (!response) {
|
||||||
|
emit(const CurtainModuleError(message: 'Failed'));
|
||||||
|
} else {
|
||||||
|
add(
|
||||||
|
FetchCurtainModuleStatusEvent(deviceId: event.deviceId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(CurtainModuleError(message: e.toString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> close() async {
|
Future<void> close() async {
|
||||||
await _firebaseSubscription?.cancel();
|
await _firebaseSubscription?.cancel();
|
||||||
|
@ -130,3 +130,64 @@ class ChangeCurtainModuleStatusEvent extends CurtainModuleEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [deviceId, status];
|
List<Object> get props => [deviceId, status];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
///batch
|
||||||
|
class CurtainModuleFetchBatchStatusEvent extends CurtainModuleEvent {
|
||||||
|
final List<String> devicesIds;
|
||||||
|
|
||||||
|
const CurtainModuleFetchBatchStatusEvent(this.devicesIds);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [devicesIds];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SendCurtainBatchPercentToApiEvent extends CurtainModuleEvent {
|
||||||
|
final List<String> devicesId;
|
||||||
|
final Status status;
|
||||||
|
|
||||||
|
const SendCurtainBatchPercentToApiEvent({
|
||||||
|
required this.devicesId,
|
||||||
|
required this.status,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [devicesId, status];
|
||||||
|
}
|
||||||
|
|
||||||
|
class OpenCurtainBatchEvent extends CurtainModuleEvent {
|
||||||
|
final List<String> devicesId;
|
||||||
|
|
||||||
|
const OpenCurtainBatchEvent({required this.devicesId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [devicesId];
|
||||||
|
}
|
||||||
|
|
||||||
|
class CloseCurtainBatchEvent extends CurtainModuleEvent {
|
||||||
|
final List<String> devicesId;
|
||||||
|
|
||||||
|
const CloseCurtainBatchEvent({required this.devicesId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [devicesId];
|
||||||
|
}
|
||||||
|
|
||||||
|
class StopCurtainBatchEvent extends CurtainModuleEvent {
|
||||||
|
final List<String> devicesId;
|
||||||
|
|
||||||
|
const StopCurtainBatchEvent({required this.devicesId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [devicesId];
|
||||||
|
}
|
||||||
|
|
||||||
|
class CurtainModuleFactoryReset extends CurtainModuleEvent {
|
||||||
|
final String deviceId;
|
||||||
|
final FactoryResetModel factoryReset;
|
||||||
|
|
||||||
|
const CurtainModuleFactoryReset(
|
||||||
|
{required this.deviceId, required this.factoryReset});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [deviceId, factoryReset];
|
||||||
|
}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain_module/bloc/batch/curtain_module_batch_bloc.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/factory_reset_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/curtain_module/bloc/curtain_module_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/curtain_movment_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/curtain_movment_widget.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/shared/batch_control/factory_reset.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/icon_name_status_container.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/icon_name_status_container.dart';
|
||||||
|
import 'package:syncrow_web/services/batch_control_devices_service.dart';
|
||||||
import 'package:syncrow_web/services/control_device_service.dart';
|
import 'package:syncrow_web/services/control_device_service.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';
|
||||||
@ -17,8 +20,10 @@ class CurtainModuleBatchView extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CurtainModuleBatchBloc(RemoteControlDeviceService())
|
create: (context) => CurtainModuleBloc(
|
||||||
..add(CutrainModuleFetchBatchStatusEvent(devicesIds: devicesIds)),
|
controlDeviceService: RemoteControlDeviceService(),
|
||||||
|
batchControlDevicesService: RemoteBatchControlDevicesService())
|
||||||
|
..add(CurtainModuleFetchBatchStatusEvent(devicesIds)),
|
||||||
child: _buildStatusControls(context),
|
child: _buildStatusControls(context),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -30,37 +35,41 @@ class CurtainModuleBatchView extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
ControlCurtainMovementWidget(
|
ControlCurtainMovementWidget(
|
||||||
deviceId: devicesIds.first,
|
devicesId: devicesIds,
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 10,
|
height: 10,
|
||||||
),
|
),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
height: 120,
|
height: 120,
|
||||||
width: 350,
|
// width: 350,
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
// Expanded(
|
||||||
child: IconNameStatusContainer(
|
// child:
|
||||||
isFullIcon: false,
|
FactoryResetWidget(
|
||||||
name: 'Factory Reset',
|
callFactoryReset: () {
|
||||||
icon: Assets.factoryReset,
|
context.read<CurtainModuleBloc>().add(
|
||||||
onTap: () {},
|
CurtainModuleFactoryReset(
|
||||||
status: false,
|
deviceId: devicesIds.first,
|
||||||
textColor: ColorsManager.blackColor,
|
factoryReset:
|
||||||
),
|
FactoryResetModel(devicesUuid: devicesIds),
|
||||||
),
|
),
|
||||||
Expanded(
|
);
|
||||||
child: IconNameStatusContainer(
|
},
|
||||||
isFullIcon: false,
|
|
||||||
name: 'Firmware Update',
|
|
||||||
icon: Assets.firmware,
|
|
||||||
onTap: () {},
|
|
||||||
status: false,
|
|
||||||
textColor: ColorsManager.blackColor,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
|
// ),
|
||||||
|
// Expanded(
|
||||||
|
// child: IconNameStatusContainer(
|
||||||
|
// isFullIcon: false,
|
||||||
|
// name: 'Firmware Update',
|
||||||
|
// icon: Assets.firmware,
|
||||||
|
// onTap: () {},
|
||||||
|
// status: false,
|
||||||
|
// textColor: ColorsManager.blackColor,
|
||||||
|
// ),
|
||||||
|
// )
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -4,6 +4,7 @@ import 'package:syncrow_web/pages/device_managment/curtain_module/bloc/curtain_m
|
|||||||
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/curtain_movment_widget.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/curtain_movment_widget.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/prefrences_dialog.dart';
|
import 'package:syncrow_web/pages/device_managment/curtain_module/widgets/prefrences_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/icon_name_status_container.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/icon_name_status_container.dart';
|
||||||
|
import 'package:syncrow_web/services/batch_control_devices_service.dart';
|
||||||
import 'package:syncrow_web/services/control_device_service.dart';
|
import 'package:syncrow_web/services/control_device_service.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';
|
||||||
@ -19,7 +20,9 @@ class CurtainModuleItems extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) => CurtainModuleBloc(RemoteControlDeviceService())
|
create: (context) => CurtainModuleBloc(
|
||||||
|
controlDeviceService: RemoteControlDeviceService(),
|
||||||
|
batchControlDevicesService: RemoteBatchControlDevicesService())
|
||||||
..add(FetchCurtainModuleStatusEvent(deviceId: deviceId)),
|
..add(FetchCurtainModuleStatusEvent(deviceId: deviceId)),
|
||||||
child: _buildStatusControls(context),
|
child: _buildStatusControls(context),
|
||||||
);
|
);
|
||||||
@ -32,7 +35,7 @@ class CurtainModuleItems extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
ControlCurtainMovementWidget(
|
ControlCurtainMovementWidget(
|
||||||
deviceId: deviceId,
|
devicesId: [deviceId],
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
height: 10,
|
height: 10,
|
||||||
@ -70,12 +73,15 @@ class CurtainModuleItems extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
icon: Assets.preferences,
|
icon: Assets.preferences,
|
||||||
onTap: () => showDialog(
|
onTap: () => showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => CurtainModulePrefrencesDialog(
|
builder: (_) => BlocProvider.value(
|
||||||
curtainModuleBloc:
|
value: context.read<CurtainModuleBloc>(),
|
||||||
context.watch<CurtainModuleBloc>(),
|
child: CurtainModulePrefrencesDialog(
|
||||||
deviceId: deviceId,
|
curtainModuleBloc:
|
||||||
curtainModuleStatusModel:
|
context.watch<CurtainModuleBloc>(),
|
||||||
state.curtainModuleStatus,
|
deviceId: deviceId,
|
||||||
|
curtainModuleStatusModel:
|
||||||
|
state.curtainModuleStatus,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
status: false,
|
status: false,
|
||||||
|
@ -9,10 +9,10 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class ControlCurtainMovementWidget extends StatelessWidget {
|
class ControlCurtainMovementWidget extends StatelessWidget {
|
||||||
final String deviceId;
|
final List<String> devicesId;
|
||||||
const ControlCurtainMovementWidget({
|
const ControlCurtainMovementWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.deviceId,
|
required this.devicesId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -26,9 +26,15 @@ class ControlCurtainMovementWidget extends StatelessWidget {
|
|||||||
CurtainActionWidget(
|
CurtainActionWidget(
|
||||||
icon: Assets.openCurtain,
|
icon: Assets.openCurtain,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.read<CurtainModuleBloc>().add(
|
if (devicesId.length == 1) {
|
||||||
OpenCurtainEvent(deviceId: deviceId),
|
context.read<CurtainModuleBloc>().add(
|
||||||
);
|
OpenCurtainEvent(deviceId: devicesId.first),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
context.read<CurtainModuleBloc>().add(
|
||||||
|
OpenCurtainBatchEvent(devicesId: devicesId),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
@ -37,9 +43,15 @@ class ControlCurtainMovementWidget extends StatelessWidget {
|
|||||||
CurtainActionWidget(
|
CurtainActionWidget(
|
||||||
icon: Assets.pauseCurtain,
|
icon: Assets.pauseCurtain,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.read<CurtainModuleBloc>().add(
|
if (devicesId.length == 1) {
|
||||||
StopCurtainEvent(deviceId: deviceId),
|
context.read<CurtainModuleBloc>().add(
|
||||||
);
|
StopCurtainEvent(deviceId: devicesId.first),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
context.read<CurtainModuleBloc>().add(
|
||||||
|
StopCurtainBatchEvent(devicesId: devicesId),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(
|
||||||
@ -48,9 +60,15 @@ class ControlCurtainMovementWidget extends StatelessWidget {
|
|||||||
CurtainActionWidget(
|
CurtainActionWidget(
|
||||||
icon: Assets.closeCurtain,
|
icon: Assets.closeCurtain,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.read<CurtainModuleBloc>().add(
|
if (devicesId.length == 1) {
|
||||||
CloseCurtainEvent(deviceId: deviceId),
|
context.read<CurtainModuleBloc>().add(
|
||||||
);
|
CloseCurtainEvent(deviceId: devicesId.first),
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
context.read<CurtainModuleBloc>().add(
|
||||||
|
CloseCurtainBatchEvent(devicesId: devicesId),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
BlocBuilder<CurtainModuleBloc, CurtainModuleState>(
|
BlocBuilder<CurtainModuleBloc, CurtainModuleState>(
|
||||||
@ -84,7 +102,7 @@ class ControlCurtainMovementWidget extends StatelessWidget {
|
|||||||
} else if (state is CurtainModuleStatusLoaded) {
|
} else if (state is CurtainModuleStatusLoaded) {
|
||||||
return CurtainSliderWidget(
|
return CurtainSliderWidget(
|
||||||
status: state.curtainModuleStatus,
|
status: state.curtainModuleStatus,
|
||||||
deviceId: deviceId,
|
devicesId: devicesId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return const Center(
|
return const Center(
|
||||||
@ -108,12 +126,12 @@ class ControlCurtainMovementWidget extends StatelessWidget {
|
|||||||
|
|
||||||
class CurtainSliderWidget extends StatefulWidget {
|
class CurtainSliderWidget extends StatefulWidget {
|
||||||
final CurtainModuleStatusModel status;
|
final CurtainModuleStatusModel status;
|
||||||
final String deviceId;
|
final List<String> devicesId;
|
||||||
|
|
||||||
const CurtainSliderWidget({
|
const CurtainSliderWidget({
|
||||||
super.key,
|
super.key,
|
||||||
required this.status,
|
required this.status,
|
||||||
required this.deviceId,
|
required this.devicesId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -167,16 +185,27 @@ class _CurtainSliderWidgetState extends State<CurtainSliderWidget> {
|
|||||||
onChangeEnd: (value) {
|
onChangeEnd: (value) {
|
||||||
final int targetPercent = (value * 100).round();
|
final int targetPercent = (value * 100).round();
|
||||||
|
|
||||||
// Dispatch API call
|
if (widget.devicesId.length == 1) {
|
||||||
context.read<CurtainModuleBloc>().add(
|
context.read<CurtainModuleBloc>().add(
|
||||||
SendCurtainPercentToApiEvent(
|
SendCurtainPercentToApiEvent(
|
||||||
deviceId: widget.deviceId,
|
deviceId: widget.devicesId.first,
|
||||||
status: Status(
|
status: Status(
|
||||||
code: 'percent_control',
|
code: 'percent_control',
|
||||||
value: targetPercent,
|
value: targetPercent,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
);
|
} else {
|
||||||
|
context.read<CurtainModuleBloc>().add(
|
||||||
|
SendCurtainBatchPercentToApiEvent(
|
||||||
|
devicesId: widget.devicesId,
|
||||||
|
status: Status(
|
||||||
|
code: 'percent_control',
|
||||||
|
value: targetPercent,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Revert back to Firebase-synced stream
|
// Revert back to Firebase-synced stream
|
||||||
setState(() {
|
setState(() {
|
||||||
|
@ -4,7 +4,8 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
|||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
class DeviceBatchControlDialog extends StatelessWidget with RouteControlsBasedCode {
|
class DeviceBatchControlDialog extends StatelessWidget
|
||||||
|
with RouteControlsBasedCode {
|
||||||
final List<AllDevicesModel> devices;
|
final List<AllDevicesModel> devices;
|
||||||
|
|
||||||
const DeviceBatchControlDialog({super.key, required this.devices});
|
const DeviceBatchControlDialog({super.key, required this.devices});
|
||||||
@ -18,7 +19,7 @@ class DeviceBatchControlDialog extends StatelessWidget with RouteControlsBasedCo
|
|||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: devices.length < 2 ? 500 : 800,
|
width: devices.length < 2 ? 600 : 800,
|
||||||
// height: context.screenHeight * 0.7,
|
// height: context.screenHeight * 0.7,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
@ -11,7 +11,8 @@ abstract interface class BatchControlDevicesService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final class RemoteBatchControlDevicesService implements BatchControlDevicesService {
|
final class RemoteBatchControlDevicesService
|
||||||
|
implements BatchControlDevicesService {
|
||||||
@override
|
@override
|
||||||
Future<bool> batchControlDevices({
|
Future<bool> batchControlDevices({
|
||||||
required List<String> uuids,
|
required List<String> uuids,
|
||||||
|
Reference in New Issue
Block a user