mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Compare commits
32 Commits
SP-1408-FE
...
bugfix/fix
Author | SHA1 | Date | |
---|---|---|---|
acefe6b433 | |||
63bc7a56de | |||
7b3635deae | |||
58755eafe1 | |||
ce225818fb | |||
8762a7aaa8 | |||
8dc833b2c3 | |||
13cef151aa | |||
ab23be9828 | |||
687b68ab22 | |||
25614c3dd0 | |||
7cbe20ae88 | |||
349fe6c555 | |||
9779f3783c | |||
fe3db663b6 | |||
888d444752 | |||
bab5e06968 | |||
d7b6174dee | |||
6ef0b2f9d1 | |||
3ceb03826e | |||
52608b1f35 | |||
ac2996629e | |||
51c52c66cb | |||
0f56273d99 | |||
34d4d892d9 | |||
3193fd26fe | |||
43802a9fad | |||
6e0b1775f0 | |||
233fb2ee2c | |||
b26928b3d5 | |||
6fc35a7b9a | |||
756457927c |
@ -1,8 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/default_button.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';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class SearchResetButtons extends StatelessWidget {
|
||||
const SearchResetButtons({
|
||||
@ -17,8 +17,10 @@ class SearchResetButtons extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 25),
|
||||
|
@ -108,7 +108,7 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
||||
return DeviceManagementBody(
|
||||
devices: deviceState.filteredDevices);
|
||||
} else {
|
||||
return const Center(child: Text('Error fetching Devices'));
|
||||
return const DeviceManagementBody(devices: []);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -72,6 +72,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
child: state is DeviceManagementLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
padding: isLargeScreenSize(context)
|
||||
|
@ -14,29 +14,29 @@ class DeviceSearchFilters extends StatefulWidget {
|
||||
|
||||
class _DeviceSearchFiltersState extends State<DeviceSearchFilters>
|
||||
with HelperResponsiveLayout {
|
||||
final _unitNameController = TextEditingController();
|
||||
final _productNameController = TextEditingController();
|
||||
late final TextEditingController _unitNameController;
|
||||
late final TextEditingController _productNameController;
|
||||
|
||||
List<Widget> get _widgets => [
|
||||
_buildSearchField("Space Name", _unitNameController, 200),
|
||||
_buildSearchField("Device Name / Product Name", _productNameController, 300),
|
||||
_buildSearchResetButtons(),
|
||||
];
|
||||
@override
|
||||
void initState() {
|
||||
_unitNameController = TextEditingController();
|
||||
_productNameController = TextEditingController();
|
||||
super.initState();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (isExtraLargeScreenSize(context)) {
|
||||
return Row(
|
||||
children: _widgets
|
||||
.map((e) => Padding(padding: const EdgeInsets.all(10), child: e))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
return Wrap(
|
||||
alignment: WrapAlignment.start,
|
||||
runAlignment: WrapAlignment.start,
|
||||
crossAxisAlignment: WrapCrossAlignment.center,
|
||||
spacing: 20,
|
||||
runSpacing: 10,
|
||||
children: _widgets,
|
||||
children: [
|
||||
_buildSearchField("Space Name", _unitNameController, 200),
|
||||
_buildSearchField("Device Name / Product Name", _productNameController, 300),
|
||||
_buildSearchResetButtons(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,10 @@ class FlushMountedPresenceSensorChangeValueEvent
|
||||
extends FlushMountedPresenceSensorEvent {
|
||||
final int value;
|
||||
final String code;
|
||||
final bool isBatchControl;
|
||||
|
||||
const FlushMountedPresenceSensorChangeValueEvent({
|
||||
required this.value,
|
||||
required this.code,
|
||||
this.isBatchControl = false,
|
||||
});
|
||||
|
||||
@override
|
||||
|
@ -75,7 +75,7 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.nearDetection / 100).toDouble(),
|
||||
value: (model.nearDetection / 100).clamp(0.0, double.infinity),
|
||||
title: 'Nearest Detect Dist:',
|
||||
description: 'm',
|
||||
minValue: 0.0,
|
||||
@ -92,7 +92,7 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.farDetection / 100).toDouble(),
|
||||
value: (model.farDetection / 100).clamp(0.0, double.infinity),
|
||||
title: 'Max Detect Dist:',
|
||||
description: 'm',
|
||||
minValue: 0.0,
|
||||
@ -109,7 +109,7 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: model.presenceDelay.toDouble(),
|
||||
value: model.sensiReduce.toDouble(),
|
||||
title: 'Trigger Level:',
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
@ -117,7 +117,7 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codePresenceDelay,
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
@ -137,19 +137,21 @@ class FlushMountedPresenceSensorBatchControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.sensiReduce.toDouble()),
|
||||
value: (model.presenceDelay / 10).toDouble(),
|
||||
title: 'Target Confirm Time:',
|
||||
description: 's',
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
minValue: 0.0,
|
||||
maxValue: 0.5,
|
||||
steps: 0.1,
|
||||
valuesPercision: 1,
|
||||
action: (double value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorBatchControlEvent(
|
||||
deviceIds: devicesIds,
|
||||
code: FlushMountedPresenceSensorModel.codePresenceDelay,
|
||||
value: (value * 10).toInt(),
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: ((model.noneDelay / 10).toDouble()),
|
||||
|
@ -15,7 +15,7 @@ import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_la
|
||||
|
||||
class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
const FlushMountedPresenceSensorControlView({super.key, required this.device});
|
||||
const FlushMountedPresenceSensorControlView({required this.device, super.key});
|
||||
|
||||
final AllDevicesModel device;
|
||||
|
||||
@ -113,7 +113,7 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.nearDetection / 100).toDouble(),
|
||||
value: (model.nearDetection / 100).clamp(0.0, double.infinity),
|
||||
title: 'Nearest Detect Dist:',
|
||||
description: 'm',
|
||||
minValue: 0.0,
|
||||
@ -129,7 +129,7 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.farDetection / 100).toDouble(),
|
||||
value: (model.farDetection / 100).clamp(0.0, double.infinity),
|
||||
title: 'Max Detect Dist:',
|
||||
description: 'm',
|
||||
minValue: 0.0,
|
||||
@ -145,20 +145,20 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.presenceDelay.toDouble()),
|
||||
value: model.sensiReduce.toDouble(),
|
||||
title: 'Trigger Level:',
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codePresenceDelay,
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.occurDistReduce.toDouble()),
|
||||
value: model.occurDistReduce.toDouble(),
|
||||
title: 'Indent Level:',
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
@ -171,21 +171,23 @@ class FlushMountedPresenceSensorControlView extends StatelessWidget
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: (model.sensiReduce.toDouble()),
|
||||
value: (model.presenceDelay / 10).toDouble(),
|
||||
valuesPercision: 1,
|
||||
title: 'Target Confirm Time:',
|
||||
description: 's',
|
||||
minValue: 0,
|
||||
maxValue: 3,
|
||||
steps: 1,
|
||||
action: (int value) => context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codeSensiReduce,
|
||||
value: value,
|
||||
),
|
||||
),
|
||||
minValue: 0.0,
|
||||
maxValue: 0.5,
|
||||
steps: 0.1,
|
||||
action: (double value) =>
|
||||
context.read<FlushMountedPresenceSensorBloc>().add(
|
||||
FlushMountedPresenceSensorChangeValueEvent(
|
||||
code: FlushMountedPresenceSensorModel.codePresenceDelay,
|
||||
value: (value * 10).toInt(),
|
||||
),
|
||||
),
|
||||
),
|
||||
PresenceUpdateData(
|
||||
value: ((model.noneDelay / 10).toDouble()),
|
||||
value: (model.noneDelay / 10).toDouble(),
|
||||
description: 's',
|
||||
title: 'Disappe Delay:',
|
||||
minValue: 20,
|
||||
|
@ -217,29 +217,31 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
try {
|
||||
var status =
|
||||
await DevicesManagementApi().getPowerClampInfo(event.deviceId);
|
||||
deviceStatus = PowerClampModel.fromJson(status);
|
||||
|
||||
deviceStatus = PowerClampModel.fromJson(status as Map<String, Object?>? ??{});
|
||||
final phaseADataPoints = deviceStatus.status.phaseA.dataPoints;
|
||||
final phaseBDataPoints = deviceStatus.status.phaseB.dataPoints;
|
||||
final phaseCDataPoints = deviceStatus.status.phaseC.dataPoints;
|
||||
phaseData = [
|
||||
{
|
||||
'name': 'Phase A',
|
||||
'voltage': '${deviceStatus.status.phaseA.dataPoints[0].value / 10} V',
|
||||
'current': '${deviceStatus.status.phaseA.dataPoints[1].value / 10} A',
|
||||
'activePower': '${deviceStatus.status.phaseA.dataPoints[2].value} W',
|
||||
'powerFactor': '${deviceStatus.status.phaseA.dataPoints[3].value}',
|
||||
'voltage': '${(phaseADataPoints.elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current': '${(phaseADataPoints.elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower': '${phaseADataPoints.elementAtOrNull(2)?.value??'N/A'} W',
|
||||
'powerFactor': '${phaseADataPoints.elementAtOrNull(3)?.value??'N/A'}',
|
||||
},
|
||||
{
|
||||
'name': 'Phase B',
|
||||
'voltage': '${deviceStatus.status.phaseB.dataPoints[0].value / 10} V',
|
||||
'current': '${deviceStatus.status.phaseB.dataPoints[1].value / 10} A',
|
||||
'activePower': '${deviceStatus.status.phaseB.dataPoints[2].value} W',
|
||||
'powerFactor': '${deviceStatus.status.phaseB.dataPoints[3].value}',
|
||||
'voltage': '${(phaseBDataPoints .elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current': '${(phaseBDataPoints .elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower': '${phaseBDataPoints.elementAtOrNull(2)?.value??'N/A'} W',
|
||||
'powerFactor': '${phaseBDataPoints.elementAtOrNull(3)?.value??'N/A'}',
|
||||
},
|
||||
{
|
||||
'name': 'Phase C',
|
||||
'voltage': '${deviceStatus.status.phaseC.dataPoints[0].value / 10} V',
|
||||
'current': '${deviceStatus.status.phaseC.dataPoints[1].value / 10} A',
|
||||
'activePower': '${deviceStatus.status.phaseC.dataPoints[2].value} W',
|
||||
'powerFactor': '${deviceStatus.status.phaseC.dataPoints[3].value}',
|
||||
'voltage': '${(phaseCDataPoints.elementAtOrNull(0)?.value as num? ?? 0) / 10} V',
|
||||
'current': '${(phaseCDataPoints.elementAtOrNull(1)?.value as num? ?? 0) / 10} A',
|
||||
'activePower': '${phaseCDataPoints.elementAtOrNull(2)?.value ?? 'N/A'} W',
|
||||
'powerFactor': '${phaseCDataPoints.elementAtOrNull(3)?.value ?? 'N/A'}',
|
||||
},
|
||||
];
|
||||
emit(GetDeviceStatus());
|
||||
@ -785,7 +787,7 @@ class SmartPowerBloc extends Bloc<SmartPowerEvent, SmartPowerState> {
|
||||
void selectDateRange() async {
|
||||
DateTime startDate = dateTime!;
|
||||
DateTime endDate = DateTime(startDate.year, startDate.month + 1, 1)
|
||||
.subtract(Duration(days: 1));
|
||||
.subtract(const Duration(days: 1));
|
||||
String formattedEndDate = DateFormat('dd/MM/yyyy').format(endDate);
|
||||
endChartDate = ' - $formattedEndDate';
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ class PowerClampModel {
|
||||
|
||||
factory PowerClampModel.fromJson(Map<String, dynamic> json) {
|
||||
return PowerClampModel(
|
||||
productUuid: json['productUuid'],
|
||||
productType: json['productType'],
|
||||
status: PowerStatus.fromJson(json['status']),
|
||||
productUuid: json['productUuid'] as String? ?? '',
|
||||
productType: json['productType'] as String? ?? '',
|
||||
status: PowerStatus.fromJson(json['status'] as Map<String, dynamic>? ?? {}),
|
||||
);
|
||||
}
|
||||
|
||||
@ -26,7 +26,7 @@ class PowerClampModel {
|
||||
return PowerClampModel(
|
||||
productUuid: productUuid ?? this.productUuid,
|
||||
productType: productType ?? this.productType,
|
||||
status: statusPower ?? this.status,
|
||||
status: statusPower ?? status,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -46,12 +46,10 @@ class PowerStatus {
|
||||
|
||||
factory PowerStatus.fromJson(Map<String, dynamic> json) {
|
||||
return PowerStatus(
|
||||
phaseA: Phase.fromJson(json['phaseA']),
|
||||
phaseB: Phase.fromJson(json['phaseB']),
|
||||
phaseC: Phase.fromJson(json['phaseC']),
|
||||
general: Phase.fromJson(json['general']
|
||||
// List<DataPoint>.from(
|
||||
// json['general'].map((x) => DataPoint.fromJson(x))),
|
||||
phaseA: Phase.fromJson(json['phaseA']as List<dynamic>? ?? []),
|
||||
phaseB: Phase.fromJson(json['phaseB']as List<dynamic>? ?? []),
|
||||
phaseC: Phase.fromJson(json['phaseC']as List<dynamic>? ?? []),
|
||||
general: Phase.fromJson(json['general']as List<dynamic>? ?? []
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -69,30 +67,30 @@ class Phase {
|
||||
}
|
||||
|
||||
class DataPoint {
|
||||
dynamic code;
|
||||
dynamic customName;
|
||||
dynamic dpId;
|
||||
dynamic time;
|
||||
dynamic type;
|
||||
dynamic value;
|
||||
final String? code;
|
||||
final String? customName;
|
||||
final int? dpId;
|
||||
final int? time;
|
||||
final String? type;
|
||||
final dynamic value;
|
||||
|
||||
DataPoint({
|
||||
required this.code,
|
||||
required this.customName,
|
||||
required this.dpId,
|
||||
required this.time,
|
||||
required this.type,
|
||||
required this.value,
|
||||
this.code,
|
||||
this.customName,
|
||||
this.dpId,
|
||||
this.time,
|
||||
this.type,
|
||||
this.value,
|
||||
});
|
||||
|
||||
factory DataPoint.fromJson(Map<String, dynamic> json) {
|
||||
return DataPoint(
|
||||
code: json['code'],
|
||||
customName: json['customName'],
|
||||
dpId: json['dpId'],
|
||||
time: json['time'],
|
||||
type: json['type'],
|
||||
value: json['value'],
|
||||
code: json['code'] as String?,
|
||||
customName: json['customName'] as String?,
|
||||
dpId: json['dpId'] as int?,
|
||||
time: json['time'] as int?,
|
||||
type: json['type'] as String?,
|
||||
value: json['value'] as dynamic,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fl_chart/fl_chart.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class EnergyConsumptionPage extends StatefulWidget {
|
||||
@ -10,7 +10,8 @@ class EnergyConsumptionPage extends StatefulWidget {
|
||||
final Widget widget;
|
||||
final Function()? onTap;
|
||||
|
||||
EnergyConsumptionPage({
|
||||
const EnergyConsumptionPage({
|
||||
super.key,
|
||||
required this.chartData,
|
||||
required this.totalConsumption,
|
||||
required this.date,
|
||||
@ -91,11 +92,12 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
],
|
||||
),
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: SizedBox(
|
||||
height: MediaQuery.of(context).size.height * 0.11,
|
||||
height: MediaQuery.sizeOf(context).height * 0.09,
|
||||
child: LineChart(
|
||||
LineChartData(
|
||||
lineTouchData: LineTouchData(
|
||||
@ -151,7 +153,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
child: RotatedBox(
|
||||
quarterTurns: -1,
|
||||
child: Text(_chartData[index].time,
|
||||
style: TextStyle(fontSize: 10)),
|
||||
style: const TextStyle(fontSize: 10)),
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -190,8 +192,8 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
spots: _chartData
|
||||
.asMap()
|
||||
.entries
|
||||
.map((entry) => FlSpot(entry.key.toDouble(),
|
||||
entry.value.consumption))
|
||||
.map((entry) => FlSpot(
|
||||
entry.key.toDouble(), entry.value.consumption))
|
||||
.toList(),
|
||||
isCurved: true,
|
||||
color: ColorsManager.primaryColor.withOpacity(0.6),
|
||||
@ -218,7 +220,7 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
borderData: FlBorderData(
|
||||
show: false,
|
||||
border: Border.all(
|
||||
color: Color(0xff023DFE).withOpacity(0.7),
|
||||
color: const Color(0xff023DFE).withOpacity(0.7),
|
||||
width: 10,
|
||||
),
|
||||
),
|
||||
@ -253,11 +255,9 @@ class _EnergyConsumptionPageState extends State<EnergyConsumptionPage> {
|
||||
child: InkWell(
|
||||
onTap: widget.onTap,
|
||||
child: Center(
|
||||
child: SizedBox(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Text(widget.date),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: Text(widget.date),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -12,8 +12,7 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
|
||||
//Smart Power Clamp
|
||||
class SmartPowerDeviceControl extends StatelessWidget
|
||||
with HelperResponsiveLayout {
|
||||
class SmartPowerDeviceControl extends StatelessWidget with HelperResponsiveLayout {
|
||||
final String deviceId;
|
||||
|
||||
const SmartPowerDeviceControl({super.key, required this.deviceId});
|
||||
@ -25,27 +24,27 @@ class SmartPowerDeviceControl extends StatelessWidget
|
||||
..add(SmartPowerFetchDeviceEvent(deviceId)),
|
||||
child: BlocBuilder<SmartPowerBloc, SmartPowerState>(
|
||||
builder: (context, state) {
|
||||
final _blocProvider = BlocProvider.of<SmartPowerBloc>(context);
|
||||
final blocProvider = BlocProvider.of<SmartPowerBloc>(context);
|
||||
|
||||
if (state is SmartPowerLoading) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is FakeState) {
|
||||
return _buildStatusControls(
|
||||
currentPage: _blocProvider.currentPage,
|
||||
currentPage: blocProvider.currentPage,
|
||||
context: context,
|
||||
blocProvider: _blocProvider,
|
||||
blocProvider: blocProvider,
|
||||
);
|
||||
} else if (state is GetDeviceStatus) {
|
||||
return _buildStatusControls(
|
||||
currentPage: _blocProvider.currentPage,
|
||||
currentPage: blocProvider.currentPage,
|
||||
context: context,
|
||||
blocProvider: _blocProvider,
|
||||
blocProvider: blocProvider,
|
||||
);
|
||||
} else if (state is FilterRecordsState) {
|
||||
return _buildStatusControls(
|
||||
currentPage: _blocProvider.currentPage,
|
||||
currentPage: blocProvider.currentPage,
|
||||
context: context,
|
||||
blocProvider: _blocProvider,
|
||||
blocProvider: blocProvider,
|
||||
);
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
@ -60,7 +59,7 @@ class SmartPowerDeviceControl extends StatelessWidget
|
||||
required SmartPowerBloc blocProvider,
|
||||
required int currentPage,
|
||||
}) {
|
||||
PageController _pageController = PageController(initialPage: currentPage);
|
||||
PageController pageController = PageController(initialPage: currentPage);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 50),
|
||||
child: DeviceControlsContainer(
|
||||
@ -85,25 +84,31 @@ class SmartPowerDeviceControl extends StatelessWidget
|
||||
PowerClampInfoCard(
|
||||
iconPath: Assets.powerActiveIcon,
|
||||
title: 'Active',
|
||||
value: blocProvider
|
||||
.deviceStatus.status.general.dataPoints[2].value
|
||||
.toString(),
|
||||
value: blocProvider.deviceStatus.status.general.dataPoints
|
||||
.elementAtOrNull(2)
|
||||
?.value
|
||||
.toString() ??
|
||||
'',
|
||||
unit: '',
|
||||
),
|
||||
PowerClampInfoCard(
|
||||
iconPath: Assets.voltMeterIcon,
|
||||
title: 'Current',
|
||||
value: blocProvider
|
||||
.deviceStatus.status.general.dataPoints[1].value
|
||||
.toString(),
|
||||
value: blocProvider.deviceStatus.status.general.dataPoints
|
||||
.elementAtOrNull(1)
|
||||
?.value
|
||||
.toString() ??
|
||||
'',
|
||||
unit: ' A',
|
||||
),
|
||||
PowerClampInfoCard(
|
||||
iconPath: Assets.frequencyIcon,
|
||||
title: 'Frequency',
|
||||
value: blocProvider
|
||||
.deviceStatus.status.general.dataPoints[4].value
|
||||
.toString(),
|
||||
value: blocProvider.deviceStatus.status.general.dataPoints
|
||||
.elementAtOrNull(4)
|
||||
?.value
|
||||
.toString() ??
|
||||
'',
|
||||
unit: ' Hz',
|
||||
),
|
||||
],
|
||||
@ -142,7 +147,7 @@ class SmartPowerDeviceControl extends StatelessWidget
|
||||
icon: const Icon(Icons.arrow_left),
|
||||
onPressed: () {
|
||||
blocProvider.add(SmartPowerArrowPressedEvent(-1));
|
||||
_pageController.previousPage(
|
||||
pageController.previousPage(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
@ -162,7 +167,7 @@ class SmartPowerDeviceControl extends StatelessWidget
|
||||
icon: const Icon(Icons.arrow_right),
|
||||
onPressed: () {
|
||||
blocProvider.add(SmartPowerArrowPressedEvent(1));
|
||||
_pageController.nextPage(
|
||||
pageController.nextPage(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
@ -177,7 +182,7 @@ class SmartPowerDeviceControl extends StatelessWidget
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: PageView(
|
||||
controller: _pageController,
|
||||
controller: pageController,
|
||||
onPageChanged: (int page) {
|
||||
blocProvider.add(SmartPowerPageChangedEvent(page));
|
||||
},
|
||||
@ -190,8 +195,8 @@ class SmartPowerDeviceControl extends StatelessWidget
|
||||
blocProvider.add(SelectDateEvent(context: context));
|
||||
blocProvider.add(FilterRecordsByDateEvent(
|
||||
selectedDate: blocProvider.dateTime!,
|
||||
viewType: blocProvider
|
||||
.views[blocProvider.currentIndex]));
|
||||
viewType:
|
||||
blocProvider.views[blocProvider.currentIndex]));
|
||||
},
|
||||
widget: blocProvider.dateSwitcher(),
|
||||
chartData: blocProvider.energyDataList.isNotEmpty
|
||||
|
@ -30,8 +30,8 @@ class _RoutinesViewState extends State<RoutinesView> {
|
||||
final spaceId = result['space'];
|
||||
final bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
||||
final routineBloc = context.read<RoutineBloc>();
|
||||
bloc.add(
|
||||
SaveCommunityIdAndSpaceIdEvent(communityID: communityId, spaceID: spaceId));
|
||||
bloc.add(SaveCommunityIdAndSpaceIdEvent(
|
||||
communityID: communityId, spaceID: spaceId));
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
routineBloc.add(const CreateNewRoutineViewEvent(createRoutineView: true));
|
||||
}
|
||||
@ -61,34 +61,38 @@ class _RoutinesViewState extends State<RoutinesView> {
|
||||
width: context.screenWidth,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsetsDirectional.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
spacing: 16,
|
||||
children: [
|
||||
Text(
|
||||
"Create New Routines",
|
||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
RoutineViewCard(
|
||||
isLoading: false,
|
||||
onChanged: (v) {},
|
||||
status: '',
|
||||
spaceId: '',
|
||||
automationId: '',
|
||||
communityId: '',
|
||||
sceneId: '',
|
||||
cardType: '',
|
||||
spaceName: '',
|
||||
onTap: () => _handleRoutineCreation(context),
|
||||
icon: Icons.add,
|
||||
textString: '',
|
||||
),
|
||||
const FetchRoutineScenesAutomation(),
|
||||
],
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(left: 20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
spacing: 16,
|
||||
children: [
|
||||
Text(
|
||||
"Create New Routines",
|
||||
style:
|
||||
Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
RoutineViewCard(
|
||||
isLoading: false,
|
||||
onChanged: (v) {},
|
||||
status: '',
|
||||
spaceId: '',
|
||||
automationId: '',
|
||||
communityId: '',
|
||||
sceneId: '',
|
||||
cardType: '',
|
||||
spaceName: '',
|
||||
onTap: () => _handleRoutineCreation(context),
|
||||
icon: Icons.add,
|
||||
textString: '',
|
||||
),
|
||||
const FetchRoutineScenesAutomation(),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -16,7 +16,8 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading) return const Center(child: CircularProgressIndicator());
|
||||
if (state.isLoading)
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
|
||||
return SingleChildScrollView(
|
||||
child: Padding(
|
||||
@ -40,7 +41,8 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
||||
const SizedBox(height: 3),
|
||||
Visibility(
|
||||
visible: state.automations.isNotEmpty,
|
||||
replacement: _buildEmptyState(context, "No automations found"),
|
||||
replacement:
|
||||
_buildEmptyState(context, "No automations found"),
|
||||
child: SizedBox(
|
||||
height: 200,
|
||||
child: _buildAutomations(state),
|
||||
@ -59,7 +61,8 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
||||
scrollDirection: Axis.horizontal,
|
||||
itemCount: state.automations.length,
|
||||
itemBuilder: (context, index) {
|
||||
final isLoading = state.automations.contains(state.automations[index].id);
|
||||
final isLoading =
|
||||
state.automations.contains(state.automations[index].id);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@ -179,10 +182,13 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(BuildContext context, String title) {
|
||||
return Text(
|
||||
title,
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 100),
|
||||
child: Text(
|
||||
title,
|
||||
style: context.textTheme.bodyMedium?.copyWith(
|
||||
color: ColorsManager.grayColor,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/common/bloc/project_manager.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/space_tree/bloc/space_tree_state.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
@ -246,7 +247,9 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
final previousState = state;
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc);
|
||||
var spaceTreeState = event.context.read<SpaceTreeBloc>().state;
|
||||
|
||||
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc, spaceTreeState);
|
||||
await fetchSpaceModels();
|
||||
await fetchTags();
|
||||
|
||||
@ -277,11 +280,13 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
LoadCommunityAndSpacesEvent event,
|
||||
Emitter<SpaceManagementState> emit,
|
||||
) async {
|
||||
var spaceTreeState = event.context.read<SpaceTreeBloc>().state;
|
||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
|
||||
_onloadProducts();
|
||||
await fetchTags();
|
||||
// Wait until `communityList` is loaded
|
||||
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc);
|
||||
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc, spaceTreeState);
|
||||
|
||||
// Fetch space models after communities are available
|
||||
final prevSpaceModels = await fetchSpaceModels();
|
||||
@ -292,23 +297,38 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
allTags: _cachedTags ?? []));
|
||||
}
|
||||
|
||||
Future<List<CommunityModel>> _waitForCommunityList(SpaceTreeBloc spaceBloc) async {
|
||||
Future<List<CommunityModel>> _waitForCommunityList(
|
||||
SpaceTreeBloc spaceBloc, SpaceTreeState spaceTreeState) async {
|
||||
// Check if communityList is already populated
|
||||
if (spaceBloc.state.communityList.isNotEmpty) {
|
||||
return spaceBloc.state.communityList;
|
||||
final filteredCommunities = spaceTreeState.searchQuery.isNotEmpty
|
||||
? spaceTreeState.filteredCommunity
|
||||
: spaceTreeState.communityList;
|
||||
if (filteredCommunities.isNotEmpty) {
|
||||
return filteredCommunities;
|
||||
}
|
||||
|
||||
final completer = Completer<List<CommunityModel>>();
|
||||
final subscription = spaceBloc.stream.listen((state) {
|
||||
if (state.communityList.isNotEmpty) {
|
||||
completer.complete(state.communityList);
|
||||
if (!completer.isCompleted && state.communityList.isNotEmpty) {
|
||||
completer
|
||||
.complete(state.searchQuery.isNotEmpty ? state.filteredCommunity : state.communityList);
|
||||
}
|
||||
});
|
||||
try {
|
||||
final communities = await completer.future.timeout(
|
||||
const Duration(seconds: 10),
|
||||
onTimeout: () {
|
||||
if (!completer.isCompleted) {
|
||||
completer.complete([]);
|
||||
}
|
||||
return [];
|
||||
},
|
||||
);
|
||||
|
||||
// Return the list once available, then cancel the listener
|
||||
final communities = await completer.future;
|
||||
await subscription.cancel();
|
||||
return communities;
|
||||
return communities;
|
||||
} finally {
|
||||
await subscription.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void _onCommunityDelete(
|
||||
@ -446,6 +466,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
|
||||
if (previousState is SpaceManagementLoaded) {
|
||||
await _updateLoadedState(
|
||||
event.context,
|
||||
previousState,
|
||||
allSpaces,
|
||||
event.communityUuid,
|
||||
@ -462,6 +483,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
}
|
||||
|
||||
Future<void> _updateLoadedState(
|
||||
BuildContext context,
|
||||
SpaceManagementLoaded previousState,
|
||||
List<SpaceModel> allSpaces,
|
||||
String communityUuid,
|
||||
@ -469,7 +491,10 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
) async {
|
||||
var prevSpaceModels = await fetchSpaceModels();
|
||||
await fetchTags();
|
||||
final communities = List<CommunityModel>.from(previousState.communities);
|
||||
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
||||
final communities = spaceTreeState.searchQuery.isNotEmpty
|
||||
? spaceTreeState.filteredCommunity
|
||||
: spaceTreeState.communityList;
|
||||
|
||||
for (var community in communities) {
|
||||
if (community.uuid == communityUuid) {
|
||||
@ -484,6 +509,8 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
spaceModels: prevSpaceModels,
|
||||
allTags: _cachedTags ?? []));
|
||||
return;
|
||||
} else {
|
||||
print("Community not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -491,12 +518,21 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
Future<List<SpaceModel>> saveSpacesHierarchically(
|
||||
BuildContext context, List<SpaceModel> spaces, String communityUuid) async {
|
||||
final orderedSpaces = flattenHierarchy(spaces);
|
||||
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||
List<CommunityModel> communities = spaceBloc.state.communityList;
|
||||
CommunityModel? selectedCommunity = communities.firstWhere(
|
||||
(community) => community.uuid == communityUuid,
|
||||
);
|
||||
CommunityModel? selectedCommunity;
|
||||
try {
|
||||
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
||||
final filteredCommunities = spaceTreeState.searchQuery.isNotEmpty
|
||||
? spaceTreeState.filteredCommunity
|
||||
: spaceTreeState.communityList;
|
||||
|
||||
selectedCommunity = filteredCommunities.firstWhere(
|
||||
(community) => community.uuid == communityUuid,
|
||||
);
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
|
||||
final parentsToDelete = orderedSpaces.where((space) =>
|
||||
space.status == SpaceStatus.deleted &&
|
||||
@ -605,11 +641,11 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
projectId: projectUuid);
|
||||
} else {
|
||||
// Call create if the space does not have a UUID
|
||||
final List<CreateTagBodyModel> tagBodyModels = space.tags != null
|
||||
List<CreateTagBodyModel> tagBodyModels = space.tags != null
|
||||
? space.tags!.map((tag) => tag.toCreateTagBodyModel()).toList()
|
||||
: [];
|
||||
|
||||
final createSubspaceBodyModels = space.subspaces?.map((subspace) {
|
||||
var createSubspaceBodyModels = space.subspaces?.map((subspace) {
|
||||
final tagBodyModels =
|
||||
subspace.tags?.map((tag) => tag.toCreateTagBodyModel()).toList() ?? [];
|
||||
return CreateSubspaceModel()
|
||||
@ -618,6 +654,11 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
}).toList() ??
|
||||
[];
|
||||
|
||||
if (space.spaceModel?.uuid != null) {
|
||||
tagBodyModels = [];
|
||||
createSubspaceBodyModels = [];
|
||||
}
|
||||
|
||||
final response = await _api.createSpace(
|
||||
communityId: communityUuid,
|
||||
name: space.name,
|
||||
@ -669,9 +710,12 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
|
||||
try {
|
||||
await fetchTags();
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
List<CommunityModel> communities = spaceBloc.state.communityList;
|
||||
final spaceTreeState = event.context.read<SpaceTreeBloc>().state;
|
||||
final filteredCommunities = spaceTreeState.searchQuery.isNotEmpty
|
||||
? spaceTreeState.filteredCommunity
|
||||
: spaceTreeState.communityList;
|
||||
|
||||
List<CommunityModel> communities = filteredCommunities;
|
||||
|
||||
var prevSpaceModels = await fetchSpaceModels();
|
||||
|
||||
|
@ -72,6 +72,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
_nameController = TextEditingController(
|
||||
text: widget.selectedCommunity?.name ?? '',
|
||||
);
|
||||
realignTree();
|
||||
|
||||
_transformationController = TransformationController();
|
||||
if (widget.selectedSpace != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
@ -96,6 +98,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||
_adjustCanvasSizeForSpaces();
|
||||
realignTree();
|
||||
});
|
||||
}
|
||||
|
||||
@ -404,12 +407,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
|
||||
List<SpaceModel> flattenSpaces(List<SpaceModel> spaces) {
|
||||
List<SpaceModel> result = [];
|
||||
Map<String, SpaceModel> idToSpace = {};
|
||||
|
||||
void flatten(SpaceModel space) {
|
||||
if (space.status == SpaceStatus.deleted || space.status == SpaceStatus.parentDeleted) {
|
||||
return;
|
||||
}
|
||||
result.add(space);
|
||||
idToSpace[space.internalId] = space;
|
||||
|
||||
for (var child in space.children) {
|
||||
flatten(child);
|
||||
}
|
||||
@ -419,6 +425,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
flatten(space);
|
||||
}
|
||||
|
||||
for (var space in result) {
|
||||
if (space.parent != null) {
|
||||
space.parent = idToSpace[space.parent!.internalId];
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -467,7 +479,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
}
|
||||
|
||||
String communityUuid = widget.selectedCommunity!.uuid;
|
||||
|
||||
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
|
||||
context,
|
||||
spaces: spacesToSave,
|
||||
@ -692,92 +703,72 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
}
|
||||
|
||||
void _duplicateSpace(SpaceModel space) {
|
||||
final double horizontalGap = 250.0;
|
||||
final double verticalGap = 180.0;
|
||||
final double nodeWidth = 200;
|
||||
final double nodeHeight = 100;
|
||||
final double breathingSpace = 300.0; // extra gap after original tree
|
||||
setState(() {
|
||||
SpaceModel? parent = space.parent;
|
||||
|
||||
/// Helper to recursively duplicate a node and its children
|
||||
SpaceModel duplicateRecursive(SpaceModel original, SpaceModel? duplicatedParent) {
|
||||
final duplicatedName = SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||
final duplicated = SpaceModel(
|
||||
name: duplicatedName,
|
||||
icon: original.icon,
|
||||
position: Offset.zero,
|
||||
isPrivate: original.isPrivate,
|
||||
children: [],
|
||||
status: SpaceStatus.newSpace,
|
||||
parent: duplicatedParent,
|
||||
spaceModel: original.spaceModel,
|
||||
subspaces: original.subspaces,
|
||||
tags: original.tags,
|
||||
);
|
||||
SpaceModel duplicated = _deepCloneSpaceTree(space, parent: parent);
|
||||
|
||||
spaces.add(duplicated);
|
||||
duplicated.position = Offset(space.position.dx + 300, space.position.dy + 100);
|
||||
List<SpaceModel> duplicatedSubtree = [];
|
||||
void collectSubtree(SpaceModel node) {
|
||||
duplicatedSubtree.add(node);
|
||||
for (var child in node.children) {
|
||||
collectSubtree(child);
|
||||
}
|
||||
}
|
||||
|
||||
collectSubtree(duplicated);
|
||||
spaces.addAll(duplicatedSubtree);
|
||||
|
||||
if (parent != null) {
|
||||
parent.children.add(duplicated);
|
||||
|
||||
if (duplicatedParent != null) {
|
||||
final newConnection = Connection(
|
||||
startSpace: duplicatedParent,
|
||||
startSpace: parent,
|
||||
endSpace: duplicated,
|
||||
direction: "down",
|
||||
);
|
||||
connections.add(newConnection);
|
||||
duplicated.incomingConnection = newConnection;
|
||||
duplicatedParent.addOutgoingConnection(newConnection);
|
||||
duplicatedParent.children.add(duplicated);
|
||||
parent.addOutgoingConnection(newConnection);
|
||||
}
|
||||
|
||||
for (var child in original.children) {
|
||||
duplicateRecursive(child, duplicated);
|
||||
}
|
||||
|
||||
return duplicated;
|
||||
}
|
||||
|
||||
/// Layout a subtree rooted at node
|
||||
void layoutSubtree(SpaceModel node, double startX, double startY) {
|
||||
double calculateSubtreeWidth(SpaceModel n) {
|
||||
if (n.children.isEmpty) return nodeWidth;
|
||||
double width = 0;
|
||||
for (var child in n.children) {
|
||||
width += calculateSubtreeWidth(child) + horizontalGap;
|
||||
}
|
||||
return width - horizontalGap;
|
||||
}
|
||||
|
||||
void assignPositions(SpaceModel n, double x, double y) {
|
||||
double subtreeWidth = calculateSubtreeWidth(n);
|
||||
double centerX = x + subtreeWidth / 2 - nodeWidth / 2;
|
||||
n.position = Offset(centerX, y);
|
||||
|
||||
if (n.children.length == 1) {
|
||||
assignPositions(n.children.first, centerX, y + verticalGap);
|
||||
} else {
|
||||
double childX = x;
|
||||
for (var child in n.children) {
|
||||
double childWidth = calculateSubtreeWidth(child);
|
||||
assignPositions(child, childX, y + verticalGap);
|
||||
childX += childWidth + horizontalGap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
double totalSubtreeWidth = calculateSubtreeWidth(node);
|
||||
assignPositions(node, startX, startY);
|
||||
}
|
||||
|
||||
/// Actual duplication process
|
||||
setState(() {
|
||||
if (space.parent == null) {
|
||||
// Duplicating a ROOT node
|
||||
SpaceModel duplicatedRoot = duplicateRecursive(space, null);
|
||||
realignTree();
|
||||
} else {
|
||||
// Duplicating a CHILD node inside its parent
|
||||
SpaceModel duplicated = duplicateRecursive(space, space.parent);
|
||||
realignTree();
|
||||
}
|
||||
realignTree();
|
||||
connections = createConnections(spaces);
|
||||
});
|
||||
}
|
||||
|
||||
SpaceModel _deepCloneSpaceTree(SpaceModel original, {SpaceModel? parent}) {
|
||||
final duplicatedName = SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||
|
||||
final newSpace = SpaceModel(
|
||||
name: duplicatedName,
|
||||
icon: original.icon,
|
||||
position: original.position,
|
||||
isPrivate: original.isPrivate,
|
||||
children: [],
|
||||
status: SpaceStatus.newSpace,
|
||||
spaceModel: original.spaceModel,
|
||||
subspaces: original.subspaces,
|
||||
tags: original.tags,
|
||||
parent: parent,
|
||||
);
|
||||
|
||||
for (var child in original.children) {
|
||||
final duplicatedChild = _deepCloneSpaceTree(child, parent: newSpace);
|
||||
newSpace.children.add(duplicatedChild);
|
||||
|
||||
final newConnection = Connection(
|
||||
startSpace: newSpace,
|
||||
endSpace: duplicatedChild,
|
||||
direction: "down",
|
||||
);
|
||||
connections.add(newConnection);
|
||||
|
||||
duplicatedChild.incomingConnection = newConnection;
|
||||
newSpace.addOutgoingConnection(newConnection);
|
||||
}
|
||||
|
||||
return newSpace;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/space_tree/view/space_tree_view.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||
@ -45,7 +46,6 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_spaceModels = List.from(widget.spaceModels ?? []);
|
||||
}
|
||||
|
||||
@ -106,9 +106,8 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
children: [
|
||||
SidebarWidget(
|
||||
communities: widget.communities,
|
||||
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
||||
widget.selectedCommunity?.uuid ??
|
||||
'',
|
||||
selectedSpaceUuid:
|
||||
widget.selectedSpace?.uuid ?? widget.selectedCommunity?.uuid ?? '',
|
||||
onCreateCommunity: (name, description) {
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
CreateCommunityEvent(name, description, context),
|
||||
|
@ -1,3 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/common/widgets/empty_search_result_widget.dart';
|
||||
@ -36,6 +38,7 @@ class SidebarWidget extends StatefulWidget {
|
||||
|
||||
class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
late final ScrollController _scrollController;
|
||||
Timer? _debounce;
|
||||
|
||||
String _searchQuery = '';
|
||||
String? _selectedSpaceUuid;
|
||||
@ -43,10 +46,12 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_scrollController = ScrollController();
|
||||
_scrollController.addListener(_onScroll);
|
||||
_selectedId = widget.selectedSpaceUuid;
|
||||
super.initState();
|
||||
_searchQuery = '';
|
||||
context.read<SpaceTreeBloc>().add(ClearCachedData());
|
||||
}
|
||||
|
||||
void _onScroll() {
|
||||
@ -67,11 +72,22 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
@override
|
||||
void dispose() {
|
||||
_scrollController.removeListener(_onScroll);
|
||||
|
||||
_scrollController.dispose();
|
||||
_debounce?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _onSearchChanged(String query) {
|
||||
if (_debounce?.isActive ?? false) _debounce?.cancel();
|
||||
|
||||
_debounce = Timer(const Duration(milliseconds: 500), () {
|
||||
setState(() {
|
||||
_searchQuery = query;
|
||||
});
|
||||
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant SidebarWidget oldWidget) {
|
||||
if (widget.selectedSpaceUuid != oldWidget.selectedSpaceUuid) {
|
||||
@ -91,7 +107,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final spaceTreeState = context.watch<SpaceTreeBloc>().state;
|
||||
final filteredCommunities = spaceTreeState.isSearching
|
||||
final filteredCommunities = spaceTreeState.searchQuery.isNotEmpty
|
||||
? spaceTreeState.filteredCommunity
|
||||
: spaceTreeState.communityList;
|
||||
|
||||
@ -104,13 +120,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
children: [
|
||||
SidebarHeader(onAddCommunity: _onAddCommunity),
|
||||
CustomSearchBar(
|
||||
onSearchChanged: (query) {
|
||||
setState(() {
|
||||
_searchQuery = query;
|
||||
});
|
||||
|
||||
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
|
||||
},
|
||||
onSearchChanged: _onSearchChanged,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Expanded(
|
||||
@ -123,10 +133,15 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
||||
communities: filteredCommunities,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == filteredCommunities.length) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
||||
if (spaceTreeState.paginationIsLoading) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.all(8.0),
|
||||
child: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
}
|
||||
return _buildCommunityTile(context, filteredCommunities[index]);
|
||||
}),
|
||||
|
@ -1,5 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_bloc.dart';
|
||||
@ -27,6 +29,8 @@ class SpaceModelPage extends StatelessWidget {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
} else if (state is SpaceModelLoaded) {
|
||||
final spaceModels = state.spaceModels;
|
||||
context.read<SpaceTreeBloc>().add(ClearCachedData());
|
||||
|
||||
final allTagValues = _getAllTagValues(spaceModels);
|
||||
final allSpaceModelNames = _getAllSpaceModelName(spaceModels);
|
||||
|
||||
|
@ -46,14 +46,14 @@ final class DebouncedBatchControlDevicesService
|
||||
final BatchControlDevicesService decoratee;
|
||||
final Duration debounceDuration;
|
||||
|
||||
final _pendingRequests = <(List<String> uuids, String code, Object value)>[];
|
||||
var _isProcessing = false;
|
||||
|
||||
DebouncedBatchControlDevicesService({
|
||||
required this.decoratee,
|
||||
this.debounceDuration = const Duration(milliseconds: 800),
|
||||
this.debounceDuration = const Duration(milliseconds: 1500),
|
||||
});
|
||||
|
||||
final _pendingRequests = <(List<String> uuids, String code, Object value)>[];
|
||||
var _isProcessing = false;
|
||||
|
||||
@override
|
||||
Future<bool> batchControlDevices({
|
||||
required List<String> uuids,
|
||||
@ -68,16 +68,26 @@ final class DebouncedBatchControlDevicesService
|
||||
|
||||
await Future.delayed(debounceDuration);
|
||||
|
||||
final lastRequest = _pendingRequests.last;
|
||||
final groupedRequests =
|
||||
<String, (List<String> uuids, String code, Object value)>{};
|
||||
for (final request in _pendingRequests) {
|
||||
final (_, requestCode, requestValue) = request;
|
||||
groupedRequests[requestCode] = request;
|
||||
}
|
||||
_pendingRequests.clear();
|
||||
|
||||
try {
|
||||
final (lastRequestUuids, lastRequestCode, lastRequestValue) = lastRequest;
|
||||
return decoratee.batchControlDevices(
|
||||
uuids: lastRequestUuids,
|
||||
code: lastRequestCode,
|
||||
value: lastRequestValue,
|
||||
);
|
||||
var allSuccessful = true;
|
||||
for (final request in groupedRequests.values) {
|
||||
final (lastRequestUuids, lastRequestCode, lastRequestValue) = request;
|
||||
final success = await decoratee.batchControlDevices(
|
||||
uuids: lastRequestUuids,
|
||||
code: lastRequestCode,
|
||||
value: lastRequestValue,
|
||||
);
|
||||
if (!success) allSuccessful = false;
|
||||
}
|
||||
return allSuccessful;
|
||||
} finally {
|
||||
_isProcessing = false;
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ final class DebouncedControlDeviceService implements ControlDeviceService {
|
||||
|
||||
DebouncedControlDeviceService({
|
||||
required this.decoratee,
|
||||
this.debounceDuration = const Duration(milliseconds: 800),
|
||||
this.debounceDuration = const Duration(milliseconds: 1500),
|
||||
});
|
||||
|
||||
final _pendingRequests = <(String deviceUuid, Status status)>[];
|
||||
@ -59,15 +59,24 @@ final class DebouncedControlDeviceService implements ControlDeviceService {
|
||||
|
||||
await Future.delayed(debounceDuration);
|
||||
|
||||
final lastRequest = _pendingRequests.last;
|
||||
final groupedRequests = <String, (String deviceUuid, Status status)>{};
|
||||
for (final request in _pendingRequests) {
|
||||
final (_, requestStatus) = request;
|
||||
groupedRequests[requestStatus.code] = request;
|
||||
}
|
||||
_pendingRequests.clear();
|
||||
|
||||
try {
|
||||
final (lastRequestDeviceUuid, lastRequestStatus) = lastRequest;
|
||||
return decoratee.controlDevice(
|
||||
deviceUuid: lastRequestDeviceUuid,
|
||||
status: lastRequestStatus,
|
||||
);
|
||||
var allSuccessful = true;
|
||||
for (final request in groupedRequests.values) {
|
||||
final (lastRequestDeviceUuid, lastRequestStatus) = request;
|
||||
final success = await decoratee.controlDevice(
|
||||
deviceUuid: lastRequestDeviceUuid,
|
||||
status: lastRequestStatus,
|
||||
);
|
||||
if (!success) allSuccessful = false;
|
||||
}
|
||||
return allSuccessful;
|
||||
} finally {
|
||||
_isProcessing = false;
|
||||
}
|
||||
|
@ -281,6 +281,7 @@ class CommunitySpaceManagementApi {
|
||||
return json['success'] ?? false;
|
||||
},
|
||||
);
|
||||
|
||||
return response;
|
||||
} catch (e) {
|
||||
debugPrint('Error updating space: $e');
|
||||
|
Reference in New Issue
Block a user