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 d6999a98..a71de8ce 100644 --- a/lib/pages/device_managment/all_devices/models/devices_model.dart +++ b/lib/pages/device_managment/all_devices/models/devices_model.dart @@ -320,17 +320,17 @@ SOS GatewaySwitchAlarmSound( deviceId: uuid ?? '', deviceName: name ?? '', - type: 'IF', + type: 'BOTH', ), GatewayMasterState( deviceId: uuid ?? '', deviceName: name ?? '', - type: 'IF', + type: 'BOTH', ), GatewayFactoryReset( deviceId: uuid ?? '', deviceName: name ?? '', - type: 'IF', + type: 'BOTH', ), ]; default: diff --git a/lib/pages/routines/models/gateway.dart b/lib/pages/routines/models/gateway.dart index be257a8b..daeebd53 100644 --- a/lib/pages/routines/models/gateway.dart +++ b/lib/pages/routines/models/gateway.dart @@ -33,7 +33,7 @@ final class GatewaySwitchAlarmSound extends GatewayFunctions { required super.deviceId, required super.deviceName, required super.type, - super.code = '', + super.code = 'switch_alarm_sound', super.operationName = 'Switch Alarm Sound', super.icon = Assets.activeBell, }); @@ -58,7 +58,7 @@ final class GatewayMasterState extends GatewayFunctions { required super.deviceId, required super.deviceName, required super.type, - super.code = '', + super.code = 'master_state', super.operationName = 'Master State', super.icon = Assets.gear, }); @@ -69,12 +69,12 @@ final class GatewayMasterState extends GatewayFunctions { GatewayOperationalValue( icon: Assets.assetsAcPower, description: "Normal", - value: true, + value: 'Normal', ), GatewayOperationalValue( icon: Assets.assetsAcPowerOFF, description: "Alarm", - value: false, + value: 'Alarm', ), ]; } @@ -85,7 +85,7 @@ final class GatewayFactoryReset extends GatewayFunctions { required super.deviceId, required super.deviceName, required super.type, - super.code = '', + super.code = 'factory_reset', super.operationName = 'Factory Reset', super.icon = Assets.factoryReset, }); diff --git a/lib/pages/routines/widgets/routine_dialogs/gateway/gateway_if_dialog.dart b/lib/pages/routines/widgets/routine_dialogs/gateway/gateway_if_dialog.dart index ecaf5ba9..457110b7 100644 --- a/lib/pages/routines/widgets/routine_dialogs/gateway/gateway_if_dialog.dart +++ b/lib/pages/routines/widgets/routine_dialogs/gateway/gateway_if_dialog.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_svg/svg.dart'; +import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart'; import 'package:syncrow_web/pages/routines/bloc/functions_bloc/functions_bloc_bloc.dart'; import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart'; import 'package:syncrow_web/pages/routines/models/device_functions.dart'; @@ -32,10 +33,7 @@ class _GatewayIfDialogState extends State { @override void initState() { super.initState(); - _gatewayFunctions = widget.functions - .whereType() - .where((function) => function.type == 'IF' || function.type == 'BOTH') - .toList(); + _gatewayFunctions = widget.functions.whereType().toList(); } @override @@ -89,11 +87,32 @@ class _GatewayIfDialogState extends State { } Widget _buildMainContent(BuildContext context, FunctionBlocState state) { + final selectedFunction = state.selectedFunction; + final selectedOperationName = state.selectedOperationName; + final selectedFunctionData = state.addedFunctions.firstWhere( + (f) => f.functionCode == selectedFunction, + orElse: () => DeviceFunctionData( + entityId: '', + functionCode: selectedFunction ?? '', + operationName: '', + value: null, + ), + ); + return Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ _buildFunctionList(context), - // if (state.selectedFunction != null) _buildValueSelector(context, state), + if (state.selectedFunction != null) + Expanded( + child: _buildValueSelector( + context: context, + selectedFunction: selectedFunction ?? '', + selectedFunctionData: selectedFunctionData, + acFunctions: _gatewayFunctions, + operationName: selectedOperationName ?? '', + ), + ), ], ); } @@ -103,7 +122,6 @@ class _GatewayIfDialogState extends State { width: 360, child: ListView.separated( shrinkWrap: false, - physics: const AlwaysScrollableScrollPhysics(), itemCount: _gatewayFunctions.length, separatorBuilder: (context, index) => const Padding( padding: EdgeInsets.symmetric(horizontal: 40.0), @@ -141,4 +159,85 @@ class _GatewayIfDialogState extends State { ), ); } + + static Widget _buildValueSelector({ + required BuildContext context, + required String selectedFunction, + required DeviceFunctionData? selectedFunctionData, + required List acFunctions, + AllDevicesModel? device, + required String operationName, + }) { + final selectedGatewayFunctions = acFunctions.firstWhere( + (f) => f.code == selectedFunction, + ); + final values = selectedGatewayFunctions.getOperationalValues(); + + return _buildOperationalValuesList( + context: context, + values: values, + selectedValue: selectedFunctionData?.value, + device: device, + operationName: operationName, + selectCode: selectedFunction, + selectedFunctionData: selectedFunctionData, + ); + } + + static Widget _buildOperationalValuesList({ + required BuildContext context, + required List values, + required dynamic selectedValue, + AllDevicesModel? device, + required String operationName, + required String selectCode, + DeviceFunctionData? selectedFunctionData, + }) { + return ListView.builder( + itemCount: values.length, + itemBuilder: (context, index) { + final value = values[index]; + final isSelected = selectedValue == value.value; + return ListTile( + leading: SvgPicture.asset( + value.icon, + width: 24, + height: 24, + placeholderBuilder: (context) => Container( + width: 24, + height: 24, + color: Colors.transparent, + ), + ), + title: Text( + value.description, + style: context.textTheme.bodyMedium, + ), + trailing: Icon( + isSelected ? Icons.radio_button_checked : Icons.radio_button_unchecked, + size: 24, + color: isSelected + ? ColorsManager.primaryColorWithOpacity + : ColorsManager.textGray, + ), + onTap: () { + if (!isSelected) { + context.read().add( + AddFunction( + functionData: DeviceFunctionData( + entityId: device?.uuid ?? '', + functionCode: selectCode, + operationName: operationName, + value: value.value, + condition: selectedFunctionData?.condition, + valueDescription: selectedFunctionData?.valueDescription, + ), + ), + ); + } + }, + ); + }, + ); + } }