mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Connected devices to widgets, and is currently making the necessary and correct api calls for everything to function properly.
This commit is contained in:
@ -33,6 +33,9 @@ class AnalyticsDevicesBloc
|
|||||||
selectedDevice: devices.firstOrNull,
|
selectedDevice: devices.firstOrNull,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
if (devices.isNotEmpty) {
|
||||||
|
event.onSuccess(devices.first);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(
|
emit(
|
||||||
AnalyticsDevicesState(
|
AnalyticsDevicesState(
|
||||||
@ -40,7 +43,7 @@ class AnalyticsDevicesBloc
|
|||||||
errorMessage: e.toString(),
|
errorMessage: e.toString(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onSelectAnalyticsDevice(
|
void _onSelectAnalyticsDevice(
|
||||||
|
@ -8,9 +8,10 @@ sealed class AnalyticsDevicesEvent extends Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final class LoadAnalyticsDevicesEvent extends AnalyticsDevicesEvent {
|
final class LoadAnalyticsDevicesEvent extends AnalyticsDevicesEvent {
|
||||||
const LoadAnalyticsDevicesEvent(this.param);
|
const LoadAnalyticsDevicesEvent({required this.param, required this.onSuccess});
|
||||||
|
|
||||||
final GetAnalyticsDevicesParam param;
|
final GetAnalyticsDevicesParam param;
|
||||||
|
final void Function(AnalyticsDevice device) onSuccess;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [param];
|
List<Object> get props => [param];
|
||||||
|
@ -92,13 +92,15 @@ abstract final class FetchEnergyManagementDataHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadRealtimeDeviceChanges(BuildContext context) {
|
static void loadRealtimeDeviceChanges(
|
||||||
|
BuildContext context, {
|
||||||
|
String? deviceUuid,
|
||||||
|
}) {
|
||||||
final selectedDevice = getSelectedDevice(context);
|
final selectedDevice = getSelectedDevice(context);
|
||||||
if (selectedDevice case final AnalyticsDevice device) {
|
|
||||||
context.read<RealtimeDeviceChangesBloc>().add(
|
context.read<RealtimeDeviceChangesBloc>().add(
|
||||||
RealtimeDeviceChangesStarted(device.uuid),
|
RealtimeDeviceChangesStarted(deviceUuid ?? selectedDevice?.uuid ?? ''),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadAnalyticsDevices(
|
static void loadAnalyticsDevices(
|
||||||
@ -108,7 +110,15 @@ abstract final class FetchEnergyManagementDataHelper {
|
|||||||
}) {
|
}) {
|
||||||
context.read<AnalyticsDevicesBloc>().add(
|
context.read<AnalyticsDevicesBloc>().add(
|
||||||
LoadAnalyticsDevicesEvent(
|
LoadAnalyticsDevicesEvent(
|
||||||
GetAnalyticsDevicesParam(
|
onSuccess: (device) {
|
||||||
|
context.read<PowerClampInfoBloc>().add(
|
||||||
|
LoadPowerClampInfoEvent(device.uuid),
|
||||||
|
);
|
||||||
|
context.read<RealtimeDeviceChangesBloc>().add(
|
||||||
|
RealtimeDeviceChangesStarted(device.uuid),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
param: GetAnalyticsDevicesParam(
|
||||||
communityUuid: communityUuid,
|
communityUuid: communityUuid,
|
||||||
spaceUuid: spaceUuid,
|
spaceUuid: spaceUuid,
|
||||||
deviceTypes: ['PC'],
|
deviceTypes: ['PC'],
|
||||||
@ -119,13 +129,12 @@ abstract final class FetchEnergyManagementDataHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void clearAllData(BuildContext context) {
|
static void clearAllData(BuildContext context) {
|
||||||
context.read<RealtimeDeviceChangesBloc>().add(
|
|
||||||
const RealtimeDeviceChangesClosed(),
|
|
||||||
);
|
|
||||||
|
|
||||||
context.read<PowerClampInfoBloc>().add(
|
context.read<PowerClampInfoBloc>().add(
|
||||||
const ClearPowerClampInfoEvent(),
|
const ClearPowerClampInfoEvent(),
|
||||||
);
|
);
|
||||||
|
context.read<RealtimeDeviceChangesBloc>().add(
|
||||||
|
const RealtimeDeviceChangesClosed(),
|
||||||
|
);
|
||||||
|
|
||||||
context.read<EnergyConsumptionPerDeviceBloc>().add(
|
context.read<EnergyConsumptionPerDeviceBloc>().add(
|
||||||
const ClearEnergyConsumptionPerDeviceEvent(),
|
const ClearEnergyConsumptionPerDeviceEvent(),
|
||||||
|
@ -6,7 +6,12 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
|
||||||
class PowerClampEnergyDataDeviceDropdown extends StatelessWidget {
|
class PowerClampEnergyDataDeviceDropdown extends StatelessWidget {
|
||||||
const PowerClampEnergyDataDeviceDropdown({super.key});
|
const PowerClampEnergyDataDeviceDropdown({
|
||||||
|
required this.onChanged,
|
||||||
|
super.key,
|
||||||
|
});
|
||||||
|
|
||||||
|
final ValueChanged<AnalyticsDevice> onChanged;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -42,7 +47,7 @@ class PowerClampEnergyDataDeviceDropdown extends StatelessWidget {
|
|||||||
items: state.devices.map((e) {
|
items: state.devices.map((e) {
|
||||||
return DropdownMenuItem(
|
return DropdownMenuItem(
|
||||||
value: e,
|
value: e,
|
||||||
child: Text(e.uuid),
|
child: Text(e.name),
|
||||||
);
|
);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
@ -50,6 +55,7 @@ class PowerClampEnergyDataDeviceDropdown extends StatelessWidget {
|
|||||||
context.read<AnalyticsDevicesBloc>().add(
|
context.read<AnalyticsDevicesBloc>().add(
|
||||||
SelectAnalyticsDeviceEvent(device),
|
SelectAnalyticsDeviceEvent(device),
|
||||||
);
|
);
|
||||||
|
onChanged.call(device);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/models/power_clamp_energy_status.dart';
|
import 'package:syncrow_web/pages/analytics/models/power_clamp_energy_status.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/power_clamp_info/power_clamp_info_bloc.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/blocs/power_clamp_info/power_clamp_info_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/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_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/energy_consumption_by_phases_chart_box.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/energy_consumption_by_phases_chart_box.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_data_device_dropdown.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_data_device_dropdown.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_status_widget.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_status_widget.dart';
|
||||||
@ -50,7 +52,8 @@ class PowerClampEnergyDataWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
SelectableText(
|
SelectableText(
|
||||||
state.powerClampModel?.productUuid ?? 'N/A',
|
context.watch<AnalyticsDevicesBloc>().state.selectedDevice?.uuid ??
|
||||||
|
'N/A',
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
@ -122,11 +125,18 @@ class PowerClampEnergyDataWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
const Expanded(
|
Expanded(
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
alignment: AlignmentDirectional.centerEnd,
|
alignment: AlignmentDirectional.centerEnd,
|
||||||
child: PowerClampEnergyDataDeviceDropdown(),
|
child: PowerClampEnergyDataDeviceDropdown(
|
||||||
|
onChanged: (value) {
|
||||||
|
FetchEnergyManagementDataHelper.loadRealtimeDeviceChanges(
|
||||||
|
context,
|
||||||
|
deviceUuid: value.uuid,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
@ -20,6 +20,7 @@ abstract final class FetchOccupancyDataHelper {
|
|||||||
}) {
|
}) {
|
||||||
if (communityId.isEmpty && spaceId.isEmpty) {
|
if (communityId.isEmpty && spaceId.isEmpty) {
|
||||||
clearAllData(context);
|
clearAllData(context);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final datePickerState = context.read<AnalyticsDatePickerBloc>().state;
|
final datePickerState = context.read<AnalyticsDatePickerBloc>().state;
|
||||||
@ -63,12 +64,17 @@ abstract final class FetchOccupancyDataHelper {
|
|||||||
}) {
|
}) {
|
||||||
context.read<AnalyticsDevicesBloc>().add(
|
context.read<AnalyticsDevicesBloc>().add(
|
||||||
LoadAnalyticsDevicesEvent(
|
LoadAnalyticsDevicesEvent(
|
||||||
GetAnalyticsDevicesParam(
|
param: GetAnalyticsDevicesParam(
|
||||||
communityUuid: communityUuid,
|
communityUuid: communityUuid,
|
||||||
spaceUuid: spaceUuid,
|
spaceUuid: spaceUuid,
|
||||||
deviceTypes: ['WPS', 'CPS'],
|
deviceTypes: ['WPS', 'CPS'],
|
||||||
requestType: AnalyticsDeviceRequestType.occupancy,
|
requestType: AnalyticsDeviceRequestType.occupancy,
|
||||||
),
|
),
|
||||||
|
onSuccess: (device) {
|
||||||
|
context.read<RealtimeDeviceChangesBloc>()
|
||||||
|
..add(const RealtimeDeviceChangesClosed())
|
||||||
|
..add(RealtimeDeviceChangesStarted(device.uuid));
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/models/power_clamp_energy_status.dart';
|
import 'package:syncrow_web/pages/analytics/models/power_clamp_energy_status.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/modules/energy_management/blocs/realtime_device_changes/realtime_device_changes_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/power_clamp_energy_data_device_dropdown.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_data_device_dropdown.dart';
|
||||||
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_status_widget.dart';
|
import 'package:syncrow_web/pages/analytics/modules/energy_management/widgets/power_clamp_energy_status_widget.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/device_status.dart';
|
||||||
@ -9,7 +11,6 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
|
||||||
|
|
||||||
class OccupancyEndSideBar extends StatelessWidget {
|
class OccupancyEndSideBar extends StatelessWidget {
|
||||||
const OccupancyEndSideBar({super.key});
|
const OccupancyEndSideBar({super.key});
|
||||||
@ -37,7 +38,8 @@ class OccupancyEndSideBar extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 6),
|
const SizedBox(height: 6),
|
||||||
SelectableText(
|
SelectableText(
|
||||||
(const Uuid().v4()),
|
context.watch<AnalyticsDevicesBloc>().state.selectedDevice?.uuid ??
|
||||||
|
'N/A',
|
||||||
style: context.textTheme.bodySmall?.copyWith(
|
style: context.textTheme.bodySmall?.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
@ -120,11 +122,17 @@ class OccupancyEndSideBar extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
const Expanded(
|
Expanded(
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
fit: BoxFit.scaleDown,
|
fit: BoxFit.scaleDown,
|
||||||
alignment: AlignmentDirectional.centerEnd,
|
alignment: AlignmentDirectional.centerEnd,
|
||||||
child: PowerClampEnergyDataDeviceDropdown(),
|
child: PowerClampEnergyDataDeviceDropdown(
|
||||||
|
onChanged: (value) =>
|
||||||
|
FetchEnergyManagementDataHelper.loadRealtimeDeviceChanges(
|
||||||
|
context,
|
||||||
|
deviceUuid: value.uuid,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user