mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
push merge
This commit is contained in:
@ -46,9 +46,19 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
void _onAddToThenContainer(
|
void _onAddToThenContainer(
|
||||||
AddToThenContainer event, Emitter<RoutineState> emit) {
|
AddToThenContainer event, Emitter<RoutineState> emit) {
|
||||||
final updatedThenItems = List<Map<String, dynamic>>.from(state.thenItems)
|
final currentItems = List<Map<String, dynamic>>.from(state.thenItems);
|
||||||
..add(event.item);
|
|
||||||
emit(state.copyWith(thenItems: updatedThenItems));
|
// Find the index of the item in teh current itemsList
|
||||||
|
int index = currentItems.indexWhere(
|
||||||
|
(map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
||||||
|
// Replace the map if the index is valid
|
||||||
|
if (index != -1) {
|
||||||
|
currentItems[index] = event.item;
|
||||||
|
} else {
|
||||||
|
currentItems.add(event.item);
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(state.copyWith(thenItems: currentItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAddFunctionsToRoutine(
|
void _onAddFunctionsToRoutine(
|
||||||
|
@ -8,13 +8,25 @@ import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
|||||||
|
|
||||||
class DelayHelper {
|
class DelayHelper {
|
||||||
static Future<Map<String, dynamic>?> showDelayPickerDialog(
|
static Future<Map<String, dynamic>?> showDelayPickerDialog(
|
||||||
BuildContext context, String uniqueCustomId) async {
|
BuildContext context, Map<String, dynamic> data) async {
|
||||||
int hours = 0;
|
int hours = 0;
|
||||||
int minutes = 0;
|
int minutes = 0;
|
||||||
|
|
||||||
return showDialog<Map<String, dynamic>?>(
|
return showDialog<Map<String, dynamic>?>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
|
final routineBloc = context.read<RoutineBloc>();
|
||||||
|
int totalSec = 0;
|
||||||
|
|
||||||
|
final selectedFunctionData =
|
||||||
|
routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? [];
|
||||||
|
|
||||||
|
if (selectedFunctionData.isNotEmpty) {
|
||||||
|
totalSec = selectedFunctionData[0].value;
|
||||||
|
// Convert seconds to hours and minutes
|
||||||
|
hours = totalSec ~/ 3600;
|
||||||
|
minutes = (totalSec % 3600) ~/ 60;
|
||||||
|
}
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
content: Container(
|
content: Container(
|
||||||
@ -31,8 +43,7 @@ class DelayHelper {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: CupertinoTimerPicker(
|
child: CupertinoTimerPicker(
|
||||||
mode: CupertinoTimerPickerMode.hm,
|
mode: CupertinoTimerPickerMode.hm,
|
||||||
initialTimerDuration:
|
initialTimerDuration: Duration(hours: hours, minutes: minutes),
|
||||||
Duration(hours: hours, minutes: minutes),
|
|
||||||
onTimerDurationChanged: (Duration newDuration) {
|
onTimerDurationChanged: (Duration newDuration) {
|
||||||
hours = newDuration.inHours;
|
hours = newDuration.inHours;
|
||||||
minutes = newDuration.inMinutes % 60;
|
minutes = newDuration.inMinutes % 60;
|
||||||
@ -54,7 +65,7 @@ class DelayHelper {
|
|||||||
value: totalSeconds,
|
value: totalSeconds,
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
uniqueCustomId,
|
data['uniqueCustomId'],
|
||||||
));
|
));
|
||||||
|
|
||||||
Navigator.pop(context, {
|
Navigator.pop(context, {
|
||||||
|
@ -34,11 +34,9 @@ class _ScenesAndAutomationsState extends State<ScenesAndAutomations> {
|
|||||||
children: scenes.asMap().entries.map((entry) {
|
children: scenes.asMap().entries.map((entry) {
|
||||||
final scene = entry.value;
|
final scene = entry.value;
|
||||||
if (state.searchText != null && state.searchText!.isNotEmpty) {
|
if (state.searchText != null && state.searchText!.isNotEmpty) {
|
||||||
return scene.name
|
return scene.name.toLowerCase().contains(state.searchText!.toLowerCase())
|
||||||
.toLowerCase()
|
|
||||||
.contains(state.searchText!.toLowerCase())
|
|
||||||
? DraggableCard(
|
? DraggableCard(
|
||||||
imagePath: Assets.logo,
|
imagePath: scene.icon ?? Assets.loginLogo,
|
||||||
title: scene.name,
|
title: scene.name,
|
||||||
deviceData: {
|
deviceData: {
|
||||||
'deviceId': scene.id,
|
'deviceId': scene.id,
|
||||||
|
@ -35,20 +35,59 @@ class ThenContainer extends StatelessWidget {
|
|||||||
runSpacing: 8,
|
runSpacing: 8,
|
||||||
children: List.generate(
|
children: List.generate(
|
||||||
state.thenItems.length,
|
state.thenItems.length,
|
||||||
(index) => DraggableCard(
|
(index) => GestureDetector(
|
||||||
imagePath:
|
onTap: () async {
|
||||||
state.thenItems[index]['imagePath'] ?? '',
|
if (state.thenItems[index]['deviceId'] ==
|
||||||
title: state.thenItems[index]['title'] ?? '',
|
'delay') {
|
||||||
deviceData: state.thenItems[index],
|
final result = await DelayHelper
|
||||||
padding: const EdgeInsets.symmetric(
|
.showDelayPickerDialog(
|
||||||
horizontal: 4, vertical: 8),
|
context, state.thenItems[index]);
|
||||||
isFromThen: true,
|
|
||||||
isFromIf: false,
|
if (result != null) {
|
||||||
onRemove: () {
|
context
|
||||||
context.read<RoutineBloc>().add(
|
.read<RoutineBloc>()
|
||||||
RemoveDragCard(
|
.add(AddToThenContainer({
|
||||||
index: index, isFromThen: true));
|
...state.thenItems[index],
|
||||||
|
'imagePath': Assets.delay,
|
||||||
|
'title': 'Delay',
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final result = await DeviceDialogHelper
|
||||||
|
.showDeviceDialog(
|
||||||
|
context, state.thenItems[index]);
|
||||||
|
|
||||||
|
if (result != null) {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
AddToThenContainer(
|
||||||
|
state.thenItems[index]));
|
||||||
|
} else if (!['AC', '1G', '2G', '3G']
|
||||||
|
.contains(state.thenItems[index]
|
||||||
|
['productType'])) {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
AddToThenContainer(
|
||||||
|
state.thenItems[index]));
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
child: DraggableCard(
|
||||||
|
imagePath: state.thenItems[index]
|
||||||
|
['imagePath'] ??
|
||||||
|
'',
|
||||||
|
title:
|
||||||
|
state.thenItems[index]['title'] ?? '',
|
||||||
|
deviceData: state.thenItems[index],
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 4, vertical: 8),
|
||||||
|
isFromThen: true,
|
||||||
|
isFromIf: false,
|
||||||
|
onRemove: () {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
RemoveDragCard(
|
||||||
|
index: index, isFromThen: true));
|
||||||
|
},
|
||||||
|
),
|
||||||
))),
|
))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -69,10 +108,9 @@ class ThenContainer extends StatelessWidget {
|
|||||||
|
|
||||||
return data.data['deviceId'] != null;
|
return data.data['deviceId'] != null;
|
||||||
},
|
},
|
||||||
onAccept: (data) async {
|
onAcceptWithDetails: (data) async {
|
||||||
final uniqueCustomId = const Uuid().v4();
|
final uniqueCustomId = const Uuid().v4();
|
||||||
|
final mutableData = Map<String, dynamic>.from(data.data);
|
||||||
final mutableData = Map<String, dynamic>.from(data);
|
|
||||||
mutableData['uniqueCustomId'] = uniqueCustomId;
|
mutableData['uniqueCustomId'] = uniqueCustomId;
|
||||||
|
|
||||||
if (mutableData['type'] == 'scene') {
|
if (mutableData['type'] == 'scene') {
|
||||||
@ -98,8 +136,8 @@ class ThenContainer extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mutableData['deviceId'] == 'delay') {
|
if (mutableData['deviceId'] == 'delay') {
|
||||||
final result = await DelayHelper.showDelayPickerDialog(
|
final result =
|
||||||
context, mutableData['uniqueCustomId']);
|
await DelayHelper.showDelayPickerDialog(context, mutableData);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(AddToThenContainer({
|
context.read<RoutineBloc>().add(AddToThenContainer({
|
||||||
|
Reference in New Issue
Block a user