Compare commits

...
Author SHA1 Message Date
mohammadnemer1 c1d6db8bba Merge branch 'dev' into Fix-Bugs-Related-TextForm-Routine 2025-05-27 09:56:07 +03:00
mohammad 50fc5f9562 Add 'PC' device to routine 2025-05-27 09:54:21 +03:00
Faris Armoush 3746c36a71 Merge pull request #205 from SyncrowIOT/sp-1493-data-foramtting-2.0
sp-1493-data-formatting-2.0.
2025-05-26 15:19:18 +03:00
Faris Armoush 0b4337fb6c sp-1493-data-formatting-2.0. 2025-05-26 15:17:29 +03:00
Faris Armoush 642d8e9591 Merge pull request #204 from SyncrowIOT/SP-1493-data-formatting
SP-1493-data-formatting
2025-05-26 14:24:46 +03:00
Faris Armoush 5a8ef578c3 SP-1493-data-formatting 2025-05-26 14:16:43 +03:00
Faris Armoush cedef666f6 Merge pull request #202 from SyncrowIOT/SP-1493-rework
SP-1493 rework
2025-05-26 10:03:10 +03:00
Faris Armoush a10d998ec6 Merge pull request #203 from SyncrowIOT/SP-1513-rework
SP-1513-rework
2025-05-26 10:02:49 +03:00
Faris Armoush ed50ac03d3 Merge pull request #201 from SyncrowIOT/SP-1492-landing_page_analytics_button_design
SP-1492-landing_page_analytics_button_design
2025-05-26 09:57:23 +03:00
Faris Armoush 12deceb7d3 SP-1513-rework 2025-05-25 11:35:01 +03:00
Faris Armoush 9d27ed2dc5 SP-1506 rework, coloring and padding. 2025-05-25 11:13:24 +03:00
Faris Armoush a878b9328a SP-1493 rework, can select a subspace in sidebar even when the space has no child-spaces. 2025-05-25 11:06:36 +03:00
Faris Armoush 0f9227a6f5 Merge pull request #200 from SyncrowIOT/SP-1591-FE-Implement-Space-Level-Structure-Selection-and-Air-Quality-Device-Dropdown
Sp 1591 fe implement space level structure selection and air quality device dropdown
2025-05-22 15:59:19 +03:00
Faris Armoush 5b13962d41 removed unnecessary * 1 calculation of height. 2025-05-22 15:57:03 +03:00
Faris Armoush 8c53d5322a SP-1591 2025-05-22 15:53:18 +03:00
Faris Armoush af4d37939b Merge branch 'dev' of https://github.com/SyncrowIOT/web into SP-1591-FE-Implement-Space-Level-Structure-Selection-and-Air-Quality-Device-Dropdown 2025-05-22 15:48:47 +03:00
Faris Armoush d43c1847ff SP-1591 2025-05-22 15:44:19 +03:00
Faris Armoush 4c5b390887 Fixed typos. 2025-05-22 15:42:49 +03:00
Faris Armoush 5eeac01666 cannot select a community in AirQualityDataLoadingStrategy. 2025-05-22 15:35:04 +03:00
Faris Armoush 717d698378 can select child spaces with children in AirQualityDataLoadingStrategy. 2025-05-22 15:23:42 +03:00
Faris Armoush 9adbbb9a2d Integrated and implemented devices dropdown into the newly created widget AirQualityEndSideWidget. 2025-05-22 15:19:50 +03:00
Faris Armoush e792dbd72f SP-1591/ Implement business logic in AirQualityDataLoadingStrategy for community structure loading strategy. 2025-05-22 14:58:42 +03:00
Faris Armoush d2eea33714 Prepared AirQualityView layout and structure with PlaceHolder widgets. 2025-05-22 12:24:13 +03:00
Faris Armoush 5a61647fe4 Prepared and created the necessary component for the air quality loading strategy for the side bar selection, and for loading data in different parts of the UI. 2025-05-21 16:49:30 +03:00
Faris Armoush 568b6be354 Created AirQualityView widget for the new Air Quality analytics module. 2025-05-21 16:46:38 +03:00
32 changed files with 1406 additions and 95 deletions
+10
View File
@@ -0,0 +1,10 @@
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M20 6.90237L13.6328 13.1837L6.60156 6.1524L2.32422 10.418L1.50391 9.59769L6.60156 4.48828L13.6328 11.5195L19.1797 6.08206L20 6.90237Z" fill="#64E1DC"/>
<path d="M20 13.1133L19.1797 13.9336L13.6328 8.49615L7.77344 14.3555L5.42969 12.0118L2.32422 15.1055L1.50391 14.2852L5.42969 10.3477L7.77344 12.6914L13.6328 6.83203L20 13.1133Z" fill="#FDBF00"/>
<path d="M20 6.90234L13.6328 13.1836L10.1172 9.668V8.00388L13.6328 11.5195L19.1797 6.08203L20 6.90234Z" fill="#00C8C8"/>
<path d="M20 13.1133L19.1797 13.9336L13.6328 8.49615L10.1172 12.0118V10.3477L13.6328 6.83203L20 13.1133Z" fill="#FF9100"/>
<path d="M19.1714 17.625V18.7813L17.7184 18.7821L10.1172 18.7851L1.32812 18.7891V0.75H2.5V17.625H19.1714Z" fill="#676E74"/>
<path d="M3.0127 2.37976L1.91406 1.50024L0.732422 2.37976L0 1.46423L1.91406 0L3.74512 1.46423L3.0127 2.37976Z" fill="#676E74"/>
<path d="M19.1714 17.625V18.7813L17.7176 18.7824L17.7184 18.7821L10.1172 18.7851V17.625H19.1714Z" fill="#474F54"/>
<path d="M19.9998 18.2108L18.1205 19.9999L17.292 19.1714L17.7174 18.7823L17.7182 18.782L18.3427 18.2108L17.7565 17.6249L17.292 17.1604L18.1205 16.332L19.9998 18.2108Z" fill="#474F54"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_devices/analytics_devices_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_bloc.dart';
import 'package:syncrow_web/pages/analytics/params/get_analytics_devices_param.dart';
abstract final class FetchAirQualityDataHelper {
const FetchAirQualityDataHelper._();
static void loadAirQualityData(
BuildContext context, {
required String communityUuid,
required String spaceUuid,
}) {
loadAnalyticsDevices(
context,
communityUuid: communityUuid,
spaceUuid: spaceUuid,
);
}
static void clearAllData(BuildContext context) {
context.read<AnalyticsDevicesBloc>().add(
const ClearAnalyticsDeviceEvent(),
);
context.read<RealtimeDeviceChangesBloc>().add(
const RealtimeDeviceChangesClosed(),
);
}
static void loadAnalyticsDevices(
BuildContext context, {
required String communityUuid,
required String spaceUuid,
}) {
context.read<AnalyticsDevicesBloc>().add(
LoadAnalyticsDevicesEvent(
param: GetAnalyticsDevicesParam(
communityUuid: communityUuid,
spaceUuid: spaceUuid,
deviceTypes: ['AQI'],
requestType: AnalyticsDeviceRequestType.energyManagement,
),
onSuccess: (device) {
context.read<RealtimeDeviceChangesBloc>()
..add(const RealtimeDeviceChangesClosed())
..add(RealtimeDeviceChangesStarted(device.uuid));
},
),
);
}
}
@@ -0,0 +1,63 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/widgets/air_quality_end_side_widget.dart';
class AirQualityView extends StatelessWidget {
const AirQualityView({super.key});
static const _padding = EdgeInsetsDirectional.all(32);
@override
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
final isMediumOrLess = constraints.maxWidth <= 900;
final height = MediaQuery.sizeOf(context).height;
if (isMediumOrLess) {
return SingleChildScrollView(
padding: _padding,
child: Column(
spacing: 32,
children: [
SizedBox(
height: height * 1.2,
child: const AirQualityEndSideWidget(),
),
SizedBox(height: height * 0.5, child: const Placeholder()),
SizedBox(height: height * 0.5, child: const Placeholder()),
],
),
);
}
return SingleChildScrollView(
child: Container(
padding: _padding,
height: height,
child: const Column(
children: [
Expanded(
child: Row(
spacing: 32,
children: [
Expanded(
flex: 2,
child: Column(
spacing: 20,
children: [
Expanded(child: Placeholder()),
Expanded(child: Placeholder()),
],
),
),
Expanded(child: AirQualityEndSideWidget()),
],
),
),
],
),
),
);
},
);
}
}
@@ -0,0 +1,88 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/blocs/analytics_devices/analytics_devices_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/helpers/fetch_energy_management_data_helper.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/analytics_device_dropdown.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
import 'package:syncrow_web/utils/style.dart';
class AirQualityEndSideWidget extends StatelessWidget {
const AirQualityEndSideWidget({super.key});
@override
Widget build(BuildContext context) {
return Container(
decoration: subSectionContainerDecoration.copyWith(
borderRadius: BorderRadius.circular(30),
),
padding: const EdgeInsetsDirectional.all(32),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_buildHeader(context),
Text(
'Device ID:',
style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.textPrimaryColor,
fontWeight: FontWeight.w400,
fontSize: 12,
),
),
const SizedBox(height: 6),
SelectableText(
context.watch<AnalyticsDevicesBloc>().state.selectedDevice?.uuid ??
'N/A',
style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.blackColor,
fontWeight: FontWeight.w400,
fontSize: 12,
),
),
],
),
);
}
Widget _buildHeader(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
children: [
Expanded(
flex: 3,
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: AlignmentDirectional.centerStart,
child: SelectableText(
'AQI Sensor',
style: context.textTheme.headlineSmall?.copyWith(
fontWeight: FontWeight.w700,
color: ColorsManager.vividBlue.withValues(alpha: 0.6),
fontSize: 18,
),
),
),
),
const Spacer(),
Expanded(
flex: 2,
child: FittedBox(
fit: BoxFit.scaleDown,
alignment: AlignmentDirectional.centerEnd,
child: AnalyticsDeviceDropdown(
onChanged: (value) {
context.read<AnalyticsDevicesBloc>().add(
SelectAnalyticsDeviceEvent(value),
);
FetchEnergyManagementDataHelper.loadRealtimeDeviceChanges(
context,
deviceUuid: value.uuid,
);
},
),
),
),
],
);
}
}
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/views/air_quality_view.dart';
import 'package:syncrow_web/pages/analytics/modules/energy_management/views/analytics_energy_management_view.dart'; import 'package:syncrow_web/pages/analytics/modules/energy_management/views/analytics_energy_management_view.dart';
import 'package:syncrow_web/pages/analytics/modules/occupancy/views/analytics_occupancy_view.dart'; import 'package:syncrow_web/pages/analytics/modules/occupancy/views/analytics_occupancy_view.dart';
@@ -10,6 +11,10 @@ enum AnalyticsPageTab {
occupancy( occupancy(
title: 'Occupancy', title: 'Occupancy',
child: AnalyticsOccupancyView(), child: AnalyticsOccupancyView(),
),
airQuality(
title: 'Air Quality',
child: AirQualityView(),
); );
const AnalyticsPageTab({ const AnalyticsPageTab({
@@ -0,0 +1,59 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/analytics/modules/air_quality/helpers/fetch_air_quality_data_helper.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/analytics_data_loading_strategy.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
final class AirQualityDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
@override
void onCommunitySelected(
BuildContext context,
CommunityModel community,
List<SpaceModel> spaces,
) {
// Do nothing
}
@override
void onSpaceSelected(
BuildContext context,
CommunityModel community,
SpaceModel space,
) {
final spaceTreeBloc = context.read<SpaceTreeBloc>();
final isSpaceSelected = spaceTreeBloc.state.selectedSpaces.contains(space.uuid);
if (isSpaceSelected) {
clearData(context);
return;
}
spaceTreeBloc
..add(const SpaceTreeClearSelectionEvent())
..add(OnSpaceSelected(community, space.uuid ?? '', []));
FetchAirQualityDataHelper.loadAirQualityData(
context,
communityUuid: community.uuid,
spaceUuid: space.uuid ?? '',
);
}
@override
void onChildSpaceSelected(
BuildContext context,
CommunityModel community,
SpaceModel child,
) {
return onSpaceSelected(context, community, child);
}
@override
void clearData(BuildContext context) {
context.read<SpaceTreeBloc>().add(const SpaceTreeClearSelectionEvent());
FetchAirQualityDataHelper.clearAllData(context);
}
}
@@ -1,4 +1,5 @@
import 'package:syncrow_web/pages/analytics/modules/analytics/enums/analytics_page_tab.dart'; import 'package:syncrow_web/pages/analytics/modules/analytics/enums/analytics_page_tab.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/air_quality_data_loading_strategy.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/analytics_data_loading_strategy.dart'; import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/analytics_data_loading_strategy.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/energy_management_data_loading_strategy.dart'; import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/energy_management_data_loading_strategy.dart';
import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/occupancy_data_loading_strategy.dart'; import 'package:syncrow_web/pages/analytics/modules/analytics/strategies/occupancy_data_loading_strategy.dart';
@@ -9,6 +10,7 @@ abstract final class AnalyticsDataLoadingStrategyFactory {
return switch (tab) { return switch (tab) {
AnalyticsPageTab.energyManagement => EnergyManagementDataLoadingStrategy(), AnalyticsPageTab.energyManagement => EnergyManagementDataLoadingStrategy(),
AnalyticsPageTab.occupancy => OccupancyDataLoadingStrategy(), AnalyticsPageTab.occupancy => OccupancyDataLoadingStrategy(),
AnalyticsPageTab.airQuality => AirQualityDataLoadingStrategy(),
}; };
} }
} }
@@ -68,10 +68,8 @@ class EnergyManagementDataLoadingStrategy implements AnalyticsDataLoadingStrateg
CommunityModel community, CommunityModel community,
SpaceModel child, SpaceModel child,
) { ) {
if (child.children.isNotEmpty) {
return onSpaceSelected(context, community, child); return onSpaceSelected(context, community, child);
} }
}
@override @override
void clearData(BuildContext context) { void clearData(BuildContext context) {
@@ -48,7 +48,7 @@ class OccupancyDataLoadingStrategy implements AnalyticsDataLoadingStrategy {
CommunityModel community, CommunityModel community,
SpaceModel child, SpaceModel child,
) { ) {
onSpaceSelected(context, community, child); return onSpaceSelected(context, community, child);
} }
@override @override
@@ -38,7 +38,7 @@ abstract final class EnergyManagementChartsHelper {
sideTitles: SideTitles( sideTitles: SideTitles(
showTitles: true, showTitles: true,
maxIncluded: false, maxIncluded: false,
minIncluded: true, minIncluded: false,
interval: leftTitlesInterval, interval: leftTitlesInterval,
reservedSize: 110, reservedSize: 110,
getTitlesWidget: (value, meta) => Padding( getTitlesWidget: (value, meta) => Padding(
@@ -50,7 +50,7 @@ abstract final class EnergyManagementChartsHelper {
value.formatNumberToKwh, value.formatNumberToKwh,
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
fontSize: 12, fontSize: 12,
color: ColorsManager.greyColor, color: ColorsManager.lightGreyColor,
), ),
), ),
), ),
@@ -170,7 +170,7 @@ class EnergyConsumptionByPhasesChart extends StatelessWidget {
child: Text( child: Text(
month, month,
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
color: ColorsManager.greyColor, color: ColorsManager.lightGreyColor,
fontSize: 11, fontSize: 11,
), ),
), ),
@@ -19,10 +19,12 @@ class EnergyConsumptionByPhasesChartBox extends StatelessWidget {
decoration: secondarySection, decoration: secondarySection,
child: Column( child: Column(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
spacing: 20,
children: [ children: [
AnalyticsErrorWidget(state.errorMessage), AnalyticsErrorWidget(state.errorMessage),
EnergyConsumptionByPhasesTitle(isLoading: state.status == EnergyConsumptionByPhasesStatus.loading,), EnergyConsumptionByPhasesTitle(
isLoading: state.status == EnergyConsumptionByPhasesStatus.loading,
),
const SizedBox(height: 20),
Expanded( Expanded(
child: EnergyConsumptionByPhasesChart( child: EnergyConsumptionByPhasesChart(
energyData: state.chartData, energyData: state.chartData,
@@ -69,13 +69,18 @@ class PowerClampEnergyDataWidget extends StatelessWidget {
PowerClampEnergyStatus( PowerClampEnergyStatus(
iconPath: Assets.powerActiveIcon, iconPath: Assets.powerActiveIcon,
title: 'Active', title: 'Active',
value: _valueFromCode('EnergyConsumed', generalDataPoints), value: _valueFromCode('ActivePower', generalDataPoints),
unit: 'W', unit: 'W',
), ),
PowerClampEnergyStatus( PowerClampEnergyStatus(
iconPath: Assets.voltMeterIcon, iconPath: Assets.voltMeterIcon,
title: 'Current', title: 'Current',
value: _valueFromCode('Current', generalDataPoints), value: _valueFromCode('Current', generalDataPoints)
.replaceAllMapped(
RegExp(r'(\d{1,3})(?=(\d{3})+(?!\d))'),
(Match m) => '${m[1]}.',
)
.replaceAll('.0', ''),
unit: 'A', unit: 'A',
), ),
PowerClampEnergyStatus( PowerClampEnergyStatus(
@@ -55,7 +55,7 @@ class PowerClampPhasesDataWidget extends StatelessWidget {
iconPath: Assets.powerActiveIcon, iconPath: Assets.powerActiveIcon,
title: 'Active Power', title: 'Active Power',
value: _valueFromCode( value: _valueFromCode(
code: 'ReactivePower$phaseSuffix', code: 'ActivePower$phaseSuffix',
points: phase?.dataPoints, points: phase?.dataPoints,
), ),
unit: 'W', unit: 'W',
@@ -125,7 +125,48 @@ class PowerClampPhasesDataWidget extends StatelessWidget {
(e) => e.code == code, (e) => e.code == code,
orElse: () => DataPoint(value: '--'), orElse: () => DataPoint(value: '--'),
); );
final value = element?.value;
if (code.contains('Current')) {
return _formatCurrentValue(value?.toString());
}
if (code.contains('PowerFactor')) {
return _formatPowerFactor(value?.toString());
}
if (code.contains('Voltage')) {
return _formatVoltage(value?.toString());
}
return value?.toString() ?? '--';
}
return element?.value.toString() ?? '--'; String _formatCurrentValue(String? value) {
if (value == null) return '--';
String str = value;
if (str.isEmpty || str == '--') return '--';
str = str.replaceAll(RegExp(r'[^0-9]'), '');
if (str.isEmpty) return '--';
if (str.length == 1) return '${str[0]}.0';
return '${str[0]}.${str.substring(1)}';
}
String _formatPowerFactor(String? value) {
if (value == null) return '--';
String str = value;
if (str.isEmpty || str == '--') return '--';
str = str.replaceAll(RegExp(r'[^0-9]'), '');
if (str.isEmpty) return '--';
final intValue = int.tryParse(str);
if (intValue == null) return '--';
final doubleValue = intValue / 100;
return doubleValue.toStringAsFixed(2);
}
String _formatVoltage(String? value) {
if (value == null) return '--';
String str = value;
if (str.isEmpty || str == '--') return '--';
str = str.replaceAll(RegExp(r'[^0-9]'), '');
if (str.isEmpty) return '--';
if (str.length == 1) return '0.${str[0]}';
return '${str.substring(0, str.length - 1)}.${str.substring(str.length - 1)}';
} }
} }
@@ -12,6 +12,7 @@ import 'package:syncrow_web/pages/routines/models/gang_switches/one_gang_switch/
import 'package:syncrow_web/pages/routines/models/gang_switches/three_gang_switch/three_gang_switch.dart'; import 'package:syncrow_web/pages/routines/models/gang_switches/three_gang_switch/three_gang_switch.dart';
import 'package:syncrow_web/pages/routines/models/gang_switches/two_gang_switch/two_gang_switch.dart'; import 'package:syncrow_web/pages/routines/models/gang_switches/two_gang_switch/two_gang_switch.dart';
import 'package:syncrow_web/pages/routines/models/gateway.dart'; import 'package:syncrow_web/pages/routines/models/gateway.dart';
import 'package:syncrow_web/pages/routines/models/pc/energy_clamp_functions.dart';
import 'package:syncrow_web/pages/routines/models/water_heater/water_heater_functions.dart'; import 'package:syncrow_web/pages/routines/models/water_heater/water_heater_functions.dart';
import 'package:syncrow_web/pages/routines/models/wps/wps_functions.dart'; import 'package:syncrow_web/pages/routines/models/wps/wps_functions.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/ceiling_sensor_helper.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/ceiling_sensor_helper.dart';
@@ -248,6 +249,8 @@ SOS
tempIcon = Assets.waterLeakNormal; tempIcon = Assets.waterLeakNormal;
} else if (type == DeviceType.NCPS) { } else if (type == DeviceType.NCPS) {
tempIcon = Assets.sensors; tempIcon = Assets.sensors;
} else if (type == DeviceType.PC) {
tempIcon = Assets.powerClamp;
} else { } else {
tempIcon = Assets.logoHorizontal; tempIcon = Assets.logoHorizontal;
} }
@@ -393,6 +396,59 @@ SOS
BacklightFunction( BacklightFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'), deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
]; ];
case 'PC':
return [
TotalEnergyConsumedStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
TotalActivePowerConsumedStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
VoltagePhaseSequenceDetectionFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
TotalCurrentStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
FrequencyStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
// Phase A
EnergyConsumedAStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
ActivePowerAStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
VoltageAStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
PowerFactorAStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
CurrentAStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
// Phase B
EnergyConsumedBStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
ActivePowerBStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
VoltageBStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
CurrentBStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
PowerFactorBStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
// Phase C
EnergyConsumedCStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
ActivePowerCStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
VoltageCStatusFunction(
deviceId: uuid ?? '', deviceName: name ?? '', type: 'IF'),
CurrentCStatusFunction(
deviceId: uuid ?? '',
deviceName: name ?? '',
type: 'IF'),
PowerFactorCStatusFunction(
deviceId: uuid ?? '',
deviceName: name ?? '',
type: 'IF'),
];
default: default:
return []; return [];
@@ -526,5 +582,6 @@ SOS
"GD": DeviceType.GarageDoor, "GD": DeviceType.GarageDoor,
"WL": DeviceType.WaterLeak, "WL": DeviceType.WaterLeak,
"NCPS": DeviceType.NCPS, "NCPS": DeviceType.NCPS,
"PC": DeviceType.PC,
}; };
} }
@@ -7,6 +7,7 @@ import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_senso
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/flush_presence_sensor/flush_presence_sensor.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/flush_presence_sensor/flush_presence_sensor.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_helper.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/gateway/gateway_helper.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/one_gang_switch_dialog.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/power_clamp_enargy/energy_clamp_dialog.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/three_gang_switch_dialog.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/three_gang_switch_dialog.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/two_gang_switch_dialog.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/two_gang_switch_dialog.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/wall_sensor/wall_presence_sensor.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/wall_sensor/wall_presence_sensor.dart';
@@ -137,6 +138,16 @@ class DeviceDialogHelper {
device: data['device'], device: data['device'],
); );
case 'PC':
return EnergyClampDialog.showEnergyClampFunctionsDialog(
context: context,
functions: functions,
uniqueCustomId: data['uniqueCustomId'],
deviceSelectedFunctions: deviceSelectedFunctions,
dialogType: dialogType,
device: data['device'],
);
default: default:
return null; return null;
} }
@@ -9,7 +9,6 @@ abstract class DeviceFunction<T> {
final double? max; final double? max;
final double? min; final double? min;
DeviceFunction({ DeviceFunction({
required this.deviceId, required this.deviceId,
required this.deviceName, required this.deviceName,
@@ -114,4 +113,28 @@ class DeviceFunctionData {
max.hashCode ^ max.hashCode ^
min.hashCode; min.hashCode;
} }
DeviceFunctionData copyWith({
String? entityId,
String? functionCode,
String? operationName,
String? condition,
dynamic value,
double? step,
String? unit,
double? max,
double? min,
}) {
return DeviceFunctionData(
entityId: entityId ?? this.entityId,
functionCode: functionCode ?? this.functionCode,
operationName: operationName ?? this.operationName,
condition: condition ?? this.condition,
value: value ?? this.value,
step: step ?? this.step,
unit: unit ?? this.unit,
max: max ?? this.max,
min: min ?? this.min,
);
}
} }
@@ -0,0 +1,416 @@
import 'package:syncrow_web/pages/device_managment/power_clamp/models/power_clamp_batch_model.dart';
import 'package:syncrow_web/pages/routines/models/device_functions.dart';
import 'package:syncrow_web/pages/routines/models/pc/enrgy_clamp_operational_value.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
abstract class EnergyClampFunctions extends DeviceFunction<PowerClampModel1> {
final String type;
EnergyClampFunctions({
required super.deviceId,
required super.deviceName,
required super.code,
required super.operationName,
required super.icon,
required this.type,
super.step,
super.unit,
super.max,
super.min,
});
List<EnergyClampOperationalValue> getOperationalValues();
}
// General & shared
class TotalEnergyConsumedStatusFunction extends EnergyClampFunctions {
TotalEnergyConsumedStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'EnergyConsumed',
operationName: 'Total Energy Consumed',
icon: Assets.energyConsumedIcon,
min: 0.00,
max: 20000000.00,
step: 1,
unit: "kWh",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class TotalActivePowerConsumedStatusFunction extends EnergyClampFunctions {
TotalActivePowerConsumedStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'ActivePower',
operationName: 'Total Active Power',
icon: Assets.powerActiveIcon,
min: -19800000,
max: 19800000,
step: 0.1,
unit: "kW",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class VoltagePhaseSequenceDetectionFunction extends EnergyClampFunctions {
VoltagePhaseSequenceDetectionFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'voltage_phase_seq',
operationName: 'Voltage phase sequence detection',
icon: Assets.voltageIcon,
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [
EnergyClampOperationalValue(
icon: Assets.voltageIcon, description: '0', value: '0'),
EnergyClampOperationalValue(
icon: Assets.voltageIcon, description: '1', value: '1'),
EnergyClampOperationalValue(
icon: Assets.voltageIcon, description: '2', value: '2'),
EnergyClampOperationalValue(
icon: Assets.voltageIcon, description: '3', value: '3'),
EnergyClampOperationalValue(
icon: Assets.voltageIcon, description: '4', value: '4'),
EnergyClampOperationalValue(
icon: Assets.voltageIcon, description: '5', value: '5'),
];
}
class TotalCurrentStatusFunction extends EnergyClampFunctions {
TotalCurrentStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'Current',
operationName: 'Total Current',
icon: Assets.voltMeterIcon,
min: 0.000,
max: 9000.000,
step: 1,
unit: "A",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class FrequencyStatusFunction extends EnergyClampFunctions {
FrequencyStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'Frequency',
operationName: 'Frequency',
icon: Assets.frequencyIcon,
min: 0,
max: 80,
step: 1,
unit: "Hz",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
// Phase A
class EnergyConsumedAStatusFunction extends EnergyClampFunctions {
EnergyConsumedAStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'EnergyConsumedA',
operationName: 'Energy Consumed A',
icon: Assets.energyConsumedIcon,
min: 0.00,
max: 20000000.00,
step: 1,
unit: "kWh",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class ActivePowerAStatusFunction extends EnergyClampFunctions {
ActivePowerAStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'ActivePowerA',
operationName: 'Active Power A',
icon: Assets.powerActiveIcon,
min: 200,
max: 300,
step: 1,
unit: "kW",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class VoltageAStatusFunction extends EnergyClampFunctions {
VoltageAStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'VoltageA',
operationName: 'Voltage A',
icon: Assets.voltageIcon,
min: 0.0,
max: 500,
step: 1,
unit: "V",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class PowerFactorAStatusFunction extends EnergyClampFunctions {
PowerFactorAStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'PowerFactorA',
operationName: 'Power Factor A',
icon: Assets.speedoMeter,
min: 0.00,
max: 1.00,
step: 0.1,
unit: "",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class CurrentAStatusFunction extends EnergyClampFunctions {
CurrentAStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'CurrentA',
operationName: 'Current A',
icon: Assets.voltMeterIcon,
min: 0.000,
max: 3000.000,
step: 1,
unit: "A",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
// Phase B
class EnergyConsumedBStatusFunction extends EnergyClampFunctions {
EnergyConsumedBStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'EnergyConsumedB',
operationName: 'Energy Consumed B',
icon: Assets.energyConsumedIcon,
min: 0.00,
max: 20000000.00,
step: 1,
unit: "kWh",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class ActivePowerBStatusFunction extends EnergyClampFunctions {
ActivePowerBStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'ActivePowerB',
operationName: 'Active Power B',
icon: Assets.powerActiveIcon,
min: -6600000,
max: 6600000,
step: 1,
unit: "kW",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class VoltageBStatusFunction extends EnergyClampFunctions {
VoltageBStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'VoltageB',
operationName: 'Voltage B',
icon: Assets.voltageIcon,
min: 0.0,
max: 500,
step: 1,
unit: "V",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class CurrentBStatusFunction extends EnergyClampFunctions {
CurrentBStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'CurrentB',
operationName: 'Current B',
icon: Assets.voltMeterIcon,
min: 0.000,
max: 3000.000,
step: 1,
unit: "A",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class PowerFactorBStatusFunction extends EnergyClampFunctions {
PowerFactorBStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'PowerFactorB',
operationName: 'Power Factor B',
icon: Assets.speedoMeter,
min: 0.0,
max: 1.0,
step: 0.1,
unit: "",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
// Phase C
class EnergyConsumedCStatusFunction extends EnergyClampFunctions {
EnergyConsumedCStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'EnergyConsumedC',
operationName: 'Energy Consumed C',
icon: Assets.energyConsumedIcon,
min: 0.00,
max: 20000000.00,
step: 1,
unit: "kWh",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class ActivePowerCStatusFunction extends EnergyClampFunctions {
ActivePowerCStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'ActivePowerC',
operationName: 'Active Power C',
icon: Assets.powerActiveIcon,
min: -6600000,
max: 6600000,
step: 1,
unit: "kW",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class VoltageCStatusFunction extends EnergyClampFunctions {
VoltageCStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'VoltageC',
operationName: 'Voltage C',
icon: Assets.voltageIcon,
min: 0.00,
max: 500,
step: 0.1,
unit: "V",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class CurrentCStatusFunction extends EnergyClampFunctions {
CurrentCStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'CurrentC',
operationName: 'Current C',
icon: Assets.voltMeterIcon,
min: 0.000,
max: 3000.000,
step: 0.1,
unit: "A",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
class PowerFactorCStatusFunction extends EnergyClampFunctions {
PowerFactorCStatusFunction({
required super.deviceId,
required super.deviceName,
required super.type,
}) : super(
code: 'PowerFactorC',
operationName: 'Power Factor C',
icon: Assets.speedoMeter,
min: 0.00,
max: 1.00,
step: 0.1,
unit: "",
);
@override
List<EnergyClampOperationalValue> getOperationalValues() => [];
}
@@ -0,0 +1,11 @@
class EnergyClampOperationalValue {
final String icon;
final String description;
final dynamic value;
EnergyClampOperationalValue({
required this.icon,
required this.description,
required this.value,
});
}
@@ -40,6 +40,7 @@ class CustomRoutinesTextbox extends StatefulWidget {
class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> { class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
late final TextEditingController _controller; late final TextEditingController _controller;
bool hasError = false; bool hasError = false;
String? errorMessage; String? errorMessage;
@@ -55,29 +56,63 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
} }
} }
bool _isInitialized = false;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
int decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount); _initializeController();
double initialValue;
if (widget.initialValue != null &&
widget.initialValue is num &&
(widget.initialValue as num) == 0) {
initialValue = 0.0;
} else {
initialValue = double.tryParse(widget.displayedValue) ?? 0.0;
} }
void _initializeController() {
final decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount);
final dynamic initialValue = widget.initialValue;
double parsedValue;
if (initialValue is num) {
parsedValue = initialValue.toDouble();
} else if (initialValue is String) {
parsedValue = double.tryParse(initialValue) ?? widget.sliderRange.$1;
} else {
parsedValue = widget.sliderRange.$1;
}
_controller = TextEditingController( _controller = TextEditingController(
text: initialValue.toStringAsFixed(decimalPlaces), text: parsedValue.toStringAsFixed(decimalPlaces),
); );
_isInitialized = true;
} }
@override @override
void dispose() { void didUpdateWidget(CustomRoutinesTextbox oldWidget) {
_controller.dispose(); super.didUpdateWidget(oldWidget);
super.dispose();
if (widget.initialValue != oldWidget.initialValue && _isInitialized) {
final decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount);
final dynamic initialValue = widget.initialValue;
double newValue;
if (initialValue is num) {
newValue = initialValue.toDouble();
} else if (initialValue is String) {
newValue = double.tryParse(initialValue) ?? widget.sliderRange.$1;
} else {
newValue = widget.sliderRange.$1;
} }
final newValueText = newValue.toStringAsFixed(decimalPlaces);
if (_controller.text != newValueText) {
WidgetsBinding.instance.addPostFrameCallback((_) {
_controller.text = newValueText;
_controller.selection =
TextSelection.collapsed(offset: _controller.text.length);
});
}
}
}
void _validateInput(String value) { void _validateInput(String value) {
final doubleValue = double.tryParse(value); final doubleValue = double.tryParse(value);
if (doubleValue == null) { if (doubleValue == null) {
@@ -121,18 +156,6 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
} }
} }
@override
void didUpdateWidget(CustomRoutinesTextbox oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.initialValue != oldWidget.initialValue) {
if (widget.initialValue != null &&
widget.initialValue is num &&
(widget.initialValue as num) == 0) {
int decimalPlaces = getDecimalPlaces(widget.stepIncreaseAmount);
_controller.text = 0.0.toStringAsFixed(decimalPlaces);
}
}
}
void _correctAndUpdateValue(String value) { void _correctAndUpdateValue(String value) {
final doubleValue = double.tryParse(value) ?? 0.0; final doubleValue = double.tryParse(value) ?? 0.0;
@@ -227,9 +250,15 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
color: ColorsManager.blackColor, color: ColorsManager.blackColor,
), ),
keyboardType: TextInputType.number, keyboardType: TextInputType.number,
inputFormatters: widget.withSpecialChar == true inputFormatters: [
? [FilteringTextInputFormatter.digitsOnly] FilteringTextInputFormatter.allow(
: null, widget.withSpecialChar
? RegExp(r'^-?\d*\.?\d{0,' +
decimalPlaces.toString() +
r'}$')
: RegExp(r'\d+'),
),
],
decoration: const InputDecoration( decoration: const InputDecoration(
border: InputBorder.none, border: InputBorder.none,
isDense: true, isDense: true,
@@ -268,8 +297,9 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
const SizedBox(height: 16), const SizedBox(height: 16),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 32), padding: const EdgeInsets.symmetric(horizontal: 32),
child: Row( child: Wrap(
mainAxisAlignment: MainAxisAlignment.spaceBetween, alignment: WrapAlignment.spaceBetween,
direction: Axis.horizontal,
children: [ children: [
Text( Text(
'Min. ${widget.sliderRange.$1.toInt()}${widget.unit}', 'Min. ${widget.sliderRange.$1.toInt()}${widget.unit}',
@@ -279,6 +309,9 @@ class _CustomRoutinesTextboxState extends State<CustomRoutinesTextbox> {
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
const SizedBox(
width: 50,
),
Text( Text(
'Max. ${widget.sliderRange.$2.toInt()}${widget.unit}', 'Max. ${widget.sliderRange.$2.toInt()}${widget.unit}',
style: context.textTheme.bodySmall?.copyWith( style: context.textTheme.bodySmall?.copyWith(
+13 -3
View File
@@ -78,9 +78,9 @@ class IfContainer extends StatelessWidget {
'CPS', 'CPS',
'NCPS', 'NCPS',
'WH', 'WH',
'PC',
].contains(state.ifItems[index] ].contains(state.ifItems[index]
['productType'])) { ['productType'])) {
context.read<RoutineBloc>().add( context.read<RoutineBloc>().add(
AddToIfContainer( AddToIfContainer(
state.ifItems[index], false)); state.ifItems[index], false));
@@ -137,8 +137,18 @@ class IfContainer extends StatelessWidget {
context context
.read<RoutineBloc>() .read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false)); .add(AddToIfContainer(mutableData, false));
} else if (!['AC', '1G', '2G', '3G', 'WPS', 'GW', 'CPS', 'NCPS','WH'] } else if (![
.contains(mutableData['productType'])) { 'AC',
'1G',
'2G',
'3G',
'WPS',
'GW',
'CPS',
'NCPS',
'WH',
'PC',
].contains(mutableData['productType'])) {
context context
.read<RoutineBloc>() .read<RoutineBloc>()
.add(AddToIfContainer(mutableData, false)); .add(AddToIfContainer(mutableData, false));
@@ -27,6 +27,7 @@ class _RoutineDevicesState extends State<RoutineDevices> {
'CPS', 'CPS',
'NCPS', 'NCPS',
'WH', 'WH',
'PC',
}; };
@override @override
@@ -76,7 +76,6 @@ class ACHelper {
child: _buildFunctionsList( child: _buildFunctionsList(
context: context, context: context,
acFunctions: acFunctions, acFunctions: acFunctions,
device: device,
onFunctionSelected: onFunctionSelected:
(functionCode, operationName) { (functionCode, operationName) {
RoutineTapFunctionHelper.onTapFunction( RoutineTapFunctionHelper.onTapFunction(
@@ -84,15 +83,15 @@ class ACHelper {
functionCode: functionCode, functionCode: functionCode,
functionOperationName: operationName, functionOperationName: operationName,
functionValueDescription: functionValueDescription:
selectedFunctionData.valueDescription, selectedFunctionData
.valueDescription,
deviceUuid: device?.uuid, deviceUuid: device?.uuid,
codesToAddIntoFunctionsWithDefaultValue: [ codesToAddIntoFunctionsWithDefaultValue: [
'temp_set', 'temp_set',
'temp_current', 'temp_current',
], ],
defaultValue: 0); defaultValue: 0);
}, }),
),
), ),
// Value selector // Value selector
if (selectedFunction != null) if (selectedFunction != null)
@@ -150,7 +149,6 @@ class ACHelper {
required BuildContext context, required BuildContext context,
required List<ACFunction> acFunctions, required List<ACFunction> acFunctions,
required Function(String, String) onFunctionSelected, required Function(String, String) onFunctionSelected,
required AllDevicesModel? device,
}) { }) {
return ListView.separated( return ListView.separated(
shrinkWrap: false, shrinkWrap: false,
@@ -193,7 +191,6 @@ class ACHelper {
); );
} }
/// Build value selector for AC functions dialog
static Widget _buildValueSelector({ static Widget _buildValueSelector({
required BuildContext context, required BuildContext context,
required String selectedFunction, required String selectedFunction,
@@ -207,19 +204,19 @@ class ACHelper {
acFunctions.firstWhere((f) => f.code == selectedFunction); acFunctions.firstWhere((f) => f.code == selectedFunction);
if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') { if (selectedFunction == 'temp_set' || selectedFunction == 'temp_current') {
// Convert stored integer value to display value
final displayValue = final displayValue =
(selectedFunctionData?.value ?? selectedFn.min ?? 0) / 10; (selectedFunctionData?.value ?? selectedFn.min!) / 10;
final minValue = selectedFn.min! / 10; final minValue = selectedFn.min! / 10;
final maxValue = selectedFn.max! / 10; final maxValue = selectedFn.max! / 10;
return CustomRoutinesTextbox( return CustomRoutinesTextbox(
withSpecialChar: true, withSpecialChar: true,
dividendOfRange: maxValue, dividendOfRange: maxValue,
currentCondition: selectedFunctionData?.condition, currentCondition: selectedFunctionData?.condition,
dialogType: selectedFn.type, dialogType: selectedFn.type,
sliderRange: (minValue, maxValue), sliderRange: (minValue, maxValue),
displayedValue: displayValue.toStringAsFixed(1), displayedValue: displayValue.toString(),
initialValue: displayValue.toDouble(), initialValue: displayValue,
unit: selectedFn.unit!, unit: selectedFn.unit!,
onConditionChanged: (condition) => context.read<FunctionBloc>().add( onConditionChanged: (condition) => context.read<FunctionBloc>().add(
AddFunction( AddFunction(
@@ -228,7 +225,7 @@ class ACHelper {
functionCode: selectedFunction, functionCode: selectedFunction,
operationName: selectedFn.operationName, operationName: selectedFn.operationName,
condition: condition, condition: condition,
value: 0, value: (displayValue * 10).round(),
step: selectedFn.step, step: selectedFn.step,
unit: selectedFn.unit, unit: selectedFn.unit,
max: selectedFn.max, max: selectedFn.max,
@@ -236,13 +233,15 @@ class ACHelper {
), ),
), ),
), ),
onTextChanged: (value) => context.read<FunctionBloc>().add( onTextChanged: (value) {
final numericValue = double.tryParse(value.toString()) ?? minValue;
context.read<FunctionBloc>().add(
AddFunction( AddFunction(
functionData: DeviceFunctionData( functionData: DeviceFunctionData(
entityId: device?.uuid ?? '', entityId: device?.uuid ?? '',
functionCode: selectedFunction, functionCode: selectedFunction,
operationName: selectedFn.operationName, operationName: selectedFn.operationName,
value: (value * 10).round(), // Store as integer value: (numericValue * 10).round(),
condition: selectedFunctionData?.condition, condition: selectedFunctionData?.condition,
step: selectedFn.step, step: selectedFn.step,
unit: selectedFn.unit, unit: selectedFn.unit,
@@ -250,14 +249,17 @@ class ACHelper {
min: selectedFn.min, min: selectedFn.min,
), ),
), ),
), );
stepIncreaseAmount: selectedFn.step! / 10, // Convert step for display },
stepIncreaseAmount: selectedFn.step! / 10,
); );
} }
// Rest of your existing code for other value selectors
final values = selectedFn.getOperationalValues();
return _buildOperationalValuesList( return _buildOperationalValuesList(
context: context, context: context,
values: selectedFn.getOperationalValues(), values: values,
selectedValue: selectedFunctionData?.value, selectedValue: selectedFunctionData?.value,
device: device, device: device,
operationName: operationName, operationName: operationName,
@@ -311,7 +313,7 @@ class ACHelper {
// ); // );
// } // }
// /// Build condition toggle for AC functions dialog /// Build condition toggle for AC functions dialog
// static Widget _buildConditionToggle( // static Widget _buildConditionToggle(
// BuildContext context, // BuildContext context,
// String? currentCondition, // String? currentCondition,
@@ -6,7 +6,6 @@ import 'package:syncrow_web/pages/routines/models/ceiling_presence_sensor_functi
import 'package:syncrow_web/pages/routines/models/device_functions.dart'; import 'package:syncrow_web/pages/routines/models/device_functions.dart';
import 'package:syncrow_web/pages/routines/widgets/custom_routines_textbox.dart'; import 'package:syncrow_web/pages/routines/widgets/custom_routines_textbox.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_slider_helpers.dart'; import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/ceiling_sensor/cps_slider_helpers.dart';
import 'package:syncrow_web/pages/routines/widgets/slider_value_selector.dart';
class CpsDialogSliderSelector extends StatelessWidget { class CpsDialogSliderSelector extends StatelessWidget {
const CpsDialogSliderSelector({ const CpsDialogSliderSelector({
@@ -33,7 +32,7 @@ class CpsDialogSliderSelector extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return CustomRoutinesTextbox( return CustomRoutinesTextbox(
withSpecialChar: false, withSpecialChar: true,
currentCondition: selectedFunctionData.condition, currentCondition: selectedFunctionData.condition,
dialogType: dialogType, dialogType: dialogType,
sliderRange: sliderRange:
@@ -0,0 +1,86 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_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/models/device_functions.dart';
import 'package:syncrow_web/pages/routines/models/pc/enrgy_clamp_operational_value.dart';
class EnergyOperationalValuesList extends StatelessWidget {
final List<EnergyClampOperationalValue> values;
final dynamic selectedValue;
final AllDevicesModel? device;
final String operationName;
final String selectCode;
const EnergyOperationalValuesList({
required this.values,
required this.selectedValue,
required this.device,
required this.operationName,
required this.selectCode,
super.key,
});
@override
Widget build(BuildContext context) {
return ListView.builder(
padding: const EdgeInsets.all(20),
itemCount: values.length,
itemBuilder: (context, index) => _buildValueItem(context, values[index]),
);
}
Widget _buildValueItem(
BuildContext context, EnergyClampOperationalValue value) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildValueIcon(context, value),
Expanded(child: _buildValueDescription(value)),
_buildValueRadio(context, value),
],
),
);
}
Widget _buildValueIcon(context, EnergyClampOperationalValue value) {
return Column(
children: [
SvgPicture.asset(value.icon, width: 25, height: 25),
],
);
}
Widget _buildValueDescription(EnergyClampOperationalValue value) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: Text(value.description),
);
}
Widget _buildValueRadio(context, EnergyClampOperationalValue value) {
return Radio<dynamic>(
value: value.value,
groupValue: selectedValue,
onChanged: (_) => _selectValue(context, value.value),
);
}
void _selectValue(BuildContext context, dynamic value) {
context.read<FunctionBloc>().add(
AddFunction(
functionData: DeviceFunctionData(
entityId: device?.uuid ?? '',
functionCode: selectCode,
operationName: operationName,
value: value,
),
),
);
}
}
@@ -0,0 +1,246 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_svg/flutter_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';
import 'package:syncrow_web/pages/routines/models/pc/energy_clamp_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_dialogs/helpers/routine_tap_function_helper.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/power_clamp_enargy/energy_value_selector_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/extension/build_context_x.dart';
class EnergyClampDialog extends StatefulWidget {
final List<DeviceFunction> functions;
final AllDevicesModel? device;
final List<DeviceFunctionData>? deviceSelectedFunctions;
final String? uniqueCustomId;
final String? dialogType;
final bool removeComparetors;
const EnergyClampDialog({
super.key,
required this.functions,
this.device,
this.deviceSelectedFunctions,
this.uniqueCustomId,
this.dialogType,
this.removeComparetors = false,
});
static Future<Map<String, dynamic>?> showEnergyClampFunctionsDialog({
required BuildContext context,
required List<DeviceFunction> functions,
AllDevicesModel? device,
List<DeviceFunctionData>? deviceSelectedFunctions,
String? uniqueCustomId,
String? dialogType,
bool removeComparetors = false,
}) async {
return showDialog<Map<String, dynamic>?>(
context: context,
builder: (context) => EnergyClampDialog(
functions: functions,
device: device,
deviceSelectedFunctions: deviceSelectedFunctions,
uniqueCustomId: uniqueCustomId,
removeComparetors: removeComparetors,
dialogType: dialogType,
),
);
}
@override
State<EnergyClampDialog> createState() => _EnergyClampDialogState();
}
class _EnergyClampDialogState extends State<EnergyClampDialog> {
late final List<EnergyClampFunctions> _functions;
@override
void initState() {
super.initState();
_functions =
widget.functions.whereType<EnergyClampFunctions>().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 BlocProvider(
create: (_) => FunctionBloc()
..add(InitializeFunctions(widget.deviceSelectedFunctions ?? [])),
child: _buildDialogContent(),
);
}
Widget _buildDialogContent() {
return AlertDialog(
contentPadding: EdgeInsets.zero,
content: BlocBuilder<FunctionBloc, FunctionBlocState>(
builder: (context, state) {
final selectedFunction = state.selectedFunction;
return Container(
width: selectedFunction != null ? 600 : 360,
height: 450,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
),
padding: const EdgeInsets.only(top: 20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const DialogHeader('Energy Clamp Conditions'),
Expanded(child: _buildMainContent(context, state)),
_buildDialogFooter(context, state),
],
),
);
},
),
);
}
Widget _buildMainContent(BuildContext context, FunctionBlocState state) {
return Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_buildFunctionList(context, state),
if (state.selectedFunction != null) _buildValueSelector(context, state),
],
);
}
Widget _buildFunctionList(BuildContext context, FunctionBlocState state) {
final selectedFunction = state.selectedFunction;
final selectedFunctionData = state.addedFunctions.firstWhere(
(f) => f.functionCode == selectedFunction,
orElse: () => DeviceFunctionData(
entityId: '',
functionCode: selectedFunction ?? '',
operationName: '',
value: null,
),
);
return SizedBox(
width: 360,
child: ListView.separated(
shrinkWrap: false,
physics: const AlwaysScrollableScrollPhysics(),
itemCount: _functions.length,
separatorBuilder: (context, index) => const Padding(
padding: EdgeInsets.symmetric(horizontal: 40.0),
child: Divider(color: ColorsManager.dividerColor),
),
itemBuilder: (context, index) {
final function = _functions[index];
return ListTile(
leading: SvgPicture.asset(
function.icon,
width: 24,
height: 24,
placeholderBuilder: (context) => const SizedBox(
width: 24,
height: 24,
),
),
title: Text(
function.operationName,
style: context.textTheme.bodyMedium,
),
trailing: const Icon(
Icons.arrow_forward_ios,
size: 16,
color: ColorsManager.textGray,
),
onTap: () => RoutineTapFunctionHelper.onTapFunction(
context,
functionCode: function.code,
functionOperationName: function.operationName,
functionValueDescription: selectedFunctionData.valueDescription,
deviceUuid: widget.device?.uuid,
codesToAddIntoFunctionsWithDefaultValue: [
'VoltageA',
'CurrentA',
'ActivePowerA',
'PowerFactorA',
'ReactivePowerA',
'EnergyConsumedA',
'VoltageB',
'CurrentB',
'ActivePowerB',
'PowerFactorB',
'ReactivePowerB',
'EnergyConsumedB',
'VoltageC',
'CurrentC',
'ActivePowerC',
'PowerFactorC',
'ReactivePowerC',
'EnergyConsumedC',
'EnergyConsumed',
'Current',
'ActivePower',
'ReactivePower',
'Frequency',
],
),
);
},
),
);
}
Widget _buildValueSelector(BuildContext context, FunctionBlocState state) {
final selectedFunction = state.selectedFunction!;
final functionData = state.addedFunctions.firstWhere(
(f) => f.functionCode == selectedFunction,
orElse: () => DeviceFunctionData(
entityId: '',
functionCode: selectedFunction,
operationName: state.selectedOperationName ?? '',
value: null,
),
);
return Expanded(
child: EnergyValueSelectorWidget(
selectedFunction: selectedFunction,
functionData: functionData,
functions: _functions,
device: widget.device,
dialogType: widget.dialogType!,
removeComparators: widget.removeComparetors,
),
);
}
Widget _buildDialogFooter(BuildContext context, FunctionBlocState state) {
return DialogFooter(
onCancel: () => Navigator.pop(context),
onConfirm: state.addedFunctions.isNotEmpty
? () {
context.read<RoutineBloc>().add(
AddFunctionToRoutine(
state.addedFunctions,
widget.uniqueCustomId!,
),
);
Navigator.pop(
context,
{'deviceId': widget.functions.first.deviceId},
);
}
: null,
isConfirmEnabled: state.selectedFunction != null,
);
}
}
@@ -0,0 +1,85 @@
import 'package:flutter/material.dart';
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/models/device_functions.dart';
import 'package:syncrow_web/pages/routines/models/pc/energy_clamp_functions.dart';
import 'package:syncrow_web/pages/routines/widgets/custom_routines_textbox.dart';
import 'package:syncrow_web/pages/routines/widgets/routine_dialogs/power_clamp_enargy/enargy_operational_values_list.dart';
class EnergyValueSelectorWidget extends StatelessWidget {
final String selectedFunction;
final DeviceFunctionData functionData;
final List<EnergyClampFunctions> functions;
final AllDevicesModel? device;
final String dialogType;
final bool removeComparators;
const EnergyValueSelectorWidget({
required this.selectedFunction,
required this.functionData,
required this.functions,
required this.device,
required this.dialogType,
required this.removeComparators,
super.key,
});
@override
Widget build(BuildContext context) {
final selectedFn =
functions.firstWhere((f) => f.code == selectedFunction);
final values = selectedFn.getOperationalValues();
final step = selectedFn.step ?? 1.0;
final _unit = selectedFn.unit ?? '';
final (double, double) sliderRange =
(selectedFn.min ?? 0.0, selectedFn.max ?? 100.0);
if (_isSliderFunction(selectedFunction)) {
return CustomRoutinesTextbox(
withSpecialChar: false,
currentCondition: functionData.condition,
dialogType: dialogType,
sliderRange: sliderRange,
displayedValue: functionData.value,
initialValue: functionData.value ?? 0.0,
onConditionChanged: (condition) => context.read<FunctionBloc>().add(
AddFunction(
functionData: DeviceFunctionData(
entityId: device?.uuid ?? '',
functionCode: selectedFunction,
operationName: functionData.operationName,
condition: condition,
value: functionData.value ?? 0,
),
),
),
onTextChanged: (value) => context.read<FunctionBloc>().add(
AddFunction(
functionData: DeviceFunctionData(
entityId: device?.uuid ?? '',
functionCode: selectedFunction,
operationName: functionData.operationName,
value: value.toInt(),
condition: functionData.condition,
),
),
),
unit: _unit,
dividendOfRange: 1,
stepIncreaseAmount: step,
);
}
return EnergyOperationalValuesList(
values: values,
selectedValue: functionData.value,
device: device,
operationName: selectedFn.operationName,
selectCode: selectedFunction,
);
}
bool _isSliderFunction(String function) =>
!['voltage_phase_seq'].contains(function);
}
@@ -33,7 +33,7 @@ class WpsValueSelectorWidget extends StatelessWidget {
if (_isSliderFunction(selectedFunction)) { if (_isSliderFunction(selectedFunction)) {
return CustomRoutinesTextbox( return CustomRoutinesTextbox(
withSpecialChar: false, withSpecialChar: true,
currentCondition: functionData.condition, currentCondition: functionData.condition,
dialogType: dialogType, dialogType: dialogType,
sliderRange: sliderRange, sliderRange: sliderRange,
@@ -242,7 +242,8 @@ class ThenContainer extends StatelessWidget {
'GW', 'GW',
'CPS', 'CPS',
"NCPS", "NCPS",
"WH" "WH",
'PC',
].contains(mutableData['productType'])) { ].contains(mutableData['productType'])) {
context.read<RoutineBloc>().add(AddToThenContainer(mutableData)); context.read<RoutineBloc>().add(AddToThenContainer(mutableData));
} }
@@ -38,7 +38,7 @@ class VisitorPasswordDialog extends StatelessWidget {
if (visitorBloc.passwordStatus!.failedOperations.isNotEmpty) if (visitorBloc.passwordStatus!.failedOperations.isNotEmpty)
Column( Column(
children: [ children: [
const Text('Failed Devises'), const Text('Failed Devices'),
SizedBox( SizedBox(
width: 200, width: 200,
height: 50, height: 50,
@@ -63,7 +63,7 @@ class VisitorPasswordDialog extends StatelessWidget {
if (visitorBloc.passwordStatus!.successOperations.isNotEmpty) if (visitorBloc.passwordStatus!.successOperations.isNotEmpty)
Column( Column(
children: [ children: [
const Text('Success Devises'), const Text('Success Devices'),
SizedBox( SizedBox(
width: 200, width: 200,
height: 50, height: 50,
+4 -1
View File
@@ -448,5 +448,8 @@ class Assets {
static const String indentLevelIcon = 'assets/icons/indent_level_icon.svg'; static const String indentLevelIcon = 'assets/icons/indent_level_icon.svg';
static const String triggerLevelIcon = 'assets/icons/trigger_level_icon.svg'; static const String triggerLevelIcon = 'assets/icons/trigger_level_icon.svg';
static const String blankCalendar = 'assets/icons/blank_calendar.svg'; static const String blankCalendar = 'assets/icons/blank_calendar.svg';
static const String refreshStatusIcon = 'assets/icons/refresh_status_icon.svg'; static const String refreshStatusIcon =
'assets/icons/refresh_status_icon.svg';
static const String energyConsumedIcon =
'assets/icons/energy_consumed_icon.svg';
} }
+2
View File
@@ -19,6 +19,7 @@ enum DeviceType {
WaterLeak, WaterLeak,
NCPS, NCPS,
DoorSensor, DoorSensor,
PC,
Other, Other,
} }
/* /*
@@ -59,4 +60,5 @@ Map<String, DeviceType> devicesTypesMap = {
'GD': DeviceType.GarageDoor, 'GD': DeviceType.GarageDoor,
'WL': DeviceType.WaterLeak, 'WL': DeviceType.WaterLeak,
'NCPS': DeviceType.NCPS, 'NCPS': DeviceType.NCPS,
'PC': DeviceType.PC,
}; };