mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Compare commits
24 Commits
bugfix/emp
...
bugfix/fix
Author | SHA1 | Date | |
---|---|---|---|
2d3345c1d9 | |||
5e05b20f68 | |||
95730cc2ba | |||
a5a37f3841 | |||
e0486deecb | |||
bc64efa557 | |||
2a065efc0e | |||
7ae3e4a933 | |||
2a0f6a4596 | |||
5b2822f973 | |||
70d31f5351 | |||
c39c693755 | |||
8ed6980264 | |||
16df75eb49 | |||
80c294f09c | |||
c806b5f59d | |||
dd01a7fddb | |||
b563cc378e | |||
2140b7eee3 | |||
7de9e25ed5 | |||
123949aa86 | |||
6d554c5953 | |||
5ed87a5794 | |||
168c997240 |
@ -244,6 +244,7 @@ SOS
|
||||
SwitchFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
|
||||
ModeFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
|
||||
TempSetFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
|
||||
CurrentTempFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
|
||||
LevelFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
|
||||
ChildLockFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
|
||||
];
|
||||
|
@ -29,7 +29,7 @@ class TwoGangSwitchBloc extends Bloc<TwoGangSwitchEvent, TwoGangSwitchState> {
|
||||
final status =
|
||||
await DevicesManagementApi().getDeviceStatus(event.deviceId);
|
||||
deviceStatus = TwoGangStatusModel.fromJson(event.deviceId, status.status);
|
||||
_listenToChanges(emit);
|
||||
_listenToChanges(event.deviceId);
|
||||
emit(TwoGangSwitchStatusLoaded(deviceStatus));
|
||||
} catch (e) {
|
||||
emit(TwoGangSwitchError(e.toString()));
|
||||
|
@ -30,7 +30,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
var response = await DevicesManagementApi().getDeviceStatus(deviceId);
|
||||
deviceStatus = WallSensorModel.fromJson(response.status);
|
||||
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
|
||||
_listenToChanges(emit);
|
||||
_listenToChanges(emit, deviceId);
|
||||
} catch (e) {
|
||||
emit(WallSensorFailedState(error: e.toString()));
|
||||
return;
|
||||
@ -52,7 +52,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
|
||||
}
|
||||
}
|
||||
|
||||
_listenToChanges(Emitter<WallSensorState> emit) {
|
||||
_listenToChanges(Emitter<WallSensorState> emit, deviceId) {
|
||||
try {
|
||||
DatabaseReference ref =
|
||||
FirebaseDatabase.instance.ref('device-status/$deviceId');
|
||||
|
@ -1,6 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||
@ -16,9 +15,6 @@ import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||
import 'package:syncrow_web/services/routines_api.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||
import 'package:syncrow_web/utils/navigation_service.dart';
|
||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@ -61,8 +57,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
TriggerSwitchTabsEvent event,
|
||||
Emitter<RoutineState> emit,
|
||||
) {
|
||||
emit(state.copyWith(
|
||||
routineTab: event.isRoutineTab, createRoutineView: false));
|
||||
emit(state.copyWith(routineTab: event.isRoutineTab, createRoutineView: false));
|
||||
add(ResetRoutineState());
|
||||
if (event.isRoutineTab) {
|
||||
add(const LoadScenes());
|
||||
@ -88,8 +83,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems);
|
||||
|
||||
// Find the index of the item in teh current itemsList
|
||||
int index = updatedIfItems.indexWhere(
|
||||
(map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
||||
int index =
|
||||
updatedIfItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
||||
// Replace the map if the index is valid
|
||||
if (index != -1) {
|
||||
updatedIfItems[index] = event.item;
|
||||
@ -98,21 +93,18 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
|
||||
if (event.isTabToRun) {
|
||||
emit(state.copyWith(
|
||||
ifItems: updatedIfItems, isTabToRun: true, isAutomation: false));
|
||||
emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: true, isAutomation: false));
|
||||
} else {
|
||||
emit(state.copyWith(
|
||||
ifItems: updatedIfItems, isTabToRun: false, isAutomation: true));
|
||||
emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: false, isAutomation: true));
|
||||
}
|
||||
}
|
||||
|
||||
void _onAddToThenContainer(
|
||||
AddToThenContainer event, Emitter<RoutineState> emit) {
|
||||
void _onAddToThenContainer(AddToThenContainer event, Emitter<RoutineState> emit) {
|
||||
final currentItems = List<Map<String, dynamic>>.from(state.thenItems);
|
||||
|
||||
// Find the index of the item in teh current itemsList
|
||||
int index = currentItems.indexWhere(
|
||||
(map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
||||
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;
|
||||
@ -123,26 +115,22 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
emit(state.copyWith(thenItems: currentItems));
|
||||
}
|
||||
|
||||
void _onAddFunctionsToRoutine(
|
||||
AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
||||
void _onAddFunctionsToRoutine(AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
||||
try {
|
||||
if (event.functions.isEmpty) return;
|
||||
|
||||
List<DeviceFunctionData> selectedFunction =
|
||||
List<DeviceFunctionData>.from(event.functions);
|
||||
List<DeviceFunctionData> selectedFunction = List<DeviceFunctionData>.from(event.functions);
|
||||
|
||||
Map<String, List<DeviceFunctionData>> currentSelectedFunctions =
|
||||
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||
if (currentSelectedFunctions.containsKey(event.uniqueCustomId)) {
|
||||
List<DeviceFunctionData> currentFunctions =
|
||||
List<DeviceFunctionData>.from(
|
||||
currentSelectedFunctions[event.uniqueCustomId] ?? []);
|
||||
List<DeviceFunctionData>.from(currentSelectedFunctions[event.uniqueCustomId] ?? []);
|
||||
|
||||
List<String> functionCode = [];
|
||||
for (int i = 0; i < selectedFunction.length; i++) {
|
||||
for (int j = 0; j < currentFunctions.length; j++) {
|
||||
if (selectedFunction[i].functionCode ==
|
||||
currentFunctions[j].functionCode) {
|
||||
if (selectedFunction[i].functionCode == currentFunctions[j].functionCode) {
|
||||
currentFunctions[j] = selectedFunction[i];
|
||||
if (!functionCode.contains(currentFunctions[j].functionCode)) {
|
||||
functionCode.add(currentFunctions[j].functionCode);
|
||||
@ -152,15 +140,13 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
|
||||
for (int i = 0; i < functionCode.length; i++) {
|
||||
selectedFunction
|
||||
.removeWhere((code) => code.functionCode == functionCode[i]);
|
||||
selectedFunction.removeWhere((code) => code.functionCode == functionCode[i]);
|
||||
}
|
||||
|
||||
currentSelectedFunctions[event.uniqueCustomId] =
|
||||
List.from(currentFunctions)..addAll(selectedFunction);
|
||||
currentSelectedFunctions[event.uniqueCustomId] = List.from(currentFunctions)
|
||||
..addAll(selectedFunction);
|
||||
} else {
|
||||
currentSelectedFunctions[event.uniqueCustomId] =
|
||||
List.from(event.functions);
|
||||
currentSelectedFunctions[event.uniqueCustomId] = List.from(event.functions);
|
||||
}
|
||||
|
||||
emit(state.copyWith(selectedFunctions: currentSelectedFunctions));
|
||||
@ -169,8 +155,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onLoadScenes(
|
||||
LoadScenes event, Emitter<RoutineState> emit) async {
|
||||
Future<void> _onLoadScenes(LoadScenes event, Emitter<RoutineState> emit) async {
|
||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||
List<ScenesModel> scenes = [];
|
||||
try {
|
||||
@ -179,11 +164,9 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList =
|
||||
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||
for (var spaceId in spacesList) {
|
||||
scenes.addAll(
|
||||
await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
||||
scenes.addAll(await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,19 +184,18 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onLoadAutomation(
|
||||
LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||
Future<void> _onLoadAutomation(LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||
List<ScenesModel> automations = [];
|
||||
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
try {
|
||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList =
|
||||
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||
for (var spaceId in spacesList) {
|
||||
automations.addAll(await SceneApi.getAutomation(spaceId));
|
||||
automations.addAll(await SceneApi.getAutomation(spaceId, communityId, projectId));
|
||||
}
|
||||
}
|
||||
emit(state.copyWith(
|
||||
@ -230,16 +212,14 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onSearchRoutines(
|
||||
SearchRoutines event, Emitter<RoutineState> emit) async {
|
||||
FutureOr<void> _onSearchRoutines(SearchRoutines event, Emitter<RoutineState> emit) async {
|
||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||
await Future.delayed(const Duration(seconds: 1));
|
||||
emit(state.copyWith(isLoading: false, errorMessage: null));
|
||||
emit(state.copyWith(searchText: event.query));
|
||||
}
|
||||
|
||||
FutureOr<void> _onAddSelectedIcon(
|
||||
AddSelectedIcon event, Emitter<RoutineState> emit) {
|
||||
FutureOr<void> _onAddSelectedIcon(AddSelectedIcon event, Emitter<RoutineState> emit) {
|
||||
emit(state.copyWith(selectedIcon: event.icon));
|
||||
}
|
||||
|
||||
@ -253,8 +233,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
return actions.last['deviceId'] == 'delay';
|
||||
}
|
||||
|
||||
Future<void> _onCreateScene(
|
||||
CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
||||
Future<void> _onCreateScene(CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
||||
try {
|
||||
// Check if first action is delay
|
||||
// if (_isFirstActionDelay(state.thenItems)) {
|
||||
@ -267,8 +246,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
|
||||
if (_isLastActionDelay(state.thenItems)) {
|
||||
emit(state.copyWith(
|
||||
errorMessage:
|
||||
'A delay condition cannot be the only or the last action',
|
||||
errorMessage: 'A delay condition cannot be the only or the last action',
|
||||
isLoading: false,
|
||||
));
|
||||
return;
|
||||
@ -344,9 +322,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onCreateAutomation(
|
||||
CreateAutomationEvent event, Emitter<RoutineState> emit) async {
|
||||
Future<void> _onCreateAutomation(CreateAutomationEvent event, Emitter<RoutineState> emit) async {
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
if (state.routineName == null || state.routineName!.isEmpty) {
|
||||
emit(state.copyWith(
|
||||
errorMessage: 'Automation name is required',
|
||||
@ -366,8 +345,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
|
||||
if (_isLastActionDelay(state.thenItems)) {
|
||||
emit(state.copyWith(
|
||||
errorMessage:
|
||||
'A delay condition cannot be the only or the last action',
|
||||
errorMessage: 'A delay condition cannot be the only or the last action',
|
||||
isLoading: false,
|
||||
));
|
||||
CustomSnackBar.redSnackBar('Cannot have delay as the last action');
|
||||
@ -458,7 +436,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
actions: actions,
|
||||
);
|
||||
|
||||
final result = await SceneApi.createAutomation(createAutomationModel);
|
||||
final result = await SceneApi.createAutomation(createAutomationModel, projectUuid);
|
||||
if (result['success']) {
|
||||
add(ResetRoutineState());
|
||||
add(const LoadAutomation());
|
||||
@ -479,21 +457,17 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onRemoveDragCard(
|
||||
RemoveDragCard event, Emitter<RoutineState> emit) {
|
||||
FutureOr<void> _onRemoveDragCard(RemoveDragCard event, Emitter<RoutineState> emit) {
|
||||
if (event.isFromThen) {
|
||||
final thenItems = List<Map<String, dynamic>>.from(state.thenItems);
|
||||
final selectedFunctions =
|
||||
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||
final selectedFunctions = Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||
|
||||
thenItems.removeAt(event.index);
|
||||
selectedFunctions.remove(event.key);
|
||||
emit(state.copyWith(
|
||||
thenItems: thenItems, selectedFunctions: selectedFunctions));
|
||||
emit(state.copyWith(thenItems: thenItems, selectedFunctions: selectedFunctions));
|
||||
} else {
|
||||
final ifItems = List<Map<String, dynamic>>.from(state.ifItems);
|
||||
final selectedFunctions =
|
||||
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||
final selectedFunctions = Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||
|
||||
ifItems.removeAt(event.index);
|
||||
selectedFunctions.remove(event.key);
|
||||
@ -504,8 +478,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
isAutomation: false,
|
||||
isTabToRun: false));
|
||||
} else {
|
||||
emit(state.copyWith(
|
||||
ifItems: ifItems, selectedFunctions: selectedFunctions));
|
||||
emit(state.copyWith(ifItems: ifItems, selectedFunctions: selectedFunctions));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -517,23 +490,18 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
));
|
||||
}
|
||||
|
||||
FutureOr<void> _onEffectiveTimeEvent(
|
||||
EffectiveTimePeriodEvent event, Emitter<RoutineState> emit) {
|
||||
FutureOr<void> _onEffectiveTimeEvent(EffectiveTimePeriodEvent event, Emitter<RoutineState> emit) {
|
||||
emit(state.copyWith(effectiveTime: event.effectiveTime));
|
||||
}
|
||||
|
||||
FutureOr<void> _onSetRoutineName(
|
||||
SetRoutineName event, Emitter<RoutineState> emit) {
|
||||
FutureOr<void> _onSetRoutineName(SetRoutineName event, Emitter<RoutineState> emit) {
|
||||
emit(state.copyWith(
|
||||
routineName: event.name,
|
||||
));
|
||||
}
|
||||
|
||||
(
|
||||
List<Map<String, dynamic>>,
|
||||
List<Map<String, dynamic>>,
|
||||
Map<String, List<DeviceFunctionData>>
|
||||
) _createCardData(
|
||||
(List<Map<String, dynamic>>, List<Map<String, dynamic>>, Map<String, List<DeviceFunctionData>>)
|
||||
_createCardData(
|
||||
List<RoutineAction> actions,
|
||||
List<RoutineCondition>? conditions,
|
||||
Map<String, List<DeviceFunctionData>> currentFunctions,
|
||||
@ -566,8 +534,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
'deviceId': condition.entityId,
|
||||
'title': matchingDevice.name ?? condition.entityId,
|
||||
'productType': condition.entityType,
|
||||
'imagePath':
|
||||
matchingDevice.getDefaultIcon(condition.entityType),
|
||||
'imagePath': matchingDevice.getDefaultIcon(condition.entityType),
|
||||
};
|
||||
|
||||
final functions = matchingDevice.functions;
|
||||
@ -603,11 +570,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
final cardData = {
|
||||
'entityId': action.entityId,
|
||||
'uniqueCustomId': const Uuid().v4(),
|
||||
'deviceId':
|
||||
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||
'title': action.actionExecutor == 'delay'
|
||||
? 'Delay'
|
||||
: (matchingDevice.name ?? 'Device'),
|
||||
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||
'title': action.actionExecutor == 'delay' ? 'Delay' : (matchingDevice.name ?? 'Device'),
|
||||
'productType': action.productType,
|
||||
'imagePath': matchingDevice.getDefaultIcon(action.productType),
|
||||
};
|
||||
@ -650,8 +614,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
return (thenItems, ifItems, currentFunctions);
|
||||
}
|
||||
|
||||
Future<void> _onGetSceneDetails(
|
||||
GetSceneDetails event, Emitter<RoutineState> emit) async {
|
||||
Future<void> _onGetSceneDetails(GetSceneDetails event, Emitter<RoutineState> emit) async {
|
||||
try {
|
||||
emit(state.copyWith(
|
||||
isLoading: true,
|
||||
@ -699,12 +662,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
if (!deviceCards.containsKey(deviceId)) {
|
||||
deviceCards[deviceId] = {
|
||||
'entityId': action.entityId,
|
||||
'deviceId':
|
||||
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||
'uniqueCustomId':
|
||||
action.type == 'automation' || action.actionExecutor == 'delay'
|
||||
? const Uuid().v4()
|
||||
: action.entityId,
|
||||
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||
'uniqueCustomId': action.type == 'automation' || action.actionExecutor == 'delay'
|
||||
? const Uuid().v4()
|
||||
: action.entityId,
|
||||
'title': action.actionExecutor == 'delay'
|
||||
? 'Delay'
|
||||
: action.type == 'automation'
|
||||
@ -739,8 +700,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
),
|
||||
);
|
||||
// emit(state.copyWith(automationActionExecutor: action.actionExecutor));
|
||||
} else if (action.executorProperty != null &&
|
||||
action.actionExecutor != 'delay') {
|
||||
} else if (action.executorProperty != null && action.actionExecutor != 'delay') {
|
||||
if (!updatedFunctions.containsKey(uniqueCustomId)) {
|
||||
updatedFunctions[uniqueCustomId] = [];
|
||||
}
|
||||
@ -812,8 +772,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onResetRoutineState(
|
||||
ResetRoutineState event, Emitter<RoutineState> emit) {
|
||||
FutureOr<void> _onResetRoutineState(ResetRoutineState event, Emitter<RoutineState> emit) {
|
||||
emit(state.copyWith(
|
||||
ifItems: [],
|
||||
thenItems: [],
|
||||
@ -837,20 +796,21 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
createRoutineView: false));
|
||||
}
|
||||
|
||||
FutureOr<void> _deleteScene(
|
||||
DeleteScene event, Emitter<RoutineState> emit) async {
|
||||
FutureOr<void> _deleteScene(DeleteScene event, Emitter<RoutineState> emit) async {
|
||||
try {
|
||||
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
emit(state.copyWith(isLoading: true));
|
||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||
if (state.isTabToRun) {
|
||||
await SceneApi.deleteScene(
|
||||
unitUuid: spaceBloc.state.selectedSpaces[0],
|
||||
sceneId: state.sceneId ?? '');
|
||||
unitUuid: spaceBloc.state.selectedSpaces[0], sceneId: state.sceneId ?? '');
|
||||
} else {
|
||||
await SceneApi.deleteAutomation(
|
||||
unitUuid: spaceBloc.state.selectedSpaces[0],
|
||||
automationId: state.automationId ?? '');
|
||||
automationId: state.automationId ?? '',
|
||||
projectId: projectId);
|
||||
}
|
||||
|
||||
add(const LoadScenes());
|
||||
@ -879,8 +839,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
// }
|
||||
// }
|
||||
|
||||
FutureOr<void> _fetchDevices(
|
||||
FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
||||
FutureOr<void> _fetchDevices(FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
@ -890,11 +849,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList =
|
||||
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||
for (var spaceId in spacesList) {
|
||||
devices.addAll(await DevicesManagementApi()
|
||||
.fetchDevices(communityId, spaceId, projectUuid));
|
||||
devices
|
||||
.addAll(await DevicesManagementApi().fetchDevices(communityId, spaceId, projectUuid));
|
||||
}
|
||||
}
|
||||
|
||||
@ -904,8 +862,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onUpdateScene(
|
||||
UpdateScene event, Emitter<RoutineState> emit) async {
|
||||
FutureOr<void> _onUpdateScene(UpdateScene event, Emitter<RoutineState> emit) async {
|
||||
try {
|
||||
// Check if first action is delay
|
||||
// if (_isFirstActionDelay(state.thenItems)) {
|
||||
@ -919,8 +876,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
|
||||
if (_isLastActionDelay(state.thenItems)) {
|
||||
emit(state.copyWith(
|
||||
errorMessage:
|
||||
'A delay condition cannot be the only or the last action',
|
||||
errorMessage: 'A delay condition cannot be the only or the last action',
|
||||
isLoading: false,
|
||||
));
|
||||
return;
|
||||
@ -973,8 +929,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
actions: actions,
|
||||
);
|
||||
|
||||
final result =
|
||||
await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
||||
final result = await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
||||
if (result['success']) {
|
||||
add(ResetRoutineState());
|
||||
add(const LoadScenes());
|
||||
@ -993,9 +948,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onUpdateAutomation(
|
||||
UpdateAutomation event, Emitter<RoutineState> emit) async {
|
||||
FutureOr<void> _onUpdateAutomation(UpdateAutomation event, Emitter<RoutineState> emit) async {
|
||||
try {
|
||||
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
if (state.routineName == null || state.routineName!.isEmpty) {
|
||||
emit(state.copyWith(
|
||||
errorMessage: 'Automation name is required',
|
||||
@ -1106,7 +1062,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
);
|
||||
|
||||
final result = await SceneApi.updateAutomation(
|
||||
createAutomationModel, state.automationId ?? '');
|
||||
createAutomationModel, state.automationId ?? '', projectId);
|
||||
|
||||
if (result['success']) {
|
||||
add(ResetRoutineState());
|
||||
@ -1129,6 +1085,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
Future<void> _onGetAutomationDetails(
|
||||
GetAutomationDetails event, Emitter<RoutineState> emit) async {
|
||||
try {
|
||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||
|
||||
emit(state.copyWith(
|
||||
isLoading: true,
|
||||
isUpdate: true,
|
||||
@ -1140,7 +1098,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
));
|
||||
|
||||
final automationDetails =
|
||||
await SceneApi.getAutomationDetails(event.automationId);
|
||||
await SceneApi.getAutomationDetails(event.automationId, projectUuid);
|
||||
|
||||
final Map<String, Map<String, dynamic>> deviceIfCards = {};
|
||||
final Map<String, Map<String, dynamic>> deviceThenCards = {};
|
||||
@ -1208,15 +1166,13 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
),
|
||||
);
|
||||
|
||||
final deviceId = action.actionExecutor == 'delay'
|
||||
? '${action.entityId}_delay'
|
||||
: action.entityId;
|
||||
final deviceId =
|
||||
action.actionExecutor == 'delay' ? '${action.entityId}_delay' : action.entityId;
|
||||
|
||||
if (!deviceThenCards.containsKey(deviceId)) {
|
||||
deviceThenCards[deviceId] = {
|
||||
'entityId': action.entityId,
|
||||
'deviceId':
|
||||
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||
'uniqueCustomId': const Uuid().v4(),
|
||||
'title': action.actionExecutor == 'delay'
|
||||
? 'Delay'
|
||||
@ -1247,8 +1203,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
updatedFunctions[uniqueCustomId] = [];
|
||||
}
|
||||
|
||||
if (action.executorProperty != null &&
|
||||
action.actionExecutor != 'delay') {
|
||||
if (action.executorProperty != null && action.actionExecutor != 'delay') {
|
||||
final functions = matchingDevice.functions;
|
||||
final functionCode = action.executorProperty!.functionCode;
|
||||
for (var function in functions) {
|
||||
@ -1290,14 +1245,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
}
|
||||
}
|
||||
|
||||
final ifItems = deviceIfCards.values
|
||||
.where((card) => card['type'] == 'condition')
|
||||
.toList();
|
||||
final ifItems = deviceIfCards.values.where((card) => card['type'] == 'condition').toList();
|
||||
final thenItems = deviceThenCards.values
|
||||
.where((card) =>
|
||||
card['type'] == 'action' ||
|
||||
card['type'] == 'automation' ||
|
||||
card['type'] == 'scene')
|
||||
card['type'] == 'action' || card['type'] == 'automation' || card['type'] == 'scene')
|
||||
.toList();
|
||||
|
||||
emit(state.copyWith(
|
||||
|
@ -41,6 +41,11 @@ class DeviceDialogHelper {
|
||||
final deviceSelectedFunctions =
|
||||
routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? [];
|
||||
|
||||
if (removeComparetors) {
|
||||
//remove the current temp function in the 'if container'
|
||||
functions.removeAt(3);
|
||||
}
|
||||
|
||||
switch (productType) {
|
||||
case 'AC':
|
||||
return ACHelper.showACFunctionsDialog(context, functions, data['device'],
|
||||
|
@ -151,3 +151,32 @@ class ChildLockFunction extends ACFunction {
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
class CurrentTempFunction extends ACFunction {
|
||||
final int min;
|
||||
final int max;
|
||||
final int step;
|
||||
|
||||
CurrentTempFunction({required super.deviceId, required super.deviceName})
|
||||
: min = -100,
|
||||
max = 990,
|
||||
step = 1,
|
||||
super(
|
||||
code: 'temp_current',
|
||||
operationName: 'Current Temperature',
|
||||
icon: Assets.currentTemp,
|
||||
);
|
||||
|
||||
@override
|
||||
List<ACOperationalValue> getOperationalValues() {
|
||||
List<ACOperationalValue> values = [];
|
||||
for (int temp = min; temp <= max; temp += step) {
|
||||
values.add(ACOperationalValue(
|
||||
icon: Assets.currentTemp,
|
||||
description: "${temp / 10}°C",
|
||||
value: temp,
|
||||
));
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
|
@ -329,8 +329,8 @@ class ACHelper {
|
||||
) {
|
||||
return Slider(
|
||||
value: initialValue is int ? initialValue.toDouble() : 200.0,
|
||||
min: 200,
|
||||
max: 300,
|
||||
min: selectCode == 'temp_current' ? -100 : 200,
|
||||
max: selectCode == 'temp_current' ? 900 : 300,
|
||||
divisions: 10,
|
||||
label: '${((initialValue ?? 160) / 10).toInt()}°C',
|
||||
onChanged: (value) {
|
||||
|
@ -33,14 +33,13 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(
|
||||
builder: (context, state) {
|
||||
List<CommunityModel> list =
|
||||
state.isSearching ? state.filteredCommunity : state.communityList;
|
||||
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(builder: (context, state) {
|
||||
List<CommunityModel> list = state.isSearching ? state.filteredCommunity : state.communityList;
|
||||
return Container(
|
||||
height: MediaQuery.sizeOf(context).height,
|
||||
decoration:
|
||||
widget.isSide == true ? subSectionContainerDecoration : null,
|
||||
decoration: widget.isSide == true
|
||||
? subSectionContainerDecoration.copyWith(color: ColorsManager.whiteColors)
|
||||
: const BoxDecoration(color: ColorsManager.whiteColors),
|
||||
child: state is SpaceTreeLoadingState
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
@ -50,8 +49,7 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
decoration: const BoxDecoration(
|
||||
color: ColorsManager.circleRolesBackground,
|
||||
borderRadius: BorderRadius.only(
|
||||
topRight: Radius.circular(20),
|
||||
topLeft: Radius.circular(20)),
|
||||
topRight: Radius.circular(20), topLeft: Radius.circular(20)),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
@ -60,35 +58,27 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: const BorderRadius.all(
|
||||
Radius.circular(20)),
|
||||
border: Border.all(
|
||||
color: ColorsManager.grayBorder)),
|
||||
borderRadius: const BorderRadius.all(Radius.circular(20)),
|
||||
border: Border.all(color: ColorsManager.grayBorder)),
|
||||
child: TextFormField(
|
||||
style:
|
||||
const TextStyle(color: Colors.black),
|
||||
style: const TextStyle(color: Colors.black),
|
||||
onChanged: (value) {
|
||||
context
|
||||
.read<SpaceTreeBloc>()
|
||||
.add(SearchQueryEvent(value));
|
||||
context.read<SpaceTreeBloc>().add(SearchQueryEvent(value));
|
||||
},
|
||||
decoration: textBoxDecoration(radios: 20)!
|
||||
.copyWith(
|
||||
decoration: textBoxDecoration(radios: 20)!.copyWith(
|
||||
fillColor: Colors.white,
|
||||
suffixIcon: Padding(
|
||||
padding:
|
||||
const EdgeInsets.only(right: 16),
|
||||
padding: const EdgeInsets.only(right: 16),
|
||||
child: SvgPicture.asset(
|
||||
Assets.textFieldSearch,
|
||||
width: 24,
|
||||
height: 24,
|
||||
),
|
||||
),
|
||||
hintStyle: context.textTheme.bodyMedium
|
||||
?.copyWith(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 12,
|
||||
color: ColorsManager.textGray),
|
||||
hintStyle: context.textTheme.bodyMedium?.copyWith(
|
||||
fontWeight: FontWeight.w400,
|
||||
fontSize: 12,
|
||||
color: ColorsManager.textGray),
|
||||
),
|
||||
),
|
||||
),
|
||||
@ -99,9 +89,7 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
)
|
||||
: CustomSearchBar(
|
||||
onSearchChanged: (query) {
|
||||
context
|
||||
.read<SpaceTreeBloc>()
|
||||
.add(SearchQueryEvent(query));
|
||||
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
@ -117,18 +105,14 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
? Center(
|
||||
child: Text(
|
||||
'No results found',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall!
|
||||
.copyWith(
|
||||
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||
color: ColorsManager.lightGrayColor,
|
||||
fontWeight: FontWeight.w400,
|
||||
),
|
||||
),
|
||||
)
|
||||
: Scrollbar(
|
||||
scrollbarOrientation:
|
||||
ScrollbarOrientation.left,
|
||||
scrollbarOrientation: ScrollbarOrientation.left,
|
||||
thumbVisibility: true,
|
||||
controller: _scrollController,
|
||||
child: Padding(
|
||||
@ -138,39 +122,30 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
shrinkWrap: true,
|
||||
children: list
|
||||
.map(
|
||||
(community) =>
|
||||
CustomExpansionTileSpaceTree(
|
||||
(community) => CustomExpansionTileSpaceTree(
|
||||
title: community.name,
|
||||
isSelected: state
|
||||
.selectedCommunities
|
||||
isSelected: state.selectedCommunities
|
||||
.contains(community.uuid),
|
||||
isSoldCheck: state
|
||||
.selectedCommunities
|
||||
isSoldCheck: state.selectedCommunities
|
||||
.contains(community.uuid),
|
||||
onExpansionChanged: () {
|
||||
context
|
||||
.read<SpaceTreeBloc>()
|
||||
.add(OnCommunityExpanded(
|
||||
community.uuid));
|
||||
.add(OnCommunityExpanded(community.uuid));
|
||||
},
|
||||
isExpanded: state
|
||||
.expandedCommunities
|
||||
isExpanded: state.expandedCommunities
|
||||
.contains(community.uuid),
|
||||
onItemSelected: () {
|
||||
context
|
||||
.read<SpaceTreeBloc>()
|
||||
.add(OnCommunitySelected(
|
||||
community.uuid,
|
||||
community.spaces));
|
||||
context.read<SpaceTreeBloc>().add(
|
||||
OnCommunitySelected(
|
||||
community.uuid, community.spaces));
|
||||
widget.onSelect();
|
||||
},
|
||||
children:
|
||||
community.spaces.map((space) {
|
||||
children: community.spaces.map((space) {
|
||||
return CustomExpansionTileSpaceTree(
|
||||
title: space.name,
|
||||
isExpanded: state
|
||||
.expandedSpaces
|
||||
.contains(space.uuid),
|
||||
isExpanded:
|
||||
state.expandedSpaces.contains(space.uuid),
|
||||
onItemSelected: () {
|
||||
context.read<SpaceTreeBloc>().add(
|
||||
OnSpaceSelected(community, space.uuid ?? '',
|
||||
@ -178,20 +153,14 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
widget.onSelect();
|
||||
},
|
||||
onExpansionChanged: () {
|
||||
context
|
||||
.read<SpaceTreeBloc>()
|
||||
.add(OnSpaceExpanded(
|
||||
community.uuid,
|
||||
space.uuid ?? ''));
|
||||
context.read<SpaceTreeBloc>().add(
|
||||
OnSpaceExpanded(
|
||||
community.uuid, space.uuid ?? ''));
|
||||
},
|
||||
isSelected: state
|
||||
.selectedSpaces
|
||||
.contains(
|
||||
space.uuid) ||
|
||||
state.soldCheck
|
||||
.contains(space.uuid),
|
||||
isSoldCheck: state.soldCheck
|
||||
.contains(space.uuid),
|
||||
isSelected:
|
||||
state.selectedSpaces.contains(space.uuid) ||
|
||||
state.soldCheck.contains(space.uuid),
|
||||
isSoldCheck: state.soldCheck.contains(space.uuid),
|
||||
children: _buildNestedSpaces(
|
||||
context, state, space, community),
|
||||
);
|
||||
@ -279,8 +248,8 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
|
||||
BuildContext context, SpaceTreeState state, SpaceModel space, CommunityModel community) {
|
||||
return space.children.map((child) {
|
||||
return CustomExpansionTileSpaceTree(
|
||||
isSelected: state.selectedSpaces.contains(child.uuid) ||
|
||||
state.soldCheck.contains(child.uuid),
|
||||
isSelected:
|
||||
state.selectedSpaces.contains(child.uuid) || state.soldCheck.contains(child.uuid),
|
||||
isSoldCheck: state.soldCheck.contains(child.uuid),
|
||||
title: child.name,
|
||||
isExpanded: state.expandedSpaces.contains(child.uuid),
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/widgets.dart';
|
||||
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';
|
||||
@ -261,27 +262,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
return;
|
||||
}
|
||||
|
||||
if (communities.isEmpty) {
|
||||
communities = await _api.fetchCommunities(projectUuid);
|
||||
|
||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||
communities.map((community) async {
|
||||
List<SpaceModel> spaces = await _fetchSpacesForCommunity(community.uuid);
|
||||
return CommunityModel(
|
||||
uuid: community.uuid,
|
||||
createdAt: community.createdAt,
|
||||
updatedAt: community.updatedAt,
|
||||
name: community.name,
|
||||
description: community.description,
|
||||
spaces: spaces,
|
||||
region: community.region,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
communities = updatedCommunities;
|
||||
}
|
||||
|
||||
emit(BlankState(
|
||||
spaceModels: prevSpaceModels,
|
||||
communities: communities,
|
||||
@ -457,7 +437,8 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
emit(SpaceManagementLoading());
|
||||
|
||||
try {
|
||||
final updatedSpaces = await saveSpacesHierarchically(event.spaces, event.communityUuid);
|
||||
final updatedSpaces =
|
||||
await saveSpacesHierarchically(event.context, event.spaces, event.communityUuid);
|
||||
|
||||
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
|
||||
|
||||
@ -508,9 +489,14 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
}
|
||||
|
||||
Future<List<SpaceModel>> saveSpacesHierarchically(
|
||||
List<SpaceModel> spaces, String communityUuid) async {
|
||||
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,
|
||||
);
|
||||
|
||||
final parentsToDelete = orderedSpaces.where((space) =>
|
||||
space.status == SpaceStatus.deleted &&
|
||||
@ -532,7 +518,13 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
if (space.uuid != null && space.uuid!.isNotEmpty) {
|
||||
List<TagModelUpdate> tagUpdates = [];
|
||||
|
||||
final prevSpace = await _api.getSpace(communityUuid, space.uuid!, projectUuid);
|
||||
List<SpaceModel> matchedSpaces =
|
||||
findMatchingSpaces(selectedCommunity.spaces, space.uuid!);
|
||||
|
||||
if (matchedSpaces.isEmpty) continue;
|
||||
|
||||
final prevSpace = matchedSpaces[0];
|
||||
|
||||
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
|
||||
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
|
||||
final List<SubspaceModel>? newSubspaces = space.subspaces;
|
||||
@ -609,6 +601,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
subspaces: subspaceUpdates,
|
||||
tags: tagUpdates,
|
||||
direction: space.incomingConnection?.direction,
|
||||
spaceModelUuid: space.spaceModel?.uuid,
|
||||
projectId: projectUuid);
|
||||
} else {
|
||||
// Call create if the space does not have a UUID
|
||||
@ -682,27 +675,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
|
||||
var prevSpaceModels = await fetchSpaceModels();
|
||||
|
||||
if (communities.isEmpty) {
|
||||
communities = await _api.fetchCommunities(projectUuid);
|
||||
|
||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||
communities.map((community) async {
|
||||
List<SpaceModel> spaces = await _fetchSpacesForCommunity(community.uuid);
|
||||
return CommunityModel(
|
||||
uuid: community.uuid,
|
||||
createdAt: community.createdAt,
|
||||
updatedAt: community.updatedAt,
|
||||
name: community.name,
|
||||
description: community.description,
|
||||
spaces: spaces,
|
||||
region: community.region,
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
|
||||
communities = updatedCommunities;
|
||||
}
|
||||
|
||||
emit(SpaceModelLoaded(
|
||||
communities: communities,
|
||||
products: _cachedProducts ?? [],
|
||||
@ -785,4 +757,18 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
|
||||
return tagUpdates;
|
||||
}
|
||||
|
||||
List<SpaceModel> findMatchingSpaces(List<SpaceModel> spaces, String targetUuid) {
|
||||
List<SpaceModel> matched = [];
|
||||
|
||||
for (var space in spaces) {
|
||||
if (space.uuid == targetUuid) {
|
||||
matched.add(space);
|
||||
}
|
||||
matched
|
||||
.addAll(findMatchingSpaces(space.children, targetUuid)); // Recursively search in children
|
||||
}
|
||||
|
||||
return matched;
|
||||
}
|
||||
}
|
||||
|
@ -58,14 +58,16 @@ class CreateSpaceEvent extends SpaceManagementEvent {
|
||||
class SaveSpacesEvent extends SpaceManagementEvent {
|
||||
final List<SpaceModel> spaces;
|
||||
final String communityUuid;
|
||||
final BuildContext context;
|
||||
|
||||
const SaveSpacesEvent({
|
||||
const SaveSpacesEvent(
|
||||
this.context, {
|
||||
required this.spaces,
|
||||
required this.communityUuid,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [spaces, communityUuid];
|
||||
List<Object> get props => [spaces, communityUuid, context];
|
||||
}
|
||||
|
||||
class UpdateSpacePositionEvent extends SpaceManagementEvent {
|
||||
@ -170,4 +172,4 @@ class UpdateSpaceModelCache extends SpaceManagementEvent {
|
||||
class DeleteSpaceModelFromCache extends SpaceManagementEvent {
|
||||
final String deletedUuid;
|
||||
DeleteSpaceModelFromCache(this.deletedUuid);
|
||||
}
|
||||
}
|
||||
|
@ -460,6 +460,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
String communityUuid = widget.selectedCommunity!.uuid;
|
||||
|
||||
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
|
||||
context,
|
||||
spaces: spacesToSave,
|
||||
communityUuid: communityUuid,
|
||||
));
|
||||
|
@ -297,6 +297,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
),
|
||||
onDeleted: () => setState(() {
|
||||
this.selectedSpaceModel = null;
|
||||
subspaces = widget.subspaces ?? [];
|
||||
tags = widget.tags ?? [];
|
||||
})),
|
||||
],
|
||||
),
|
||||
|
@ -28,10 +28,11 @@ class LinkSpaceToModelBloc
|
||||
try {
|
||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||
spacesListIds.clear();
|
||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList =
|
||||
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||
spacesListIds = spacesList;
|
||||
spacesListIds.addAll(spacesList);
|
||||
}
|
||||
hasSelectedSpaces =
|
||||
spaceBloc.state.selectedCommunities.any((communityId) {
|
||||
|
@ -18,8 +18,10 @@ import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_room_widget.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
import 'package:syncrow_web/utils/string_utils.dart';
|
||||
|
||||
class SpaceModelCardWidget extends StatelessWidget {
|
||||
class SpaceModelCardWidget extends StatelessWidget with HelperResponsiveLayout {
|
||||
final SpaceTemplateModel model;
|
||||
final BuildContext? pageContext;
|
||||
final bool topActionsDisabled;
|
||||
@ -76,14 +78,17 @@ class SpaceModelCardWidget extends StatelessWidget {
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
model.modelName,
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
Expanded(
|
||||
child: Text(
|
||||
StringUtils.capitalizeFirstLetter(model.modelName),
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
color: ColorsManager.blackColor,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: isSmallScreenSize(context) ? 13 : 20,
|
||||
),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
if (!topActionsDisabled)
|
||||
Row(
|
||||
@ -95,15 +100,12 @@ class SpaceModelCardWidget extends StatelessWidget {
|
||||
builder: (BuildContext dialogContext) {
|
||||
return BlocProvider<LinkSpaceToModelBloc>(
|
||||
create: (_) => LinkSpaceToModelBloc(),
|
||||
child: BlocListener<LinkSpaceToModelBloc,
|
||||
LinkSpaceToModelState>(
|
||||
child: BlocListener<LinkSpaceToModelBloc, LinkSpaceToModelState>(
|
||||
listenWhen: (previous, current) {
|
||||
return previous != current;
|
||||
},
|
||||
listener: (context, state) {
|
||||
final _bloc =
|
||||
BlocProvider.of<LinkSpaceToModelBloc>(
|
||||
context);
|
||||
final _bloc = BlocProvider.of<LinkSpaceToModelBloc>(context);
|
||||
if (state is SpaceModelLoading) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@ -111,19 +113,14 @@ class SpaceModelCardWidget extends StatelessWidget {
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(
|
||||
20)),
|
||||
borderRadius: BorderRadius.circular(20)),
|
||||
elevation: 10,
|
||||
backgroundColor: Colors.white,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(
|
||||
vertical: 30,
|
||||
horizontal: 50),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 30, horizontal: 50),
|
||||
child: Column(
|
||||
mainAxisSize:
|
||||
MainAxisSize.min,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CustomLoadingIndicator(),
|
||||
],
|
||||
@ -132,19 +129,14 @@ class SpaceModelCardWidget extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
);
|
||||
} else if (state
|
||||
is AlreadyHaveLinkedState) {
|
||||
} else if (state is AlreadyHaveLinkedState) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
showOverwriteDialog(
|
||||
context, _bloc, model);
|
||||
} else if (state
|
||||
is SpaceValidationSuccess) {
|
||||
showOverwriteDialog(context, _bloc, model);
|
||||
} else if (state is SpaceValidationSuccess) {
|
||||
_bloc.add(LinkSpaceModelEvent(
|
||||
isOverWrite: false,
|
||||
selectedSpaceMode: model.uuid));
|
||||
isOverWrite: false, selectedSpaceMode: model.uuid));
|
||||
|
||||
Future.delayed(
|
||||
const Duration(seconds: 1), () {
|
||||
Future.delayed(const Duration(seconds: 1), () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
Navigator.of(dialogContext).pop();
|
||||
Navigator.of(dialogContext).pop();
|
||||
@ -152,29 +144,23 @@ class SpaceModelCardWidget extends StatelessWidget {
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder:
|
||||
(BuildContext dialogContext) {
|
||||
builder: (BuildContext dialogContext) {
|
||||
return const LinkingSuccessful();
|
||||
},
|
||||
).then((v) {
|
||||
Future.delayed(
|
||||
const Duration(seconds: 2), () {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
});
|
||||
});
|
||||
} else if (state
|
||||
is SpaceModelLinkSuccess) {
|
||||
} else if (state is SpaceModelLinkSuccess) {
|
||||
Navigator.of(dialogContext).pop();
|
||||
Navigator.of(dialogContext).pop();
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext
|
||||
successDialogContext) {
|
||||
Future.delayed(
|
||||
const Duration(seconds: 2), () {
|
||||
Navigator.of(successDialogContext)
|
||||
.pop();
|
||||
builder: (BuildContext successDialogContext) {
|
||||
Future.delayed(const Duration(seconds: 2), () {
|
||||
Navigator.of(successDialogContext).pop();
|
||||
});
|
||||
|
||||
return const LinkingSuccessful();
|
||||
@ -232,8 +218,7 @@ class SpaceModelCardWidget extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
),
|
||||
if (productTagCount.isNotEmpty &&
|
||||
model.subspaceModels != null)
|
||||
if (productTagCount.isNotEmpty && model.subspaceModels != null)
|
||||
Container(
|
||||
width: 1.0,
|
||||
color: ColorsManager.softGray,
|
||||
|
@ -6,14 +6,12 @@ import 'package:syncrow_web/pages/routines/models/routine_details_model.dart';
|
||||
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
|
||||
import 'package:syncrow_web/services/api/http_service.dart';
|
||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||
|
||||
class SceneApi {
|
||||
static final HTTPService _httpService = HTTPService();
|
||||
|
||||
// //create scene
|
||||
static Future<Map<String, dynamic>> createScene(
|
||||
CreateSceneModel createSceneModel) async {
|
||||
static Future<Map<String, dynamic>> createScene(CreateSceneModel createSceneModel) async {
|
||||
try {
|
||||
debugPrint('create scene model: ${createSceneModel.toMap()}');
|
||||
final response = await _httpService.post(
|
||||
@ -35,10 +33,10 @@ class SceneApi {
|
||||
//
|
||||
// create automation
|
||||
static Future<Map<String, dynamic>> createAutomation(
|
||||
CreateAutomationModel createAutomationModel) async {
|
||||
CreateAutomationModel createAutomationModel, String projectId) async {
|
||||
try {
|
||||
final response = await _httpService.post(
|
||||
path: ApiEndpoints.createAutomation,
|
||||
path: ApiEndpoints.createAutomation.replaceAll('{projectId}', projectId),
|
||||
body: createAutomationModel.toMap(),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
@ -70,8 +68,7 @@ class SceneApi {
|
||||
|
||||
//get scenes by community id and space id
|
||||
|
||||
static Future<List<ScenesModel>> getScenes(
|
||||
String spaceId, String communityId, String projectId,
|
||||
static Future<List<ScenesModel>> getScenes(String spaceId, String communityId, String projectId,
|
||||
{showInDevice = false}) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
@ -99,11 +96,14 @@ class SceneApi {
|
||||
|
||||
//getAutomation
|
||||
|
||||
static Future<List<ScenesModel>> getAutomation(String spaceId) async {
|
||||
static Future<List<ScenesModel>> getAutomation(
|
||||
String spaceId, String communityId, String projectId) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path:
|
||||
ApiEndpoints.getSpaceAutomation.replaceAll('{spaceUuid}', spaceId),
|
||||
path: ApiEndpoints.getSpaceAutomation
|
||||
.replaceAll('{spaceUuid}', spaceId)
|
||||
.replaceAll('{communityId}', communityId)
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScenesModel> scenes = [];
|
||||
@ -134,11 +134,12 @@ class SceneApi {
|
||||
|
||||
//automation details
|
||||
static Future<RoutineDetailsModel> getAutomationDetails(
|
||||
String automationId) async {
|
||||
String automationId, String projectId) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getAutomationDetails
|
||||
.replaceAll('{automationId}', automationId),
|
||||
.replaceAll('{automationId}', automationId)
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => RoutineDetailsModel.fromMap(json),
|
||||
);
|
||||
@ -153,8 +154,7 @@ class SceneApi {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
|
||||
body: createSceneModel
|
||||
.toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
||||
body: createSceneModel.toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
@ -167,13 +167,13 @@ class SceneApi {
|
||||
|
||||
//update automation
|
||||
static updateAutomation(
|
||||
CreateAutomationModel createAutomationModel, String automationId) async {
|
||||
CreateAutomationModel createAutomationModel, String automationId, String projectId) async {
|
||||
try {
|
||||
final response = await _httpService.put(
|
||||
path: ApiEndpoints.updateAutomation
|
||||
.replaceAll('{automationId}', automationId),
|
||||
body: createAutomationModel
|
||||
.toJson(automationId.isNotEmpty == true ? automationId : null),
|
||||
.replaceAll('{automationId}', automationId)
|
||||
.replaceAll('{projectId}', projectId),
|
||||
body: createAutomationModel.toJson(automationId.isNotEmpty == true ? automationId : null),
|
||||
expectedResponseModel: (json) {
|
||||
return json;
|
||||
},
|
||||
@ -190,8 +190,7 @@ class SceneApi {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) =>
|
||||
RoutineDetailsModel.fromMap(json['data']),
|
||||
expectedResponseModel: (json) => RoutineDetailsModel.fromMap(json['data']),
|
||||
);
|
||||
return response;
|
||||
} catch (e) {
|
||||
@ -200,8 +199,7 @@ class SceneApi {
|
||||
}
|
||||
|
||||
//delete Scene
|
||||
static Future<bool> deleteScene(
|
||||
{required String unitUuid, required String sceneId}) async {
|
||||
static Future<bool> deleteScene({required String unitUuid, required String sceneId}) async {
|
||||
try {
|
||||
final response = await _httpService.delete(
|
||||
path: ApiEndpoints.deleteScene
|
||||
@ -218,12 +216,12 @@ class SceneApi {
|
||||
|
||||
// delete automation
|
||||
static Future<bool> deleteAutomation(
|
||||
{required String unitUuid, required String automationId}) async {
|
||||
{required String unitUuid, required String automationId, required String projectId}) async {
|
||||
try {
|
||||
final response = await _httpService.delete(
|
||||
path: ApiEndpoints.deleteAutomation
|
||||
.replaceAll('{automationId}', automationId)
|
||||
.replaceAll('{unitUuid}', unitUuid),
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) => json['statusCode'] == 200,
|
||||
);
|
||||
|
@ -227,6 +227,7 @@ class CommunitySpaceManagementApi {
|
||||
required Offset position,
|
||||
List<TagModelUpdate>? tags,
|
||||
List<UpdateSubspaceTemplateModel>? subspaces,
|
||||
String? spaceModelUuid,
|
||||
required String projectId}) async {
|
||||
try {
|
||||
final body = {
|
||||
@ -238,6 +239,7 @@ class CommunitySpaceManagementApi {
|
||||
'icon': icon,
|
||||
'subspace': subspaces,
|
||||
'tags': tags,
|
||||
'spaceModelUuid': spaceModelUuid,
|
||||
};
|
||||
if (parentId != null) {
|
||||
body['parentUuid'] = parentId;
|
||||
|
@ -69,20 +69,21 @@ abstract class ApiEndpoints {
|
||||
//product
|
||||
static const String listProducts = '/products';
|
||||
static const String getSpaceScenes = '/scene/tap-to-run/{spaceUuid}';
|
||||
static const String getSpaceAutomation = '/automation/{spaceUuid}';
|
||||
static const String getSpaceAutomation =
|
||||
'/projects/{projectId}/communities/{communityId}/spaces/{spaceUuid}/automations';
|
||||
static const String getIconScene = '/scene/icon';
|
||||
static const String createScene = '/scene/tap-to-run';
|
||||
static const String createAutomation = '/automation';
|
||||
static const String createAutomation = '/projects/{projectId}/automations';
|
||||
static const String getUnitScenes =
|
||||
'/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/scenes';
|
||||
static const String getAutomationDetails = '/automation/details/{automationId}';
|
||||
static const String getAutomationDetails = '/projects/{projectId}/automations/{automationId}';
|
||||
static const String getScene = '/scene/tap-to-run/{sceneId}';
|
||||
static const String deleteScene = '/scene/tap-to-run/{sceneId}';
|
||||
|
||||
static const String deleteAutomation = '/automation/{automationId}';
|
||||
static const String deleteAutomation = '/projects/{projectId}/automations/{automationId}';
|
||||
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
||||
|
||||
static const String updateAutomation = '/automation/{automationId}';
|
||||
static const String updateAutomation = '/projects/{projectId}/automations/{automationId}';
|
||||
|
||||
//space model
|
||||
static const String listSpaceModels = '/projects/{projectId}/space-models';
|
||||
|
6
lib/utils/string_utils.dart
Normal file
6
lib/utils/string_utils.dart
Normal file
@ -0,0 +1,6 @@
|
||||
class StringUtils {
|
||||
static String capitalizeFirstLetter(String text) {
|
||||
if (text.isEmpty) return text;
|
||||
return text[0].toUpperCase() + text.substring(1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user