mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
Update operation names in CpsFunctions and add toggle codes to CeilingSensorHelper
This commit is contained in:
@ -90,8 +90,8 @@ final class CpsSensitivityFunction extends CpsFunctions {
|
||||
step = 1,
|
||||
scale = 0,
|
||||
super(
|
||||
code: 'far_detection',
|
||||
operationName: 'Far Detection',
|
||||
code: 'sensitivity',
|
||||
operationName: 'Sensitivity',
|
||||
icon: Assets.sensitivity,
|
||||
);
|
||||
|
||||
@ -123,7 +123,7 @@ final class CpsMovingSpeedFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Moving Speed',
|
||||
icon: Assets.speedoMeter,
|
||||
);
|
||||
@override
|
||||
@ -139,7 +139,7 @@ final class CpsSpatialStaticValueFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Spacial Static Value',
|
||||
icon: Assets.spatialStaticValue,
|
||||
);
|
||||
@override
|
||||
@ -149,7 +149,6 @@ final class CpsSpatialStaticValueFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsSpatialMotionValueFunction extends CpsFunctions {
|
||||
CpsSpatialMotionValueFunction({
|
||||
required super.deviceId,
|
||||
@ -157,7 +156,7 @@ final class CpsSpatialMotionValueFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Spatial Motion Value',
|
||||
icon: Assets.spatialMotionValue,
|
||||
);
|
||||
@override
|
||||
@ -167,7 +166,6 @@ final class CpsSpatialMotionValueFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsMaxDistanceOfDetectionFunction extends CpsFunctions {
|
||||
CpsMaxDistanceOfDetectionFunction({
|
||||
required super.deviceId,
|
||||
@ -175,7 +173,7 @@ final class CpsMaxDistanceOfDetectionFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Maximum Distance Of Detection',
|
||||
icon: Assets.currentDistanceIcon,
|
||||
);
|
||||
@override
|
||||
@ -185,7 +183,6 @@ final class CpsMaxDistanceOfDetectionFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsMaxDistanceOfStaticDetectionFunction extends CpsFunctions {
|
||||
CpsMaxDistanceOfStaticDetectionFunction({
|
||||
required super.deviceId,
|
||||
@ -193,7 +190,7 @@ final class CpsMaxDistanceOfStaticDetectionFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Maximum Distance Of Static Detection',
|
||||
icon: Assets.currentDistanceIcon,
|
||||
);
|
||||
@override
|
||||
@ -203,7 +200,6 @@ final class CpsMaxDistanceOfStaticDetectionFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsDetectionRangeFunction extends CpsFunctions {
|
||||
CpsDetectionRangeFunction({
|
||||
required super.deviceId,
|
||||
@ -211,7 +207,7 @@ final class CpsDetectionRangeFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Detection Range',
|
||||
icon: Assets.farDetection,
|
||||
);
|
||||
@override
|
||||
@ -221,7 +217,6 @@ final class CpsDetectionRangeFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsDistanceOfMovingObjectsFunction extends CpsFunctions {
|
||||
CpsDistanceOfMovingObjectsFunction({
|
||||
required super.deviceId,
|
||||
@ -229,7 +224,7 @@ final class CpsDistanceOfMovingObjectsFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Distance Of Moving Objects',
|
||||
icon: Assets.currentDistanceIcon,
|
||||
);
|
||||
@override
|
||||
@ -239,7 +234,6 @@ final class CpsDistanceOfMovingObjectsFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsPresenceJudgementThrsholdFunction extends CpsFunctions {
|
||||
CpsPresenceJudgementThrsholdFunction({
|
||||
required super.deviceId,
|
||||
@ -247,7 +241,7 @@ final class CpsPresenceJudgementThrsholdFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Presence Judgement Threshold',
|
||||
icon: Assets.presenceJudgementThrshold,
|
||||
);
|
||||
@override
|
||||
@ -264,7 +258,7 @@ final class CpsMotionAmplitudeTriggerThresholdFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Motion Amplitude Trigger Threshold',
|
||||
icon: Assets.presenceJudgementThrshold,
|
||||
);
|
||||
@override
|
||||
@ -274,7 +268,6 @@ final class CpsMotionAmplitudeTriggerThresholdFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsPerpetualBoundaryFunction extends CpsFunctions {
|
||||
CpsPerpetualBoundaryFunction({
|
||||
required super.deviceId,
|
||||
@ -282,7 +275,7 @@ final class CpsPerpetualBoundaryFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Perpetual Boundary',
|
||||
icon: Assets.boundary,
|
||||
);
|
||||
@override
|
||||
@ -292,9 +285,6 @@ final class CpsPerpetualBoundaryFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
final class CpsMotionTriggerBoundaryFunction extends CpsFunctions {
|
||||
CpsMotionTriggerBoundaryFunction({
|
||||
required super.deviceId,
|
||||
@ -302,7 +292,7 @@ final class CpsMotionTriggerBoundaryFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Motion Trigger Boundary',
|
||||
icon: Assets.motionMeter,
|
||||
);
|
||||
@override
|
||||
@ -312,7 +302,6 @@ final class CpsMotionTriggerBoundaryFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsMotionTriggerTimeFunction extends CpsFunctions {
|
||||
CpsMotionTriggerTimeFunction({
|
||||
required super.deviceId,
|
||||
@ -320,7 +309,7 @@ final class CpsMotionTriggerTimeFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Motion Trigger Time',
|
||||
icon: Assets.motionMeter,
|
||||
);
|
||||
@override
|
||||
@ -337,7 +326,7 @@ final class CpsMotionToStaticTimeFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Motion To Static Time',
|
||||
icon: Assets.motionMeter,
|
||||
);
|
||||
@override
|
||||
@ -354,7 +343,7 @@ final class CpsEnteringNoBodyStateTimeFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Entering Nobody State Time',
|
||||
icon: Assets.motionMeter,
|
||||
);
|
||||
@override
|
||||
@ -364,8 +353,6 @@ final class CpsEnteringNoBodyStateTimeFunction extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
final class CpsSelfTestResultFunctions extends CpsFunctions {
|
||||
CpsSelfTestResultFunctions({
|
||||
required super.deviceId,
|
||||
@ -404,6 +391,11 @@ final class CpsSelfTestResultFunctions extends CpsFunctions {
|
||||
icon: Assets.communicationFault,
|
||||
value: 'communication_fault',
|
||||
),
|
||||
CpsOperationalValue(
|
||||
description: 'Radar Fault',
|
||||
icon: Assets.radarFault,
|
||||
value: 'radar_fault',
|
||||
),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -503,7 +495,6 @@ final class CpsMovementFunctions extends CpsFunctions {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final class CpsCustomModeFunction extends CpsFunctions {
|
||||
CpsCustomModeFunction({
|
||||
required super.deviceId,
|
||||
@ -624,7 +615,7 @@ final class CpsSportsParaFunction extends CpsFunctions {
|
||||
required super.type,
|
||||
}) : super(
|
||||
code: '',
|
||||
operationName: '',
|
||||
operationName: 'Sports Para',
|
||||
icon: Assets.sportsPara,
|
||||
);
|
||||
@override
|
||||
@ -632,4 +623,4 @@ final class CpsSportsParaFunction extends CpsFunctions {
|
||||
// TODO: implement getOperationalValues
|
||||
throw UnimplementedError();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,13 @@ import 'package:flutter_bloc/flutter_bloc.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/ceiling_presence_sensor_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_footer.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/dialog_header.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialog_function_list_tile.dart';
|
||||
import 'package:syncrow_web/pages/routines/widgets/routine_dialog_selection_list_tile.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class CeilingSensorDialog extends StatefulWidget {
|
||||
const CeilingSensorDialog({
|
||||
@ -27,6 +31,20 @@ class CeilingSensorDialog extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
||||
late final List<CpsFunctions> _cpsFunctions;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_cpsFunctions = widget.functions.whereType<CpsFunctions>().where((function) {
|
||||
if (widget.dialogType == 'THEN') {
|
||||
return function.type == 'THEN' || function.type == 'BOTH';
|
||||
}
|
||||
return function.type == 'IF' || function.type == 'BOTH';
|
||||
}).toList();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
@ -56,17 +74,20 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const DialogHeader('Presence Sensor Condition'),
|
||||
Expanded(child: _buildMainContent(context, state)),
|
||||
DialogFooter(
|
||||
onCancel: () => Navigator.pop(context),
|
||||
onConfirm: state.addedFunctions.isNotEmpty
|
||||
? () {
|
||||
context.read<RoutineBloc>().add(
|
||||
AddFunctionToRoutine(
|
||||
state.addedFunctions, '{uniqueCustomId}'),
|
||||
state.addedFunctions,
|
||||
'${widget.uniqueCustomId}',
|
||||
),
|
||||
);
|
||||
|
||||
Navigator.pop(context, {
|
||||
// 'deviceId': functions.first.deviceId,
|
||||
'deviceId': widget.functions.first.deviceId,
|
||||
});
|
||||
}
|
||||
: null,
|
||||
@ -79,4 +100,130 @@ class _CeilingSensorDialogState extends State<CeilingSensorDialog> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
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,
|
||||
),
|
||||
);
|
||||
final selectedCpsFunctions = _cpsFunctions.firstWhere(
|
||||
(f) => f.code == selectedFunction,
|
||||
orElse: () => CpsMovementFunctions(
|
||||
deviceId: '',
|
||||
deviceName: '',
|
||||
type: '',
|
||||
),
|
||||
);
|
||||
final operations = selectedCpsFunctions.getOperationalValues();
|
||||
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
CpsFunctionsList(cpsFunctions: _cpsFunctions),
|
||||
if (state.selectedFunction != null)
|
||||
Expanded(
|
||||
child: CpsDialogValueSelector(
|
||||
operations: operations,
|
||||
selectedFunction: selectedFunction ?? '',
|
||||
selectedFunctionData: selectedFunctionData,
|
||||
cpsFunctions: _cpsFunctions,
|
||||
operationName: selectedOperationName ?? '',
|
||||
device: widget.device,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CpsFunctionsList extends StatelessWidget {
|
||||
const CpsFunctionsList({required this.cpsFunctions, super.key});
|
||||
|
||||
final List<CpsFunctions> cpsFunctions;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SizedBox(
|
||||
width: 360,
|
||||
child: ListView.separated(
|
||||
shrinkWrap: false,
|
||||
itemCount: cpsFunctions.length,
|
||||
separatorBuilder: (context, index) => const Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 40.0),
|
||||
child: Divider(color: ColorsManager.dividerColor),
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
final function = cpsFunctions[index];
|
||||
return RoutineDialogFunctionListTile(
|
||||
iconPath: function.icon,
|
||||
operationName: function.operationName,
|
||||
onTap: () => context.read<FunctionBloc>().add(
|
||||
SelectFunction(
|
||||
functionCode: function.code,
|
||||
operationName: function.operationName,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class CpsDialogValueSelector extends StatelessWidget {
|
||||
const CpsDialogValueSelector({
|
||||
required this.operations,
|
||||
required this.selectedFunction,
|
||||
required this.selectedFunctionData,
|
||||
required this.cpsFunctions,
|
||||
required this.device,
|
||||
required this.operationName,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final List<CpsOperationalValue> operations;
|
||||
final String selectedFunction;
|
||||
final DeviceFunctionData? selectedFunctionData;
|
||||
final List<CpsFunctions> cpsFunctions;
|
||||
final AllDevicesModel? device;
|
||||
final String operationName;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: operations.length,
|
||||
itemBuilder: (context, index) {
|
||||
final operation = operations[index];
|
||||
final isSelected = selectedFunctionData?.value == operation.value;
|
||||
return RoutineDialogSelectionListTile(
|
||||
iconPath: operation.icon,
|
||||
description: operation.description,
|
||||
isSelected: isSelected,
|
||||
onTap: () {
|
||||
if (!isSelected) {
|
||||
context.read<FunctionBloc>().add(
|
||||
AddFunction(
|
||||
functionData: DeviceFunctionData(
|
||||
entityId: device?.uuid ?? '',
|
||||
functionCode: selectedFunction,
|
||||
operationName: operationName,
|
||||
value: operation.value,
|
||||
condition: selectedFunctionData?.condition,
|
||||
valueDescription: selectedFunctionData?.valueDescription,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -162,4 +162,15 @@ abstract final class CeilingSensorHelper {
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
static const toggleCodes = <String>{
|
||||
'radar_switch',
|
||||
'space_para_switch',
|
||||
'self_test_result',
|
||||
'nobody_time',
|
||||
'movement',
|
||||
'custom_mode',
|
||||
'space_type',
|
||||
'presence_state',
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user