push bugs

This commit is contained in:
ashraf_personal
2024-11-28 02:02:01 +03:00
parent 64ea9de3cb
commit 4b33929315
7 changed files with 186 additions and 115 deletions

View File

@ -10,8 +10,9 @@ import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
class DeviceDialogHelper { class DeviceDialogHelper {
static Future<Map<String, dynamic>?> showDeviceDialog( static Future<Map<String, dynamic>?> showDeviceDialog(
BuildContext context, BuildContext context,
Map<String, dynamic> data, Map<String, dynamic> data, {
) async { required bool removeComparetors,
}) async {
final functions = data['functions'] as List<DeviceFunction>; final functions = data['functions'] as List<DeviceFunction>;
try { try {
@ -20,6 +21,7 @@ class DeviceDialogHelper {
data['productType'], data['productType'],
data, data,
functions, functions,
removeComparetors: removeComparetors,
); );
if (result != null) { if (result != null) {
@ -33,34 +35,49 @@ class DeviceDialogHelper {
} }
static Future<Map<String, dynamic>?> _getDialogForDeviceType( static Future<Map<String, dynamic>?> _getDialogForDeviceType(
BuildContext context, BuildContext context,
String productType, String productType,
Map<String, dynamic> data, Map<String, dynamic> data,
List<DeviceFunction> functions, List<DeviceFunction> functions,
) async { {required bool removeComparetors}) async {
final routineBloc = context.read<RoutineBloc>(); final routineBloc = context.read<RoutineBloc>();
final deviceSelectedFunctions = final deviceSelectedFunctions =
routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? []; routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? [];
switch (productType) { switch (productType) {
case 'AC': case 'AC':
return ACHelper.showACFunctionsDialog(context, functions, return ACHelper.showACFunctionsDialog(
data['device'], deviceSelectedFunctions, data['uniqueCustomId']); context,
functions,
data['device'],
deviceSelectedFunctions,
data['uniqueCustomId'],
removeComparetors);
case '1G': case '1G':
return OneGangSwitchHelper.showSwitchFunctionsDialog(context, functions, return OneGangSwitchHelper.showSwitchFunctionsDialog(
data['device'], deviceSelectedFunctions, data['uniqueCustomId']); context,
functions,
data['device'],
deviceSelectedFunctions,
data['uniqueCustomId'],
removeComparetors);
case '2G': case '2G':
return TwoGangSwitchHelper.showSwitchFunctionsDialog(context, functions, return TwoGangSwitchHelper.showSwitchFunctionsDialog(
data['device'], deviceSelectedFunctions, data['uniqueCustomId']); context,
functions,
data['device'],
deviceSelectedFunctions,
data['uniqueCustomId'],
removeComparetors);
case '3G': case '3G':
return ThreeGangSwitchHelper.showSwitchFunctionsDialog( return ThreeGangSwitchHelper.showSwitchFunctionsDialog(
context, context,
functions, functions,
data['device'], data['device'],
deviceSelectedFunctions, deviceSelectedFunctions,
data['uniqueCustomId'], data['uniqueCustomId'],
); removeComparetors);
default: default:
return null; return null;
} }

View File

@ -26,7 +26,9 @@ class IfContainer extends StatelessWidget {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
const Text('IF', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const Text('IF',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold)),
if (state.isAutomation && state.ifItems.isNotEmpty) if (state.isAutomation && state.ifItems.isNotEmpty)
AutomationOperatorSelector( AutomationOperatorSelector(
selectedOperator: state.selectedAutomationOperator), selectedOperator: state.selectedAutomationOperator),
@ -53,33 +55,44 @@ class IfContainer extends StatelessWidget {
(index) => GestureDetector( (index) => GestureDetector(
onTap: () async { onTap: () async {
if (!state.isTabToRun) { if (!state.isTabToRun) {
final result = await DeviceDialogHelper.showDeviceDialog( final result = await DeviceDialogHelper
context, state.ifItems[index]); .showDeviceDialog(
context, state.ifItems[index],
removeComparetors: false);
if (result != null) { if (result != null) {
context context.read<RoutineBloc>().add(
.read<RoutineBloc>() AddToIfContainer(
.add(AddToIfContainer(state.ifItems[index], false)); state.ifItems[index], false));
} else if (!['AC', '1G', '2G', '3G'] } else if (![
.contains(state.ifItems[index]['productType'])) { 'AC',
context '1G',
.read<RoutineBloc>() '2G',
.add(AddToIfContainer(state.ifItems[index], false)); '3G'
].contains(
state.ifItems[index]['productType'])) {
context.read<RoutineBloc>().add(
AddToIfContainer(
state.ifItems[index], false));
} }
} }
}, },
child: DraggableCard( child: DraggableCard(
imagePath: state.ifItems[index]['imagePath'] ?? '', imagePath:
state.ifItems[index]['imagePath'] ?? '',
title: state.ifItems[index]['title'] ?? '', title: state.ifItems[index]['title'] ?? '',
deviceData: state.ifItems[index], deviceData: state.ifItems[index],
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8), padding: const EdgeInsets.symmetric(
horizontal: 4, vertical: 8),
isFromThen: false, isFromThen: false,
isFromIf: true, isFromIf: true,
onRemove: () { onRemove: () {
context.read<RoutineBloc>().add(RemoveDragCard( context.read<RoutineBloc>().add(
index: index, RemoveDragCard(
isFromThen: false, index: index,
key: state.ifItems[index]['uniqueCustomId'])); isFromThen: false,
key: state.ifItems[index]
['uniqueCustomId']));
}, },
), ),
)), )),
@ -100,14 +113,23 @@ class IfContainer extends StatelessWidget {
if (!state.isTabToRun) { if (!state.isTabToRun) {
if (mutableData['deviceId'] == 'tab_to_run') { if (mutableData['deviceId'] == 'tab_to_run') {
context.read<RoutineBloc>().add(AddToIfContainer(mutableData, true)); context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, true));
} else { } else {
final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData); final result = await DeviceDialogHelper.showDeviceDialog(
context, mutableData,
removeComparetors: false);
if (result != null) { if (result != null) {
context.read<RoutineBloc>().add(AddToIfContainer(mutableData, false)); context
} else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) { .read<RoutineBloc>()
context.read<RoutineBloc>().add(AddToIfContainer(mutableData, false)); .add(AddToIfContainer(mutableData, false));
} else if (!['AC', '1G', '2G', '3G']
.contains(mutableData['productType'])) {
context
.read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false));
} }
} }
} }
@ -153,7 +175,9 @@ class AutomationOperatorSelector extends StatelessWidget {
), ),
), ),
onPressed: () { onPressed: () {
context.read<RoutineBloc>().add(const ChangeAutomationOperator(operator: 'or')); context
.read<RoutineBloc>()
.add(const ChangeAutomationOperator(operator: 'or'));
}, },
), ),
Container( Container(
@ -179,7 +203,9 @@ class AutomationOperatorSelector extends StatelessWidget {
), ),
), ),
onPressed: () { onPressed: () {
context.read<RoutineBloc>().add(const ChangeAutomationOperator(operator: 'and')); context
.read<RoutineBloc>()
.add(const ChangeAutomationOperator(operator: 'and'));
}, },
), ),
], ],

