mirror of
https://github.com/SyncrowIOT/web.git
synced 2026-10-26 22:17:56 +00:00
Compare commits
31
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76e44c8910 | ||
|
|
02c788d03a | ||
|
|
938f8c6b51 | ||
|
|
3ce9a313f7 | ||
|
|
b732b0b957 | ||
|
|
fb6b922df4 | ||
|
|
ce6e7700bc | ||
|
|
8d388ac482 | ||
|
|
42c7577b35 | ||
|
|
ae2b4b9b06 | ||
|
|
98faef2bde | ||
|
|
edf297c569 | ||
|
|
2cd850b66f | ||
|
|
3c543b2e0f | ||
|
|
a3c6421b0d | ||
|
|
875787919e | ||
|
|
51402720dd | ||
|
|
123291fd89 | ||
|
|
69e3f50269 | ||
|
|
bd78c8c1cc | ||
|
|
4047664c59 | ||
|
|
084f4fbda8 | ||
|
|
817671dbeb | ||
|
|
660b5aaf6c | ||
|
|
0f500a4efa | ||
|
|
0b2d44fc2b | ||
|
|
b75f8a3440 | ||
|
|
d02d680520 | ||
|
|
68ae992963 | ||
|
|
ea20afd34e | ||
|
|
b0f0a91cda |
@@ -94,7 +94,7 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
return const RoutinesView();
|
return const RoutinesView();
|
||||||
}
|
}
|
||||||
if (state is ShowCreateRoutineState && state.showCreateRoutine) {
|
if (state is ShowCreateRoutineState && state.showCreateRoutine) {
|
||||||
return const CreateNewRoutineView();
|
return CreateNewRoutineView();
|
||||||
}
|
}
|
||||||
|
|
||||||
return BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
|
return BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
EffectPeriodBloc() : super(EffectPeriodState.initial()) {
|
EffectPeriodBloc() : super(EffectPeriodState.initial()) {
|
||||||
|
on<InitialEffectPeriodEvent>(_initialEvent);
|
||||||
on<SetPeriod>(_onSetPeriod);
|
on<SetPeriod>(_onSetPeriod);
|
||||||
on<ToggleDay>(_onToggleDay);
|
on<ToggleDay>(_onToggleDay);
|
||||||
on<SetCustomTime>(_onSetCustomTime);
|
on<SetCustomTime>(_onSetCustomTime);
|
||||||
@@ -24,6 +25,15 @@ class EffectPeriodBloc extends Bloc<EffectPeriodEvent, EffectPeriodState> {
|
|||||||
on<SetDays>(_setAllDays);
|
on<SetDays>(_setAllDays);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _initialEvent(InitialEffectPeriodEvent event, Emitter<EffectPeriodState> emit) {
|
||||||
|
add(SetCustomTime(event.effectiveTime.start, event.effectiveTime.end));
|
||||||
|
emit(state.copyWith(
|
||||||
|
selectedDaysBinary: event.effectiveTime.loops,
|
||||||
|
customStartTime: event.effectiveTime.start,
|
||||||
|
customEndTime: event.effectiveTime.end,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
void _onSetPeriod(SetPeriod event, Emitter<EffectPeriodState> emit) {
|
void _onSetPeriod(SetPeriod event, Emitter<EffectPeriodState> emit) {
|
||||||
String startTime = '';
|
String startTime = '';
|
||||||
String endTime = '';
|
String endTime = '';
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
import 'package:syncrow_web/utils/constants/app_enum.dart';
|
import 'package:syncrow_web/utils/constants/app_enum.dart';
|
||||||
|
|
||||||
abstract class EffectPeriodEvent extends Equatable {
|
abstract class EffectPeriodEvent extends Equatable {
|
||||||
@@ -8,6 +9,15 @@ abstract class EffectPeriodEvent extends Equatable {
|
|||||||
List<Object> get props => [];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class InitialEffectPeriodEvent extends EffectPeriodEvent {
|
||||||
|
final EffectiveTime effectiveTime;
|
||||||
|
|
||||||
|
const InitialEffectPeriodEvent(this.effectiveTime);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [effectiveTime];
|
||||||
|
}
|
||||||
|
|
||||||
class SetPeriod extends EffectPeriodEvent {
|
class SetPeriod extends EffectPeriodEvent {
|
||||||
final EnumEffectivePeriodOptions period;
|
final EnumEffectivePeriodOptions period;
|
||||||
|
|
||||||
|
|||||||
@@ -3,12 +3,18 @@ import 'dart:async';
|
|||||||
import 'package:bloc/bloc.dart';
|
import 'package:bloc/bloc.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/models/delay/delay_fucntions.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/routine_details_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/routine_details_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
|
||||||
|
import 'package:syncrow_web/services/devices_mang_api.dart';
|
||||||
import 'package:syncrow_web/services/routines_api.dart';
|
import 'package:syncrow_web/services/routines_api.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:syncrow_web/utils/navigation_service.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
part 'routine_event.dart';
|
part 'routine_event.dart';
|
||||||
part 'routine_state.dart';
|
part 'routine_state.dart';
|
||||||
@@ -34,11 +40,12 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
on<ResetRoutineState>(_onResetRoutineState);
|
on<ResetRoutineState>(_onResetRoutineState);
|
||||||
on<GetSceneDetails>(_onGetSceneDetails);
|
on<GetSceneDetails>(_onGetSceneDetails);
|
||||||
on<GetAutomationDetails>(_onGetAutomationDetails);
|
on<GetAutomationDetails>(_onGetAutomationDetails);
|
||||||
// on<InitializeRoutineState>(_onInitializeRoutineState);
|
|
||||||
on<DeleteScene>(_deleteScene);
|
on<DeleteScene>(_deleteScene);
|
||||||
on<DeleteAutomation>(_deleteAutomation);
|
// on<DeleteAutomation>(_deleteAutomation);
|
||||||
// on<RemoveFunction>(_onRemoveFunction);
|
on<FetchDevicesInRoutine>(_fetchDevices);
|
||||||
// on<ClearFunctions>(_onClearFunctions);
|
on<UpdateScene>(_onUpdateScene);
|
||||||
|
on<UpdateAutomation>(_onUpdateAutomation);
|
||||||
|
on<SetAutomationActionExecutor>(_onSetAutomationActionExecutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAddToIfContainer(AddToIfContainer event, Emitter<RoutineState> emit) {
|
void _onAddToIfContainer(AddToIfContainer event, Emitter<RoutineState> emit) {
|
||||||
@@ -194,6 +201,11 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
return actions.first['deviceId'] == 'delay';
|
return actions.first['deviceId'] == 'delay';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _isLastActionDelay(List<Map<String, dynamic>> actions) {
|
||||||
|
if (actions.isEmpty) return false;
|
||||||
|
return actions.last['deviceId'] == 'delay';
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _onCreateScene(
|
Future<void> _onCreateScene(
|
||||||
CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
@@ -206,7 +218,15 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(state.copyWith(isLoading: true));
|
if (_isLastActionDelay(state.thenItems)) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
errorMessage: 'Cannot have delay as the last action',
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
|
|
||||||
final actions = state.thenItems.expand((item) {
|
final actions = state.thenItems.expand((item) {
|
||||||
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
@@ -254,8 +274,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
final result = await SceneApi.createScene(createSceneModel);
|
final result = await SceneApi.createScene(createSceneModel);
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
emit(_resetState());
|
Navigator.of(NavigationService.navigatorKey.currentContext!).pop();
|
||||||
|
add(ResetRoutineState());
|
||||||
add(const LoadScenes(spaceId, communityId));
|
add(const LoadScenes(spaceId, communityId));
|
||||||
|
add(const LoadAutomation(spaceId));
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -279,8 +301,22 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (_isFirstActionDelay(state.thenItems)) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
errorMessage: 'Cannot have delay as the first action',
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emit(state.copyWith(isLoading: true));
|
if (_isLastActionDelay(state.thenItems)) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
errorMessage: 'Cannot have delay as the last action',
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
|
|
||||||
final conditions = state.ifItems.expand((item) {
|
final conditions = state.ifItems.expand((item) {
|
||||||
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
@@ -355,8 +391,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
final result = await SceneApi.createAutomation(createAutomationModel);
|
final result = await SceneApi.createAutomation(createAutomationModel);
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
emit(_resetState());
|
Navigator.of(NavigationService.navigatorKey.currentContext!).pop();
|
||||||
|
add(ResetRoutineState());
|
||||||
add(const LoadAutomation(spaceId));
|
add(const LoadAutomation(spaceId));
|
||||||
|
add(const LoadScenes(spaceId, communityId));
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -419,21 +457,285 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
emit(state.copyWith(routineName: event.name));
|
emit(state.copyWith(routineName: event.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
(
|
||||||
|
List<Map<String, dynamic>>,
|
||||||
|
List<Map<String, dynamic>>,
|
||||||
|
Map<String, List<DeviceFunctionData>>
|
||||||
|
) _createCardData(
|
||||||
|
List<RoutineAction> actions,
|
||||||
|
List<RoutineCondition>? conditions,
|
||||||
|
Map<String, List<DeviceFunctionData>> currentFunctions,
|
||||||
|
bool isTabToRun,
|
||||||
|
) {
|
||||||
|
final ifItems = isTabToRun
|
||||||
|
? [
|
||||||
|
{
|
||||||
|
'entityId': 'tab_to_run',
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId': 'tab_to_run',
|
||||||
|
'title': 'Tab to run',
|
||||||
|
'productType': 'tab_to_run',
|
||||||
|
'imagePath': Assets.tabToRun,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
: conditions?.map((condition) {
|
||||||
|
final matchingDevice = state.devices.firstWhere(
|
||||||
|
(device) => device.uuid == condition.entityId,
|
||||||
|
orElse: () => AllDevicesModel(
|
||||||
|
uuid: condition.entityId,
|
||||||
|
name: condition.entityId,
|
||||||
|
productType: condition.entityType,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final cardData = {
|
||||||
|
'entityId': condition.entityId,
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId': condition.entityId,
|
||||||
|
'title': matchingDevice.name ?? condition.entityId,
|
||||||
|
'productType': condition.entityType,
|
||||||
|
'imagePath':
|
||||||
|
matchingDevice.getDefaultIcon(condition.entityType),
|
||||||
|
};
|
||||||
|
|
||||||
|
final functions = matchingDevice.functions;
|
||||||
|
|
||||||
|
for (var function in functions) {
|
||||||
|
if (function.code == condition.expr.statusCode) {
|
||||||
|
currentFunctions[cardData['uniqueCustomId'] ?? ''] = [
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: condition.entityId,
|
||||||
|
functionCode: condition.expr.statusCode,
|
||||||
|
value: condition.expr.statusValue,
|
||||||
|
operationName: function.operationName,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardData;
|
||||||
|
}).toList() ??
|
||||||
|
[];
|
||||||
|
|
||||||
|
final thenItems = actions.map((action) {
|
||||||
|
final matchingDevice = state.devices.firstWhere(
|
||||||
|
(device) => device.uuid == action.entityId,
|
||||||
|
orElse: () => AllDevicesModel(
|
||||||
|
uuid: action.entityId,
|
||||||
|
name: action.entityId,
|
||||||
|
productType: action.productType,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final cardData = {
|
||||||
|
'entityId': action.entityId,
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId':
|
||||||
|
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||||
|
'title': action.actionExecutor == 'delay'
|
||||||
|
? 'Delay'
|
||||||
|
: (matchingDevice.name ?? 'Device'),
|
||||||
|
'productType': action.productType,
|
||||||
|
'imagePath': matchingDevice.getDefaultIcon(action.productType),
|
||||||
|
};
|
||||||
|
|
||||||
|
final functions = matchingDevice.functions;
|
||||||
|
|
||||||
|
if (action.executorProperty != null && action.actionExecutor != 'delay') {
|
||||||
|
final functionCode = action.executorProperty!.functionCode;
|
||||||
|
for (var function in functions) {
|
||||||
|
if (function.code == functionCode) {
|
||||||
|
currentFunctions[cardData['uniqueCustomId'] ?? ''] = [
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: functionCode ?? '',
|
||||||
|
value: action.executorProperty!.functionValue,
|
||||||
|
operationName: function.operationName,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (action.actionExecutor == 'delay') {
|
||||||
|
final delayFunction = DelayFunction(
|
||||||
|
deviceId: action.entityId,
|
||||||
|
deviceName: 'Delay',
|
||||||
|
);
|
||||||
|
currentFunctions[cardData['uniqueCustomId'] ?? ''] = [
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: 'delay',
|
||||||
|
value: action.executorProperty?.delaySeconds ?? 0,
|
||||||
|
operationName: delayFunction.operationName,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardData;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
return (thenItems, ifItems, currentFunctions);
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _onGetSceneDetails(
|
Future<void> _onGetSceneDetails(
|
||||||
GetSceneDetails event, Emitter<RoutineState> emit) async {
|
GetSceneDetails event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
isTabToRun: event.isTabToRun,
|
isTabToRun: true,
|
||||||
isUpdate: true,
|
isUpdate: true,
|
||||||
sceneId: event.sceneId,
|
sceneId: event.sceneId,
|
||||||
isAutomation: false));
|
routineName: null,
|
||||||
|
isAutomation: false,
|
||||||
|
selectedFunctions: {},
|
||||||
|
ifItems: [],
|
||||||
|
thenItems: [],
|
||||||
|
errorMessage: null,
|
||||||
|
loadScenesErrorMessage: null,
|
||||||
|
loadAutomationErrorMessage: null,
|
||||||
|
searchText: '',
|
||||||
|
selectedIcon: null,
|
||||||
|
selectedAutomationOperator: 'or',
|
||||||
|
effectiveTime: null,
|
||||||
|
));
|
||||||
|
|
||||||
final sceneDetails = await SceneApi.getSceneDetails(event.sceneId);
|
final sceneDetails = await SceneApi.getSceneDetails(event.sceneId);
|
||||||
add(InitializeRoutineState(sceneDetails));
|
|
||||||
|
final List<Map<String, dynamic>> thenItems;
|
||||||
|
final List<Map<String, dynamic>> ifItems;
|
||||||
|
final Map<String, List<DeviceFunctionData>> updatedFunctions =
|
||||||
|
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||||
|
|
||||||
|
final Map<String, Map<String, dynamic>> deviceCards = {};
|
||||||
|
|
||||||
|
for (var action in sceneDetails.actions) {
|
||||||
|
AllDevicesModel? matchingDevice;
|
||||||
|
for (var device in state.devices) {
|
||||||
|
if (device.uuid == action.entityId) {
|
||||||
|
matchingDevice = device;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final deviceId = action.type == 'automation'
|
||||||
|
? '${action.entityId}_automation'
|
||||||
|
: action.actionExecutor == 'delay'
|
||||||
|
? '${action.entityId}_delay'
|
||||||
|
: action.entityId;
|
||||||
|
|
||||||
|
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,
|
||||||
|
'title': action.actionExecutor == 'delay'
|
||||||
|
? 'Delay'
|
||||||
|
: action.type == 'automation'
|
||||||
|
? action.name ?? 'Automation'
|
||||||
|
: (matchingDevice?.name ?? 'Device'),
|
||||||
|
'productType': action.productType,
|
||||||
|
'functions': matchingDevice?.functions,
|
||||||
|
'imagePath': action.type == 'automation'
|
||||||
|
? Assets.automation
|
||||||
|
: action.actionExecutor == 'delay'
|
||||||
|
? Assets.delay
|
||||||
|
: matchingDevice?.getDefaultIcon(action.productType),
|
||||||
|
'device': matchingDevice,
|
||||||
|
'name': action.name,
|
||||||
|
'type': action.type,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
final cardData = deviceCards[deviceId]!;
|
||||||
|
final uniqueCustomId = cardData['uniqueCustomId'].toString();
|
||||||
|
|
||||||
|
if (action.type == 'automation') {
|
||||||
|
if (!updatedFunctions.containsKey(uniqueCustomId)) {
|
||||||
|
updatedFunctions[uniqueCustomId] = [];
|
||||||
|
}
|
||||||
|
updatedFunctions[uniqueCustomId]!.add(
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: 'automation',
|
||||||
|
value: action.actionExecutor,
|
||||||
|
operationName: 'Automation',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
emit(state.copyWith(automationActionExecutor: action.actionExecutor));
|
||||||
|
} else if (action.executorProperty != null &&
|
||||||
|
action.actionExecutor != 'delay') {
|
||||||
|
if (!updatedFunctions.containsKey(uniqueCustomId)) {
|
||||||
|
updatedFunctions[uniqueCustomId] = [];
|
||||||
|
}
|
||||||
|
final functions = matchingDevice?.functions;
|
||||||
|
final functionCode = action.executorProperty?.functionCode;
|
||||||
|
for (DeviceFunction function in functions ?? []) {
|
||||||
|
if (function.code == functionCode) {
|
||||||
|
updatedFunctions[uniqueCustomId]!.add(
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: functionCode ?? '',
|
||||||
|
value: action.executorProperty?.functionValue,
|
||||||
|
operationName: function.operationName,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (action.actionExecutor == 'delay') {
|
||||||
|
if (!updatedFunctions.containsKey(uniqueCustomId)) {
|
||||||
|
updatedFunctions[uniqueCustomId] = [];
|
||||||
|
}
|
||||||
|
final delayFunction = DelayFunction(
|
||||||
|
deviceId: action.entityId,
|
||||||
|
deviceName: 'Delay',
|
||||||
|
);
|
||||||
|
updatedFunctions[uniqueCustomId]!.add(
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: 'delay',
|
||||||
|
value: action.executorProperty?.delaySeconds ?? 0,
|
||||||
|
operationName: delayFunction.operationName,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
thenItems = deviceCards.values.toList();
|
||||||
|
|
||||||
|
ifItems = [
|
||||||
|
{
|
||||||
|
'entityId': 'tab_to_run',
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId': 'tab_to_run',
|
||||||
|
'title': 'Tab to run',
|
||||||
|
'productType': 'tab_to_run',
|
||||||
|
'imagePath': Assets.tabToRun,
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
routineName: sceneDetails.name,
|
||||||
|
selectedIcon: sceneDetails.iconId,
|
||||||
|
selectedAutomationOperator: sceneDetails.decisionExpr,
|
||||||
|
effectiveTime: sceneDetails.effectiveTime,
|
||||||
|
isAutomation: false,
|
||||||
|
isTabToRun: event.isTabToRun,
|
||||||
|
thenItems: thenItems,
|
||||||
|
ifItems: ifItems,
|
||||||
|
selectedFunctions: updatedFunctions,
|
||||||
|
sceneId: sceneDetails.sceneId,
|
||||||
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
errorMessage: 'Failed to load scene details',
|
errorMessage: 'Failed to load scene details: $e',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -443,102 +745,158 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
try {
|
try {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
isAutomation: event.isAutomation,
|
|
||||||
automationId: event.automationId,
|
|
||||||
isTabToRun: false,
|
|
||||||
isUpdate: true,
|
isUpdate: true,
|
||||||
|
isTabToRun: false,
|
||||||
|
automationId: event.automationId,
|
||||||
|
isAutomation: true,
|
||||||
|
ifItems: [],
|
||||||
|
thenItems: [],
|
||||||
));
|
));
|
||||||
|
|
||||||
final automationDetails =
|
final automationDetails =
|
||||||
await SceneApi.getAutomationDetails(event.automationId);
|
await SceneApi.getAutomationDetails(event.automationId);
|
||||||
add(InitializeRoutineState(automationDetails));
|
|
||||||
|
final List<Map<String, dynamic>> thenItems;
|
||||||
|
final List<Map<String, dynamic>> ifItems;
|
||||||
|
final Map<String, List<DeviceFunctionData>> updatedFunctions =
|
||||||
|
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||||
|
|
||||||
|
ifItems = automationDetails.conditions?.map((condition) {
|
||||||
|
late AllDevicesModel? matchingDevice;
|
||||||
|
for (var device in state.devices) {
|
||||||
|
if (device.uuid == condition.entityId) {
|
||||||
|
matchingDevice = device;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final cardData = {
|
||||||
|
'entityId': condition.entityId,
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId': condition.expr.statusCode == 'delay'
|
||||||
|
? 'delay'
|
||||||
|
: condition.entityId,
|
||||||
|
'title': condition.expr.statusCode == 'delay'
|
||||||
|
? 'Delay'
|
||||||
|
: (matchingDevice?.name ?? 'Device'),
|
||||||
|
'productType': condition.productType,
|
||||||
|
'functions': matchingDevice?.functions ?? [],
|
||||||
|
'imagePath':
|
||||||
|
matchingDevice?.getDefaultIcon(condition.productType) ?? '',
|
||||||
|
'device': matchingDevice,
|
||||||
|
};
|
||||||
|
|
||||||
|
final functions = matchingDevice?.functions ?? [];
|
||||||
|
for (var function in functions) {
|
||||||
|
if (function.code == condition.expr.statusCode) {
|
||||||
|
updatedFunctions[cardData['uniqueCustomId'].toString()] = [
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: condition.entityId,
|
||||||
|
functionCode: condition.expr.statusCode,
|
||||||
|
value: condition.expr.statusValue,
|
||||||
|
operationName: function.operationName,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardData;
|
||||||
|
}).toList() ??
|
||||||
|
[];
|
||||||
|
|
||||||
|
// Create then items from actions
|
||||||
|
thenItems = automationDetails.actions.map((action) {
|
||||||
|
final matchingDevice = state.devices.firstWhere(
|
||||||
|
(device) => device.uuid == action.entityId,
|
||||||
|
orElse: () => AllDevicesModel(
|
||||||
|
uuid: action.entityId,
|
||||||
|
name: action.entityId,
|
||||||
|
productType: action.productType,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
final cardData = {
|
||||||
|
'entityId': action.entityId,
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId':
|
||||||
|
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||||
|
'title': action.actionExecutor == 'delay'
|
||||||
|
? 'Delay'
|
||||||
|
: (matchingDevice.name ?? 'Device'),
|
||||||
|
'productType': action.productType,
|
||||||
|
'functions': matchingDevice.functions,
|
||||||
|
'imagePath': matchingDevice.getDefaultIcon(action.productType),
|
||||||
|
'device': matchingDevice,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (action.executorProperty != null &&
|
||||||
|
action.actionExecutor != 'delay') {
|
||||||
|
final functions = matchingDevice.functions;
|
||||||
|
final functionCode = action.executorProperty!.functionCode;
|
||||||
|
for (var function in functions) {
|
||||||
|
if (function.code == functionCode) {
|
||||||
|
updatedFunctions[cardData['uniqueCustomId'].toString()] = [
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: functionCode ?? '',
|
||||||
|
value: action.executorProperty!.functionValue,
|
||||||
|
operationName: function.operationName,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (action.actionExecutor == 'delay') {
|
||||||
|
final delayFunction = DelayFunction(
|
||||||
|
deviceId: action.entityId,
|
||||||
|
deviceName: 'Delay',
|
||||||
|
);
|
||||||
|
updatedFunctions[cardData['uniqueCustomId'].toString()] = [
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: 'delay',
|
||||||
|
value: action.executorProperty?.delaySeconds ?? 0,
|
||||||
|
operationName: delayFunction.operationName,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
} else if (action.actionExecutor == 'rule_disable' ||
|
||||||
|
action.actionExecutor == 'rule_enable') {
|
||||||
|
updatedFunctions[cardData['uniqueCustomId'].toString()] = [
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: 'automation',
|
||||||
|
value: action.actionExecutor,
|
||||||
|
operationName: action.name ?? 'Automation',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardData;
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
routineName: automationDetails.name,
|
||||||
|
selectedAutomationOperator: automationDetails.decisionExpr,
|
||||||
|
effectiveTime: automationDetails.effectiveTime,
|
||||||
|
isAutomation: true,
|
||||||
|
thenItems: thenItems,
|
||||||
|
ifItems: ifItems,
|
||||||
|
selectedFunctions: updatedFunctions,
|
||||||
|
automationId: automationDetails.automationId,
|
||||||
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
errorMessage: 'Failed to load automation details',
|
errorMessage: 'Failed to load automation details: $e',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// void _onInitializeRoutineState(
|
FutureOr<void> _onResetRoutineState(
|
||||||
// InitializeRoutineState event, Emitter<RoutineState> emit) {
|
ResetRoutineState event, Emitter<RoutineState> emit) {
|
||||||
// final routineDetails = event.routineDetails;
|
emit(state.copyWith(
|
||||||
|
|
||||||
// // Convert actions to draggable cards for the THEN container
|
|
||||||
// final thenItems = routineDetails.actions.map((action) {
|
|
||||||
// final Map<String, dynamic> cardData = {
|
|
||||||
// 'entityId': action.entityId,
|
|
||||||
// 'uniqueCustomId': const Uuid().v4(),
|
|
||||||
// 'deviceId':
|
|
||||||
// action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
|
||||||
// 'title': action.actionExecutor == 'delay' ? 'Delay' : 'Device',
|
|
||||||
// // fix this
|
|
||||||
// 'imagePath':
|
|
||||||
// action.actionExecutor == 'delay' ? Assets.delay : Assets.logo,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// // Add functions to selectedFunctions
|
|
||||||
// if (action.executorProperty != null) {
|
|
||||||
// final functions = <DeviceFunctionData>[
|
|
||||||
// DeviceFunctionData(
|
|
||||||
// entityId: action.entityId,
|
|
||||||
// functionCode: action.executorProperty!.functionCode ?? '',
|
|
||||||
// value: action.executorProperty!.functionValue,
|
|
||||||
|
|
||||||
// /// fix this
|
|
||||||
// operationName: action.executorProperty?.functionCode ?? ''),
|
|
||||||
// ];
|
|
||||||
// state.selectedFunctions[cardData['uniqueCustomId']] = functions;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// return cardData;
|
|
||||||
// }).toList();
|
|
||||||
|
|
||||||
// // Convert conditions to draggable cards for the IF container
|
|
||||||
// final ifItems = routineDetails.conditions?.map((condition) {
|
|
||||||
// final Map<String, dynamic> cardData = {
|
|
||||||
// 'entityId': condition.entityId,
|
|
||||||
// 'uniqueCustomId': const Uuid().v4(),
|
|
||||||
// 'deviceId': condition.entityId,
|
|
||||||
|
|
||||||
// /// fix this
|
|
||||||
// 'title': 'Device',
|
|
||||||
|
|
||||||
// /// fix this
|
|
||||||
// 'imagePath': Assets.logo,
|
|
||||||
// };
|
|
||||||
|
|
||||||
// // Add functions to selectedFunctions
|
|
||||||
// final functions = <DeviceFunctionData>[
|
|
||||||
// DeviceFunctionData(
|
|
||||||
// entityId: condition.entityId,
|
|
||||||
// functionCode: condition.expr.statusCode,
|
|
||||||
// value: condition.expr.statusValue,
|
|
||||||
// condition: condition.expr.comparator,
|
|
||||||
// operationName: condition.expr.comparator,
|
|
||||||
// ),
|
|
||||||
// ];
|
|
||||||
// state.selectedFunctions[cardData['uniqueCustomId']] = functions;
|
|
||||||
|
|
||||||
// return cardData;
|
|
||||||
// }).toList() ??
|
|
||||||
// [];
|
|
||||||
|
|
||||||
// emit(state.copyWith(
|
|
||||||
// isLoading: false,
|
|
||||||
// routineName: routineDetails.name,
|
|
||||||
// selectedIcon: routineDetails.iconId,
|
|
||||||
// selectedAutomationOperator: routineDetails.decisionExpr,
|
|
||||||
// effectiveTime: routineDetails.effectiveTime,
|
|
||||||
// isAutomation: routineDetails.conditions != null,
|
|
||||||
// isTabToRun: routineDetails.conditions == null,
|
|
||||||
// thenItems: thenItems,
|
|
||||||
// ifItems: ifItems,
|
|
||||||
// selectedFunctions: Map.from(state.selectedFunctions),
|
|
||||||
// ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
RoutineState _resetState() {
|
|
||||||
return const RoutineState(
|
|
||||||
ifItems: [],
|
ifItems: [],
|
||||||
thenItems: [],
|
thenItems: [],
|
||||||
selectedFunctions: {},
|
selectedFunctions: {},
|
||||||
@@ -555,20 +913,22 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
selectedAutomationOperator: 'or',
|
selectedAutomationOperator: 'or',
|
||||||
effectiveTime: null,
|
effectiveTime: null,
|
||||||
routineName: null,
|
routineName: null,
|
||||||
);
|
));
|
||||||
}
|
|
||||||
|
|
||||||
FutureOr<void> _onResetRoutineState(
|
|
||||||
ResetRoutineState event, Emitter<RoutineState> emit) {
|
|
||||||
emit(_resetState());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _deleteScene(DeleteScene event, Emitter<RoutineState> emit) {
|
FutureOr<void> _deleteScene(DeleteScene event, Emitter<RoutineState> emit) {
|
||||||
try {
|
try {
|
||||||
// emit(state.copyWith(isLoading: true));
|
emit(state.copyWith(isLoading: true));
|
||||||
SceneApi.deleteScene(unitUuid: spaceId, sceneId: event.sceneId);
|
if (state.isTabToRun) {
|
||||||
|
SceneApi.deleteScene(unitUuid: spaceId, sceneId: state.sceneId ?? '');
|
||||||
|
} else {
|
||||||
|
SceneApi.deleteAutomation(
|
||||||
|
unitUuid: spaceId, automationId: state.automationId ?? '');
|
||||||
|
}
|
||||||
|
|
||||||
add(const LoadScenes(spaceId, communityId));
|
add(const LoadScenes(spaceId, communityId));
|
||||||
//emit(_resetState());
|
add(const LoadAutomation(spaceId));
|
||||||
|
add(ResetRoutineState());
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@@ -577,19 +937,200 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _deleteAutomation(
|
// FutureOr<void> _deleteAutomation(DeleteAutomation event, Emitter<RoutineState> emit) {
|
||||||
DeleteAutomation event, Emitter<RoutineState> emit) {
|
// try {
|
||||||
|
// emit(state.copyWith(isLoading: true));
|
||||||
|
// add(const LoadAutomation(spaceId));
|
||||||
|
// add(const LoadScenes(spaceId, communityId));
|
||||||
|
// emit(_resetState());
|
||||||
|
// } catch (e) {
|
||||||
|
// emit(state.copyWith(
|
||||||
|
// isLoading: false,
|
||||||
|
// errorMessage: 'Failed to delete automation',
|
||||||
|
// ));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
FutureOr<void> _fetchDevices(
|
||||||
|
FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
||||||
|
emit(state.copyWith(isLoading: true));
|
||||||
try {
|
try {
|
||||||
//emit(state.copyWith(isLoading: true));
|
final devices = await DevicesManagementApi().fetchDevices();
|
||||||
SceneApi.deleteAutomation(
|
|
||||||
unitUuid: spaceId, automationId: event.automationId);
|
emit(state.copyWith(isLoading: false, devices: devices));
|
||||||
add(const LoadAutomation(spaceId));
|
} catch (e) {
|
||||||
// emit(_resetState());
|
emit(state.copyWith(isLoading: false));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onUpdateScene(
|
||||||
|
UpdateScene event, Emitter<RoutineState> emit) async {
|
||||||
|
try {
|
||||||
|
// Check if first action is delay
|
||||||
|
if (_isFirstActionDelay(state.thenItems)) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
errorMessage: 'Cannot have delay as the first action',
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isLastActionDelay(state.thenItems)) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
errorMessage: 'Cannot have delay as the last action',
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
|
|
||||||
|
final actions = state.thenItems.expand((item) {
|
||||||
|
final functions = state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
|
return functions.map((function) {
|
||||||
|
if (function.functionCode == 'automation') {
|
||||||
|
return CreateSceneAction(
|
||||||
|
entityId: function.entityId,
|
||||||
|
actionExecutor: function.value,
|
||||||
|
executorProperty: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (item['deviceId'] == 'delay') {
|
||||||
|
return CreateSceneAction(
|
||||||
|
entityId: function.entityId,
|
||||||
|
actionExecutor: 'delay',
|
||||||
|
executorProperty: CreateSceneExecutorProperty(
|
||||||
|
functionCode: '',
|
||||||
|
functionValue: '',
|
||||||
|
delaySeconds: int.tryParse(function.value.toString()) ?? 0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CreateSceneAction(
|
||||||
|
entityId: function.entityId,
|
||||||
|
actionExecutor: 'device_issue',
|
||||||
|
executorProperty: CreateSceneExecutorProperty(
|
||||||
|
functionCode: function.functionCode,
|
||||||
|
functionValue: function.value,
|
||||||
|
delaySeconds: 0,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
final createSceneModel = CreateSceneModel(
|
||||||
|
spaceUuid: state.sceneId ?? '',
|
||||||
|
iconId: state.selectedIcon ?? '',
|
||||||
|
showInDevice: true,
|
||||||
|
sceneName: state.routineName ?? '',
|
||||||
|
decisionExpr: 'and',
|
||||||
|
actions: actions,
|
||||||
|
);
|
||||||
|
|
||||||
|
final result =
|
||||||
|
await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
||||||
|
if (result['success']) {
|
||||||
|
Navigator.of(NavigationService.navigatorKey.currentContext!).pop();
|
||||||
|
add(ResetRoutineState());
|
||||||
|
add(const LoadScenes(spaceId, communityId));
|
||||||
|
add(const LoadAutomation(spaceId));
|
||||||
|
} else {
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
errorMessage: result['message'],
|
||||||
|
));
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
errorMessage: 'Failed to delete automation',
|
errorMessage: 'Something went wrong',
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onUpdateAutomation(
|
||||||
|
UpdateAutomation event, Emitter<RoutineState> emit) async {
|
||||||
|
if (_isFirstActionDelay(state.thenItems)) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
errorMessage: 'Cannot have delay as the first action',
|
||||||
|
isLoading: false,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
emit(state.copyWith(isLoading: true));
|
||||||
|
try {
|
||||||
|
final conditions = state.ifItems
|
||||||
|
.map((item) {
|
||||||
|
final functions =
|
||||||
|
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
|
if (functions.isEmpty) return null;
|
||||||
|
|
||||||
|
final function = functions.first;
|
||||||
|
return Condition(
|
||||||
|
code: state.ifItems.indexOf(item) + 1,
|
||||||
|
entityId: function.entityId,
|
||||||
|
entityType: item['productType'],
|
||||||
|
expr: ConditionExpr(
|
||||||
|
statusCode: function.functionCode,
|
||||||
|
statusValue: function.value,
|
||||||
|
comparator: function.condition ?? '==',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.whereType<Condition>()
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final actions = state.thenItems
|
||||||
|
.map((item) {
|
||||||
|
final functions =
|
||||||
|
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
||||||
|
if (functions.isEmpty) return null;
|
||||||
|
|
||||||
|
final function = functions.first;
|
||||||
|
return AutomationAction(
|
||||||
|
entityId: function.entityId,
|
||||||
|
actionExecutor: function.actionExecutor,
|
||||||
|
executorProperty: ExecutorProperty(
|
||||||
|
functionCode: function.functionCode,
|
||||||
|
functionValue: function.value,
|
||||||
|
delaySeconds: function.functionCode == 'delay'
|
||||||
|
? (function.value as num).toInt()
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.whereType<AutomationAction>()
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final createAutomationModel = CreateAutomationModel(
|
||||||
|
spaceUuid: spaceId,
|
||||||
|
automationName: state.routineName ?? '',
|
||||||
|
decisionExpr: state.selectedAutomationOperator,
|
||||||
|
effectiveTime:
|
||||||
|
state.effectiveTime ?? EffectiveTime(start: '', end: '', loops: ''),
|
||||||
|
conditions: conditions,
|
||||||
|
actions: actions,
|
||||||
|
);
|
||||||
|
|
||||||
|
await SceneApi.updateAutomation(
|
||||||
|
createAutomationModel, state.automationId ?? '');
|
||||||
|
|
||||||
|
add(const LoadAutomation(spaceId));
|
||||||
|
emit(state.copyWith(isLoading: false));
|
||||||
|
} catch (e) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
errorMessage: 'Failed to update automation: $e',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FutureOr<void> _onSetAutomationActionExecutor(
|
||||||
|
SetAutomationActionExecutor event, Emitter<RoutineState> emit) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
automationActionExecutor: event.automationActionExecutor));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ class RemoveDragCard extends RoutineEvent {
|
|||||||
final int index;
|
final int index;
|
||||||
final bool isFromThen;
|
final bool isFromThen;
|
||||||
final String key;
|
final String key;
|
||||||
const RemoveDragCard(
|
const RemoveDragCard({required this.index, required this.isFromThen, required this.key});
|
||||||
{required this.index, required this.isFromThen, required this.key});
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [index, isFromThen, key];
|
List<Object> get props => [index, isFromThen, key];
|
||||||
}
|
}
|
||||||
@@ -105,12 +104,10 @@ class EffectiveTimePeriodEvent extends RoutineEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class CreateAutomationEvent extends RoutineEvent {
|
class CreateAutomationEvent extends RoutineEvent {
|
||||||
// final CreateAutomationModel createAutomationModel;
|
|
||||||
final String? automationId;
|
final String? automationId;
|
||||||
final bool updateAutomation;
|
final bool updateAutomation;
|
||||||
|
|
||||||
const CreateAutomationEvent({
|
const CreateAutomationEvent({
|
||||||
//required this.createAutomationModel,
|
|
||||||
this.automationId,
|
this.automationId,
|
||||||
this.updateAutomation = false,
|
this.updateAutomation = false,
|
||||||
});
|
});
|
||||||
@@ -159,21 +156,39 @@ class InitializeRoutineState extends RoutineEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DeleteScene extends RoutineEvent {
|
class DeleteScene extends RoutineEvent {
|
||||||
final String sceneId;
|
const DeleteScene();
|
||||||
final String unitUuid;
|
|
||||||
const DeleteScene({required this.sceneId, required this.unitUuid});
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [sceneId];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeleteAutomation extends RoutineEvent {
|
// class DeleteAutomation extends RoutineEvent {
|
||||||
final String automationId;
|
// final String automationId;
|
||||||
final String unitUuid;
|
// const DeleteAutomation({required this.automationId});
|
||||||
const DeleteAutomation({required this.automationId, required this.unitUuid});
|
// @override
|
||||||
|
// List<Object> get props => [automationId];
|
||||||
|
// }
|
||||||
|
|
||||||
|
class UpdateScene extends RoutineEvent {
|
||||||
|
const UpdateScene();
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [automationId];
|
List<Object> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateAutomation extends RoutineEvent {
|
||||||
|
const UpdateAutomation();
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SetAutomationActionExecutor extends RoutineEvent {
|
||||||
|
final String automationActionExecutor;
|
||||||
|
const SetAutomationActionExecutor({required this.automationActionExecutor});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [automationActionExecutor];
|
||||||
|
}
|
||||||
|
|
||||||
|
class FetchDevicesInRoutine extends RoutineEvent {}
|
||||||
|
|
||||||
class ResetRoutineState extends RoutineEvent {}
|
class ResetRoutineState extends RoutineEvent {}
|
||||||
|
|
||||||
class ClearFunctions extends RoutineEvent {}
|
class ClearFunctions extends RoutineEvent {}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ class RoutineState extends Equatable {
|
|||||||
final String? sceneId;
|
final String? sceneId;
|
||||||
final String? automationId;
|
final String? automationId;
|
||||||
final bool? isUpdate;
|
final bool? isUpdate;
|
||||||
|
final List<AllDevicesModel> devices;
|
||||||
|
final String? automationActionExecutor;
|
||||||
|
|
||||||
const RoutineState({
|
const RoutineState({
|
||||||
this.ifItems = const [],
|
this.ifItems = const [],
|
||||||
@@ -43,6 +45,8 @@ class RoutineState extends Equatable {
|
|||||||
this.sceneId,
|
this.sceneId,
|
||||||
this.automationId,
|
this.automationId,
|
||||||
this.isUpdate,
|
this.isUpdate,
|
||||||
|
this.devices = const [],
|
||||||
|
this.automationActionExecutor,
|
||||||
});
|
});
|
||||||
|
|
||||||
RoutineState copyWith({
|
RoutineState copyWith({
|
||||||
@@ -65,6 +69,8 @@ class RoutineState extends Equatable {
|
|||||||
String? sceneId,
|
String? sceneId,
|
||||||
String? automationId,
|
String? automationId,
|
||||||
bool? isUpdate,
|
bool? isUpdate,
|
||||||
|
List<AllDevicesModel>? devices,
|
||||||
|
String? automationActionExecutor,
|
||||||
}) {
|
}) {
|
||||||
return RoutineState(
|
return RoutineState(
|
||||||
ifItems: ifItems ?? this.ifItems,
|
ifItems: ifItems ?? this.ifItems,
|
||||||
@@ -89,6 +95,9 @@ class RoutineState extends Equatable {
|
|||||||
sceneId: sceneId ?? this.sceneId,
|
sceneId: sceneId ?? this.sceneId,
|
||||||
automationId: automationId ?? this.automationId,
|
automationId: automationId ?? this.automationId,
|
||||||
isUpdate: isUpdate ?? this.isUpdate,
|
isUpdate: isUpdate ?? this.isUpdate,
|
||||||
|
devices: devices ?? this.devices,
|
||||||
|
automationActionExecutor:
|
||||||
|
automationActionExecutor ?? this.automationActionExecutor,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,6 +121,8 @@ class RoutineState extends Equatable {
|
|||||||
effectiveTime,
|
effectiveTime,
|
||||||
sceneId,
|
sceneId,
|
||||||
automationId,
|
automationId,
|
||||||
isUpdate
|
isUpdate,
|
||||||
|
devices,
|
||||||
|
automationActionExecutor,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,23 +54,27 @@ class SaveRoutineHelper {
|
|||||||
),
|
),
|
||||||
if (state.isAutomation)
|
if (state.isAutomation)
|
||||||
...state.ifItems.map((item) {
|
...state.ifItems.map((item) {
|
||||||
final functions =
|
final functions = state.selectedFunctions[
|
||||||
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
item['uniqueCustomId']] ??
|
||||||
|
[];
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: SvgPicture.asset(
|
leading: SvgPicture.asset(
|
||||||
item['imagePath'],
|
item['imagePath'],
|
||||||
width: 22,
|
width: 22,
|
||||||
height: 22,
|
height: 22,
|
||||||
),
|
),
|
||||||
title:
|
title: Text(item['title'],
|
||||||
Text(item['title'], style: const TextStyle(fontSize: 14)),
|
style: const TextStyle(fontSize: 14)),
|
||||||
subtitle: Wrap(
|
subtitle: Wrap(
|
||||||
children: functions
|
children: functions
|
||||||
.map((f) => Text(
|
.map((f) => Text(
|
||||||
'${f.operationName}: ${f.value}, ',
|
'${f.operationName}: ${f.value}, ',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: ColorsManager.grayColor, fontSize: 8),
|
color: ColorsManager
|
||||||
overflow: TextOverflow.ellipsis,
|
.grayColor,
|
||||||
|
fontSize: 8),
|
||||||
|
overflow:
|
||||||
|
TextOverflow.ellipsis,
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
))
|
))
|
||||||
.toList(),
|
.toList(),
|
||||||
@@ -95,22 +99,25 @@ class SaveRoutineHelper {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
...state.thenItems.map((item) {
|
...state.thenItems.map((item) {
|
||||||
final functions =
|
final functions = state.selectedFunctions[
|
||||||
state.selectedFunctions[item['uniqueCustomId']] ?? [];
|
item['uniqueCustomId']] ??
|
||||||
|
[];
|
||||||
return ListTile(
|
return ListTile(
|
||||||
leading: SvgPicture.asset(
|
leading: SvgPicture.asset(
|
||||||
item['imagePath'],
|
item['imagePath'],
|
||||||
width: 22,
|
width: 22,
|
||||||
height: 22,
|
height: 22,
|
||||||
),
|
),
|
||||||
title:
|
title: Text(item['title'],
|
||||||
Text(item['title'], style: const TextStyle(fontSize: 14)),
|
style: const TextStyle(fontSize: 14)),
|
||||||
subtitle: Wrap(
|
subtitle: Wrap(
|
||||||
children: functions
|
children: functions
|
||||||
.map((f) => Text(
|
.map((f) => Text(
|
||||||
'${f.operationName}: ${f.value}, ',
|
'${f.operationName}: ${f.value}, ',
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: ColorsManager.grayColor, fontSize: 8),
|
color:
|
||||||
|
ColorsManager.grayColor,
|
||||||
|
fontSize: 8),
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
maxLines: 3,
|
maxLines: 3,
|
||||||
))
|
))
|
||||||
@@ -136,12 +143,30 @@ class SaveRoutineHelper {
|
|||||||
onCancel: () => Navigator.pop(context, false),
|
onCancel: () => Navigator.pop(context, false),
|
||||||
onConfirm: () {
|
onConfirm: () {
|
||||||
if (state.isAutomation) {
|
if (state.isAutomation) {
|
||||||
context.read<RoutineBloc>().add(const CreateAutomationEvent());
|
if (state.automationId != null) {
|
||||||
|
context
|
||||||
|
.read<RoutineBloc>()
|
||||||
|
.add(const UpdateAutomation());
|
||||||
|
} else {
|
||||||
|
context
|
||||||
|
.read<RoutineBloc>()
|
||||||
|
.add(const CreateAutomationEvent());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
context.read<RoutineBloc>().add(const CreateSceneEvent());
|
if (state.sceneId != null) {
|
||||||
|
context
|
||||||
|
.read<RoutineBloc>()
|
||||||
|
.add(const UpdateScene());
|
||||||
|
} else {
|
||||||
|
context
|
||||||
|
.read<RoutineBloc>()
|
||||||
|
.add(const CreateSceneEvent());
|
||||||
|
}
|
||||||
|
if (context.read<RoutineBloc>().state.errorMessage ==
|
||||||
|
null) {
|
||||||
|
Navigator.pop(context, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Navigator.pop(context, true);
|
|
||||||
},
|
},
|
||||||
isConfirmEnabled: true,
|
isConfirmEnabled: true,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class CreateAutomationModel {
|
|||||||
required this.actions,
|
required this.actions,
|
||||||
});
|
});
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap([String? automationId]) {
|
||||||
return {
|
return {
|
||||||
'spaceUuid': spaceUuid,
|
'spaceUuid': spaceUuid,
|
||||||
'automationName': automationName,
|
'automationName': automationName,
|
||||||
@@ -41,7 +41,7 @@ class CreateAutomationModel {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
String toJson() => json.encode(toMap());
|
String toJson(String? automationId) => json.encode(toMap(automationId));
|
||||||
|
|
||||||
factory CreateAutomationModel.fromJson(String source) =>
|
factory CreateAutomationModel.fromJson(String source) =>
|
||||||
CreateAutomationModel.fromMap(json.decode(source));
|
CreateAutomationModel.fromMap(json.decode(source));
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ class RoutineDetailsModel {
|
|||||||
final EffectiveTime? effectiveTime;
|
final EffectiveTime? effectiveTime;
|
||||||
final List<RoutineCondition>? conditions;
|
final List<RoutineCondition>? conditions;
|
||||||
final String? type;
|
final String? type;
|
||||||
|
final String? sceneId;
|
||||||
|
final String? automationId;
|
||||||
|
|
||||||
RoutineDetailsModel({
|
RoutineDetailsModel({
|
||||||
required this.spaceUuid,
|
required this.spaceUuid,
|
||||||
@@ -24,6 +26,8 @@ class RoutineDetailsModel {
|
|||||||
this.effectiveTime,
|
this.effectiveTime,
|
||||||
this.conditions,
|
this.conditions,
|
||||||
this.type,
|
this.type,
|
||||||
|
this.sceneId,
|
||||||
|
this.automationId,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Convert to CreateSceneModel
|
// Convert to CreateSceneModel
|
||||||
@@ -57,12 +61,14 @@ class RoutineDetailsModel {
|
|||||||
'name': name,
|
'name': name,
|
||||||
'decisionExpr': decisionExpr,
|
'decisionExpr': decisionExpr,
|
||||||
'actions': actions.map((x) => x.toMap()).toList(),
|
'actions': actions.map((x) => x.toMap()).toList(),
|
||||||
if (iconId != null) 'iconId': iconId,
|
if (iconId != null) 'iconUuid': iconId,
|
||||||
if (showInDevice != null) 'showInDevice': showInDevice,
|
if (showInDevice != null) 'showInDevice': showInDevice,
|
||||||
if (effectiveTime != null) 'effectiveTime': effectiveTime!.toMap(),
|
if (effectiveTime != null) 'effectiveTime': effectiveTime!.toMap(),
|
||||||
if (conditions != null)
|
if (conditions != null)
|
||||||
'conditions': conditions!.map((x) => x.toMap()).toList(),
|
'conditions': conditions!.map((x) => x.toMap()).toList(),
|
||||||
if (type != null) 'type': type,
|
if (type != null) 'type': type,
|
||||||
|
if (sceneId != null) 'sceneId': sceneId,
|
||||||
|
if (automationId != null) 'automationId': automationId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +80,7 @@ class RoutineDetailsModel {
|
|||||||
actions: List<RoutineAction>.from(
|
actions: List<RoutineAction>.from(
|
||||||
map['actions']?.map((x) => RoutineAction.fromMap(x)) ?? [],
|
map['actions']?.map((x) => RoutineAction.fromMap(x)) ?? [],
|
||||||
),
|
),
|
||||||
iconId: map['iconId'],
|
iconId: map['iconUuid'],
|
||||||
showInDevice: map['showInDevice'],
|
showInDevice: map['showInDevice'],
|
||||||
effectiveTime: map['effectiveTime'] != null
|
effectiveTime: map['effectiveTime'] != null
|
||||||
? EffectiveTime.fromMap(map['effectiveTime'])
|
? EffectiveTime.fromMap(map['effectiveTime'])
|
||||||
@@ -84,6 +90,8 @@ class RoutineDetailsModel {
|
|||||||
map['conditions'].map((x) => RoutineCondition.fromMap(x)))
|
map['conditions'].map((x) => RoutineCondition.fromMap(x)))
|
||||||
: null,
|
: null,
|
||||||
type: map['type'],
|
type: map['type'],
|
||||||
|
sceneId: map['sceneId'],
|
||||||
|
automationId: map['automationId'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,12 +104,18 @@ class RoutineDetailsModel {
|
|||||||
class RoutineAction {
|
class RoutineAction {
|
||||||
final String entityId;
|
final String entityId;
|
||||||
final String actionExecutor;
|
final String actionExecutor;
|
||||||
|
final String? name;
|
||||||
final RoutineExecutorProperty? executorProperty;
|
final RoutineExecutorProperty? executorProperty;
|
||||||
|
final String productType;
|
||||||
|
final String? type;
|
||||||
|
|
||||||
RoutineAction({
|
RoutineAction({
|
||||||
required this.entityId,
|
required this.entityId,
|
||||||
required this.actionExecutor,
|
required this.actionExecutor,
|
||||||
|
required this.productType,
|
||||||
this.executorProperty,
|
this.executorProperty,
|
||||||
|
this.name,
|
||||||
|
this.type,
|
||||||
});
|
});
|
||||||
|
|
||||||
CreateSceneAction toCreateSceneAction() {
|
CreateSceneAction toCreateSceneAction() {
|
||||||
@@ -124,6 +138,8 @@ class RoutineAction {
|
|||||||
return {
|
return {
|
||||||
'entityId': entityId,
|
'entityId': entityId,
|
||||||
'actionExecutor': actionExecutor,
|
'actionExecutor': actionExecutor,
|
||||||
|
if (type != null) 'type': type,
|
||||||
|
if (name != null) 'name': name,
|
||||||
if (executorProperty != null)
|
if (executorProperty != null)
|
||||||
'executorProperty': executorProperty!.toMap(),
|
'executorProperty': executorProperty!.toMap(),
|
||||||
};
|
};
|
||||||
@@ -133,6 +149,9 @@ class RoutineAction {
|
|||||||
return RoutineAction(
|
return RoutineAction(
|
||||||
entityId: map['entityId'] ?? '',
|
entityId: map['entityId'] ?? '',
|
||||||
actionExecutor: map['actionExecutor'] ?? '',
|
actionExecutor: map['actionExecutor'] ?? '',
|
||||||
|
productType: map['productType'] ?? '',
|
||||||
|
name: map['name'] ?? '',
|
||||||
|
type: map['type'] ?? '',
|
||||||
executorProperty: map['executorProperty'] != null
|
executorProperty: map['executorProperty'] != null
|
||||||
? RoutineExecutorProperty.fromMap(map['executorProperty'])
|
? RoutineExecutorProperty.fromMap(map['executorProperty'])
|
||||||
: null,
|
: null,
|
||||||
@@ -189,12 +208,14 @@ class RoutineCondition {
|
|||||||
final String entityId;
|
final String entityId;
|
||||||
final String entityType;
|
final String entityType;
|
||||||
final RoutineConditionExpr expr;
|
final RoutineConditionExpr expr;
|
||||||
|
final String productType;
|
||||||
|
|
||||||
RoutineCondition({
|
RoutineCondition({
|
||||||
required this.code,
|
required this.code,
|
||||||
required this.entityId,
|
required this.entityId,
|
||||||
required this.entityType,
|
required this.entityType,
|
||||||
required this.expr,
|
required this.expr,
|
||||||
|
required this.productType,
|
||||||
});
|
});
|
||||||
|
|
||||||
Condition toCondition() {
|
Condition toCondition() {
|
||||||
@@ -221,6 +242,7 @@ class RoutineCondition {
|
|||||||
entityId: map['entityId'] ?? '',
|
entityId: map['entityId'] ?? '',
|
||||||
entityType: map['entityType'] ?? '',
|
entityType: map['entityType'] ?? '',
|
||||||
expr: RoutineConditionExpr.fromMap(map['expr']),
|
expr: RoutineConditionExpr.fromMap(map['expr']),
|
||||||
|
productType: map['productType'] ?? '',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class CreateNewRoutineView extends StatelessWidget {
|
|||||||
this.routineId,
|
this.routineId,
|
||||||
this.isScene = true,
|
this.isScene = true,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
@@ -67,7 +68,7 @@ class CreateNewRoutineView extends StatelessWidget {
|
|||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
color: ColorsManager.dialogBlueTitle,
|
color: ColorsManager.dialogBlueTitle,
|
||||||
),
|
),
|
||||||
|
|
||||||
/// THEN Container
|
/// THEN Container
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Card(
|
child: Card(
|
||||||
|
|||||||
@@ -7,15 +7,28 @@ import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/fetch_routi
|
|||||||
import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class RoutinesView extends StatelessWidget {
|
class RoutinesView extends StatefulWidget {
|
||||||
const RoutinesView({super.key});
|
const RoutinesView({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RoutinesView> createState() => _RoutinesViewState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RoutinesViewState extends State<RoutinesView> {
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
context.read<RoutineBloc>().add(FetchDevicesInRoutine());
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<SwitchTabsBloc, SwitchTabsState>(
|
return BlocBuilder<SwitchTabsBloc, SwitchTabsState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is ShowCreateRoutineState && state.showCreateRoutine) {
|
if (state is ShowCreateRoutineState && state.showCreateRoutine) {
|
||||||
return const CreateNewRoutineView();
|
return const CreateNewRoutineView(
|
||||||
|
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return Padding(
|
return Padding(
|
||||||
padding: const EdgeInsets.all(16),
|
padding: const EdgeInsets.all(16),
|
||||||
|
|||||||
@@ -0,0 +1,95 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/custom_dialog.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class DeleteSceneWidget extends StatelessWidget {
|
||||||
|
const DeleteSceneWidget({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () async {
|
||||||
|
await showCustomDialog(
|
||||||
|
context: context,
|
||||||
|
message: 'Are you sure you want to delete this scene?',
|
||||||
|
actions: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
alignment: AlignmentDirectional.center,
|
||||||
|
child: Text(
|
||||||
|
'Cancel',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium!
|
||||||
|
.copyWith(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: 1, height: 50, color: ColorsManager.greyColor),
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
context.read<RoutineBloc>().add(const DeleteScene());
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pop(true);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
alignment: AlignmentDirectional.center,
|
||||||
|
child: Text(
|
||||||
|
'Confirm',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium!
|
||||||
|
.copyWith(
|
||||||
|
color: ColorsManager.primaryColorWithOpacity,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
},
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Icon(
|
||||||
|
Icons.delete,
|
||||||
|
color: ColorsManager.red,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 2,
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
'Delete',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
color: ColorsManager.red,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -83,15 +83,19 @@ class DraggableCard extends StatelessWidget {
|
|||||||
? SvgPicture.asset(
|
? SvgPicture.asset(
|
||||||
imagePath,
|
imagePath,
|
||||||
)
|
)
|
||||||
: Image.memory(
|
: imagePath.contains('.png')
|
||||||
base64Decode(imagePath),
|
? Image.asset(
|
||||||
),
|
imagePath,
|
||||||
|
)
|
||||||
|
: Image.memory(
|
||||||
|
base64Decode(imagePath),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 3),
|
padding: const EdgeInsets.symmetric(horizontal: 3),
|
||||||
child: Text(
|
child: Text(
|
||||||
title,
|
deviceData['title'] ?? deviceData['name'] ?? title,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
@@ -104,7 +108,6 @@ class DraggableCard extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (deviceFunctions.isNotEmpty)
|
if (deviceFunctions.isNotEmpty)
|
||||||
// const Divider(height: 1),
|
|
||||||
...deviceFunctions.map((function) => Row(
|
...deviceFunctions.map((function) => Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/switch_tabs/switch_tabs_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
@@ -11,8 +12,7 @@ class FetchRoutineScenesAutomation extends StatefulWidget {
|
|||||||
const FetchRoutineScenesAutomation({super.key});
|
const FetchRoutineScenesAutomation({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<FetchRoutineScenesAutomation> createState() =>
|
State<FetchRoutineScenesAutomation> createState() => _FetchRoutineScenesState();
|
||||||
_FetchRoutineScenesState();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
||||||
@@ -67,49 +67,23 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
||||||
),
|
),
|
||||||
child: Stack(
|
child: RoutineViewCard(
|
||||||
children: [
|
onTap: () {
|
||||||
RoutineViewCard(
|
BlocProvider.of<SwitchTabsBloc>(context).add(
|
||||||
onTap: () {},
|
const CreateNewRoutineViewEvent(true),
|
||||||
textString: state.scenes[index].name,
|
);
|
||||||
icon: state.scenes[index].icon ??
|
context.read<RoutineBloc>().add(
|
||||||
Assets.logoHorizontal,
|
GetSceneDetails(
|
||||||
isFromScenes: true,
|
sceneId: state.scenes[index].id,
|
||||||
iconInBytes:
|
isTabToRun: true,
|
||||||
state.scenes[index].iconInBytes,
|
isUpdate: true,
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
top: 0,
|
|
||||||
right: 0,
|
|
||||||
child: InkWell(
|
|
||||||
onTap: () => context
|
|
||||||
.read<RoutineBloc>()
|
|
||||||
.add(
|
|
||||||
DeleteScene(
|
|
||||||
sceneId: state.scenes[index].id,
|
|
||||||
unitUuid: spaceId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
height: 20,
|
|
||||||
width: 20,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: ColorsManager.whiteColors,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
border: Border.all(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
width: 2.0,
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
child: const Center(
|
);
|
||||||
child: Icon(Icons.delete,
|
},
|
||||||
size: 15,
|
textString: state.scenes[index].name,
|
||||||
color: ColorsManager.grayColor),
|
icon: state.scenes[index].icon ?? Assets.logoHorizontal,
|
||||||
),
|
isFromScenes: true,
|
||||||
),
|
iconInBytes: state.scenes[index].iconInBytes,
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -142,46 +116,20 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|||||||
padding: EdgeInsets.only(
|
padding: EdgeInsets.only(
|
||||||
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
right: isSmallScreenSize(context) ? 4.0 : 8.0,
|
||||||
),
|
),
|
||||||
child: Stack(
|
child: RoutineViewCard(
|
||||||
children: [
|
onTap: () {
|
||||||
RoutineViewCard(
|
BlocProvider.of<SwitchTabsBloc>(context).add(
|
||||||
onTap: () {},
|
const CreateNewRoutineViewEvent(true),
|
||||||
textString: state.automations[index].name,
|
);
|
||||||
icon: state.automations[index].icon ??
|
context.read<RoutineBloc>().add(
|
||||||
Assets.automation,
|
GetAutomationDetails(
|
||||||
),
|
automationId: state.automations[index].id,
|
||||||
Positioned(
|
isAutomation: true,
|
||||||
top: 0,
|
isUpdate: true),
|
||||||
right: 0,
|
);
|
||||||
child: InkWell(
|
},
|
||||||
onTap: () =>
|
textString: state.automations[index].name,
|
||||||
context.read<RoutineBloc>().add(
|
icon: state.automations[index].icon ?? Assets.automation,
|
||||||
DeleteAutomation(
|
|
||||||
automationId: state
|
|
||||||
.automations[index].id,
|
|
||||||
unitUuid: spaceId,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: Container(
|
|
||||||
height: 20,
|
|
||||||
width: 20,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: ColorsManager.whiteColors,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
border: Border.all(
|
|
||||||
color: ColorsManager.grayColor,
|
|
||||||
width: 2.0,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: const Center(
|
|
||||||
child: Icon(Icons.delete,
|
|
||||||
size: 15,
|
|
||||||
color: ColorsManager.grayColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dragable_card.dart';
|
||||||
@@ -10,68 +9,67 @@ class RoutineDevices extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
create: (context) => DeviceManagementBloc()..add(FetchDevices()),
|
builder: (context, state) {
|
||||||
child: BlocBuilder<DeviceManagementBloc, DeviceManagementState>(
|
if (state.isLoading) {
|
||||||
builder: (context, state) {
|
|
||||||
if (state is DeviceManagementLoaded) {
|
|
||||||
List<AllDevicesModel> deviceList = state.devices
|
|
||||||
.where((device) =>
|
|
||||||
device.productType == 'AC' ||
|
|
||||||
device.productType == '1G' ||
|
|
||||||
device.productType == '2G' ||
|
|
||||||
device.productType == '3G')
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
// Provide the RoutineBloc to the child widgets
|
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
|
||||||
builder: (context, routineState) {
|
|
||||||
return Wrap(
|
|
||||||
spacing: 10,
|
|
||||||
runSpacing: 10,
|
|
||||||
children: deviceList.asMap().entries.map((entry) {
|
|
||||||
final device = entry.value;
|
|
||||||
if (routineState.searchText != null && routineState.searchText!.isNotEmpty) {
|
|
||||||
return device.name!
|
|
||||||
.toLowerCase()
|
|
||||||
.contains(routineState.searchText!.toLowerCase())
|
|
||||||
? DraggableCard(
|
|
||||||
imagePath: device.getDefaultIcon(device.productType),
|
|
||||||
title: device.name ?? '',
|
|
||||||
deviceData: {
|
|
||||||
'device': device,
|
|
||||||
'imagePath': device.getDefaultIcon(device.productType),
|
|
||||||
'title': device.name ?? '',
|
|
||||||
'deviceId': device.uuid,
|
|
||||||
'productType': device.productType,
|
|
||||||
'functions': device.functions,
|
|
||||||
'uniqueCustomId': '',
|
|
||||||
},
|
|
||||||
)
|
|
||||||
: Container();
|
|
||||||
} else {
|
|
||||||
return DraggableCard(
|
|
||||||
imagePath: device.getDefaultIcon(device.productType),
|
|
||||||
title: device.name ?? '',
|
|
||||||
deviceData: {
|
|
||||||
'device': device,
|
|
||||||
'imagePath': device.getDefaultIcon(device.productType),
|
|
||||||
'title': device.name ?? '',
|
|
||||||
'deviceId': device.uuid,
|
|
||||||
'productType': device.productType,
|
|
||||||
'functions': device.functions,
|
|
||||||
'uniqueCustomId': '',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}).toList(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
},
|
}
|
||||||
),
|
|
||||||
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
|
if (state.devices.isEmpty) {
|
||||||
|
return const Center(child: Text('No devices found'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
List<AllDevicesModel> deviceList = state.devices
|
||||||
|
.where((device) =>
|
||||||
|
device.productType == 'AC' ||
|
||||||
|
device.productType == '1G' ||
|
||||||
|
device.productType == '2G' ||
|
||||||
|
device.productType == '3G')
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
return Wrap(
|
||||||
|
spacing: 10,
|
||||||
|
runSpacing: 10,
|
||||||
|
children: deviceList.asMap().entries.map((entry) {
|
||||||
|
final device = entry.value;
|
||||||
|
if (state.searchText != null && state.searchText!.isNotEmpty) {
|
||||||
|
return device.name!
|
||||||
|
.toLowerCase()
|
||||||
|
.contains(state.searchText!.toLowerCase())
|
||||||
|
? DraggableCard(
|
||||||
|
imagePath: device.getDefaultIcon(device.productType),
|
||||||
|
title: device.name ?? '',
|
||||||
|
deviceData: {
|
||||||
|
'device': device,
|
||||||
|
'imagePath': device.getDefaultIcon(device.productType),
|
||||||
|
'title': device.name ?? '',
|
||||||
|
'deviceId': device.uuid,
|
||||||
|
'productType': device.productType,
|
||||||
|
'functions': device.functions,
|
||||||
|
'uniqueCustomId': '',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: Container();
|
||||||
|
} else {
|
||||||
|
return DraggableCard(
|
||||||
|
imagePath: device.getDefaultIcon(device.productType),
|
||||||
|
title: device.name ?? '',
|
||||||
|
deviceData: {
|
||||||
|
'device': device,
|
||||||
|
'imagePath': device.getDefaultIcon(device.productType),
|
||||||
|
'title': device.name ?? '',
|
||||||
|
'deviceId': device.uuid,
|
||||||
|
'productType': device.productType,
|
||||||
|
'functions': device.functions,
|
||||||
|
'uniqueCustomId': '',
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
|||||||
import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dialog_footer.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
|
||||||
class AutomationDialog extends StatefulWidget {
|
class AutomationDialog extends StatelessWidget {
|
||||||
final String automationName;
|
final String automationName;
|
||||||
final String automationId;
|
final String automationId;
|
||||||
final String uniqueCustomId;
|
final String uniqueCustomId;
|
||||||
@@ -19,77 +19,86 @@ class AutomationDialog extends StatefulWidget {
|
|||||||
required this.uniqueCustomId,
|
required this.uniqueCustomId,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
|
||||||
_AutomationDialogState createState() => _AutomationDialogState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _AutomationDialogState extends State<AutomationDialog> {
|
|
||||||
bool _isEnabled = true;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Dialog(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
builder: (context, state) {
|
||||||
child: Container(
|
final isEnabled = state.automationActionExecutor == 'rule_enable';
|
||||||
width: 400,
|
|
||||||
padding: const EdgeInsets.all(16),
|
return Dialog(
|
||||||
child: Column(
|
shape:
|
||||||
mainAxisSize: MainAxisSize.min,
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
children: [
|
child: Container(
|
||||||
DialogHeader(widget.automationName),
|
width: 400,
|
||||||
const SizedBox(height: 16),
|
padding: const EdgeInsets.all(16),
|
||||||
ListTile(
|
child: Column(
|
||||||
leading: SvgPicture.asset(Assets.acPower, width: 24, height: 24),
|
mainAxisSize: MainAxisSize.min,
|
||||||
title: const Text('Enable'),
|
children: [
|
||||||
trailing: Radio<bool>(
|
DialogHeader(automationName),
|
||||||
value: true,
|
const SizedBox(height: 16),
|
||||||
groupValue: _isEnabled,
|
ListTile(
|
||||||
onChanged: (bool? value) {
|
leading:
|
||||||
setState(() {
|
SvgPicture.asset(Assets.acPower, width: 24, height: 24),
|
||||||
_isEnabled = value!;
|
title: const Text('Enable'),
|
||||||
});
|
trailing: Radio<bool>(
|
||||||
},
|
value: true,
|
||||||
),
|
groupValue: isEnabled,
|
||||||
),
|
onChanged: (bool? value) {
|
||||||
ListTile(
|
if (value == true) {
|
||||||
leading:
|
context.read<RoutineBloc>().add(
|
||||||
SvgPicture.asset(Assets.acPowerOff, width: 24, height: 24),
|
const SetAutomationActionExecutor(
|
||||||
title: const Text('Disable'),
|
automationActionExecutor: 'rule_enable',
|
||||||
trailing: Radio<bool>(
|
),
|
||||||
value: false,
|
);
|
||||||
groupValue: _isEnabled,
|
}
|
||||||
onChanged: (bool? value) {
|
},
|
||||||
setState(() {
|
),
|
||||||
_isEnabled = value!;
|
),
|
||||||
});
|
ListTile(
|
||||||
},
|
leading: SvgPicture.asset(Assets.acPowerOff,
|
||||||
),
|
width: 24, height: 24),
|
||||||
),
|
title: const Text('Disable'),
|
||||||
const SizedBox(height: 16),
|
trailing: Radio<bool>(
|
||||||
DialogFooter(
|
value: false,
|
||||||
onConfirm: () {
|
groupValue: isEnabled,
|
||||||
context.read<RoutineBloc>().add(
|
onChanged: (bool? value) {
|
||||||
AddFunctionToRoutine(
|
if (value == false) {
|
||||||
[
|
context.read<RoutineBloc>().add(
|
||||||
DeviceFunctionData(
|
const SetAutomationActionExecutor(
|
||||||
entityId: widget.automationId,
|
automationActionExecutor: 'rule_disable',
|
||||||
functionCode: 'automation',
|
),
|
||||||
value: _isEnabled ? 'rule_enable' : 'rule_disable',
|
);
|
||||||
operationName: 'Automation',
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
DialogFooter(
|
||||||
|
onConfirm: () {
|
||||||
|
context.read<RoutineBloc>().add(
|
||||||
|
AddFunctionToRoutine(
|
||||||
|
[
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: automationId,
|
||||||
|
functionCode: 'automation',
|
||||||
|
value: state.automationActionExecutor,
|
||||||
|
operationName: 'Automation',
|
||||||
|
),
|
||||||
|
],
|
||||||
|
uniqueCustomId,
|
||||||
),
|
),
|
||||||
],
|
);
|
||||||
widget.uniqueCustomId,
|
Navigator.of(context).pop(true);
|
||||||
),
|
},
|
||||||
);
|
onCancel: () => Navigator.of(context).pop(false),
|
||||||
Navigator.of(context).pop(true);
|
isConfirmEnabled: true,
|
||||||
},
|
dialogWidth: 400,
|
||||||
onCancel: () => Navigator.of(context).pop(false),
|
),
|
||||||
isConfirmEnabled: true,
|
],
|
||||||
dialogWidth: 400,
|
|
||||||
),
|
),
|
||||||
],
|
),
|
||||||
),
|
);
|
||||||
),
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_event.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/effective_period/effect_period_state.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_bloc.dart';
|
||||||
@@ -9,6 +10,7 @@ import 'package:syncrow_web/pages/routiens/bloc/setting_bloc/setting_state.dart'
|
|||||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/icon_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/icon_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/view/effective_period_view.dart';
|
import 'package:syncrow_web/pages/routiens/view/effective_period_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/widgets/delete_scene.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/dialog_header.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
@@ -22,11 +24,18 @@ class SettingHelper {
|
|||||||
context: context,
|
context: context,
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
final isAutomation = context.read<RoutineBloc>().state.isAutomation;
|
final isAutomation = context.read<RoutineBloc>().state.isAutomation;
|
||||||
|
final effectiveTime = context.read<RoutineBloc>().state.effectiveTime;
|
||||||
|
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(
|
if (effectiveTime != null)
|
||||||
create: (_) => EffectPeriodBloc(),
|
BlocProvider(
|
||||||
),
|
create: (_) => EffectPeriodBloc()..add(InitialEffectPeriodEvent(effectiveTime)),
|
||||||
|
),
|
||||||
|
if (effectiveTime == null)
|
||||||
|
BlocProvider(
|
||||||
|
create: (_) => EffectPeriodBloc(),
|
||||||
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (_) => SettingBloc()..add(InitialEvent(selectedIcon: iconId ?? ''))),
|
create: (_) => SettingBloc()..add(InitialEvent(selectedIcon: iconId ?? ''))),
|
||||||
],
|
],
|
||||||
@@ -44,7 +53,7 @@ class SettingHelper {
|
|||||||
}
|
}
|
||||||
return Container(
|
return Container(
|
||||||
width: context.read<SettingBloc>().isExpanded ? 800 : 400,
|
width: context.read<SettingBloc>().isExpanded ? 800 : 400,
|
||||||
height: context.read<SettingBloc>().isExpanded && isAutomation ? 500 : 300,
|
height: context.read<SettingBloc>().isExpanded && isAutomation ? 500 : 350,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: Colors.white,
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
@@ -167,6 +176,9 @@ class SettingHelper {
|
|||||||
fontSize: 14)),
|
fontSize: 14)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
if (context.read<RoutineBloc>().state.isUpdate ??
|
||||||
|
false)
|
||||||
|
const DeleteSceneWidget()
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
@@ -284,6 +296,9 @@ class SettingHelper {
|
|||||||
fontSize: 14)),
|
fontSize: 14)),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
if (context.read<RoutineBloc>().state.isUpdate ??
|
||||||
|
false)
|
||||||
|
const DeleteSceneWidget()
|
||||||
],
|
],
|
||||||
)),
|
)),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -10,14 +10,41 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
|||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
class RoutineSearchAndButtons extends StatelessWidget {
|
class RoutineSearchAndButtons extends StatefulWidget {
|
||||||
const RoutineSearchAndButtons({
|
const RoutineSearchAndButtons({
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<RoutineSearchAndButtons> createState() =>
|
||||||
|
_RoutineSearchAndButtonsState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RoutineSearchAndButtonsState extends State<RoutineSearchAndButtons> {
|
||||||
|
late TextEditingController _nameController;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_nameController = TextEditingController();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_nameController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocConsumer<RoutineBloc, RoutineState>(
|
||||||
|
listenWhen: (previous, current) =>
|
||||||
|
previous.routineName != current.routineName,
|
||||||
|
listener: (context, state) {
|
||||||
|
if (state.routineName != _nameController.text) {
|
||||||
|
_nameController.text = state.routineName ?? '';
|
||||||
|
}
|
||||||
|
},
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return LayoutBuilder(
|
return LayoutBuilder(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
builder: (BuildContext context, BoxConstraints constraints) {
|
||||||
@@ -35,26 +62,9 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
ConstrainedBox(
|
ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(
|
||||||
maxWidth:
|
maxWidth: constraints.maxWidth > 700
|
||||||
constraints.maxWidth > 700 ? 450 : constraints.maxWidth - 32),
|
? 450
|
||||||
// child: StatefulTextField(
|
: constraints.maxWidth - 32),
|
||||||
// title: 'Routine Name',
|
|
||||||
// initialValue: state.routineName ?? '',
|
|
||||||
// height: 40,
|
|
||||||
// // controller: TextEditingController(),
|
|
||||||
// hintText: 'Please enter the name',
|
|
||||||
// boxDecoration: containerWhiteDecoration,
|
|
||||||
// elevation: 0,
|
|
||||||
// borderRadius: 15,
|
|
||||||
// isRequired: true,
|
|
||||||
// width: 450,
|
|
||||||
// onSubmitted: (value) {
|
|
||||||
// // context.read<RoutineBloc>().add(SetRoutineName(value));
|
|
||||||
// },
|
|
||||||
// onChanged: (value) {
|
|
||||||
// context.read<RoutineBloc>().add(SetRoutineName(value));
|
|
||||||
// },
|
|
||||||
// ),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -63,10 +73,13 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
children: [
|
children: [
|
||||||
Text('* ',
|
Text('* ',
|
||||||
style: context.textTheme.bodyMedium!
|
style: context.textTheme.bodyMedium!
|
||||||
.copyWith(color: ColorsManager.red, fontSize: 13)),
|
.copyWith(
|
||||||
|
color: ColorsManager.red,
|
||||||
|
fontSize: 13)),
|
||||||
Text(
|
Text(
|
||||||
'Routine Name',
|
'Routine Name',
|
||||||
style: context.textTheme.bodyMedium!.copyWith(
|
style: context.textTheme.bodyMedium!
|
||||||
|
.copyWith(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
@@ -80,18 +93,24 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
decoration: containerWhiteDecoration,
|
decoration: containerWhiteDecoration,
|
||||||
child: TextFormField(
|
child: TextFormField(
|
||||||
style: context.textTheme.bodyMedium!
|
style: context.textTheme.bodyMedium!
|
||||||
.copyWith(color: ColorsManager.blackColor),
|
.copyWith(
|
||||||
initialValue: state.routineName,
|
color: ColorsManager.blackColor),
|
||||||
|
controller: _nameController,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Please enter the name',
|
hintText: 'Please enter the name',
|
||||||
hintStyle: context.textTheme.bodyMedium!
|
hintStyle: context.textTheme.bodyMedium!
|
||||||
.copyWith(fontSize: 12, color: ColorsManager.grayColor),
|
.copyWith(
|
||||||
|
fontSize: 12,
|
||||||
|
color: ColorsManager.grayColor),
|
||||||
contentPadding:
|
contentPadding:
|
||||||
const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
const EdgeInsets.symmetric(
|
||||||
|
horizontal: 12, vertical: 10),
|
||||||
border: InputBorder.none,
|
border: InputBorder.none,
|
||||||
),
|
),
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
context.read<RoutineBloc>().add(SetRoutineName(value));
|
context
|
||||||
|
.read<RoutineBloc>()
|
||||||
|
.add(SetRoutineName(value));
|
||||||
},
|
},
|
||||||
validator: (value) {
|
validator: (value) {
|
||||||
if (value == null || value.isEmpty) {
|
if (value == null || value.isEmpty) {
|
||||||
@@ -111,15 +130,18 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
width: 200,
|
width: 200,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: state.isAutomation || state.isTabToRun
|
onPressed: state.isAutomation ||
|
||||||
|
state.isTabToRun
|
||||||
? () async {
|
? () async {
|
||||||
final result = await SettingHelper.showSettingDialog(
|
final result = await SettingHelper
|
||||||
|
.showSettingDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
iconId:
|
||||||
|
state.selectedIcon ?? '',
|
||||||
);
|
);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context
|
context.read<RoutineBloc>().add(
|
||||||
.read<RoutineBloc>()
|
AddSelectedIcon(result));
|
||||||
.add(AddSelectedIcon(result));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
@@ -175,10 +197,12 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
child: Center(
|
child: Center(
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (state.routineName == null || state.routineName!.isEmpty) {
|
if (state.routineName == null ||
|
||||||
|
state.routineName!.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: const Text('Please enter the routine name'),
|
content: const Text(
|
||||||
|
'Please enter the routine name'),
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
backgroundColor: ColorsManager.red,
|
backgroundColor: ColorsManager.red,
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
@@ -192,10 +216,12 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.ifItems.isEmpty || state.thenItems.isEmpty) {
|
if (state.ifItems.isEmpty ||
|
||||||
|
state.thenItems.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: const Text('Please add if and then condition'),
|
content: const Text(
|
||||||
|
'Please add if and then condition'),
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
backgroundColor: ColorsManager.red,
|
backgroundColor: ColorsManager.red,
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
@@ -208,13 +234,15 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final result =
|
final result = await SaveRoutineHelper
|
||||||
await SaveRoutineHelper.showSaveRoutineDialog(context);
|
.showSaveRoutineDialog(context);
|
||||||
if (result != null && result) {
|
if (result != null && result) {
|
||||||
BlocProvider.of<SwitchTabsBloc>(context).add(
|
BlocProvider.of<SwitchTabsBloc>(context)
|
||||||
|
.add(
|
||||||
const CreateNewRoutineViewEvent(false),
|
const CreateNewRoutineViewEvent(false),
|
||||||
);
|
);
|
||||||
BlocProvider.of<SwitchTabsBloc>(context).add(
|
BlocProvider.of<SwitchTabsBloc>(context)
|
||||||
|
.add(
|
||||||
const TriggerSwitchTabsEvent(true),
|
const TriggerSwitchTabsEvent(true),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -248,11 +276,14 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: state.isAutomation || state.isTabToRun
|
onPressed: state.isAutomation || state.isTabToRun
|
||||||
? () async {
|
? () async {
|
||||||
final result = await SettingHelper.showSettingDialog(
|
final result =
|
||||||
context: context,
|
await SettingHelper.showSettingDialog(
|
||||||
);
|
context: context,
|
||||||
|
iconId: state.selectedIcon ?? '');
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(AddSelectedIcon(result));
|
context
|
||||||
|
.read<RoutineBloc>()
|
||||||
|
.add(AddSelectedIcon(result));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
@@ -301,11 +332,13 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
width: 200,
|
width: 200,
|
||||||
child: Center(
|
child: Center(
|
||||||
child: DefaultButton(
|
child: DefaultButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
if (state.routineName == null || state.routineName!.isEmpty) {
|
if (state.routineName == null ||
|
||||||
|
state.routineName!.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: const Text('Please enter the routine name'),
|
content: const Text(
|
||||||
|
'Please enter the routine name'),
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
backgroundColor: ColorsManager.red,
|
backgroundColor: ColorsManager.red,
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
@@ -319,10 +352,12 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.ifItems.isEmpty || state.thenItems.isEmpty) {
|
if (state.ifItems.isEmpty ||
|
||||||
|
state.thenItems.isEmpty) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: const Text('Please add if and then condition'),
|
content: const Text(
|
||||||
|
'Please add if and then condition'),
|
||||||
duration: const Duration(seconds: 2),
|
duration: const Duration(seconds: 2),
|
||||||
backgroundColor: ColorsManager.red,
|
backgroundColor: ColorsManager.red,
|
||||||
action: SnackBarAction(
|
action: SnackBarAction(
|
||||||
@@ -335,7 +370,17 @@ class RoutineSearchAndButtons extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SaveRoutineHelper.showSaveRoutineDialog(context);
|
final result =
|
||||||
|
await SaveRoutineHelper.showSaveRoutineDialog(
|
||||||
|
context);
|
||||||
|
if (result != null && result) {
|
||||||
|
BlocProvider.of<SwitchTabsBloc>(context).add(
|
||||||
|
const CreateNewRoutineViewEvent(false),
|
||||||
|
);
|
||||||
|
BlocProvider.of<SwitchTabsBloc>(context).add(
|
||||||
|
const TriggerSwitchTabsEvent(true),
|
||||||
|
);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
borderRadius: 15,
|
borderRadius: 15,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
|
|||||||
@@ -30,69 +30,109 @@ class ThenContainer extends StatelessWidget {
|
|||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 18, fontWeight: FontWeight.bold)),
|
fontSize: 18, fontWeight: FontWeight.bold)),
|
||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
Wrap(
|
state.isLoading && state.isUpdate == true
|
||||||
spacing: 8,
|
? const Center(
|
||||||
runSpacing: 8,
|
child: CircularProgressIndicator(),
|
||||||
children: List.generate(
|
)
|
||||||
state.thenItems.length,
|
: Wrap(
|
||||||
(index) => GestureDetector(
|
spacing: 8,
|
||||||
onTap: () async {
|
runSpacing: 8,
|
||||||
if (state.thenItems[index]['deviceId'] ==
|
children: List.generate(
|
||||||
'delay') {
|
state.thenItems.length,
|
||||||
final result = await DelayHelper
|
(index) => GestureDetector(
|
||||||
.showDelayPickerDialog(
|
onTap: () async {
|
||||||
context, state.thenItems[index]);
|
if (state.thenItems[index]
|
||||||
|
['deviceId'] ==
|
||||||
|
'delay') {
|
||||||
|
final result = await DelayHelper
|
||||||
|
.showDelayPickerDialog(context,
|
||||||
|
state.thenItems[index]);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context
|
context
|
||||||
.read<RoutineBloc>()
|
.read<RoutineBloc>()
|
||||||
.add(AddToThenContainer({
|
.add(AddToThenContainer({
|
||||||
...state.thenItems[index],
|
...state.thenItems[index],
|
||||||
'imagePath': Assets.delay,
|
'imagePath': Assets.delay,
|
||||||
'title': 'Delay',
|
'title': 'Delay',
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await DeviceDialogHelper
|
if (state.thenItems[index]['type'] ==
|
||||||
.showDeviceDialog(
|
'automation') {
|
||||||
context, state.thenItems[index],
|
final result = await showDialog<bool>(
|
||||||
removeComparetors: true);
|
context: context,
|
||||||
|
builder: (BuildContext context) =>
|
||||||
|
AutomationDialog(
|
||||||
|
automationName:
|
||||||
|
state.thenItems[index]
|
||||||
|
['name'] ??
|
||||||
|
'Automation',
|
||||||
|
automationId:
|
||||||
|
state.thenItems[index]
|
||||||
|
['deviceId'] ??
|
||||||
|
'',
|
||||||
|
uniqueCustomId:
|
||||||
|
state.thenItems[index]
|
||||||
|
['uniqueCustomId'],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
context.read<RoutineBloc>().add(
|
context
|
||||||
AddToThenContainer(
|
.read<RoutineBloc>()
|
||||||
state.thenItems[index]));
|
.add(AddToThenContainer({
|
||||||
} else if (!['AC', '1G', '2G', '3G']
|
...state.thenItems[index],
|
||||||
.contains(state.thenItems[index]
|
'imagePath':
|
||||||
['productType'])) {
|
Assets.automation,
|
||||||
context.read<RoutineBloc>().add(
|
'title': state
|
||||||
AddToThenContainer(
|
.thenItems[index]['name'],
|
||||||
state.thenItems[index]));
|
}));
|
||||||
}
|
}
|
||||||
},
|
return;
|
||||||
child: DraggableCard(
|
}
|
||||||
imagePath: state.thenItems[index]
|
|
||||||
['imagePath'] ??
|
final result = await DeviceDialogHelper
|
||||||
'',
|
.showDeviceDialog(
|
||||||
title:
|
context, state.thenItems[index],
|
||||||
state.thenItems[index]['title'] ?? '',
|
removeComparetors: true);
|
||||||
deviceData: state.thenItems[index],
|
|
||||||
padding: const EdgeInsets.symmetric(
|
if (result != null) {
|
||||||
horizontal: 4, vertical: 8),
|
context.read<RoutineBloc>().add(
|
||||||
isFromThen: true,
|
AddToThenContainer(
|
||||||
isFromIf: false,
|
state.thenItems[index]));
|
||||||
onRemove: () {
|
} else if (!['AC', '1G', '2G', '3G']
|
||||||
context.read<RoutineBloc>().add(
|
.contains(state.thenItems[index]
|
||||||
RemoveDragCard(
|
['productType'])) {
|
||||||
index: index,
|
context.read<RoutineBloc>().add(
|
||||||
isFromThen: true,
|
AddToThenContainer(
|
||||||
key: state.thenItems[index]
|
state.thenItems[index]));
|
||||||
['uniqueCustomId']));
|
}
|
||||||
},
|
},
|
||||||
),
|
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,
|
||||||
|
key: state.thenItems[index]
|
||||||
|
['uniqueCustomId']));
|
||||||
|
},
|
||||||
|
),
|
||||||
|
))),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,20 +7,25 @@ import 'package:syncrow_web/pages/spaces_management/bloc/space_management_state.
|
|||||||
import 'package:syncrow_web/services/product_api.dart';
|
import 'package:syncrow_web/services/product_api.dart';
|
||||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||||
|
|
||||||
class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
class SpaceManagementBloc
|
||||||
|
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
||||||
final CommunitySpaceManagementApi _api;
|
final CommunitySpaceManagementApi _api;
|
||||||
final ProductApi _productApi;
|
final ProductApi _productApi;
|
||||||
|
|
||||||
List<ProductModel>? _cachedProducts;
|
List<ProductModel>? _cachedProducts;
|
||||||
|
|
||||||
SpaceManagementBloc(this._api, this._productApi) : super(SpaceManagementInitial()) {
|
SpaceManagementBloc(this._api, this._productApi)
|
||||||
|
: super(SpaceManagementInitial()) {
|
||||||
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
||||||
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
||||||
on<CreateCommunityEvent>(_onCreateCommunity);
|
on<CreateCommunityEvent>(_onCreateCommunity);
|
||||||
on<SaveSpacesEvent>(_onSaveSpaces);
|
on<SelectCommunityEvent>(_onSelectCommunity);
|
||||||
on<FetchProductsEvent>(_onFetchProducts);
|
|
||||||
on<DeleteCommunityEvent>(_onCommunityDelete);
|
on<DeleteCommunityEvent>(_onCommunityDelete);
|
||||||
on<UpdateCommunityEvent>(_onUpdateCommunity);
|
on<UpdateCommunityEvent>(_onUpdateCommunity);
|
||||||
|
on<SaveSpacesEvent>(_onSaveSpaces);
|
||||||
|
on<FetchProductsEvent>(_onFetchProducts);
|
||||||
|
on<SelectSpaceEvent>(_onSelectSpace);
|
||||||
|
on<NewCommunityEvent>(_onNewCommunity);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUpdateCommunity(
|
void _onUpdateCommunity(
|
||||||
@@ -30,22 +35,23 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
final previousState = state;
|
final previousState = state;
|
||||||
try {
|
try {
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
final success = await _api.updateCommunity(event.communityUuid, event.name);
|
final success =
|
||||||
|
await _api.updateCommunity(event.communityUuid, event.name);
|
||||||
if (success) {
|
if (success) {
|
||||||
if (previousState is SpaceManagementLoaded) {
|
if (previousState is SpaceManagementLoaded) {
|
||||||
final updatedCommunities = List<CommunityModel>.from(previousState.communities);
|
final updatedCommunities =
|
||||||
for(var community in updatedCommunities){
|
List<CommunityModel>.from(previousState.communities);
|
||||||
if(community.uuid == event.communityUuid){
|
for (var community in updatedCommunities) {
|
||||||
|
if (community.uuid == event.communityUuid) {
|
||||||
community.name = event.name;
|
community.name = event.name;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
products: previousState.products,
|
products: previousState.products,
|
||||||
selectedCommunity: previousState.selectedCommunity,
|
selectedCommunity: previousState.selectedCommunity,
|
||||||
));
|
));
|
||||||
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
emit(const SpaceManagementError('Failed to update the community.'));
|
emit(const SpaceManagementError('Failed to update the community.'));
|
||||||
@@ -55,40 +61,61 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onloadProducts() async {
|
||||||
|
if (_cachedProducts == null) {
|
||||||
|
final products = await _productApi.fetchProducts();
|
||||||
|
_cachedProducts = products;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onFetchProducts(
|
void _onFetchProducts(
|
||||||
FetchProductsEvent event,
|
FetchProductsEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
if (_cachedProducts != null) {
|
|
||||||
// Products are already cached, no need to fetch again
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final products = await _productApi.fetchProducts();
|
_onloadProducts();
|
||||||
_cachedProducts = products; // Cache the products locally
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error fetching products: $e'));
|
emit(SpaceManagementError('Error fetching products: $e'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<List<SpaceModel>> _fetchSpacesForCommunity(
|
||||||
|
String communityUuid) async {
|
||||||
|
return await _api.getSpaceHierarchy(communityUuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onNewCommunity(
|
||||||
|
NewCommunityEvent event,
|
||||||
|
Emitter<SpaceManagementState> emit,
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
if (event.communities.isEmpty) {
|
||||||
|
emit(const SpaceManagementError('No communities provided.'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(BlankState(
|
||||||
|
communities: event.communities,
|
||||||
|
products: _cachedProducts ?? [],
|
||||||
|
));
|
||||||
|
} catch (error) {
|
||||||
|
emit(SpaceManagementError('Error loading communities: $error'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onLoadCommunityAndSpaces(
|
void _onLoadCommunityAndSpaces(
|
||||||
LoadCommunityAndSpacesEvent event,
|
LoadCommunityAndSpacesEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
try {
|
try {
|
||||||
if (_cachedProducts == null) {
|
_onloadProducts();
|
||||||
final products = await _productApi.fetchProducts();
|
|
||||||
_cachedProducts = products;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch all communities
|
|
||||||
List<CommunityModel> communities = await _api.fetchCommunities();
|
List<CommunityModel> communities = await _api.fetchCommunities();
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
communities.map((community) async {
|
communities.map((community) async {
|
||||||
List<SpaceModel> spaces = await _api.getSpaceHierarchy(community.uuid);
|
List<SpaceModel> spaces =
|
||||||
|
await _fetchSpacesForCommunity(community.uuid);
|
||||||
return CommunityModel(
|
return CommunityModel(
|
||||||
uuid: community.uuid,
|
uuid: community.uuid,
|
||||||
createdAt: community.createdAt,
|
createdAt: community.createdAt,
|
||||||
@@ -101,7 +128,8 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
}).toList(),
|
}).toList(),
|
||||||
);
|
);
|
||||||
|
|
||||||
emit(SpaceManagementLoaded(communities: updatedCommunities, products: _cachedProducts ?? []));
|
emit(SpaceManagementLoaded(
|
||||||
|
communities: updatedCommunities, products: _cachedProducts ?? []));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||||
}
|
}
|
||||||
@@ -139,16 +167,21 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CommunityModel? newCommunity = await _api.createCommunity(event.name, event.description);
|
CommunityModel? newCommunity =
|
||||||
|
await _api.createCommunity(event.name, event.description);
|
||||||
|
|
||||||
if (newCommunity != null) {
|
if (newCommunity != null) {
|
||||||
if (previousState is SpaceManagementLoaded) {
|
if (previousState is SpaceManagementLoaded ||
|
||||||
final updatedCommunities = List<CommunityModel>.from(previousState.communities)
|
previousState is BlankState) {
|
||||||
..add(newCommunity);
|
final prevCommunities = List<CommunityModel>.from(
|
||||||
|
(previousState as dynamic).communities,
|
||||||
|
);
|
||||||
|
final updatedCommunities = prevCommunities..add(newCommunity);
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
selectedCommunity: newCommunity));
|
selectedCommunity: newCommunity,
|
||||||
|
selectedSpace: null));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
emit(const SpaceManagementError('Error creating community'));
|
emit(const SpaceManagementError('Error creating community'));
|
||||||
@@ -158,6 +191,54 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _onSelectCommunity(
|
||||||
|
SelectCommunityEvent event,
|
||||||
|
Emitter<SpaceManagementState> emit,
|
||||||
|
) async {
|
||||||
|
_handleCommunitySpaceStateUpdate(
|
||||||
|
emit: emit,
|
||||||
|
selectedCommunity: event.selectedCommunity,
|
||||||
|
selectedSpace: null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onSelectSpace(
|
||||||
|
SelectSpaceEvent event,
|
||||||
|
Emitter<SpaceManagementState> emit,
|
||||||
|
) {
|
||||||
|
_handleCommunitySpaceStateUpdate(
|
||||||
|
emit: emit,
|
||||||
|
selectedCommunity: event.selectedCommunity,
|
||||||
|
selectedSpace: event.selectedSpace,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleCommunitySpaceStateUpdate({
|
||||||
|
required Emitter<SpaceManagementState> emit,
|
||||||
|
CommunityModel? selectedCommunity,
|
||||||
|
SpaceModel? selectedSpace,
|
||||||
|
}) {
|
||||||
|
final previousState = state;
|
||||||
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (previousState is SpaceManagementLoaded ||
|
||||||
|
previousState is BlankState) {
|
||||||
|
final communities = List<CommunityModel>.from(
|
||||||
|
(previousState as dynamic).communities,
|
||||||
|
);
|
||||||
|
emit(SpaceManagementLoaded(
|
||||||
|
communities: communities,
|
||||||
|
products: _cachedProducts ?? [],
|
||||||
|
selectedCommunity: selectedCommunity,
|
||||||
|
selectedSpace: selectedSpace,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(SpaceManagementError('Error updating state: $e'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _onSaveSpaces(
|
void _onSaveSpaces(
|
||||||
SaveSpacesEvent event,
|
SaveSpacesEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
@@ -166,17 +247,54 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final updatedSpaces = await saveSpacesHierarchically(event.spaces, event.communityUuid);
|
final updatedSpaces =
|
||||||
|
await saveSpacesHierarchically(event.spaces, event.communityUuid);
|
||||||
|
|
||||||
|
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
|
||||||
|
|
||||||
emit(SpaceCreationSuccess(spaces: updatedSpaces));
|
emit(SpaceCreationSuccess(spaces: updatedSpaces));
|
||||||
add(LoadCommunityAndSpacesEvent());
|
|
||||||
|
if (previousState is SpaceManagementLoaded) {
|
||||||
|
_updateLoadedState(
|
||||||
|
previousState,
|
||||||
|
allSpaces,
|
||||||
|
event.communityUuid,
|
||||||
|
emit,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
add(LoadCommunityAndSpacesEvent());
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error saving spaces: $e'));
|
emit(SpaceManagementError('Error saving spaces: $e'));
|
||||||
|
|
||||||
if (previousState is SpaceManagementLoaded) {
|
if (previousState is SpaceManagementLoaded) {
|
||||||
emit(previousState);
|
emit(previousState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _updateLoadedState(
|
||||||
|
SpaceManagementLoaded previousState,
|
||||||
|
List<SpaceModel> allSpaces,
|
||||||
|
String communityUuid,
|
||||||
|
Emitter<SpaceManagementState> emit,
|
||||||
|
) {
|
||||||
|
final communities = List<CommunityModel>.from(previousState.communities);
|
||||||
|
|
||||||
|
for (var community in communities) {
|
||||||
|
if (community.uuid == communityUuid) {
|
||||||
|
community.spaces = allSpaces;
|
||||||
|
emit(SpaceManagementLoaded(
|
||||||
|
communities: communities,
|
||||||
|
products: _cachedProducts ?? [],
|
||||||
|
selectedCommunity: community,
|
||||||
|
selectedSpace: null,
|
||||||
|
));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<SpaceModel>> saveSpacesHierarchically(
|
Future<List<SpaceModel>> saveSpacesHierarchically(
|
||||||
List<SpaceModel> spaces, String communityUuid) async {
|
List<SpaceModel> spaces, String communityUuid) async {
|
||||||
final orderedSpaces = flattenHierarchy(spaces);
|
final orderedSpaces = flattenHierarchy(spaces);
|
||||||
@@ -187,7 +305,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
|
|
||||||
for (var parent in parentsToDelete) {
|
for (var parent in parentsToDelete) {
|
||||||
try {
|
try {
|
||||||
// Ensure parent.uuid is not null before calling the API
|
|
||||||
if (parent.uuid != null) {
|
if (parent.uuid != null) {
|
||||||
await _api.deleteSpace(communityUuid, parent.uuid!);
|
await _api.deleteSpace(communityUuid, parent.uuid!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart'; // Import for Offset
|
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart'; // Import for Offset
|
||||||
|
|
||||||
abstract class SpaceManagementEvent extends Equatable {
|
abstract class SpaceManagementEvent extends Equatable {
|
||||||
@@ -83,17 +84,6 @@ class CreateCommunityEvent extends SpaceManagementEvent {
|
|||||||
List<Object> get props => [name, description];
|
List<Object> get props => [name, description];
|
||||||
}
|
}
|
||||||
|
|
||||||
class FetchProductsEvent extends SpaceManagementEvent {}
|
|
||||||
|
|
||||||
class LoadSpaceHierarchyEvent extends SpaceManagementEvent {
|
|
||||||
final String communityId;
|
|
||||||
|
|
||||||
const LoadSpaceHierarchyEvent({required this.communityId});
|
|
||||||
|
|
||||||
@override
|
|
||||||
List<Object> get props => [communityId];
|
|
||||||
}
|
|
||||||
|
|
||||||
class UpdateCommunityEvent extends SpaceManagementEvent {
|
class UpdateCommunityEvent extends SpaceManagementEvent {
|
||||||
final String communityUuid;
|
final String communityUuid;
|
||||||
final String name;
|
final String name;
|
||||||
@@ -106,3 +96,47 @@ class UpdateCommunityEvent extends SpaceManagementEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [communityUuid, name];
|
List<Object> get props => [communityUuid, name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SelectCommunityEvent extends SpaceManagementEvent {
|
||||||
|
final CommunityModel? selectedCommunity;
|
||||||
|
|
||||||
|
const SelectCommunityEvent({
|
||||||
|
required this.selectedCommunity,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class NewCommunityEvent extends SpaceManagementEvent {
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
|
||||||
|
const NewCommunityEvent({required this.communities});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [communities];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SelectSpaceEvent extends SpaceManagementEvent {
|
||||||
|
final CommunityModel? selectedCommunity;
|
||||||
|
final SpaceModel? selectedSpace;
|
||||||
|
|
||||||
|
const SelectSpaceEvent({
|
||||||
|
required this.selectedCommunity,
|
||||||
|
required this.selectedSpace,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class FetchProductsEvent extends SpaceManagementEvent {}
|
||||||
|
|
||||||
|
class LoadSpaceHierarchyEvent extends SpaceManagementEvent {
|
||||||
|
final String communityId;
|
||||||
|
|
||||||
|
const LoadSpaceHierarchyEvent({required this.communityId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [communityId];
|
||||||
|
}
|
||||||
|
|||||||
@@ -17,10 +17,24 @@ class SpaceManagementLoading extends SpaceManagementState {}
|
|||||||
class SpaceManagementLoaded extends SpaceManagementState {
|
class SpaceManagementLoaded extends SpaceManagementState {
|
||||||
final List<CommunityModel> communities;
|
final List<CommunityModel> communities;
|
||||||
final List<ProductModel> products;
|
final List<ProductModel> products;
|
||||||
CommunityModel? selectedCommunity; // Include products in the state
|
CommunityModel? selectedCommunity;
|
||||||
|
SpaceModel? selectedSpace;
|
||||||
|
|
||||||
SpaceManagementLoaded(
|
SpaceManagementLoaded(
|
||||||
{required this.communities, required this.products, this.selectedCommunity});
|
{required this.communities,
|
||||||
|
required this.products,
|
||||||
|
this.selectedCommunity,
|
||||||
|
this.selectedSpace});
|
||||||
|
}
|
||||||
|
|
||||||
|
class BlankState extends SpaceManagementState {
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
final List<ProductModel> products;
|
||||||
|
|
||||||
|
BlankState({
|
||||||
|
required this.communities,
|
||||||
|
required this.products,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpaceCreationSuccess extends SpaceManagementState {
|
class SpaceCreationSuccess extends SpaceManagementState {
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ class SpaceModel {
|
|||||||
this.selectedProducts = const [],
|
this.selectedProducts = const [],
|
||||||
}) : internalId = internalId ?? const Uuid().v4();
|
}) : internalId = internalId ?? const Uuid().v4();
|
||||||
|
|
||||||
factory SpaceModel.fromJson(Map<String, dynamic> json, {String? parentInternalId}) {
|
factory SpaceModel.fromJson(Map<String, dynamic> json,
|
||||||
|
{String? parentInternalId}) {
|
||||||
final String internalId = json['internalId'] ?? const Uuid().v4();
|
final String internalId = json['internalId'] ?? const Uuid().v4();
|
||||||
|
|
||||||
final List<SpaceModel> children = json['children'] != null
|
final List<SpaceModel> children = json['children'] != null
|
||||||
@@ -56,7 +57,7 @@ class SpaceModel {
|
|||||||
}).toList()
|
}).toList()
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
return SpaceModel(
|
final instance = SpaceModel(
|
||||||
internalId: internalId,
|
internalId: internalId,
|
||||||
uuid: json['uuid'] ?? '',
|
uuid: json['uuid'] ?? '',
|
||||||
spaceTuyaUuid: json['spaceTuyaUuid'],
|
spaceTuyaUuid: json['spaceTuyaUuid'],
|
||||||
@@ -72,11 +73,14 @@ class SpaceModel {
|
|||||||
isPrivate: json['parent']?['isPrivate'] ?? false,
|
isPrivate: json['parent']?['isPrivate'] ?? false,
|
||||||
invitationCode: json['parent']?['invitationCode'],
|
invitationCode: json['parent']?['invitationCode'],
|
||||||
children: [],
|
children: [],
|
||||||
position: Offset(json['parent']?['x'] ?? 0, json['parent']?['y'] ?? 0),
|
position:
|
||||||
|
Offset(json['parent']?['x'] ?? 0, json['parent']?['y'] ?? 0),
|
||||||
icon: json['parent']?['icon'] ?? Assets.location,
|
icon: json['parent']?['icon'] ?? Assets.location,
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
community: json['community'] != null ? CommunityModel.fromJson(json['community']) : null,
|
community: json['community'] != null
|
||||||
|
? CommunityModel.fromJson(json['community'])
|
||||||
|
: null,
|
||||||
children: children,
|
children: children,
|
||||||
icon: json['icon'] ?? Assets.location,
|
icon: json['icon'] ?? Assets.location,
|
||||||
position: Offset(json['x'] ?? 0, json['y'] ?? 0),
|
position: Offset(json['x'] ?? 0, json['y'] ?? 0),
|
||||||
@@ -90,6 +94,20 @@ class SpaceModel {
|
|||||||
}).toList()
|
}).toList()
|
||||||
: [],
|
: [],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (json['incomingConnections'] != null &&
|
||||||
|
json['incomingConnections'] is List &&
|
||||||
|
(json['incomingConnections'] as List).isNotEmpty &&
|
||||||
|
instance.parent != null) {
|
||||||
|
final conn = json['incomingConnections'][0];
|
||||||
|
instance.incomingConnection = Connection(
|
||||||
|
startSpace: instance.parent ?? instance, // Parent space
|
||||||
|
endSpace: instance, // This space instance
|
||||||
|
direction: conn['direction'],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
|
|||||||
@@ -20,8 +20,6 @@ class SpaceManagementPage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class SpaceManagementPageState extends State<SpaceManagementPage> {
|
class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||||
CommunityModel? selectedCommunity;
|
|
||||||
SpaceModel? selectedSpace;
|
|
||||||
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
|
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
|
||||||
final ProductApi _productApi = ProductApi();
|
final ProductApi _productApi = ProductApi();
|
||||||
Map<String, List<SpaceModel>> communitySpaces = {};
|
Map<String, List<SpaceModel>> communitySpaces = {};
|
||||||
@@ -36,43 +34,30 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (context) =>
|
create: (context) => SpaceManagementBloc(_api, _productApi)
|
||||||
SpaceManagementBloc(_api, _productApi)..add(LoadCommunityAndSpacesEvent()),
|
..add(LoadCommunityAndSpacesEvent()),
|
||||||
child: WebScaffold(
|
child: WebScaffold(
|
||||||
appBarTitle: Text('Space Management', style: Theme.of(context).textTheme.headlineLarge),
|
appBarTitle: Text('Space Management',
|
||||||
|
style: Theme.of(context).textTheme.headlineLarge),
|
||||||
enableMenuSidebar: false,
|
enableMenuSidebar: false,
|
||||||
rightBody: const NavigateHomeGridView(),
|
rightBody: const NavigateHomeGridView(),
|
||||||
scaffoldBody:
|
scaffoldBody: BlocBuilder<SpaceManagementBloc, SpaceManagementState>(
|
||||||
BlocBuilder<SpaceManagementBloc, SpaceManagementState>(builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state is SpaceManagementLoading) {
|
if (state is SpaceManagementLoading) {
|
||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
} else if (state is SpaceManagementLoaded) {
|
} else if (state is BlankState) {
|
||||||
int selectedIndex = state.communities.indexWhere(
|
|
||||||
(community) => community.uuid == selectedCommunity?.uuid,
|
|
||||||
);
|
|
||||||
if (selectedIndex != -1) {
|
|
||||||
selectedCommunity = state.communities[selectedIndex];
|
|
||||||
} else if (state.selectedCommunity != null) {
|
|
||||||
selectedCommunity = state.selectedCommunity;
|
|
||||||
} else {
|
|
||||||
selectedCommunity = null;
|
|
||||||
selectedSpace = null;
|
|
||||||
}
|
|
||||||
return LoadedSpaceView(
|
return LoadedSpaceView(
|
||||||
communities: state.communities,
|
communities: state.communities,
|
||||||
selectedCommunity: selectedCommunity,
|
selectedCommunity: null,
|
||||||
selectedSpace: selectedSpace,
|
selectedSpace: null,
|
||||||
|
products: state.products,
|
||||||
|
);
|
||||||
|
} else if (state is SpaceManagementLoaded) {
|
||||||
|
return LoadedSpaceView(
|
||||||
|
communities: state.communities,
|
||||||
|
selectedCommunity: state.selectedCommunity,
|
||||||
|
selectedSpace: state.selectedSpace,
|
||||||
products: state.products,
|
products: state.products,
|
||||||
onCommunitySelected: (community) {
|
|
||||||
setState(() {
|
|
||||||
selectedCommunity = community;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onSpaceSelected: (space) {
|
|
||||||
setState(() {
|
|
||||||
selectedSpace = space;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
} else if (state is SpaceManagementError) {
|
} else if (state is SpaceManagementError) {
|
||||||
return Center(child: Text('Error: ${state.errorMessage}'));
|
return Center(child: Text('Error: ${state.errorMessage}'));
|
||||||
|
|||||||
@@ -2,31 +2,41 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/create_community_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/create_community_dialog.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class BlankCommunityWidget extends StatelessWidget {
|
class BlankCommunityWidget extends StatefulWidget {
|
||||||
const BlankCommunityWidget({Key? key}) : super(key: key);
|
final List<CommunityModel> communities;
|
||||||
|
|
||||||
|
BlankCommunityWidget({required this.communities});
|
||||||
|
|
||||||
|
@override
|
||||||
|
_BlankCommunityWidgetState createState() => _BlankCommunityWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BlankCommunityWidgetState extends State<BlankCommunityWidget> {
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: Container(
|
child: Container(
|
||||||
color: ColorsManager.whiteColors, // Parent container with white background
|
color:
|
||||||
|
ColorsManager.whiteColors, // Parent container with white background
|
||||||
child: GridView.builder(
|
child: GridView.builder(
|
||||||
padding: const EdgeInsets.only(left: 40.0, top: 20.0),
|
padding: const EdgeInsets.only(left: 40.0, top: 20.0),
|
||||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||||
maxCrossAxisExtent: 400, // Each item's width will be 400 or less
|
maxCrossAxisExtent: 400,
|
||||||
mainAxisSpacing: 10, // Spacing between items
|
mainAxisSpacing: 10,
|
||||||
crossAxisSpacing: 10, // Spacing between items
|
crossAxisSpacing: 10,
|
||||||
childAspectRatio: 2.0, // Aspect ratio for width:height (e.g., 300:150 = 2.0)
|
childAspectRatio: 2.0,
|
||||||
),
|
),
|
||||||
itemCount: 1, // Only one item
|
itemCount: 1, // Only one item
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () => _showCreateCommunityDialog(context),
|
onTap: () => _showCreateCommunityDialog(context),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.center, // Center align the content
|
crossAxisAlignment:
|
||||||
|
CrossAxisAlignment.center, // Center align the content
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: AspectRatio(
|
child: AspectRatio(
|
||||||
@@ -34,7 +44,7 @@ class BlankCommunityWidget extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
decoration: ShapeDecoration(
|
decoration: ShapeDecoration(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
side: BorderSide(
|
side: const BorderSide(
|
||||||
width: 4,
|
width: 4,
|
||||||
strokeAlign: BorderSide.strokeAlignOutside,
|
strokeAlign: BorderSide.strokeAlignOutside,
|
||||||
color: ColorsManager.borderColor,
|
color: ColorsManager.borderColor,
|
||||||
@@ -45,9 +55,8 @@ class BlankCommunityWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
const SizedBox(height: 9),
|
||||||
const SizedBox(height: 9), // Space between item and text
|
Text('Blank',
|
||||||
Text('Blank', // Text below the item
|
|
||||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||||
color: ColorsManager.blackColor,
|
color: ColorsManager.blackColor,
|
||||||
)),
|
)),
|
||||||
@@ -63,6 +72,7 @@ class BlankCommunityWidget extends StatelessWidget {
|
|||||||
showDialog(
|
showDialog(
|
||||||
context: parentContext,
|
context: parentContext,
|
||||||
builder: (context) => CreateCommunityDialog(
|
builder: (context) => CreateCommunityDialog(
|
||||||
|
communities: widget.communities,
|
||||||
onCreateCommunity: (String communityName, String description) {
|
onCreateCommunity: (String communityName, String description) {
|
||||||
parentContext.read<SpaceManagementBloc>().add(
|
parentContext.read<SpaceManagementBloc>().add(
|
||||||
CreateCommunityEvent(
|
CreateCommunityEvent(
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ class CommunityStructureHeader extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
if (isEditingName)
|
if (isEditingName)
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: screenWidth * 0.3,
|
width: screenWidth * 0.1,
|
||||||
child: TextField(
|
child: TextField(
|
||||||
controller: nameController,
|
controller: nameController,
|
||||||
decoration: const InputDecoration(
|
decoration: const InputDecoration(
|
||||||
|
|||||||
@@ -24,12 +24,13 @@ class CommunityStructureArea extends StatefulWidget {
|
|||||||
SpaceModel? selectedSpace;
|
SpaceModel? selectedSpace;
|
||||||
final List<ProductModel>? products;
|
final List<ProductModel>? products;
|
||||||
final ValueChanged<SpaceModel?>? onSpaceSelected;
|
final ValueChanged<SpaceModel?>? onSpaceSelected;
|
||||||
|
final List<CommunityModel> communities;
|
||||||
final List<SpaceModel> spaces;
|
final List<SpaceModel> spaces;
|
||||||
|
|
||||||
CommunityStructureArea({
|
CommunityStructureArea({
|
||||||
this.selectedCommunity,
|
this.selectedCommunity,
|
||||||
this.selectedSpace,
|
this.selectedSpace,
|
||||||
|
required this.communities,
|
||||||
this.products,
|
this.products,
|
||||||
required this.spaces,
|
required this.spaces,
|
||||||
this.onSpaceSelected,
|
this.onSpaceSelected,
|
||||||
@@ -52,7 +53,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
connections =
|
||||||
|
widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||||
_adjustCanvasSizeForSpaces();
|
_adjustCanvasSizeForSpaces();
|
||||||
_nameController = TextEditingController(
|
_nameController = TextEditingController(
|
||||||
text: widget.selectedCommunity?.name ?? '',
|
text: widget.selectedCommunity?.name ?? '',
|
||||||
@@ -79,12 +81,14 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
if (oldWidget.spaces != widget.spaces) {
|
if (oldWidget.spaces != widget.spaces) {
|
||||||
setState(() {
|
setState(() {
|
||||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
connections =
|
||||||
|
widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||||
_adjustCanvasSizeForSpaces();
|
_adjustCanvasSizeForSpaces();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget.selectedSpace != oldWidget.selectedSpace && widget.selectedSpace != null) {
|
if (widget.selectedSpace != oldWidget.selectedSpace &&
|
||||||
|
widget.selectedSpace != null) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
_moveToSpace(widget.selectedSpace!);
|
_moveToSpace(widget.selectedSpace!);
|
||||||
});
|
});
|
||||||
@@ -94,14 +98,16 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (widget.selectedCommunity == null) {
|
if (widget.selectedCommunity == null) {
|
||||||
return BlankCommunityWidget();
|
return BlankCommunityWidget(
|
||||||
|
communities: widget.communities,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Size screenSize = MediaQuery.of(context).size;
|
Size screenSize = MediaQuery.of(context).size;
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: GestureDetector(
|
child: GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_deselectSpace();
|
_deselectSpace(context);
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
decoration: const BoxDecoration(
|
decoration: const BoxDecoration(
|
||||||
@@ -156,9 +162,11 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
children: [
|
children: [
|
||||||
for (var connection in connections)
|
for (var connection in connections)
|
||||||
Opacity(
|
Opacity(
|
||||||
opacity:
|
opacity: _isHighlightedConnection(connection)
|
||||||
_isHighlightedConnection(connection) ? 1.0 : 0.3, // Adjust opacity
|
? 1.0
|
||||||
child: CustomPaint(painter: CurvedLinePainter([connection])),
|
: 0.3, // Adjust opacity
|
||||||
|
child: CustomPaint(
|
||||||
|
painter: CurvedLinePainter([connection])),
|
||||||
),
|
),
|
||||||
for (var entry in spaces.asMap().entries)
|
for (var entry in spaces.asMap().entries)
|
||||||
if (entry.value.status != SpaceStatus.deleted)
|
if (entry.value.status != SpaceStatus.deleted)
|
||||||
@@ -167,10 +175,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
top: entry.value.position.dy,
|
top: entry.value.position.dy,
|
||||||
child: SpaceCardWidget(
|
child: SpaceCardWidget(
|
||||||
index: entry.key,
|
index: entry.key,
|
||||||
onButtonTap: (int index, Offset newPosition, String direction) {
|
onButtonTap: (int index, Offset newPosition,
|
||||||
|
String direction) {
|
||||||
_showCreateSpaceDialog(
|
_showCreateSpaceDialog(
|
||||||
screenSize,
|
screenSize,
|
||||||
position: spaces[index].position + newPosition,
|
position:
|
||||||
|
spaces[index].position + newPosition,
|
||||||
parentIndex: index,
|
parentIndex: index,
|
||||||
direction: direction,
|
direction: direction,
|
||||||
);
|
);
|
||||||
@@ -183,7 +193,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
_updateNodePosition(entry.value, newPosition);
|
_updateNodePosition(entry.value, newPosition);
|
||||||
},
|
},
|
||||||
buildSpaceContainer: (int index) {
|
buildSpaceContainer: (int index) {
|
||||||
final bool isHighlighted = _isHighlightedSpace(spaces[index]);
|
final bool isHighlighted =
|
||||||
|
_isHighlightedSpace(spaces[index]);
|
||||||
|
|
||||||
return Opacity(
|
return Opacity(
|
||||||
opacity: isHighlighted ? 1.0 : 0.3,
|
opacity: isHighlighted ? 1.0 : 0.3,
|
||||||
@@ -193,7 +204,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
_showEditSpaceDialog(spaces[index]);
|
_showEditSpaceDialog(spaces[index]);
|
||||||
},
|
},
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_selectSpace(spaces[index]);
|
_selectSpace(context, spaces[index]);
|
||||||
},
|
},
|
||||||
icon: spaces[index].icon ?? '',
|
icon: spaces[index].icon ?? '',
|
||||||
name: spaces[index].name,
|
name: spaces[index].name,
|
||||||
@@ -210,7 +221,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
child: AddSpaceButton(
|
child: AddSpaceButton(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_showCreateSpaceDialog(screenSize,
|
_showCreateSpaceDialog(screenSize,
|
||||||
canvasHeight: canvasHeight, canvasWidth: canvasWidth);
|
canvasHeight: canvasHeight,
|
||||||
|
canvasWidth: canvasWidth);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -270,12 +282,14 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return CreateSpaceDialog(
|
return CreateSpaceDialog(
|
||||||
products: widget.products,
|
products: widget.products,
|
||||||
parentSpace: parentIndex != null? spaces[parentIndex] : null,
|
parentSpace: parentIndex != null ? spaces[parentIndex] : null,
|
||||||
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts) {
|
onCreateSpace: (String name, String icon,
|
||||||
|
List<SelectedProduct> selectedProducts) {
|
||||||
setState(() {
|
setState(() {
|
||||||
// Set the first space in the center or use passed position
|
// Set the first space in the center or use passed position
|
||||||
|
|
||||||
Offset centerPosition = position ?? _getCenterPosition(screenSize);
|
Offset centerPosition =
|
||||||
|
position ?? _getCenterPosition(screenSize);
|
||||||
SpaceModel newSpace = SpaceModel(
|
SpaceModel newSpace = SpaceModel(
|
||||||
name: name,
|
name: name,
|
||||||
icon: icon,
|
icon: icon,
|
||||||
@@ -317,9 +331,11 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
products: widget.products,
|
products: widget.products,
|
||||||
name: space.name,
|
name: space.name,
|
||||||
icon: space.icon,
|
icon: space.icon,
|
||||||
|
editSpace: space,
|
||||||
isEdit: true,
|
isEdit: true,
|
||||||
selectedProducts: space.selectedProducts,
|
selectedProducts: space.selectedProducts,
|
||||||
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts) {
|
onCreateSpace: (String name, String icon,
|
||||||
|
List<SelectedProduct> selectedProducts) {
|
||||||
setState(() {
|
setState(() {
|
||||||
// Update the space's properties
|
// Update the space's properties
|
||||||
space.name = name;
|
space.name = name;
|
||||||
@@ -331,8 +347,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// Pre-fill the dialog with current space data
|
key: Key(space.name),
|
||||||
key: Key(space.name), // Add a unique key to ensure dialog refresh
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -465,40 +480,30 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
..scale(1.2);
|
..scale(1.2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _selectSpace(SpaceModel space) {
|
void _selectSpace(BuildContext context, SpaceModel space) {
|
||||||
setState(() {
|
context.read<SpaceManagementBloc>().add(
|
||||||
widget.selectedSpace = space;
|
SelectSpaceEvent(
|
||||||
});
|
selectedCommunity: widget.selectedCommunity,
|
||||||
|
selectedSpace: space),
|
||||||
if (widget.onSpaceSelected != null) {
|
);
|
||||||
widget.onSpaceSelected!(space);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isHighlightedSpace(SpaceModel space) {
|
bool _isHighlightedSpace(SpaceModel space) {
|
||||||
if (widget.selectedSpace == null) return true;
|
final selectedSpace = widget.selectedSpace;
|
||||||
if (space == widget.selectedSpace) return true;
|
if (selectedSpace == null) return true;
|
||||||
if (widget.selectedSpace?.parent?.internalId == space.internalId) return true;
|
|
||||||
if (widget.selectedSpace?.children != null) {
|
return space == selectedSpace ||
|
||||||
for (var child in widget.selectedSpace!.children) {
|
selectedSpace.parent?.internalId == space.internalId ||
|
||||||
if (child.internalId == space.internalId) {
|
selectedSpace.children
|
||||||
return true;
|
?.any((child) => child.internalId == space.internalId) ==
|
||||||
}
|
true;
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _deselectSpace() {
|
void _deselectSpace(BuildContext context) {
|
||||||
if (widget.selectedSpace != null) {
|
context.read<SpaceManagementBloc>().add(
|
||||||
setState(() {
|
SelectSpaceEvent(
|
||||||
widget.selectedSpace = null;
|
selectedCommunity: widget.selectedCommunity, selectedSpace: null),
|
||||||
});
|
);
|
||||||
|
|
||||||
if (widget.onSpaceSelected != null) {
|
|
||||||
widget.onSpaceSelected!(null); // Notify parent that no space is selected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isHighlightedConnection(Connection connection) {
|
bool _isHighlightedConnection(Connection connection) {
|
||||||
|
|||||||
@@ -1,37 +1,47 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class CreateCommunityDialog extends StatefulWidget {
|
class CreateCommunityDialog extends StatefulWidget {
|
||||||
final Function(String name, String description) onCreateCommunity;
|
final Function(String name, String description) onCreateCommunity;
|
||||||
|
final List<CommunityModel> communities;
|
||||||
|
|
||||||
const CreateCommunityDialog({super.key, required this.onCreateCommunity});
|
const CreateCommunityDialog(
|
||||||
|
{super.key, required this.onCreateCommunity, required this.communities});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
CreateCommunityDialogState createState() => CreateCommunityDialogState();
|
CreateCommunityDialogState createState() => CreateCommunityDialogState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
||||||
String enteredName = ''; // Store the entered community name
|
String enteredName = '';
|
||||||
|
bool isNameFieldExist = false;
|
||||||
|
bool isNameEmpty = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
return Dialog(
|
return Dialog(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
backgroundColor: Colors.transparent, // Transparent for shadow effect
|
backgroundColor:
|
||||||
|
ColorsManager.transparentColor, // Transparent for shadow effect
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
// Background container with shadow and rounded corners
|
// Background container with shadow and rounded corners
|
||||||
Container(
|
Container(
|
||||||
width: 490,
|
width: screenWidth * 0.3,
|
||||||
padding: const EdgeInsets.all(20),
|
padding: const EdgeInsets.all(20),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: Colors.white,
|
color: ColorsManager.whiteColors,
|
||||||
borderRadius: BorderRadius.circular(20),
|
borderRadius: BorderRadius.circular(20),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(
|
BoxShadow(
|
||||||
color: Colors.black.withOpacity(0.25),
|
color: ColorsManager.blackColor.withOpacity(0.25),
|
||||||
blurRadius: 20,
|
blurRadius: 20,
|
||||||
spreadRadius: 5,
|
spreadRadius: 5,
|
||||||
offset: const Offset(0, 5),
|
offset: const Offset(0, 5),
|
||||||
@@ -53,10 +63,20 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
// Input field for the community name
|
// Input field for the community name
|
||||||
TextField(
|
TextField(
|
||||||
onChanged: (value) {
|
onChanged: (value) {
|
||||||
enteredName = value; // Capture entered name
|
setState(() {
|
||||||
|
enteredName = value.trim();
|
||||||
|
isNameFieldExist = widget.communities.any(
|
||||||
|
(community) => community.name == enteredName,
|
||||||
|
);
|
||||||
|
if (value.isEmpty) {
|
||||||
|
isNameEmpty = true;
|
||||||
|
} else {
|
||||||
|
isNameEmpty = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
color: Colors.black,
|
color: ColorsManager.blackColor,
|
||||||
),
|
),
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Please enter the community name',
|
hintText: 'Please enter the community name',
|
||||||
@@ -68,45 +88,68 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
border: OutlineInputBorder(
|
border: OutlineInputBorder(
|
||||||
borderSide: const BorderSide(color: ColorsManager.boxColor, width: 1),
|
borderSide: BorderSide(
|
||||||
|
color: isNameFieldExist || isNameEmpty
|
||||||
|
? ColorsManager.red
|
||||||
|
: ColorsManager.boxColor,
|
||||||
|
width: 1),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
enabledBorder: OutlineInputBorder(
|
enabledBorder: OutlineInputBorder(
|
||||||
borderSide: const BorderSide(color: ColorsManager.boxColor, width: 1),
|
borderSide: BorderSide(
|
||||||
|
color: isNameFieldExist || isNameEmpty
|
||||||
|
? ColorsManager.red
|
||||||
|
: ColorsManager.boxColor, width: 1),
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
),
|
),
|
||||||
focusedBorder: OutlineInputBorder(
|
focusedBorder: OutlineInputBorder(
|
||||||
borderRadius: BorderRadius.circular(10),
|
borderRadius: BorderRadius.circular(10),
|
||||||
borderSide: const BorderSide(color: ColorsManager.boxColor, width: 1),
|
borderSide: BorderSide(
|
||||||
|
color: isNameFieldExist || isNameEmpty
|
||||||
|
? ColorsManager.red
|
||||||
|
: ColorsManager.boxColor,
|
||||||
|
width: 1),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (isNameFieldExist)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
|
child: Text(
|
||||||
|
'*Name already exists.',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(color: ColorsManager.red),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (isNameEmpty)
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 8.0),
|
||||||
|
child: Text(
|
||||||
|
'*Name should not be empty.',
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodySmall
|
||||||
|
?.copyWith(color: ColorsManager.red),
|
||||||
|
),
|
||||||
|
),
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
// Action buttons
|
// Action buttons
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Expanded(
|
Expanded(
|
||||||
child: TextButton(
|
child: CancelButton(
|
||||||
|
label: 'Cancel',
|
||||||
onPressed: () => Navigator.of(context).pop(),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
style: TextButton.styleFrom(
|
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
||||||
backgroundColor: ColorsManager.boxColor,
|
|
||||||
shape: RoundedRectangleBorder(
|
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: const Text(
|
|
||||||
'Cancel',
|
|
||||||
style: TextStyle(color: Colors.black),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 16),
|
const SizedBox(width: 16),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: ElevatedButton(
|
child: DefaultButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
if (enteredName.isNotEmpty) {
|
if (enteredName.isNotEmpty && !isNameFieldExist) {
|
||||||
widget.onCreateCommunity(
|
widget.onCreateCommunity(
|
||||||
enteredName,
|
enteredName,
|
||||||
"",
|
"",
|
||||||
@@ -114,14 +157,11 @@ class CreateCommunityDialogState extends State<CreateCommunityDialog> {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
style: ElevatedButton.styleFrom(
|
backgroundColor: isNameFieldExist || isNameEmpty
|
||||||
padding: const EdgeInsets.symmetric(vertical: 16),
|
? ColorsManager.lightGrayColor
|
||||||
backgroundColor: ColorsManager.secondaryColor,
|
: ColorsManager.secondaryColor,
|
||||||
foregroundColor: Colors.white,
|
borderRadius: 10,
|
||||||
shape: RoundedRectangleBorder(
|
foregroundColor: ColorsManager.whiteColors,
|
||||||
borderRadius: BorderRadius.circular(10),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
child: const Text('OK'),
|
child: const Text('OK'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ import 'package:syncrow_web/utils/constants/assets.dart';
|
|||||||
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
|
import 'package:syncrow_web/utils/constants/space_icon_const.dart';
|
||||||
|
|
||||||
class CreateSpaceDialog extends StatefulWidget {
|
class CreateSpaceDialog extends StatefulWidget {
|
||||||
final Function(String, String, List<SelectedProduct> selectedProducts) onCreateSpace;
|
final Function(String, String, List<SelectedProduct> selectedProducts)
|
||||||
|
onCreateSpace;
|
||||||
final List<ProductModel>? products;
|
final List<ProductModel>? products;
|
||||||
final String? name;
|
final String? name;
|
||||||
final String? icon;
|
final String? icon;
|
||||||
final bool isEdit;
|
final bool isEdit;
|
||||||
final List<SelectedProduct> selectedProducts;
|
final List<SelectedProduct> selectedProducts;
|
||||||
final SpaceModel? parentSpace;
|
final SpaceModel? parentSpace;
|
||||||
|
final SpaceModel? editSpace;
|
||||||
|
|
||||||
const CreateSpaceDialog(
|
const CreateSpaceDialog(
|
||||||
{super.key,
|
{super.key,
|
||||||
@@ -29,6 +31,7 @@ class CreateSpaceDialog extends StatefulWidget {
|
|||||||
this.name,
|
this.name,
|
||||||
this.icon,
|
this.icon,
|
||||||
this.isEdit = false,
|
this.isEdit = false,
|
||||||
|
this.editSpace,
|
||||||
this.selectedProducts = const []});
|
this.selectedProducts = const []});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -49,8 +52,10 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
selectedIcon = widget.icon ?? Assets.location;
|
selectedIcon = widget.icon ?? Assets.location;
|
||||||
nameController = TextEditingController(text: widget.name ?? '');
|
nameController = TextEditingController(text: widget.name ?? '');
|
||||||
selectedProducts = widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
selectedProducts =
|
||||||
isOkButtonEnabled = enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||||
|
isOkButtonEnabled =
|
||||||
|
enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -59,7 +64,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: widget.isEdit ? const Text('Edit Space') : const Text('Create New Space'),
|
title: widget.isEdit
|
||||||
|
? const Text('Edit Space')
|
||||||
|
: const Text('Create New Space'),
|
||||||
backgroundColor: ColorsManager.whiteColors,
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
content: SizedBox(
|
content: SizedBox(
|
||||||
width: screenWidth * 0.5, // Limit dialog width
|
width: screenWidth * 0.5, // Limit dialog width
|
||||||
@@ -126,11 +133,17 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
isNameFieldInvalid = value.isEmpty;
|
isNameFieldInvalid = value.isEmpty;
|
||||||
|
|
||||||
if (!isNameFieldInvalid) {
|
if (!isNameFieldInvalid) {
|
||||||
if (widget.parentSpace?.children
|
if ((widget.parentSpace?.children.any(
|
||||||
.any((child) => child.name == value) ??
|
(child) => child.name == value) ??
|
||||||
false) {
|
false) ||
|
||||||
|
(widget.parentSpace?.name == value) ||
|
||||||
|
(widget.editSpace?.children.any(
|
||||||
|
(child) => child.name == value) ??
|
||||||
|
false)) {
|
||||||
isNameFieldExist = true;
|
isNameFieldExist = true;
|
||||||
|
isOkButtonEnabled = false;
|
||||||
} else {
|
} else {
|
||||||
|
isNameFieldExist = false;
|
||||||
isOkButtonEnabled = true;
|
isOkButtonEnabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -218,7 +231,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
padding: const EdgeInsets.only(left: 6.0),
|
padding: const EdgeInsets.only(left: 6.0),
|
||||||
child: SvgPicture.asset(
|
child: SvgPicture.asset(
|
||||||
Assets.addIcon,
|
Assets.addIcon,
|
||||||
width: screenWidth * 0.015, // Adjust icon size
|
width: screenWidth *
|
||||||
|
0.015, // Adjust icon size
|
||||||
height: screenWidth * 0.015,
|
height: screenWidth * 0.015,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -226,8 +240,11 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
Flexible(
|
Flexible(
|
||||||
child: Text(
|
child: Text(
|
||||||
'Add devices / Assign a space model',
|
'Add devices / Assign a space model',
|
||||||
overflow: TextOverflow.ellipsis, // Prevent overflow
|
overflow: TextOverflow
|
||||||
style: Theme.of(context).textTheme.bodyMedium,
|
.ellipsis, // Prevent overflow
|
||||||
|
style: Theme.of(context)
|
||||||
|
.textTheme
|
||||||
|
.bodyMedium,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -262,16 +279,20 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? '');
|
String newName = enteredName.isNotEmpty
|
||||||
|
? enteredName
|
||||||
|
: (widget.name ?? '');
|
||||||
if (newName.isNotEmpty) {
|
if (newName.isNotEmpty) {
|
||||||
widget.onCreateSpace(newName, selectedIcon, selectedProducts);
|
widget.onCreateSpace(
|
||||||
|
newName, selectedIcon, selectedProducts);
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
backgroundColor:
|
backgroundColor: isOkButtonEnabled
|
||||||
isOkButtonEnabled ? ColorsManager.secondaryColor : ColorsManager.grayColor,
|
? ColorsManager.secondaryColor
|
||||||
|
: ColorsManager.grayColor,
|
||||||
foregroundColor: ColorsManager.whiteColors,
|
foregroundColor: ColorsManager.whiteColors,
|
||||||
child: const Text('OK'),
|
child: const Text('OK'),
|
||||||
),
|
),
|
||||||
@@ -318,7 +339,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
children: [
|
children: [
|
||||||
for (var i = 0; i < selectedProducts.length; i++) ...[
|
for (var i = 0; i < selectedProducts.length; i++) ...[
|
||||||
HoverableButton(
|
HoverableButton(
|
||||||
iconPath: _mapIconToProduct(selectedProducts[i].productId, products),
|
iconPath:
|
||||||
|
_mapIconToProduct(selectedProducts[i].productId, products),
|
||||||
text: 'x${selectedProducts[i].count}',
|
text: 'x${selectedProducts[i].count}',
|
||||||
onTap: () {
|
onTap: () {
|
||||||
setState(() {
|
setState(() {
|
||||||
@@ -328,7 +350,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
if (i < selectedProducts.length - 1)
|
if (i < selectedProducts.length - 1)
|
||||||
const SizedBox(width: 2), // Add space except after the last button
|
const SizedBox(
|
||||||
|
width: 2), // Add space except after the last button
|
||||||
],
|
],
|
||||||
const SizedBox(width: 2),
|
const SizedBox(width: 2),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
@@ -364,6 +387,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String _mapIconToProduct(String uuid, List<ProductModel> products) {
|
String _mapIconToProduct(String uuid, List<ProductModel> products) {
|
||||||
// Find the product with the matching UUID
|
// Find the product with the matching UUID
|
||||||
final product = products.firstWhere(
|
final product = products.firstWhere(
|
||||||
|
|||||||
@@ -10,8 +10,6 @@ class LoadedSpaceView extends StatefulWidget {
|
|||||||
final List<CommunityModel> communities;
|
final List<CommunityModel> communities;
|
||||||
final CommunityModel? selectedCommunity;
|
final CommunityModel? selectedCommunity;
|
||||||
final SpaceModel? selectedSpace;
|
final SpaceModel? selectedSpace;
|
||||||
final ValueChanged<CommunityModel>? onCommunitySelected;
|
|
||||||
final ValueChanged<SpaceModel?>? onSpaceSelected;
|
|
||||||
final List<ProductModel>? products;
|
final List<ProductModel>? products;
|
||||||
|
|
||||||
const LoadedSpaceView({
|
const LoadedSpaceView({
|
||||||
@@ -19,8 +17,6 @@ class LoadedSpaceView extends StatefulWidget {
|
|||||||
required this.communities,
|
required this.communities,
|
||||||
this.selectedCommunity,
|
this.selectedCommunity,
|
||||||
this.selectedSpace,
|
this.selectedSpace,
|
||||||
required this.onCommunitySelected,
|
|
||||||
required this.onSpaceSelected,
|
|
||||||
this.products,
|
this.products,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -37,28 +33,17 @@ class _LoadedStateViewState extends State<LoadedSpaceView> {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
SidebarWidget(
|
SidebarWidget(
|
||||||
communities: widget.communities,
|
communities: widget.communities,
|
||||||
onCommunitySelected: widget.onCommunitySelected,
|
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
||||||
onSpaceSelected: widget.onSpaceSelected,
|
widget.selectedCommunity?.uuid ??
|
||||||
selectedSpaceUuid: widget.selectedSpace?.uuid,
|
'',
|
||||||
onSelectedSpaceChanged: (String? spaceUuid) {
|
),
|
||||||
setState(() {
|
|
||||||
final selectedSpace = findSpaceByUuid(spaceUuid, widget.communities);
|
|
||||||
if (selectedSpace != null) {
|
|
||||||
widget.onSpaceSelected!(selectedSpace);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}),
|
|
||||||
CommunityStructureArea(
|
CommunityStructureArea(
|
||||||
selectedCommunity: widget.selectedCommunity,
|
selectedCommunity: widget.selectedCommunity,
|
||||||
selectedSpace: widget.selectedSpace,
|
selectedSpace: widget.selectedSpace,
|
||||||
spaces: widget.selectedCommunity?.spaces ?? [],
|
spaces: widget.selectedCommunity?.spaces ?? [],
|
||||||
products: widget.products,
|
products: widget.products,
|
||||||
onSpaceSelected: (SpaceModel? space) {
|
communities: widget.communities,
|
||||||
setState(() {
|
|
||||||
widget.onSpaceSelected!(space);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -7,25 +7,17 @@ import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.
|
|||||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/create_community_dialog.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/widgets/space_tile_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/widgets/space_tile_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
class SidebarWidget extends StatefulWidget {
|
class SidebarWidget extends StatefulWidget {
|
||||||
final Function(CommunityModel)? onCommunitySelected;
|
|
||||||
final Function(SpaceModel?)? onSpaceSelected;
|
|
||||||
final List<CommunityModel> communities;
|
final List<CommunityModel> communities;
|
||||||
final Function(String?)? onSelectedSpaceChanged; // New callback
|
|
||||||
|
|
||||||
final String? selectedSpaceUuid;
|
final String? selectedSpaceUuid;
|
||||||
|
|
||||||
const SidebarWidget({
|
const SidebarWidget({
|
||||||
super.key,
|
super.key,
|
||||||
this.onCommunitySelected,
|
|
||||||
this.onSpaceSelected,
|
|
||||||
this.onSelectedSpaceChanged,
|
|
||||||
required this.communities,
|
required this.communities,
|
||||||
this.selectedSpaceUuid,
|
this.selectedSpaceUuid,
|
||||||
});
|
});
|
||||||
@@ -42,7 +34,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_selectedId = widget.selectedSpaceUuid; // Initialize with the passed selected space UUID
|
_selectedId = widget
|
||||||
|
.selectedSpaceUuid; // Initialize with the passed selected space UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -55,22 +48,6 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showCreateCommunityDialog(BuildContext parentContext) {
|
|
||||||
showDialog(
|
|
||||||
context: parentContext,
|
|
||||||
builder: (context) => CreateCommunityDialog(
|
|
||||||
onCreateCommunity: (String communityName, String description) {
|
|
||||||
parentContext.read<SpaceManagementBloc>().add(
|
|
||||||
CreateCommunityEvent(
|
|
||||||
name: communityName,
|
|
||||||
description: description,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to filter communities based on the search query
|
// Function to filter communities based on the search query
|
||||||
List<CommunityModel> _filterCommunities() {
|
List<CommunityModel> _filterCommunities() {
|
||||||
if (_searchQuery.isEmpty) {
|
if (_searchQuery.isEmpty) {
|
||||||
@@ -83,8 +60,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
return widget.communities.where((community) {
|
return widget.communities.where((community) {
|
||||||
final containsQueryInCommunity =
|
final containsQueryInCommunity =
|
||||||
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
community.name.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||||
final containsQueryInSpaces =
|
final containsQueryInSpaces = community.spaces
|
||||||
community.spaces.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
.any((space) => _containsQuery(space, _searchQuery.toLowerCase()));
|
||||||
|
|
||||||
return containsQueryInCommunity || containsQueryInSpaces;
|
return containsQueryInCommunity || containsQueryInSpaces;
|
||||||
}).toList();
|
}).toList();
|
||||||
@@ -93,8 +70,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
// Helper function to determine if any space or its children match the search query
|
// Helper function to determine if any space or its children match the search query
|
||||||
bool _containsQuery(SpaceModel space, String query) {
|
bool _containsQuery(SpaceModel space, String query) {
|
||||||
final matchesSpace = space.name.toLowerCase().contains(query);
|
final matchesSpace = space.name.toLowerCase().contains(query);
|
||||||
final matchesChildren =
|
final matchesChildren = space.children.any((child) =>
|
||||||
space.children.any((child) => _containsQuery(child, query)); // Recursive check for children
|
_containsQuery(child, query)); // Recursive check for children
|
||||||
|
|
||||||
// If the space or any of its children match the query, expand this space
|
// If the space or any of its children match the query, expand this space
|
||||||
if (matchesSpace || matchesChildren) {
|
if (matchesSpace || matchesChildren) {
|
||||||
@@ -128,7 +105,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
width: 300,
|
width: 300,
|
||||||
decoration: subSectionContainerDecoration,
|
decoration: subSectionContainerDecoration,
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min, // Ensures the Column only takes necessary height
|
mainAxisSize:
|
||||||
|
MainAxisSize.min, // Ensures the Column only takes necessary height
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// Communities title with the add button
|
// Communities title with the add button
|
||||||
@@ -143,7 +121,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
)),
|
)),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => _showCreateCommunityDialog(context),
|
onTap: () => _navigateToBlank(context),
|
||||||
child: Container(
|
child: Container(
|
||||||
width: 30,
|
width: 30,
|
||||||
height: 30,
|
height: 30,
|
||||||
@@ -176,7 +154,7 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: ListView(
|
child: ListView(
|
||||||
children: filteredCommunities.map((community) {
|
children: filteredCommunities.map((community) {
|
||||||
return _buildCommunityTile(community);
|
return _buildCommunityTile(context, community);
|
||||||
}).toList(),
|
}).toList(),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -185,7 +163,16 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildCommunityTile(CommunityModel community) {
|
void _navigateToBlank(BuildContext context) {
|
||||||
|
setState(() {
|
||||||
|
_selectedId = '';
|
||||||
|
});
|
||||||
|
context.read<SpaceManagementBloc>().add(
|
||||||
|
NewCommunityEvent(communities: widget.communities),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCommunityTile(BuildContext context, CommunityModel community) {
|
||||||
bool hasChildren = community.spaces.isNotEmpty;
|
bool hasChildren = community.spaces.isNotEmpty;
|
||||||
|
|
||||||
return CommunityTile(
|
return CommunityTile(
|
||||||
@@ -199,23 +186,23 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
_selectedSpaceUuid = null; // Update the selected community
|
_selectedSpaceUuid = null; // Update the selected community
|
||||||
});
|
});
|
||||||
|
|
||||||
if (widget.onCommunitySelected != null) {
|
context.read<SpaceManagementBloc>().add(
|
||||||
widget.onCommunitySelected!(community);
|
SelectCommunityEvent(selectedCommunity: community),
|
||||||
widget.onSpaceSelected!(null); // Pass the entire community
|
);
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onExpansionChanged: (String title, bool expanded) {
|
onExpansionChanged: (String title, bool expanded) {
|
||||||
_handleExpansionChange(community.uuid, expanded);
|
_handleExpansionChange(community.uuid, expanded);
|
||||||
},
|
},
|
||||||
children: hasChildren
|
children: hasChildren
|
||||||
? community.spaces.map((space) => _buildSpaceTile(space, community)).toList()
|
? community.spaces
|
||||||
|
.map((space) => _buildSpaceTile(space, community))
|
||||||
|
.toList()
|
||||||
: null, // Render spaces within the community
|
: null, // Render spaces within the community
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildSpaceTile(SpaceModel space, CommunityModel community) {
|
Widget _buildSpaceTile(SpaceModel space, CommunityModel community) {
|
||||||
bool isExpandedSpace = _isSpaceOrChildSelected(space);
|
bool isExpandedSpace = _isSpaceOrChildSelected(space);
|
||||||
// Check if space should be expanded
|
|
||||||
return SpaceTile(
|
return SpaceTile(
|
||||||
title: space.name,
|
title: space.name,
|
||||||
key: ValueKey(space.uuid),
|
key: ValueKey(space.uuid),
|
||||||
@@ -230,17 +217,15 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
_selectedSpaceUuid = space.uuid;
|
_selectedSpaceUuid = space.uuid;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (widget.onSpaceSelected != null) {
|
context.read<SpaceManagementBloc>().add(
|
||||||
widget.onCommunitySelected!(community);
|
SelectSpaceEvent(
|
||||||
widget.onSpaceSelected!(space);
|
selectedCommunity: community, selectedSpace: space),
|
||||||
}
|
);
|
||||||
|
|
||||||
if (widget.onSelectedSpaceChanged != null) {
|
|
||||||
widget.onSelectedSpaceChanged!(space.uuid);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
children: space.children.isNotEmpty
|
children: space.children.isNotEmpty
|
||||||
? space.children.map((childSpace) => _buildSpaceTile(childSpace, community)).toList()
|
? space.children
|
||||||
|
.map((childSpace) => _buildSpaceTile(childSpace, community))
|
||||||
|
.toList()
|
||||||
: [], // Recursively render child spaces if available
|
: [], // Recursively render child spaces if available
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ class SceneApi {
|
|||||||
static Future<Map<String, dynamic>> createAutomation(
|
static Future<Map<String, dynamic>> createAutomation(
|
||||||
CreateAutomationModel createAutomationModel) async {
|
CreateAutomationModel createAutomationModel) async {
|
||||||
try {
|
try {
|
||||||
debugPrint("automation body ${createAutomationModel.toMap()}");
|
|
||||||
final response = await _httpService.post(
|
final response = await _httpService.post(
|
||||||
path: ApiEndpoints.createAutomation,
|
path: ApiEndpoints.createAutomation,
|
||||||
body: createAutomationModel.toMap(),
|
body: createAutomationModel.toMap(),
|
||||||
@@ -138,29 +137,49 @@ class SceneApi {
|
|||||||
path: ApiEndpoints.getAutomationDetails
|
path: ApiEndpoints.getAutomationDetails
|
||||||
.replaceAll('{automationId}', automationId),
|
.replaceAll('{automationId}', automationId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) => RoutineDetailsModel.fromJson(json),
|
expectedResponseModel: (json) => RoutineDetailsModel.fromMap(json),
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update Scene
|
||||||
|
static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.put(
|
||||||
|
path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
|
||||||
|
body: createSceneModel
|
||||||
|
.toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
return json;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//update automation
|
||||||
|
static updateAutomation(
|
||||||
|
CreateAutomationModel createAutomationModel, String automationId) async {
|
||||||
|
try {
|
||||||
|
final response = await _httpService.put(
|
||||||
|
path: ApiEndpoints.updateAutomation
|
||||||
|
.replaceAll('{automationId}', automationId),
|
||||||
|
body: createAutomationModel
|
||||||
|
.toJson(automationId.isNotEmpty == true ? automationId : null),
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
return json;
|
||||||
|
},
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// //updateAutomationStatus
|
|
||||||
// static Future<bool> updateAutomationStatus(String automationId,
|
|
||||||
// AutomationStatusUpdate createAutomationEnable) async {
|
|
||||||
// try {
|
|
||||||
// final response = await _httpService.put(
|
|
||||||
// path: ApiEndpoints.updateAutomationStatus
|
|
||||||
// .replaceAll('{automationId}', automationId),
|
|
||||||
// body: createAutomationEnable.toMap(),
|
|
||||||
// expectedResponseModel: (json) => json['success'],
|
|
||||||
// );
|
|
||||||
// return response;
|
|
||||||
// } catch (e) {
|
|
||||||
// rethrow;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
//getScene
|
//getScene
|
||||||
static Future<RoutineDetailsModel> getSceneDetails(String sceneId) async {
|
static Future<RoutineDetailsModel> getSceneDetails(String sceneId) async {
|
||||||
@@ -168,52 +187,15 @@ class SceneApi {
|
|||||||
final response = await _httpService.get(
|
final response = await _httpService.get(
|
||||||
path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
|
path: ApiEndpoints.getScene.replaceAll('{sceneId}', sceneId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) => RoutineDetailsModel.fromJson(json),
|
expectedResponseModel: (json) =>
|
||||||
|
RoutineDetailsModel.fromMap(json['data']),
|
||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//
|
|
||||||
// //update Scene
|
|
||||||
// static updateScene(CreateSceneModel createSceneModel, String sceneId) async {
|
|
||||||
// try {
|
|
||||||
// final response = await _httpService.put(
|
|
||||||
// path: ApiEndpoints.updateScene.replaceAll('{sceneId}', sceneId),
|
|
||||||
// body: createSceneModel
|
|
||||||
// .toJson(sceneId.isNotEmpty == true ? sceneId : null),
|
|
||||||
// expectedResponseModel: (json) {
|
|
||||||
// return json;
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// return response;
|
|
||||||
// } catch (e) {
|
|
||||||
// rethrow;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //update automation
|
|
||||||
// static updateAutomation(
|
|
||||||
// CreateAutomationModel createAutomationModel, String automationId) async {
|
|
||||||
// try {
|
|
||||||
// final response = await _httpService.put(
|
|
||||||
// path: ApiEndpoints.updateAutomation
|
|
||||||
// .replaceAll('{automationId}', automationId),
|
|
||||||
// body: createAutomationModel
|
|
||||||
// .toJson(automationId.isNotEmpty == true ? automationId : null),
|
|
||||||
// expectedResponseModel: (json) {
|
|
||||||
// return json;
|
|
||||||
// },
|
|
||||||
// );
|
|
||||||
// return response;
|
|
||||||
// } catch (e) {
|
|
||||||
// rethrow;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
//delete Scene
|
//delete Scene
|
||||||
static Future<bool> deleteScene(
|
static Future<bool> deleteScene(
|
||||||
{required String unitUuid, required String sceneId}) async {
|
{required String unitUuid, required String sceneId}) async {
|
||||||
@@ -230,7 +212,7 @@ class SceneApi {
|
|||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete automation
|
// delete automation
|
||||||
static Future<bool> deleteAutomation(
|
static Future<bool> deleteAutomation(
|
||||||
{required String unitUuid, required String automationId}) async {
|
{required String unitUuid, required String automationId}) async {
|
||||||
|
|||||||
@@ -8,22 +8,31 @@ import 'package:syncrow_web/utils/constants/api_const.dart';
|
|||||||
|
|
||||||
class CommunitySpaceManagementApi {
|
class CommunitySpaceManagementApi {
|
||||||
// Community Management APIs
|
// Community Management APIs
|
||||||
Future<List<CommunityModel>> fetchCommunities() async {
|
Future<List<CommunityModel>> fetchCommunities({int page = 1}) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
List<CommunityModel> allCommunities = [];
|
||||||
path: ApiEndpoints.getCommunityList,
|
bool hasNext = true;
|
||||||
expectedResponseModel: (json) {
|
|
||||||
// Access the 'data' key from the response
|
|
||||||
List<dynamic> jsonData = json['data'];
|
|
||||||
|
|
||||||
// Check if jsonData is actually a List
|
while (hasNext) {
|
||||||
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
await HTTPService().get(
|
||||||
return CommunityModel.fromJson(jsonItem);
|
path: ApiEndpoints.getCommunityList,
|
||||||
}).toList();
|
queryParameters: {'page': page},
|
||||||
return communityList;
|
expectedResponseModel: (json) {
|
||||||
},
|
List<dynamic> jsonData = json['data'];
|
||||||
);
|
hasNext = json['hasNext'] ?? false;
|
||||||
return response;
|
int currentPage = json['page'] ?? 1;
|
||||||
|
List<CommunityModel> communityList = jsonData.map((jsonItem) {
|
||||||
|
return CommunityModel.fromJson(jsonItem);
|
||||||
|
}).toList();
|
||||||
|
|
||||||
|
allCommunities.addAll(communityList);
|
||||||
|
page = currentPage + 1;
|
||||||
|
return communityList;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allCommunities;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Error fetching communities: $e');
|
debugPrint('Error fetching communities: $e');
|
||||||
return [];
|
return [];
|
||||||
@@ -33,7 +42,8 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<CommunityModel?> getCommunityById(String communityId) async {
|
Future<CommunityModel?> getCommunityById(String communityId) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getCommunityById.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.getCommunityById
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return CommunityModel.fromJson(json['data']);
|
return CommunityModel.fromJson(json['data']);
|
||||||
},
|
},
|
||||||
@@ -45,7 +55,8 @@ class CommunitySpaceManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<CommunityModel?> createCommunity(String name, String description) async {
|
Future<CommunityModel?> createCommunity(
|
||||||
|
String name, String description) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().post(
|
final response = await HTTPService().post(
|
||||||
path: ApiEndpoints.createCommunity,
|
path: ApiEndpoints.createCommunity,
|
||||||
@@ -67,7 +78,8 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<bool> updateCommunity(String communityId, String name) async {
|
Future<bool> updateCommunity(String communityId, String name) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().put(
|
final response = await HTTPService().put(
|
||||||
path: ApiEndpoints.updateCommunity.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.updateCommunity
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
body: {
|
body: {
|
||||||
'name': name,
|
'name': name,
|
||||||
},
|
},
|
||||||
@@ -85,7 +97,8 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<bool> deleteCommunity(String communityId) async {
|
Future<bool> deleteCommunity(String communityId) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().delete(
|
final response = await HTTPService().delete(
|
||||||
path: ApiEndpoints.deleteCommunity.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.deleteCommunity
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json['success'] ?? false;
|
return json['success'] ?? false;
|
||||||
},
|
},
|
||||||
@@ -236,10 +249,12 @@ class CommunitySpaceManagementApi {
|
|||||||
Future<List<SpaceModel>> getSpaceHierarchy(String communityId) async {
|
Future<List<SpaceModel>> getSpaceHierarchy(String communityId) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getSpaceHierarchy.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.getSpaceHierarchy
|
||||||
|
.replaceAll('{communityId}', communityId),
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
final spaceModels =
|
final spaceModels = (json['data'] as List)
|
||||||
(json['data'] as List).map((spaceJson) => SpaceModel.fromJson(spaceJson)).toList();
|
.map((spaceJson) => SpaceModel.fromJson(spaceJson))
|
||||||
|
.toList();
|
||||||
|
|
||||||
return spaceModels;
|
return spaceModels;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -74,4 +74,7 @@ abstract class ApiEndpoints {
|
|||||||
static const String deleteScene = '/scene/tap-to-run/{sceneId}';
|
static const String deleteScene = '/scene/tap-to-run/{sceneId}';
|
||||||
|
|
||||||
static const String deleteAutomation = '/automation/{automationId}';
|
static const String deleteAutomation = '/automation/{automationId}';
|
||||||
|
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
||||||
|
|
||||||
|
static const String updateAutomation = '/automation/{automationId}';
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user