View File

@ -19,6 +19,7 @@ class ACHelper {
AllDevicesModel? device, AllDevicesModel? device,
List<DeviceFunctionData>? deviceSelectedFunctions, List<DeviceFunctionData>? deviceSelectedFunctions,
String uniqueCustomId, String uniqueCustomId,
bool? removeComparetors,
) async { ) async {
List<ACFunction> acFunctions = functions.whereType<ACFunction>().toList(); List<ACFunction> acFunctions = functions.whereType<ACFunction>().toList();
@ -84,6 +85,7 @@ class ACHelper {
acFunctions: acFunctions, acFunctions: acFunctions,
device: device, device: device,
operationName: selectedOperationName ?? '', operationName: selectedOperationName ?? '',
removeComparators: removeComparetors,
), ),
), ),
], ],
@ -179,6 +181,7 @@ class ACHelper {
required List<ACFunction> acFunctions, required List<ACFunction> acFunctions,
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
bool? removeComparators,
}) { }) {
if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') { if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') {
final initialValue = selectedFunctionData?.value ?? 200; final initialValue = selectedFunctionData?.value ?? 200;
@ -190,6 +193,7 @@ class ACHelper {
device: device, device: device,
operationName: operationName, operationName: operationName,
selectedFunctionData: selectedFunctionData, selectedFunctionData: selectedFunctionData,
removeComparators: removeComparators,
); );
} }
@ -217,18 +221,20 @@ class ACHelper {
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
DeviceFunctionData? selectedFunctionData, DeviceFunctionData? selectedFunctionData,
bool? removeComparators,
}) { }) {
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_buildConditionToggle( if (removeComparators != true)
context, _buildConditionToggle(
currentCondition, context,
selectCode, currentCondition,
device, selectCode,
operationName, device,
selectedFunctionData, operationName,
), selectedFunctionData,
),
const SizedBox(height: 20), const SizedBox(height: 20),
_buildTemperatureDisplay( _buildTemperatureDisplay(
context, context,

View File

@ -20,6 +20,7 @@ class OneGangSwitchHelper {
AllDevicesModel? device, AllDevicesModel? device,
List<DeviceFunctionData>? deviceSelectedFunctions, List<DeviceFunctionData>? deviceSelectedFunctions,
String uniqueCustomId, String uniqueCustomId,
bool removeComparetors,
) async { ) async {
List<BaseSwitchFunction> acFunctions = List<BaseSwitchFunction> acFunctions =
functions.whereType<BaseSwitchFunction>().toList(); functions.whereType<BaseSwitchFunction>().toList();
@ -106,6 +107,7 @@ class OneGangSwitchHelper {
acFunctions: acFunctions, acFunctions: acFunctions,
device: device, device: device,
operationName: selectedOperationName ?? '', operationName: selectedOperationName ?? '',
removeComparetors: removeComparetors,
), ),
), ),
], ],
@ -162,6 +164,7 @@ class OneGangSwitchHelper {
required List<BaseSwitchFunction> acFunctions, required List<BaseSwitchFunction> acFunctions,
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
required bool removeComparetors,
}) { }) {
if (selectedFunction == 'countdown_1') { if (selectedFunction == 'countdown_1') {
final initialValue = selectedFunctionData?.value ?? 200; final initialValue = selectedFunctionData?.value ?? 200;
@ -173,6 +176,7 @@ class OneGangSwitchHelper {
device: device, device: device,
operationName: operationName, operationName: operationName,
selectedFunctionData: selectedFunctionData, selectedFunctionData: selectedFunctionData,
removeComparetors: removeComparetors,
); );
} }
@ -199,18 +203,20 @@ class OneGangSwitchHelper {
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
DeviceFunctionData? selectedFunctionData, DeviceFunctionData? selectedFunctionData,
required bool removeComparetors,
}) { }) {
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_buildConditionToggle( if (removeComparetors != true)
context, _buildConditionToggle(
currentCondition, context,
selectCode, currentCondition,
device, selectCode,
operationName, device,
selectedFunctionData, operationName,
), selectedFunctionData,
),
const SizedBox(height: 20), const SizedBox(height: 20),
_buildCountDownDisplay(context, initialValue, device, operationName, _buildCountDownDisplay(context, initialValue, device, operationName,
selectedFunctionData, selectCode), selectedFunctionData, selectCode),

View File

@ -20,6 +20,7 @@ class ThreeGangSwitchHelper {
AllDevicesModel? device, AllDevicesModel? device,
List<DeviceFunctionData>? deviceSelectedFunctions, List<DeviceFunctionData>? deviceSelectedFunctions,
String uniqueCustomId, String uniqueCustomId,
bool removeComparetors,
) async { ) async {
List<BaseSwitchFunction> switchFunctions = List<BaseSwitchFunction> switchFunctions =
functions.whereType<BaseSwitchFunction>().toList(); functions.whereType<BaseSwitchFunction>().toList();
@ -106,6 +107,7 @@ class ThreeGangSwitchHelper {
switchFunctions: switchFunctions, switchFunctions: switchFunctions,
device: device, device: device,
operationName: selectedOperationName ?? '', operationName: selectedOperationName ?? '',
removeComparetors: removeComparetors,
), ),
), ),
], ],
@ -162,6 +164,7 @@ class ThreeGangSwitchHelper {
required List<BaseSwitchFunction> switchFunctions, required List<BaseSwitchFunction> switchFunctions,
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
required bool removeComparetors,
}) { }) {
if (selectedFunction == 'countdown_1' || if (selectedFunction == 'countdown_1' ||
selectedFunction == 'countdown_2' || selectedFunction == 'countdown_2' ||
@ -175,6 +178,7 @@ class ThreeGangSwitchHelper {
device: device, device: device,
operationName: operationName, operationName: operationName,
selectedFunctionData: selectedFunctionData, selectedFunctionData: selectedFunctionData,
removeComparetors: removeComparetors,
); );
} }
@ -201,18 +205,20 @@ class ThreeGangSwitchHelper {
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
DeviceFunctionData? selectedFunctionData, DeviceFunctionData? selectedFunctionData,
bool? removeComparetors,
}) { }) {
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_buildConditionToggle( if (removeComparetors != true)
context, _buildConditionToggle(
currentCondition, context,
selectCode, currentCondition,
device, selectCode,
operationName, device,
selectedFunctionData, operationName,
), selectedFunctionData,
),
const SizedBox(height: 20), const SizedBox(height: 20),
_buildCountDownDisplay(context, initialValue, device, operationName, _buildCountDownDisplay(context, initialValue, device, operationName,
selectedFunctionData, selectCode), selectedFunctionData, selectCode),

View File

@ -20,6 +20,7 @@ class TwoGangSwitchHelper {
AllDevicesModel? device, AllDevicesModel? device,
List<DeviceFunctionData>? deviceSelectedFunctions, List<DeviceFunctionData>? deviceSelectedFunctions,
String uniqueCustomId, String uniqueCustomId,
bool removeComparetors,
) async { ) async {
List<BaseSwitchFunction> switchFunctions = List<BaseSwitchFunction> switchFunctions =
functions.whereType<BaseSwitchFunction>().toList(); functions.whereType<BaseSwitchFunction>().toList();
@ -106,6 +107,7 @@ class TwoGangSwitchHelper {
switchFunctions: switchFunctions, switchFunctions: switchFunctions,
device: device, device: device,
operationName: selectedOperationName ?? '', operationName: selectedOperationName ?? '',
removeComparetors: removeComparetors,
), ),
), ),
], ],
@ -162,6 +164,7 @@ class TwoGangSwitchHelper {
required List<BaseSwitchFunction> switchFunctions, required List<BaseSwitchFunction> switchFunctions,
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
required bool removeComparetors,
}) { }) {
if (selectedFunction == 'countdown_1' || if (selectedFunction == 'countdown_1' ||
selectedFunction == 'countdown_2') { selectedFunction == 'countdown_2') {
@ -174,6 +177,7 @@ class TwoGangSwitchHelper {
device: device, device: device,
operationName: operationName, operationName: operationName,
selectedFunctionData: selectedFunctionData, selectedFunctionData: selectedFunctionData,
removeComparetors: removeComparetors,
); );
} }
@ -200,18 +204,20 @@ class TwoGangSwitchHelper {
AllDevicesModel? device, AllDevicesModel? device,
required String operationName, required String operationName,
DeviceFunctionData? selectedFunctionData, DeviceFunctionData? selectedFunctionData,
bool? removeComparetors,
}) { }) {
return Column( return Column(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
_buildConditionToggle( if (removeComparetors != true)
context, _buildConditionToggle(
currentCondition, context,
selectCode, currentCondition,
device, selectCode,
operationName, device,
selectedFunctionData, operationName,
), selectedFunctionData,
),
const SizedBox(height: 20), const SizedBox(height: 20),
_buildCountDownDisplay(context, initialValue, device, operationName, _buildCountDownDisplay(context, initialValue, device, operationName,
selectedFunctionData, selectCode), selectedFunctionData, selectCode),

View File

@ -26,7 +26,9 @@ class ThenContainer extends StatelessWidget {
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
const Text('THEN', style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)), const Text('THEN',
style: TextStyle(
fontSize: 18, fontWeight: FontWeight.bold)),
const SizedBox(height: 16), const SizedBox(height: 16),
Wrap( Wrap(
spacing: 8, spacing: 8,
@ -35,12 +37,16 @@ class ThenContainer extends StatelessWidget {
state.thenItems.length, state.thenItems.length,
(index) => GestureDetector( (index) => GestureDetector(
onTap: () async { onTap: () async {
if (state.thenItems[index]['deviceId'] == 'delay') { if (state.thenItems[index]['deviceId'] ==
final result = await DelayHelper.showDelayPickerDialog( 'delay') {
context, state.thenItems[index]); final result = await DelayHelper
.showDelayPickerDialog(
context, state.thenItems[index]);
if (result != null) { if (result != null) {
context.read<RoutineBloc>().add(AddToThenContainer({ context
.read<RoutineBloc>()
.add(AddToThenContainer({
...state.thenItems[index], ...state.thenItems[index],
'imagePath': Assets.delay, 'imagePath': Assets.delay,
'title': 'Delay', 'title': 'Delay',
@ -49,32 +55,41 @@ class ThenContainer extends StatelessWidget {
return; return;
} }
final result = await DeviceDialogHelper.showDeviceDialog( final result = await DeviceDialogHelper
context, state.thenItems[index]); .showDeviceDialog(
context, state.thenItems[index],
removeComparetors: true);
if (result != null) { if (result != null) {
context context.read<RoutineBloc>().add(
.read<RoutineBloc>() AddToThenContainer(
.add(AddToThenContainer(state.thenItems[index])); state.thenItems[index]));
} else if (!['AC', '1G', '2G', '3G'] } else if (!['AC', '1G', '2G', '3G']
.contains(state.thenItems[index]['productType'])) { .contains(state.thenItems[index]
context ['productType'])) {
.read<RoutineBloc>() context.read<RoutineBloc>().add(
.add(AddToThenContainer(state.thenItems[index])); AddToThenContainer(
state.thenItems[index]));
} }
}, },
child: DraggableCard( child: DraggableCard(
imagePath: state.thenItems[index]['imagePath'] ?? '', imagePath: state.thenItems[index]
title: state.thenItems[index]['title'] ?? '', ['imagePath'] ??
'',
title:
state.thenItems[index]['title'] ?? '',
deviceData: state.thenItems[index], deviceData: state.thenItems[index],
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 8), padding: const EdgeInsets.symmetric(
horizontal: 4, vertical: 8),
isFromThen: true, isFromThen: true,
isFromIf: false, isFromIf: false,
onRemove: () { onRemove: () {
context.read<RoutineBloc>().add(RemoveDragCard( context.read<RoutineBloc>().add(
index: index, RemoveDragCard(
isFromThen: true, index: index,
key: state.thenItems[index]['uniqueCustomId'])); isFromThen: true,
key: state.thenItems[index]
['uniqueCustomId']));
}, },
), ),
))), ))),
@ -83,21 +98,6 @@ class ThenContainer extends StatelessWidget {
), ),
); );
}, },
// onWillAcceptWithDetails: (data) {
// if (data == null) return false;
// return data.data;
// // if (state.isTabToRun) {
// // return data.data['type'] == 'automation';
// // }
// // if (state.isAutomation) {
// // return data.data['type'] == 'scene' ||
// // data.data['type'] == 'automation';
// // }
// // return data.data['deviceId'] != null;
// },
onAcceptWithDetails: (data) async { onAcceptWithDetails: (data) async {
final uniqueCustomId = const Uuid().v4(); final uniqueCustomId = const Uuid().v4();
final mutableData = Map<String, dynamic>.from(data.data); final mutableData = Map<String, dynamic>.from(data.data);
@ -131,7 +131,7 @@ class ThenContainer extends StatelessWidget {
if (mutableData['type'] == 'tap_to_run' && state.isAutomation) { if (mutableData['type'] == 'tap_to_run' && state.isAutomation) {
context.read<RoutineBloc>().add(AddToThenContainer({ context.read<RoutineBloc>().add(AddToThenContainer({
...mutableData, ...mutableData,
'imagePath': Assets.loginLogo, 'imagePath': Assets.logo,
'title': mutableData['name'], 'title': mutableData['name'],
})); }));
@ -143,7 +143,8 @@ class ThenContainer extends StatelessWidget {
} }
if (mutableData['deviceId'] == 'delay') { if (mutableData['deviceId'] == 'delay') {
final result = await DelayHelper.showDelayPickerDialog(context, mutableData); final result =
await DelayHelper.showDelayPickerDialog(context, mutableData);
if (result != null) { if (result != null) {
context.read<RoutineBloc>().add(AddToThenContainer({ context.read<RoutineBloc>().add(AddToThenContainer({
@ -155,10 +156,13 @@ class ThenContainer extends StatelessWidget {
return; return;
} }
final result = await DeviceDialogHelper.showDeviceDialog(context, mutableData); final result = await DeviceDialogHelper.showDeviceDialog(
context, mutableData,
removeComparetors: true);
if (result != null) { if (result != null) {
context.read<RoutineBloc>().add(AddToThenContainer(mutableData)); context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
} else if (!['AC', '1G', '2G', '3G'].contains(mutableData['productType'])) { } else if (!['AC', '1G', '2G', '3G']
.contains(mutableData['productType'])) {
context.read<RoutineBloc>().add(AddToThenContainer(mutableData)); context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
} }
}, },