mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
create routine dialog flow
This commit is contained in:
@ -8,6 +8,7 @@ import 'package:syncrow_web/firebase_options_prod.dart';
|
|||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
@ -54,7 +55,9 @@ class MyApp extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
BlocProvider<CreateRoutineBloc>(
|
||||||
|
create: (context) => CreateRoutineBloc(),
|
||||||
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
|
@ -8,6 +8,7 @@ import 'package:syncrow_web/firebase_options_dev.dart';
|
|||||||
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
import 'package:syncrow_web/pages/home/bloc/home_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
@ -55,7 +56,9 @@ class MyApp extends StatelessWidget {
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
BlocProvider<CreateRoutineBloc>(
|
||||||
|
create: (context) => CreateRoutineBloc(),
|
||||||
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
create: (context) => HomeBloc()..add(const FetchUserInfo())),
|
||||||
BlocProvider<VisitorPasswordBloc>(
|
BlocProvider<VisitorPasswordBloc>(
|
||||||
|
@ -43,8 +43,7 @@ class DeviceManagementBloc
|
|||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||||
devices = await DevicesManagementApi()
|
devices = await DevicesManagementApi().fetchDevices('', '', projectUuid);
|
||||||
.fetchDevices('', '', projectUuid );
|
|
||||||
} else {
|
} else {
|
||||||
for (var community in spaceBloc.state.selectedCommunities) {
|
for (var community in spaceBloc.state.selectedCommunities) {
|
||||||
List<String> spacesList =
|
List<String> spacesList =
|
||||||
|
@ -3,6 +3,8 @@ 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/bloc/device_mgmt_bloc/device_managment_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_managment_body.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_managment_body.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/routines_view.dart';
|
import 'package:syncrow_web/pages/routines/view/routines_view.dart';
|
||||||
@ -23,6 +25,9 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
create: (context) =>
|
create: (context) =>
|
||||||
DeviceManagementBloc()..add(FetchDevices(context)),
|
DeviceManagementBloc()..add(FetchDevices(context)),
|
||||||
),
|
),
|
||||||
|
BlocProvider<CreateRoutineBloc>(
|
||||||
|
create: (context) => CreateRoutineBloc(),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
child: WebScaffold(
|
child: WebScaffold(
|
||||||
appBarTitle: Text(
|
appBarTitle: Text(
|
||||||
@ -39,10 +44,15 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
backgroundColor: null,
|
backgroundColor: null,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
BlocProvider.of<CreateRoutineBloc>(context)
|
||||||
|
.add(const ResetSelectedEvent());
|
||||||
|
|
||||||
context
|
context
|
||||||
.read<RoutineBloc>()
|
.read<RoutineBloc>()
|
||||||
.add(const TriggerSwitchTabsEvent(isRoutineTab: false));
|
.add(const TriggerSwitchTabsEvent(isRoutineTab: false));
|
||||||
context.read<DeviceManagementBloc>().add(FetchDevices(context));
|
context
|
||||||
|
.read<DeviceManagementBloc>()
|
||||||
|
.add(FetchDevices(context));
|
||||||
},
|
},
|
||||||
child: Text(
|
child: Text(
|
||||||
'Devices',
|
'Devices',
|
||||||
@ -60,6 +70,9 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
backgroundColor: null,
|
backgroundColor: null,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
BlocProvider.of<CreateRoutineBloc>(context)
|
||||||
|
.add(const ResetSelectedEvent());
|
||||||
|
|
||||||
context
|
context
|
||||||
.read<RoutineBloc>()
|
.read<RoutineBloc>()
|
||||||
.add(const TriggerSwitchTabsEvent(isRoutineTab: true));
|
.add(const TriggerSwitchTabsEvent(isRoutineTab: true));
|
||||||
|
@ -0,0 +1,51 @@
|
|||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_state.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||||
|
|
||||||
|
class CreateRoutineBloc extends Bloc<CreateRoutineEvent, CreateRoutineState> {
|
||||||
|
CreateRoutineBloc() : super(const CreateRoutineInitial()) {
|
||||||
|
on<SpaceOnlyWithDevicesEvent>(_fetchSpaceOnlyWithDevices);
|
||||||
|
on<SaveCommunityIdAndSpaceIdEvent>(saveSpaceIdCommunityId);
|
||||||
|
on<ResetSelectedEvent>(resetSelected);
|
||||||
|
}
|
||||||
|
|
||||||
|
String selectedSpaceId = '';
|
||||||
|
String selectedCommunityId = '';
|
||||||
|
|
||||||
|
List<SpaceModel> spacesOnlyWithDevices = [];
|
||||||
|
|
||||||
|
Future<void> _fetchSpaceOnlyWithDevices(
|
||||||
|
SpaceOnlyWithDevicesEvent event, Emitter<CreateRoutineState> emit) async {
|
||||||
|
emit(const SpaceWithDeviceLoadingState());
|
||||||
|
|
||||||
|
try {
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
|
spacesOnlyWithDevices = await CommunitySpaceManagementApi()
|
||||||
|
.getSpaceOnlyWithDevices(
|
||||||
|
communityId: event.communityID, projectId: projectUuid);
|
||||||
|
|
||||||
|
emit(SpaceWithDeviceLoadedState(spacesOnlyWithDevices));
|
||||||
|
} catch (e) {
|
||||||
|
emit(SpaceTreeErrorState('Error loading communities and spaces: $e'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
saveSpaceIdCommunityId(
|
||||||
|
SaveCommunityIdAndSpaceIdEvent event, Emitter<CreateRoutineState> emit) {
|
||||||
|
emit(const SpaceWithDeviceLoadingState());
|
||||||
|
selectedSpaceId = event.spaceID!;
|
||||||
|
selectedCommunityId = event.communityID!;
|
||||||
|
emit(const SelectedState());
|
||||||
|
}
|
||||||
|
|
||||||
|
resetSelected(ResetSelectedEvent event, Emitter<CreateRoutineState> emit) {
|
||||||
|
emit(const SpaceWithDeviceLoadingState());
|
||||||
|
selectedSpaceId = '';
|
||||||
|
selectedCommunityId = '';
|
||||||
|
emit(const ResetSelectedState());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
|
|
||||||
|
abstract class CreateRoutineEvent extends Equatable {
|
||||||
|
const CreateRoutineEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddToIfContainer extends CreateRoutineEvent {
|
||||||
|
final SpaceModel spaceModel;
|
||||||
|
|
||||||
|
const AddToIfContainer(this.spaceModel);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [spaceModel];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpaceOnlyWithDevicesEvent extends CreateRoutineEvent {
|
||||||
|
final String communityID;
|
||||||
|
const SpaceOnlyWithDevicesEvent(this.communityID);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [communityID];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SaveCommunityIdAndSpaceIdEvent extends CreateRoutineEvent {
|
||||||
|
final String? communityID;
|
||||||
|
final String? spaceID;
|
||||||
|
|
||||||
|
const SaveCommunityIdAndSpaceIdEvent({this.communityID, this.spaceID});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [communityID!, spaceID!];
|
||||||
|
}
|
||||||
|
|
||||||
|
class ResetSelectedEvent extends CreateRoutineEvent {
|
||||||
|
const ResetSelectedEvent();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [];
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
|
||||||
|
import 'package:equatable/equatable.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
|
|
||||||
|
abstract class CreateRoutineState extends Equatable {
|
||||||
|
const CreateRoutineState();
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [];
|
||||||
|
}
|
||||||
|
|
||||||
|
class CreateRoutineInitial extends CreateRoutineState {
|
||||||
|
const CreateRoutineInitial();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpaceWithDeviceLoadingState extends CreateRoutineState {
|
||||||
|
const SpaceWithDeviceLoadingState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpaceWithDeviceLoadedState extends CreateRoutineState {
|
||||||
|
final List<SpaceModel> spaces;
|
||||||
|
|
||||||
|
const SpaceWithDeviceLoadedState(this.spaces);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [spaces];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SpaceTreeErrorState extends CreateRoutineState {
|
||||||
|
final String errorMessage;
|
||||||
|
|
||||||
|
const SpaceTreeErrorState(this.errorMessage);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [errorMessage];
|
||||||
|
}
|
||||||
|
|
||||||
|
class SelectedState extends CreateRoutineState {
|
||||||
|
const SelectedState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class ResetSelectedState extends CreateRoutineState {
|
||||||
|
const ResetSelectedState();
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,14 @@
|
|||||||
|
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
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/common/bloc/project_manager.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_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/routines/bloc/automation_scene_trigger_bloc/automation_status_update.dart';
|
import 'package:syncrow_web/pages/routines/bloc/automation_scene_trigger_bloc/automation_status_update.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart';
|
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart';
|
import 'package:syncrow_web/pages/routines/models/create_scene_and_autoamtion/create_scene_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/delay/delay_fucntions.dart';
|
import 'package:syncrow_web/pages/routines/models/delay/delay_fucntions.dart';
|
||||||
@ -13,9 +16,14 @@ import 'package:syncrow_web/pages/routines/models/device_functions.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/models/routine_details_model.dart';
|
import 'package:syncrow_web/pages/routines/models/routine_details_model.dart';
|
||||||
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
|
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
import 'package:syncrow_web/services/devices_mang_api.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/services/space_mana_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/strings_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
|
||||||
import 'package:syncrow_web/utils/navigation_service.dart';
|
import 'package:syncrow_web/utils/navigation_service.dart';
|
||||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||||
import 'package:uuid/uuid.dart';
|
import 'package:uuid/uuid.dart';
|
||||||
@ -52,15 +60,18 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
on<TriggerSwitchTabsEvent>(_triggerSwitchTabsEvent);
|
on<TriggerSwitchTabsEvent>(_triggerSwitchTabsEvent);
|
||||||
on<CreateNewRoutineViewEvent>(_createNewRoutineViewEvent);
|
on<CreateNewRoutineViewEvent>(_createNewRoutineViewEvent);
|
||||||
on<ResetErrorMessage>(_resetErrorMessage);
|
on<ResetErrorMessage>(_resetErrorMessage);
|
||||||
on<SceneTrigger>(_onSceneTrigger);
|
on<SceneTrigger>(_onSceneTrigger);
|
||||||
on<UpdateAutomationStatus>(_onUpdateAutomationStatus);
|
on<UpdateAutomationStatus>(_onUpdateAutomationStatus);
|
||||||
}
|
}
|
||||||
|
String selectedSpaceId = '';
|
||||||
|
String selectedCommunityId = '';
|
||||||
|
|
||||||
FutureOr<void> _triggerSwitchTabsEvent(
|
FutureOr<void> _triggerSwitchTabsEvent(
|
||||||
TriggerSwitchTabsEvent event,
|
TriggerSwitchTabsEvent event,
|
||||||
Emitter<RoutineState> emit,
|
Emitter<RoutineState> emit,
|
||||||
) {
|
) {
|
||||||
emit(state.copyWith(routineTab: event.isRoutineTab, createRoutineView: false));
|
emit(state.copyWith(
|
||||||
|
routineTab: event.isRoutineTab, createRoutineView: false));
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
if (event.isRoutineTab) {
|
if (event.isRoutineTab) {
|
||||||
add(const LoadScenes());
|
add(const LoadScenes());
|
||||||
@ -86,8 +97,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems);
|
final updatedIfItems = List<Map<String, dynamic>>.from(state.ifItems);
|
||||||
|
|
||||||
// Find the index of the item in teh current itemsList
|
// Find the index of the item in teh current itemsList
|
||||||
int index =
|
int index = updatedIfItems.indexWhere(
|
||||||
updatedIfItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
(map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
||||||
// Replace the map if the index is valid
|
// Replace the map if the index is valid
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
updatedIfItems[index] = event.item;
|
updatedIfItems[index] = event.item;
|
||||||
@ -96,18 +107,21 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (event.isTabToRun) {
|
if (event.isTabToRun) {
|
||||||
emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: true, isAutomation: false));
|
emit(state.copyWith(
|
||||||
|
ifItems: updatedIfItems, isTabToRun: true, isAutomation: false));
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(ifItems: updatedIfItems, isTabToRun: false, isAutomation: true));
|
emit(state.copyWith(
|
||||||
|
ifItems: updatedIfItems, isTabToRun: false, isAutomation: true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAddToThenContainer(AddToThenContainer event, Emitter<RoutineState> emit) {
|
void _onAddToThenContainer(
|
||||||
|
AddToThenContainer event, Emitter<RoutineState> emit) {
|
||||||
final currentItems = List<Map<String, dynamic>>.from(state.thenItems);
|
final currentItems = List<Map<String, dynamic>>.from(state.thenItems);
|
||||||
|
|
||||||
// Find the index of the item in teh current itemsList
|
// Find the index of the item in teh current itemsList
|
||||||
int index =
|
int index = currentItems.indexWhere(
|
||||||
currentItems.indexWhere((map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
(map) => map['uniqueCustomId'] == event.item['uniqueCustomId']);
|
||||||
// Replace the map if the index is valid
|
// Replace the map if the index is valid
|
||||||
if (index != -1) {
|
if (index != -1) {
|
||||||
currentItems[index] = event.item;
|
currentItems[index] = event.item;
|
||||||
@ -118,22 +132,26 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
emit(state.copyWith(thenItems: currentItems));
|
emit(state.copyWith(thenItems: currentItems));
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAddFunctionsToRoutine(AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
void _onAddFunctionsToRoutine(
|
||||||
|
AddFunctionToRoutine event, Emitter<RoutineState> emit) {
|
||||||
try {
|
try {
|
||||||
if (event.functions.isEmpty) return;
|
if (event.functions.isEmpty) return;
|
||||||
|
|
||||||
List<DeviceFunctionData> selectedFunction = List<DeviceFunctionData>.from(event.functions);
|
List<DeviceFunctionData> selectedFunction =
|
||||||
|
List<DeviceFunctionData>.from(event.functions);
|
||||||
|
|
||||||
Map<String, List<DeviceFunctionData>> currentSelectedFunctions =
|
Map<String, List<DeviceFunctionData>> currentSelectedFunctions =
|
||||||
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||||
if (currentSelectedFunctions.containsKey(event.uniqueCustomId)) {
|
if (currentSelectedFunctions.containsKey(event.uniqueCustomId)) {
|
||||||
List<DeviceFunctionData> currentFunctions =
|
List<DeviceFunctionData> currentFunctions =
|
||||||
List<DeviceFunctionData>.from(currentSelectedFunctions[event.uniqueCustomId] ?? []);
|
List<DeviceFunctionData>.from(
|
||||||
|
currentSelectedFunctions[event.uniqueCustomId] ?? []);
|
||||||
|
|
||||||
List<String> functionCode = [];
|
List<String> functionCode = [];
|
||||||
for (int i = 0; i < selectedFunction.length; i++) {
|
for (int i = 0; i < selectedFunction.length; i++) {
|
||||||
for (int j = 0; j < currentFunctions.length; j++) {
|
for (int j = 0; j < currentFunctions.length; j++) {
|
||||||
if (selectedFunction[i].functionCode == currentFunctions[j].functionCode) {
|
if (selectedFunction[i].functionCode ==
|
||||||
|
currentFunctions[j].functionCode) {
|
||||||
currentFunctions[j] = selectedFunction[i];
|
currentFunctions[j] = selectedFunction[i];
|
||||||
if (!functionCode.contains(currentFunctions[j].functionCode)) {
|
if (!functionCode.contains(currentFunctions[j].functionCode)) {
|
||||||
functionCode.add(currentFunctions[j].functionCode);
|
functionCode.add(currentFunctions[j].functionCode);
|
||||||
@ -143,13 +161,15 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < functionCode.length; i++) {
|
for (int i = 0; i < functionCode.length; i++) {
|
||||||
selectedFunction.removeWhere((code) => code.functionCode == functionCode[i]);
|
selectedFunction
|
||||||
|
.removeWhere((code) => code.functionCode == functionCode[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentSelectedFunctions[event.uniqueCustomId] = List.from(currentFunctions)
|
currentSelectedFunctions[event.uniqueCustomId] =
|
||||||
..addAll(selectedFunction);
|
List.from(currentFunctions)..addAll(selectedFunction);
|
||||||
} else {
|
} else {
|
||||||
currentSelectedFunctions[event.uniqueCustomId] = List.from(event.functions);
|
currentSelectedFunctions[event.uniqueCustomId] =
|
||||||
|
List.from(event.functions);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(state.copyWith(selectedFunctions: currentSelectedFunctions));
|
emit(state.copyWith(selectedFunctions: currentSelectedFunctions));
|
||||||
@ -158,19 +178,30 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadScenes(LoadScenes event, Emitter<RoutineState> emit) async {
|
Future<void> _onLoadScenes(
|
||||||
|
LoadScenes event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
|
||||||
|
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
||||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
if (createRoutineBloc.selectedSpaceId == '' &&
|
||||||
for (var spaceId in spacesList) {
|
createRoutineBloc.selectedCommunityId == '') {
|
||||||
scenes.addAll(await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
|
List<String> spacesList =
|
||||||
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
|
for (var spaceId in spacesList) {
|
||||||
|
scenes.addAll(
|
||||||
|
await SceneApi.getScenes(spaceId, communityId, projectUuid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
scenes.addAll(await SceneApi.getScenes(
|
||||||
|
createRoutineBloc.selectedSpaceId,
|
||||||
|
createRoutineBloc.selectedCommunityId,
|
||||||
|
projectUuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
@ -187,19 +218,31 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onLoadAutomation(LoadAutomation event, Emitter<RoutineState> emit) async {
|
Future<void> _onLoadAutomation(
|
||||||
|
LoadAutomation event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
List<ScenesModel> automations = [];
|
List<ScenesModel> automations = [];
|
||||||
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
||||||
try {
|
try {
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
if (createRoutineBloc.selectedSpaceId == '' &&
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
createRoutineBloc.selectedCommunityId == '') {
|
||||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
for (var spaceId in spacesList) {
|
List<String> spacesList =
|
||||||
automations.addAll(await SceneApi.getAutomation(spaceId, communityId, projectId));
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
|
for (var spaceId in spacesList) {
|
||||||
|
automations.addAll(
|
||||||
|
await SceneApi.getAutomation(spaceId, communityId, projectId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
automations.addAll(await SceneApi.getAutomation(
|
||||||
|
createRoutineBloc.selectedSpaceId,
|
||||||
|
createRoutineBloc.selectedCommunityId,
|
||||||
|
projectId));
|
||||||
}
|
}
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
automations: automations,
|
automations: automations,
|
||||||
@ -215,14 +258,16 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onSearchRoutines(SearchRoutines event, Emitter<RoutineState> emit) async {
|
FutureOr<void> _onSearchRoutines(
|
||||||
|
SearchRoutines event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true, errorMessage: null));
|
emit(state.copyWith(isLoading: true, errorMessage: null));
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
emit(state.copyWith(isLoading: false, errorMessage: null));
|
emit(state.copyWith(isLoading: false, errorMessage: null));
|
||||||
emit(state.copyWith(searchText: event.query));
|
emit(state.copyWith(searchText: event.query));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onAddSelectedIcon(AddSelectedIcon event, Emitter<RoutineState> emit) {
|
FutureOr<void> _onAddSelectedIcon(
|
||||||
|
AddSelectedIcon event, Emitter<RoutineState> emit) {
|
||||||
emit(state.copyWith(selectedIcon: event.icon));
|
emit(state.copyWith(selectedIcon: event.icon));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,7 +281,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
return actions.last['deviceId'] == 'delay';
|
return actions.last['deviceId'] == 'delay';
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onCreateScene(CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
Future<void> _onCreateScene(
|
||||||
|
CreateSceneEvent event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
// Check if first action is delay
|
// Check if first action is delay
|
||||||
// if (_isFirstActionDelay(state.thenItems)) {
|
// if (_isFirstActionDelay(state.thenItems)) {
|
||||||
@ -249,7 +295,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
if (_isLastActionDelay(state.thenItems)) {
|
if (_isLastActionDelay(state.thenItems)) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
errorMessage: 'A delay condition cannot be the only or the last action',
|
errorMessage:
|
||||||
|
'A delay condition cannot be the only or the last action',
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
@ -295,10 +342,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
var spaceBloc = context.read<CreateRoutineBloc>();
|
||||||
|
|
||||||
final createSceneModel = CreateSceneModel(
|
final createSceneModel = CreateSceneModel(
|
||||||
spaceUuid: spaceBloc.state.selectedSpaces[0],
|
spaceUuid: spaceBloc.selectedSpaceId,
|
||||||
iconId: state.selectedIcon ?? '',
|
iconId: state.selectedIcon ?? '',
|
||||||
showInDevice: true,
|
showInDevice: true,
|
||||||
sceneName: state.routineName ?? '',
|
sceneName: state.routineName ?? '',
|
||||||
@ -325,10 +372,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onCreateAutomation(CreateAutomationEvent event, Emitter<RoutineState> emit) async {
|
Future<void> _onCreateAutomation(
|
||||||
|
CreateAutomationEvent event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
if (state.routineName == null || state.routineName!.isEmpty) {
|
if (state.routineName == null || state.routineName!.isEmpty) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
errorMessage: 'Automation name is required',
|
errorMessage: 'Automation name is required',
|
||||||
@ -348,7 +395,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
if (_isLastActionDelay(state.thenItems)) {
|
if (_isLastActionDelay(state.thenItems)) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
errorMessage: 'A delay condition cannot be the only or the last action',
|
errorMessage:
|
||||||
|
'A delay condition cannot be the only or the last action',
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
));
|
));
|
||||||
CustomSnackBar.redSnackBar('Cannot have delay as the last action');
|
CustomSnackBar.redSnackBar('Cannot have delay as the last action');
|
||||||
@ -424,10 +472,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
});
|
});
|
||||||
}).toList();
|
}).toList();
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
var spaceBloc = context.read<CreateRoutineBloc>();
|
||||||
|
|
||||||
final createAutomationModel = CreateAutomationModel(
|
final createAutomationModel = CreateAutomationModel(
|
||||||
spaceUuid: spaceBloc.state.selectedSpaces[0],
|
spaceUuid: spaceBloc.selectedSpaceId,
|
||||||
automationName: state.routineName ?? '',
|
automationName: state.routineName ?? '',
|
||||||
decisionExpr: state.selectedAutomationOperator,
|
decisionExpr: state.selectedAutomationOperator,
|
||||||
effectiveTime: EffectiveTime(
|
effectiveTime: EffectiveTime(
|
||||||
@ -439,7 +487,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
actions: actions,
|
actions: actions,
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = await SceneApi.createAutomation(createAutomationModel, projectUuid);
|
final result =
|
||||||
|
await SceneApi.createAutomation(createAutomationModel, projectUuid);
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(const LoadAutomation());
|
add(const LoadAutomation());
|
||||||
@ -460,17 +509,21 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onRemoveDragCard(RemoveDragCard event, Emitter<RoutineState> emit) {
|
FutureOr<void> _onRemoveDragCard(
|
||||||
|
RemoveDragCard event, Emitter<RoutineState> emit) {
|
||||||
if (event.isFromThen) {
|
if (event.isFromThen) {
|
||||||
final thenItems = List<Map<String, dynamic>>.from(state.thenItems);
|
final thenItems = List<Map<String, dynamic>>.from(state.thenItems);
|
||||||
final selectedFunctions = Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
final selectedFunctions =
|
||||||
|
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||||
|
|
||||||
thenItems.removeAt(event.index);
|
thenItems.removeAt(event.index);
|
||||||
selectedFunctions.remove(event.key);
|
selectedFunctions.remove(event.key);
|
||||||
emit(state.copyWith(thenItems: thenItems, selectedFunctions: selectedFunctions));
|
emit(state.copyWith(
|
||||||
|
thenItems: thenItems, selectedFunctions: selectedFunctions));
|
||||||
} else {
|
} else {
|
||||||
final ifItems = List<Map<String, dynamic>>.from(state.ifItems);
|
final ifItems = List<Map<String, dynamic>>.from(state.ifItems);
|
||||||
final selectedFunctions = Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
final selectedFunctions =
|
||||||
|
Map<String, List<DeviceFunctionData>>.from(state.selectedFunctions);
|
||||||
|
|
||||||
ifItems.removeAt(event.index);
|
ifItems.removeAt(event.index);
|
||||||
selectedFunctions.remove(event.key);
|
selectedFunctions.remove(event.key);
|
||||||
@ -481,7 +534,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
isAutomation: false,
|
isAutomation: false,
|
||||||
isTabToRun: false));
|
isTabToRun: false));
|
||||||
} else {
|
} else {
|
||||||
emit(state.copyWith(ifItems: ifItems, selectedFunctions: selectedFunctions));
|
emit(state.copyWith(
|
||||||
|
ifItems: ifItems, selectedFunctions: selectedFunctions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -493,18 +547,23 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onEffectiveTimeEvent(EffectiveTimePeriodEvent event, Emitter<RoutineState> emit) {
|
FutureOr<void> _onEffectiveTimeEvent(
|
||||||
|
EffectiveTimePeriodEvent event, Emitter<RoutineState> emit) {
|
||||||
emit(state.copyWith(effectiveTime: event.effectiveTime));
|
emit(state.copyWith(effectiveTime: event.effectiveTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onSetRoutineName(SetRoutineName event, Emitter<RoutineState> emit) {
|
FutureOr<void> _onSetRoutineName(
|
||||||
|
SetRoutineName event, Emitter<RoutineState> emit) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
routineName: event.name,
|
routineName: event.name,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
(List<Map<String, dynamic>>, List<Map<String, dynamic>>, Map<String, List<DeviceFunctionData>>)
|
(
|
||||||
_createCardData(
|
List<Map<String, dynamic>>,
|
||||||
|
List<Map<String, dynamic>>,
|
||||||
|
Map<String, List<DeviceFunctionData>>
|
||||||
|
) _createCardData(
|
||||||
List<RoutineAction> actions,
|
List<RoutineAction> actions,
|
||||||
List<RoutineCondition>? conditions,
|
List<RoutineCondition>? conditions,
|
||||||
Map<String, List<DeviceFunctionData>> currentFunctions,
|
Map<String, List<DeviceFunctionData>> currentFunctions,
|
||||||
@ -537,7 +596,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
'deviceId': condition.entityId,
|
'deviceId': condition.entityId,
|
||||||
'title': matchingDevice.name ?? condition.entityId,
|
'title': matchingDevice.name ?? condition.entityId,
|
||||||
'productType': condition.entityType,
|
'productType': condition.entityType,
|
||||||
'imagePath': matchingDevice.getDefaultIcon(condition.entityType),
|
'imagePath':
|
||||||
|
matchingDevice.getDefaultIcon(condition.entityType),
|
||||||
};
|
};
|
||||||
|
|
||||||
final functions = matchingDevice.functions;
|
final functions = matchingDevice.functions;
|
||||||
@ -573,8 +633,11 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
final cardData = {
|
final cardData = {
|
||||||
'entityId': action.entityId,
|
'entityId': action.entityId,
|
||||||
'uniqueCustomId': const Uuid().v4(),
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
'deviceId':
|
||||||
'title': action.actionExecutor == 'delay' ? 'Delay' : (matchingDevice.name ?? 'Device'),
|
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||||
|
'title': action.actionExecutor == 'delay'
|
||||||
|
? 'Delay'
|
||||||
|
: (matchingDevice.name ?? 'Device'),
|
||||||
'productType': action.productType,
|
'productType': action.productType,
|
||||||
'imagePath': matchingDevice.getDefaultIcon(action.productType),
|
'imagePath': matchingDevice.getDefaultIcon(action.productType),
|
||||||
};
|
};
|
||||||
@ -617,7 +680,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
return (thenItems, ifItems, currentFunctions);
|
return (thenItems, ifItems, currentFunctions);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onGetSceneDetails(GetSceneDetails event, Emitter<RoutineState> emit) async {
|
Future<void> _onGetSceneDetails(
|
||||||
|
GetSceneDetails event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
@ -665,10 +729,12 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
if (!deviceCards.containsKey(deviceId)) {
|
if (!deviceCards.containsKey(deviceId)) {
|
||||||
deviceCards[deviceId] = {
|
deviceCards[deviceId] = {
|
||||||
'entityId': action.entityId,
|
'entityId': action.entityId,
|
||||||
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
'deviceId':
|
||||||
'uniqueCustomId': action.type == 'automation' || action.actionExecutor == 'delay'
|
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||||
? const Uuid().v4()
|
'uniqueCustomId':
|
||||||
: action.entityId,
|
action.type == 'automation' || action.actionExecutor == 'delay'
|
||||||
|
? const Uuid().v4()
|
||||||
|
: action.entityId,
|
||||||
'title': action.actionExecutor == 'delay'
|
'title': action.actionExecutor == 'delay'
|
||||||
? 'Delay'
|
? 'Delay'
|
||||||
: action.type == 'automation'
|
: action.type == 'automation'
|
||||||
@ -703,7 +769,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
// emit(state.copyWith(automationActionExecutor: action.actionExecutor));
|
// emit(state.copyWith(automationActionExecutor: action.actionExecutor));
|
||||||
} else if (action.executorProperty != null && action.actionExecutor != 'delay') {
|
} else if (action.executorProperty != null &&
|
||||||
|
action.actionExecutor != 'delay') {
|
||||||
if (!updatedFunctions.containsKey(uniqueCustomId)) {
|
if (!updatedFunctions.containsKey(uniqueCustomId)) {
|
||||||
updatedFunctions[uniqueCustomId] = [];
|
updatedFunctions[uniqueCustomId] = [];
|
||||||
}
|
}
|
||||||
@ -775,7 +842,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onResetRoutineState(ResetRoutineState event, Emitter<RoutineState> emit) {
|
FutureOr<void> _onResetRoutineState(
|
||||||
|
ResetRoutineState event, Emitter<RoutineState> emit) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
ifItems: [],
|
ifItems: [],
|
||||||
thenItems: [],
|
thenItems: [],
|
||||||
@ -799,21 +867,22 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
createRoutineView: false));
|
createRoutineView: false));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _deleteScene(DeleteScene event, Emitter<RoutineState> emit) async {
|
FutureOr<void> _deleteScene(
|
||||||
|
DeleteScene event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
|
||||||
|
|
||||||
emit(state.copyWith(isLoading: true));
|
emit(state.copyWith(isLoading: true));
|
||||||
|
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
||||||
if (state.isTabToRun) {
|
if (state.isTabToRun) {
|
||||||
await SceneApi.deleteScene(
|
await SceneApi.deleteScene(
|
||||||
unitUuid: spaceBloc.state.selectedSpaces[0], sceneId: state.sceneId ?? '');
|
unitUuid: createRoutineBloc.selectedSpaceId,
|
||||||
|
sceneId: state.sceneId ?? '');
|
||||||
} else {
|
} else {
|
||||||
await SceneApi.deleteAutomation(
|
await SceneApi.deleteAutomation(
|
||||||
unitUuid: spaceBloc.state.selectedSpaces[0],
|
projectId: projectId,
|
||||||
automationId: state.automationId ?? '',
|
unitUuid: createRoutineBloc.selectedSpaceId,
|
||||||
projectId: projectId);
|
automationId: state.automationId ?? '');
|
||||||
}
|
}
|
||||||
|
|
||||||
add(const LoadScenes());
|
add(const LoadScenes());
|
||||||
@ -842,21 +911,31 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
FutureOr<void> _fetchDevices(FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
FutureOr<void> _fetchDevices(
|
||||||
|
FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
||||||
emit(state.copyWith(isLoading: true));
|
emit(state.copyWith(isLoading: true));
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
List<AllDevicesModel> devices = [];
|
List<AllDevicesModel> devices = [];
|
||||||
|
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
|
var createRoutineBloc = context.read<CreateRoutineBloc>();
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
for (var communityId in spaceBloc.state.selectedCommunities) {
|
|
||||||
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
if (createRoutineBloc.selectedSpaceId == '' &&
|
||||||
for (var spaceId in spacesList) {
|
createRoutineBloc.selectedCommunityId == '') {
|
||||||
devices
|
for (var communityId in spaceBloc.state.selectedCommunities) {
|
||||||
.addAll(await DevicesManagementApi().fetchDevices(communityId, spaceId, projectUuid));
|
List<String> spacesList =
|
||||||
|
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
|
||||||
|
for (var spaceId in spacesList) {
|
||||||
|
devices.addAll(await DevicesManagementApi()
|
||||||
|
.fetchDevices(communityId, spaceId, projectUuid));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
devices.addAll(await DevicesManagementApi().fetchDevices(
|
||||||
|
createRoutineBloc.selectedCommunityId,
|
||||||
|
createRoutineBloc.selectedSpaceId,
|
||||||
|
projectUuid));
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(state.copyWith(isLoading: false, devices: devices));
|
emit(state.copyWith(isLoading: false, devices: devices));
|
||||||
@ -865,7 +944,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onUpdateScene(UpdateScene event, Emitter<RoutineState> emit) async {
|
FutureOr<void> _onUpdateScene(
|
||||||
|
UpdateScene event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
// Check if first action is delay
|
// Check if first action is delay
|
||||||
// if (_isFirstActionDelay(state.thenItems)) {
|
// if (_isFirstActionDelay(state.thenItems)) {
|
||||||
@ -879,7 +959,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
|
|
||||||
if (_isLastActionDelay(state.thenItems)) {
|
if (_isLastActionDelay(state.thenItems)) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
errorMessage: 'A delay condition cannot be the only or the last action',
|
errorMessage:
|
||||||
|
'A delay condition cannot be the only or the last action',
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
));
|
));
|
||||||
return;
|
return;
|
||||||
@ -932,7 +1013,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
actions: actions,
|
actions: actions,
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
final result =
|
||||||
|
await SceneApi.updateScene(createSceneModel, state.sceneId ?? '');
|
||||||
if (result['success']) {
|
if (result['success']) {
|
||||||
add(ResetRoutineState());
|
add(ResetRoutineState());
|
||||||
add(const LoadScenes());
|
add(const LoadScenes());
|
||||||
@ -951,10 +1033,9 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onUpdateAutomation(UpdateAutomation event, Emitter<RoutineState> emit) async {
|
FutureOr<void> _onUpdateAutomation(
|
||||||
|
UpdateAutomation event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
|
||||||
|
|
||||||
if (state.routineName == null || state.routineName!.isEmpty) {
|
if (state.routineName == null || state.routineName!.isEmpty) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
errorMessage: 'Automation name is required',
|
errorMessage: 'Automation name is required',
|
||||||
@ -1049,10 +1130,10 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
BuildContext context = NavigationService.navigatorKey.currentContext!;
|
||||||
var spaceBloc = context.read<SpaceTreeBloc>();
|
var spaceBloc = context.read<CreateRoutineBloc>();
|
||||||
|
|
||||||
final createAutomationModel = CreateAutomationModel(
|
final createAutomationModel = CreateAutomationModel(
|
||||||
spaceUuid: spaceBloc.state.selectedSpaces[0],
|
spaceUuid: spaceBloc.selectedSpaceId,
|
||||||
automationName: state.routineName ?? '',
|
automationName: state.routineName ?? '',
|
||||||
decisionExpr: state.selectedAutomationOperator,
|
decisionExpr: state.selectedAutomationOperator,
|
||||||
effectiveTime: EffectiveTime(
|
effectiveTime: EffectiveTime(
|
||||||
@ -1063,7 +1144,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
conditions: conditions,
|
conditions: conditions,
|
||||||
actions: actions,
|
actions: actions,
|
||||||
);
|
);
|
||||||
|
final projectId = await ProjectManager.getProjectUUID() ?? '';
|
||||||
final result = await SceneApi.updateAutomation(
|
final result = await SceneApi.updateAutomation(
|
||||||
createAutomationModel, state.automationId ?? '', projectId);
|
createAutomationModel, state.automationId ?? '', projectId);
|
||||||
|
|
||||||
@ -1089,7 +1170,6 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
GetAutomationDetails event, Emitter<RoutineState> emit) async {
|
GetAutomationDetails event, Emitter<RoutineState> emit) async {
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
isUpdate: true,
|
isUpdate: true,
|
||||||
@ -1169,13 +1249,15 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final deviceId =
|
final deviceId = action.actionExecutor == 'delay'
|
||||||
action.actionExecutor == 'delay' ? '${action.entityId}_delay' : action.entityId;
|
? '${action.entityId}_delay'
|
||||||
|
: action.entityId;
|
||||||
|
|
||||||
if (!deviceThenCards.containsKey(deviceId)) {
|
if (!deviceThenCards.containsKey(deviceId)) {
|
||||||
deviceThenCards[deviceId] = {
|
deviceThenCards[deviceId] = {
|
||||||
'entityId': action.entityId,
|
'entityId': action.entityId,
|
||||||
'deviceId': action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
'deviceId':
|
||||||
|
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||||
'uniqueCustomId': const Uuid().v4(),
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
'title': action.actionExecutor == 'delay'
|
'title': action.actionExecutor == 'delay'
|
||||||
? 'Delay'
|
? 'Delay'
|
||||||
@ -1206,7 +1288,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
updatedFunctions[uniqueCustomId] = [];
|
updatedFunctions[uniqueCustomId] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (action.executorProperty != null && action.actionExecutor != 'delay') {
|
if (action.executorProperty != null &&
|
||||||
|
action.actionExecutor != 'delay') {
|
||||||
final functions = matchingDevice.functions;
|
final functions = matchingDevice.functions;
|
||||||
final functionCode = action.executorProperty!.functionCode;
|
final functionCode = action.executorProperty!.functionCode;
|
||||||
for (var function in functions) {
|
for (var function in functions) {
|
||||||
@ -1248,10 +1331,14 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final ifItems = deviceIfCards.values.where((card) => card['type'] == 'condition').toList();
|
final ifItems = deviceIfCards.values
|
||||||
|
.where((card) => card['type'] == 'condition')
|
||||||
|
.toList();
|
||||||
final thenItems = deviceThenCards.values
|
final thenItems = deviceThenCards.values
|
||||||
.where((card) =>
|
.where((card) =>
|
||||||
card['type'] == 'action' || card['type'] == 'automation' || card['type'] == 'scene')
|
card['type'] == 'action' ||
|
||||||
|
card['type'] == 'automation' ||
|
||||||
|
card['type'] == 'scene')
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
@ -1301,8 +1388,6 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Future<void> _onUpdateAutomationStatus(
|
Future<void> _onUpdateAutomationStatus(
|
||||||
UpdateAutomationStatus event, Emitter<RoutineState> emit) async {
|
UpdateAutomationStatus event, Emitter<RoutineState> emit) async {
|
||||||
// Create a new set safely
|
// Create a new set safely
|
||||||
|
96
lib/pages/routines/create_new_routines/commu_dropdown.dart
Normal file
96
lib/pages/routines/create_new_routines/commu_dropdown.dart
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
|
class CommunityDropdown extends StatelessWidget {
|
||||||
|
final String? selectedValue;
|
||||||
|
final Function(String?) onChanged;
|
||||||
|
|
||||||
|
const CommunityDropdown({
|
||||||
|
Key? key,
|
||||||
|
required this.selectedValue,
|
||||||
|
required this.onChanged,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Community",
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 13,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
BlocBuilder<SpaceTreeBloc, SpaceTreeState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
List<CommunityModel> communities = state.isSearching
|
||||||
|
? state.filteredCommunity
|
||||||
|
: state.communityList;
|
||||||
|
|
||||||
|
return SizedBox(
|
||||||
|
child: DropdownButtonFormField<String>(
|
||||||
|
dropdownColor: ColorsManager.whiteColors,
|
||||||
|
value: selectedValue,
|
||||||
|
items: communities.map((community) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: community.uuid,
|
||||||
|
child: Text(' ${community.name}'),
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
onChanged: onChanged,
|
||||||
|
icon: const SizedBox.shrink(),
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||||
|
hint: Padding(
|
||||||
|
padding: EdgeInsets.only(left: 10),
|
||||||
|
child: Text(
|
||||||
|
"Please Select",
|
||||||
|
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
decoration: inputTextFormDeco().copyWith(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
suffixIcon: Container(
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
width: 70,
|
||||||
|
height: 45,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey[100],
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
bottomRight: Radius.circular(10),
|
||||||
|
topRight: Radius.circular(10),
|
||||||
|
),
|
||||||
|
border: Border.all(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Center(
|
||||||
|
child: Icon(
|
||||||
|
Icons.keyboard_arrow_down,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
148
lib/pages/routines/create_new_routines/create_new_routines.dart
Normal file
148
lib/pages/routines/create_new_routines/create_new_routines.dart
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_state.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/create_new_routines/commu_dropdown.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/create_new_routines/space_dropdown.dart';
|
||||||
|
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
|
class CreateNewRoutinesDialog extends StatefulWidget {
|
||||||
|
const CreateNewRoutinesDialog({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CreateNewRoutinesDialog> createState() =>
|
||||||
|
_CreateNewRoutinesDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CreateNewRoutinesDialogState extends State<CreateNewRoutinesDialog> {
|
||||||
|
String? _selectedCommunity;
|
||||||
|
String? _selectedSpace;
|
||||||
|
void _fetchSpaces(String communityId) {
|
||||||
|
context
|
||||||
|
.read<CreateRoutineBloc>()
|
||||||
|
.add(SpaceOnlyWithDevicesEvent(communityId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return BlocBuilder<CreateRoutineBloc, CreateRoutineState>(
|
||||||
|
builder: (context, state) {
|
||||||
|
final _bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
||||||
|
final spaces = _bloc.spacesOnlyWithDevices;
|
||||||
|
final isLoading = state is SpaceWithDeviceLoadingState;
|
||||||
|
|
||||||
|
String spaceHint = 'Select a community first';
|
||||||
|
|
||||||
|
if (_selectedCommunity != null) {
|
||||||
|
if (isLoading) {
|
||||||
|
spaceHint = 'Loading spaces...';
|
||||||
|
} else if (spaces.isEmpty) {
|
||||||
|
spaceHint = 'No spaces available';
|
||||||
|
} else {
|
||||||
|
spaceHint = 'Select Space';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return AlertDialog(
|
||||||
|
backgroundColor: Colors.white,
|
||||||
|
insetPadding: EdgeInsets.zero,
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
shape:
|
||||||
|
RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
title: Text(
|
||||||
|
'Create New Routines',
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
color: ColorsManager.primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const Divider(),
|
||||||
|
CommunityDropdown(
|
||||||
|
selectedValue: _selectedCommunity,
|
||||||
|
onChanged: (String? newValue) {
|
||||||
|
setState(() {
|
||||||
|
_selectedCommunity = newValue;
|
||||||
|
_selectedSpace = null;
|
||||||
|
});
|
||||||
|
if (newValue != null) {
|
||||||
|
_fetchSpaces(newValue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
SpaceDropdown(
|
||||||
|
hintMessage: spaceHint,
|
||||||
|
spaces: spaces,
|
||||||
|
selectedValue: _selectedSpace,
|
||||||
|
onChanged: (String? newValue) {
|
||||||
|
setState(() {
|
||||||
|
_selectedSpace = newValue;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 20,
|
||||||
|
right: 20,
|
||||||
|
),
|
||||||
|
child: TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
'Cancel',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 14,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
left: 20,
|
||||||
|
right: 20,
|
||||||
|
),
|
||||||
|
child: TextButton(
|
||||||
|
onPressed:
|
||||||
|
_selectedCommunity != null && _selectedSpace != null
|
||||||
|
? () {
|
||||||
|
Navigator.of(context).pop({
|
||||||
|
'community': _selectedCommunity,
|
||||||
|
'space': _selectedSpace,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
child: Text(
|
||||||
|
'Next',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 14,
|
||||||
|
color: _selectedCommunity != null &&
|
||||||
|
_selectedSpace != null
|
||||||
|
? ColorsManager.blueColor
|
||||||
|
: Colors.blue.shade100,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
100
lib/pages/routines/create_new_routines/space_dropdown.dart
Normal file
100
lib/pages/routines/create_new_routines/space_dropdown.dart
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
|
class SpaceDropdown extends StatelessWidget {
|
||||||
|
final List<SpaceModel> spaces;
|
||||||
|
final String? selectedValue;
|
||||||
|
final Function(String?)? onChanged;
|
||||||
|
final String hintMessage;
|
||||||
|
|
||||||
|
const SpaceDropdown({
|
||||||
|
Key? key,
|
||||||
|
required this.spaces,
|
||||||
|
required this.selectedValue,
|
||||||
|
required this.onChanged,
|
||||||
|
required this.hintMessage,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"Space",
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontWeight: FontWeight.w400,
|
||||||
|
fontSize: 13,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
DropdownButtonFormField<String>(
|
||||||
|
value: selectedValue,
|
||||||
|
items: spaces.map((space) {
|
||||||
|
return DropdownMenuItem<String>(
|
||||||
|
value: space.uuid,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
' ${space.name}',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontSize: 12,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
' ${space.lastThreeParents}',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium!.copyWith(
|
||||||
|
fontSize: 12,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
));
|
||||||
|
}).toList(),
|
||||||
|
onChanged: onChanged,
|
||||||
|
icon: const SizedBox.shrink(),
|
||||||
|
borderRadius: const BorderRadius.all(Radius.circular(10)),
|
||||||
|
hint: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 10),
|
||||||
|
child: Text(
|
||||||
|
hintMessage,
|
||||||
|
style: Theme.of(context).textTheme.bodySmall!.copyWith(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
decoration: inputTextFormDeco().copyWith(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
suffixIcon: Container(
|
||||||
|
width: 70,
|
||||||
|
height: 45,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.grey[200],
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
bottomRight: Radius.circular(10),
|
||||||
|
topRight: Radius.circular(10),
|
||||||
|
),
|
||||||
|
border: Border.all(
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
width: 1.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: const Icon(
|
||||||
|
Icons.keyboard_arrow_down,
|
||||||
|
color: ColorsManager.textGray,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
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/routines/bloc/create_routine_bloc/create_routine_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/bloc/create_routine_bloc/create_routine_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routines/bloc/routine_bloc/routine_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routines/create_new_routines/create_new_routines.dart';
|
||||||
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart';
|
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart';
|
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
@ -16,10 +18,23 @@ class RoutinesView extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _RoutinesViewState extends State<RoutinesView> {
|
class _RoutinesViewState extends State<RoutinesView> {
|
||||||
@override
|
void _handleRoutineCreation(BuildContext context) async {
|
||||||
void initState() {
|
final result = await showDialog<Map<String, dynamic>>(
|
||||||
super.initState();
|
context: context,
|
||||||
// context.read<RoutineBloc>().add(FetchDevicesInRoutine());
|
builder: (context) => const CreateNewRoutinesDialog(),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result == null) return;
|
||||||
|
final communityId = result['community'];
|
||||||
|
final spaceId = result['space'];
|
||||||
|
final _bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
||||||
|
final routineBloc = context.read<RoutineBloc>();
|
||||||
|
_bloc.add(SaveCommunityIdAndSpaceIdEvent(
|
||||||
|
communityID: communityId, spaceID: spaceId));
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
routineBloc.add(const CreateNewRoutineViewEvent(createRoutineView: true));
|
||||||
|
await Future.delayed(const Duration(milliseconds: 500));
|
||||||
|
BlocProvider.of<CreateRoutineBloc>(context).add(const ResetSelectedEvent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -29,96 +44,57 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
if (state.createRoutineView) {
|
if (state.createRoutineView) {
|
||||||
return const CreateNewRoutineView();
|
return const CreateNewRoutineView();
|
||||||
}
|
}
|
||||||
|
|
||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
Expanded(child: SpaceTreeView(
|
Expanded(
|
||||||
onSelect: () {
|
child: SpaceTreeView(
|
||||||
context.read<RoutineBloc>()
|
onSelect: () => context.read<RoutineBloc>()
|
||||||
..add(const LoadScenes())
|
..add(const LoadScenes())
|
||||||
..add(const LoadAutomation());
|
..add(const LoadAutomation()),
|
||||||
},
|
),
|
||||||
)),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 4,
|
flex: 4,
|
||||||
child: ListView(children: [
|
child: ListView(
|
||||||
Container(
|
children: [
|
||||||
padding: const EdgeInsets.all(16),
|
Container(
|
||||||
height: MediaQuery.sizeOf(context).height,
|
padding: const EdgeInsets.all(16),
|
||||||
child: Column(
|
height: MediaQuery.sizeOf(context).height,
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Text(
|
||||||
Text(
|
"Create New Routines",
|
||||||
"Create New Routines",
|
style:
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
color: ColorsManager.grayColor,
|
color: ColorsManager.grayColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
const SizedBox(height: 10),
|
||||||
height: 10,
|
RoutineViewCard(
|
||||||
),
|
isLoading: false,
|
||||||
RoutineViewCard(
|
onChanged: (v) {},
|
||||||
isLoading: false,
|
status: '',
|
||||||
onChanged: (v) {},
|
spaceId: '',
|
||||||
status: '',
|
automationId: '',
|
||||||
spaceId: '',
|
communityId: '',
|
||||||
automationId: '',
|
sceneId: '',
|
||||||
communityId: '',
|
cardType: '',
|
||||||
sceneId: '',
|
spaceName: '',
|
||||||
cardType: '',
|
onTap: () => _handleRoutineCreation(context),
|
||||||
spaceName: '',
|
icon: Icons.add,
|
||||||
onTap: () {
|
textString: '',
|
||||||
if (context
|
),
|
||||||
.read<SpaceTreeBloc>()
|
const SizedBox(height: 15),
|
||||||
.state
|
const Expanded(child: FetchRoutineScenesAutomation()),
|
||||||
.selectedCommunities
|
],
|
||||||
.length ==
|
),
|
||||||
1 &&
|
|
||||||
context
|
|
||||||
.read<SpaceTreeBloc>()
|
|
||||||
.state
|
|
||||||
.selectedSpaces
|
|
||||||
.length ==
|
|
||||||
1) {
|
|
||||||
context.read<RoutineBloc>().add(
|
|
||||||
(ResetRoutineState()),
|
|
||||||
);
|
|
||||||
BlocProvider.of<RoutineBloc>(context).add(
|
|
||||||
const CreateNewRoutineViewEvent(
|
|
||||||
createRoutineView: true),
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(
|
|
||||||
content: Text(context
|
|
||||||
.read<SpaceTreeBloc>()
|
|
||||||
.state
|
|
||||||
.selectedSpaces
|
|
||||||
.isEmpty
|
|
||||||
? 'Please select a space'
|
|
||||||
: 'Please select only one space to proceed'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// CustomSnackBar.redSnackBar(
|
|
||||||
// context.read<SpaceTreeBloc>().state.selectedSpaces.isEmpty
|
|
||||||
// ? 'Please select a space'
|
|
||||||
// : 'Please select only one space to proceed');
|
|
||||||
}
|
|
||||||
},
|
|
||||||
icon: Icons.add,
|
|
||||||
textString: '',
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 15,
|
|
||||||
),
|
|
||||||
const Expanded(child: FetchRoutineScenesAutomation()),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
],
|
||||||
]),
|
),
|
||||||
),
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -109,7 +109,7 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 15),
|
const SizedBox(height: 10),
|
||||||
Text(
|
Text(
|
||||||
"Automations",
|
"Automations",
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
@ -117,7 +117,7 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 5),
|
||||||
if (state.automations.isEmpty)
|
if (state.automations.isEmpty)
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
@ -130,7 +130,7 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|||||||
if (state.automations.isNotEmpty)
|
if (state.automations.isNotEmpty)
|
||||||
ConstrainedBox(
|
ConstrainedBox(
|
||||||
constraints: BoxConstraints(
|
constraints: BoxConstraints(
|
||||||
maxHeight: isSmallScreenSize(context) ? 190 : 200,
|
maxHeight: isSmallScreenSize(context) ? 185 : 192,
|
||||||
maxWidth: MediaQuery.sizeOf(context).width * 0.7),
|
maxWidth: MediaQuery.sizeOf(context).width * 0.7),
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
@ -149,16 +149,17 @@ class _FetchRoutineScenesState extends State<FetchRoutineScenesAutomation>
|
|||||||
// BlocProvider.of<RoutineBloc>(context)
|
// BlocProvider.of<RoutineBloc>(context)
|
||||||
context.read<RoutineBloc>().add(
|
context.read<RoutineBloc>().add(
|
||||||
UpdateAutomationStatus(
|
UpdateAutomationStatus(
|
||||||
automationId:
|
automationId:
|
||||||
state.automations[index].id,
|
state.automations[index].id,
|
||||||
automationStatusUpdate:
|
automationStatusUpdate:
|
||||||
AutomationStatusUpdate(
|
AutomationStatusUpdate(
|
||||||
spaceUuid: state
|
spaceUuid: state
|
||||||
.automations[index]
|
.automations[index]
|
||||||
.spaceId,
|
.spaceId,
|
||||||
isEnable: v),
|
isEnable: v),
|
||||||
communityId:
|
communityId: state
|
||||||
'aff21a57-2f91-4e5c-b99b-0182c3ab65a9'),
|
.automations[index].communityId,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
status: state.automations[index].status,
|
status: state.automations[index].status,
|
||||||
|
@ -14,6 +14,7 @@ class SpaceModel {
|
|||||||
String? icon;
|
String? icon;
|
||||||
final String? spaceTuyaUuid;
|
final String? spaceTuyaUuid;
|
||||||
String name;
|
String name;
|
||||||
|
String? lastThreeParents;
|
||||||
final bool isPrivate;
|
final bool isPrivate;
|
||||||
final String? invitationCode;
|
final String? invitationCode;
|
||||||
SpaceModel? parent;
|
SpaceModel? parent;
|
||||||
@ -33,6 +34,7 @@ class SpaceModel {
|
|||||||
SpaceModel({
|
SpaceModel({
|
||||||
this.uuid,
|
this.uuid,
|
||||||
String? internalId,
|
String? internalId,
|
||||||
|
this.lastThreeParents,
|
||||||
this.spaceTuyaUuid,
|
this.spaceTuyaUuid,
|
||||||
required this.icon,
|
required this.icon,
|
||||||
required this.name,
|
required this.name,
|
||||||
@ -67,6 +69,7 @@ class SpaceModel {
|
|||||||
internalId: internalId,
|
internalId: internalId,
|
||||||
uuid: json['uuid'] ?? '',
|
uuid: json['uuid'] ?? '',
|
||||||
name: json['spaceName'],
|
name: json['spaceName'],
|
||||||
|
lastThreeParents: json['lastThreeParents'],
|
||||||
isPrivate: json['isPrivate'] ?? false,
|
isPrivate: json['isPrivate'] ?? false,
|
||||||
invitationCode: json['invitationCode'],
|
invitationCode: json['invitationCode'],
|
||||||
subspaces: (json['subspaces'] as List<dynamic>?)
|
subspaces: (json['subspaces'] as List<dynamic>?)
|
||||||
@ -125,6 +128,7 @@ class SpaceModel {
|
|||||||
'uuid': uuid ?? '',
|
'uuid': uuid ?? '',
|
||||||
'spaceTuyaUuid': spaceTuyaUuid,
|
'spaceTuyaUuid': spaceTuyaUuid,
|
||||||
'name': name,
|
'name': name,
|
||||||
|
'lastThreeParents': lastThreeParents,
|
||||||
'isPrivate': isPrivate,
|
'isPrivate': isPrivate,
|
||||||
'invitationCode': invitationCode,
|
'invitationCode': invitationCode,
|
||||||
'parent': parent?.uuid,
|
'parent': parent?.uuid,
|
||||||
|
@ -23,8 +23,9 @@ class DevicesManagementApi {
|
|||||||
: ApiEndpoints.getAllDevices.replaceAll('{projectId}', projectId),
|
: ApiEndpoints.getAllDevices.replaceAll('{projectId}', projectId),
|
||||||
showServerMessage: true,
|
showServerMessage: true,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
List<dynamic> jsonData =
|
List<dynamic> jsonData = communityId.isNotEmpty && spaceId.isNotEmpty
|
||||||
communityId.isNotEmpty && spaceId.isNotEmpty ? json['data'] : json;
|
? json['data']
|
||||||
|
: json;
|
||||||
List<AllDevicesModel> devicesList = jsonData.map((jsonItem) {
|
List<AllDevicesModel> devicesList = jsonData.map((jsonItem) {
|
||||||
return AllDevicesModel.fromJson(jsonItem);
|
return AllDevicesModel.fromJson(jsonItem);
|
||||||
}).toList();
|
}).toList();
|
||||||
@ -33,7 +34,7 @@ class DevicesManagementApi {
|
|||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugPrint('Error fetching $e');
|
debugPrint('fetchDevices Error fetching $e');
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -92,7 +93,8 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> deviceBatchControl(List<String> uuids, String code, dynamic value) async {
|
Future<bool> deviceBatchControl(
|
||||||
|
List<String> uuids, String code, dynamic value) async {
|
||||||
try {
|
try {
|
||||||
final body = {
|
final body = {
|
||||||
'devicesUuid': uuids,
|
'devicesUuid': uuids,
|
||||||
@ -116,7 +118,8 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<List<DeviceModel>> getDevicesByGatewayId(String gatewayId) async {
|
static Future<List<DeviceModel>> getDevicesByGatewayId(
|
||||||
|
String gatewayId) async {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
|
path: ApiEndpoints.gatewayApi.replaceAll('{gatewayUuid}', gatewayId),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
@ -150,7 +153,9 @@ class DevicesManagementApi {
|
|||||||
String code,
|
String code,
|
||||||
) async {
|
) async {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getDeviceLogs.replaceAll('{uuid}', uuid).replaceAll('{code}', code),
|
path: ApiEndpoints.getDeviceLogs
|
||||||
|
.replaceAll('{uuid}', uuid)
|
||||||
|
.replaceAll('{code}', code),
|
||||||
showServerMessage: false,
|
showServerMessage: false,
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return DeviceReport.fromJson(json);
|
return DeviceReport.fromJson(json);
|
||||||
@ -223,7 +228,8 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> addScheduleRecord(ScheduleEntry sendSchedule, String uuid) async {
|
Future<bool> addScheduleRecord(
|
||||||
|
ScheduleEntry sendSchedule, String uuid) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().post(
|
final response = await HTTPService().post(
|
||||||
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
|
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
|
||||||
@ -240,7 +246,8 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<ScheduleModel>> getDeviceSchedules(String uuid, String category) async {
|
Future<List<ScheduleModel>> getDeviceSchedules(
|
||||||
|
String uuid, String category) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().get(
|
final response = await HTTPService().get(
|
||||||
path: ApiEndpoints.getScheduleByDeviceId
|
path: ApiEndpoints.getScheduleByDeviceId
|
||||||
@ -263,7 +270,9 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> updateScheduleRecord(
|
Future<bool> updateScheduleRecord(
|
||||||
{required bool enable, required String uuid, required String scheduleId}) async {
|
{required bool enable,
|
||||||
|
required String uuid,
|
||||||
|
required String scheduleId}) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().put(
|
final response = await HTTPService().put(
|
||||||
path: ApiEndpoints.updateScheduleByDeviceId
|
path: ApiEndpoints.updateScheduleByDeviceId
|
||||||
@ -284,7 +293,8 @@ class DevicesManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> editScheduleRecord(String uuid, ScheduleEntry newSchedule) async {
|
Future<bool> editScheduleRecord(
|
||||||
|
String uuid, ScheduleEntry newSchedule) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().put(
|
final response = await HTTPService().put(
|
||||||
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
|
path: ApiEndpoints.scheduleByDeviceId.replaceAll('{deviceUuid}', uuid),
|
||||||
|
@ -302,4 +302,24 @@ class CommunitySpaceManagementApi {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Future<List<SpaceModel>> getSpaceOnlyWithDevices(
|
||||||
|
{String? communityId, String? projectId}) async {
|
||||||
|
try {
|
||||||
|
final response = await HTTPService().get(
|
||||||
|
path: ApiEndpoints.spaceOnlyWithDevices
|
||||||
|
.replaceAll('{communityId}', communityId!)
|
||||||
|
.replaceAll('{projectId}', projectId!),
|
||||||
|
expectedResponseModel: (json) {
|
||||||
|
final spaceModels = (json['data'] as List)
|
||||||
|
.map((spaceJson) => SpaceModel.fromJson(spaceJson))
|
||||||
|
.toList();
|
||||||
|
return spaceModels;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Error fetching space hierarchy: $e');
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,15 +9,19 @@ abstract class ApiEndpoints {
|
|||||||
static const String sendOtp = '/authentication/user/send-otp';
|
static const String sendOtp = '/authentication/user/send-otp';
|
||||||
static const String verifyOtp = '/authentication/user/verify-otp';
|
static const String verifyOtp = '/authentication/user/verify-otp';
|
||||||
static const String getRegion = '/region';
|
static const String getRegion = '/region';
|
||||||
static const String visitorPassword = '/projects/{projectId}/visitor-password';
|
static const String visitorPassword =
|
||||||
static const String getDevices = '/projects/{projectId}/visitor-password/devices';
|
'/projects/{projectId}/visitor-password';
|
||||||
|
static const String getDevices =
|
||||||
|
'/projects/{projectId}/visitor-password/devices';
|
||||||
|
|
||||||
static const String sendOnlineOneTime = '/visitor-password/temporary-password/online/one-time';
|
static const String sendOnlineOneTime =
|
||||||
|
'/visitor-password/temporary-password/online/one-time';
|
||||||
static const String sendOnlineMultipleTime =
|
static const String sendOnlineMultipleTime =
|
||||||
'/visitor-password/temporary-password/online/multiple-time';
|
'/visitor-password/temporary-password/online/multiple-time';
|
||||||
|
|
||||||
//offline Password
|
//offline Password
|
||||||
static const String sendOffLineOneTime = '/visitor-password/temporary-password/offline/one-time';
|
static const String sendOffLineOneTime =
|
||||||
|
'/visitor-password/temporary-password/offline/one-time';
|
||||||
static const String sendOffLineMultipleTime =
|
static const String sendOffLineMultipleTime =
|
||||||
'/visitor-password/temporary-password/offline/multiple-time';
|
'/visitor-password/temporary-password/offline/multiple-time';
|
||||||
|
|
||||||
@ -39,32 +43,45 @@ abstract class ApiEndpoints {
|
|||||||
static const String getDeviceLogs = '/device/report-logs/{uuid}?code={code}';
|
static const String getDeviceLogs = '/device/report-logs/{uuid}?code={code}';
|
||||||
|
|
||||||
// Space Module
|
// Space Module
|
||||||
static const String createSpace = '/projects/{projectId}/communities/{communityId}/spaces';
|
static const String createSpace =
|
||||||
static const String listSpaces = '/projects/{projectId}/communities/{communityId}/spaces';
|
'/projects/{projectId}/communities/{communityId}/spaces';
|
||||||
|
static const String listSpaces =
|
||||||
|
'/projects/{projectId}/communities/{communityId}/spaces';
|
||||||
static const String deleteSpace =
|
static const String deleteSpace =
|
||||||
'/projects/{projectId}/communities/{communityId}/spaces/{spaceId}';
|
'/projects/{projectId}/communities/{communityId}/spaces/{spaceId}';
|
||||||
static const String updateSpace =
|
static const String updateSpace =
|
||||||
'/projects/{projectId}/communities/{communityId}/spaces/{spaceId}';
|
'/projects/{projectId}/communities/{communityId}/spaces/{spaceId}';
|
||||||
static const String getSpace = '/projects/{projectId}/communities/{communityId}/spaces/{spaceId}';
|
static const String getSpace =
|
||||||
static const String getSpaceHierarchy = '/projects/{projectId}/communities/{communityId}/spaces';
|
'/projects/{projectId}/communities/{communityId}/spaces/{spaceId}';
|
||||||
|
static const String getSpaceHierarchy =
|
||||||
|
'/projects/{projectId}/communities/{communityId}/spaces';
|
||||||
|
|
||||||
// Community Module
|
// Community Module
|
||||||
static const String createCommunity = '/projects/{projectId}/communities';
|
static const String createCommunity = '/projects/{projectId}/communities';
|
||||||
static const String getCommunityList = '/projects/{projectId}/communities';
|
static const String getCommunityList = '/projects/{projectId}/communities';
|
||||||
static const String getCommunityById = '/projects/{projectId}/communities/{communityId}';
|
static const String getCommunityById =
|
||||||
static const String updateCommunity = '/projects/{projectId}/communities/{communityId}';
|
'/projects/{projectId}/communities/{communityId}';
|
||||||
static const String deleteCommunity = '/projects/{projectId}communities/{communityId}';
|
static const String updateCommunity =
|
||||||
static const String getUserCommunities = '/projects/{projectId}/communities/user/{userUuid}';
|
'/projects/{projectId}/communities/{communityId}';
|
||||||
static const String createUserCommunity = '/projects/{projectId}/communities/user';
|
static const String deleteCommunity =
|
||||||
|
'/projects/{projectId}communities/{communityId}';
|
||||||
|
static const String getUserCommunities =
|
||||||
|
'/projects/{projectId}/communities/user/{userUuid}';
|
||||||
|
static const String createUserCommunity =
|
||||||
|
'/projects/{projectId}/communities/user';
|
||||||
static const String getDeviceLogsByDate =
|
static const String getDeviceLogsByDate =
|
||||||
'/device/report-logs/{uuid}?code={code}&startTime={startTime}&endTime={endTime}';
|
'/device/report-logs/{uuid}?code={code}&startTime={startTime}&endTime={endTime}';
|
||||||
|
|
||||||
static const String scheduleByDeviceId = '/schedule/{deviceUuid}';
|
static const String scheduleByDeviceId = '/schedule/{deviceUuid}';
|
||||||
static const String getScheduleByDeviceId = '/schedule/{deviceUuid}?category={category}';
|
static const String getScheduleByDeviceId =
|
||||||
static const String deleteScheduleByDeviceId = '/schedule/{deviceUuid}/{scheduleUuid}';
|
'/schedule/{deviceUuid}?category={category}';
|
||||||
static const String updateScheduleByDeviceId = '/schedule/enable/{deviceUuid}';
|
static const String deleteScheduleByDeviceId =
|
||||||
|
'/schedule/{deviceUuid}/{scheduleUuid}';
|
||||||
|
static const String updateScheduleByDeviceId =
|
||||||
|
'/schedule/enable/{deviceUuid}';
|
||||||
static const String factoryReset = '/device/factory/reset/{deviceUuid}';
|
static const String factoryReset = '/device/factory/reset/{deviceUuid}';
|
||||||
static const String powerClamp = '/device/{powerClampUuid}/power-clamp/status';
|
static const String powerClamp =
|
||||||
|
'/device/{powerClampUuid}/power-clamp/status';
|
||||||
|
|
||||||
//product
|
//product
|
||||||
static const String listProducts = '/products';
|
static const String listProducts = '/products';
|
||||||
@ -76,27 +93,33 @@ abstract class ApiEndpoints {
|
|||||||
static const String createAutomation = '/projects/{projectId}/automations';
|
static const String createAutomation = '/projects/{projectId}/automations';
|
||||||
static const String getUnitScenes =
|
static const String getUnitScenes =
|
||||||
'/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/scenes';
|
'/projects/{projectId}/communities/{communityUuid}/spaces/{spaceUuid}/scenes';
|
||||||
static const String getAutomationDetails = '/projects/{projectId}/automations/{automationId}';
|
static const String getAutomationDetails =
|
||||||
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
static const String getScene = '/scene/tap-to-run/{sceneId}';
|
static const String getScene = '/scene/tap-to-run/{sceneId}';
|
||||||
static const String deleteScene = '/scene/tap-to-run/{sceneId}';
|
static const String deleteScene = '/scene/tap-to-run/{sceneId}';
|
||||||
|
|
||||||
static const String deleteAutomation = '/projects/{projectId}/automations/{automationId}';
|
static const String deleteAutomation =
|
||||||
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
static const String updateScene = '/scene/tap-to-run/{sceneId}';
|
||||||
|
|
||||||
static const String updateAutomation = '/projects/{projectId}/automations/{automationId}';
|
static const String updateAutomation =
|
||||||
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
|
|
||||||
//space model
|
//space model
|
||||||
static const String listSpaceModels = '/projects/{projectId}/space-models';
|
static const String listSpaceModels = '/projects/{projectId}/space-models';
|
||||||
static const String createSpaceModel = '/projects/{projectId}/space-models';
|
static const String createSpaceModel = '/projects/{projectId}/space-models';
|
||||||
static const String getSpaceModel = '/projects/{projectId}/space-models/{spaceModelUuid}';
|
static const String getSpaceModel =
|
||||||
static const String updateSpaceModel = '/projects/{projectId}/space-models/{spaceModelUuid}';
|
'/projects/{projectId}/space-models/{spaceModelUuid}';
|
||||||
|
static const String updateSpaceModel =
|
||||||
|
'/projects/{projectId}/space-models/{spaceModelUuid}';
|
||||||
//tag
|
//tag
|
||||||
static const String listTags = '/projects/{projectId}/tags';
|
static const String listTags = '/projects/{projectId}/tags';
|
||||||
|
|
||||||
static const String linkSpaceModel =
|
static const String linkSpaceModel =
|
||||||
'/projects/{projectId}/space-models/{spaceModelUuid}/spaces/link';
|
'/projects/{projectId}/space-models/{spaceModelUuid}/spaces/link';
|
||||||
|
|
||||||
static const String validateSpaceModel = '/projects/{projectId}/spaces/validate';
|
static const String validateSpaceModel =
|
||||||
|
'/projects/{projectId}/spaces/validate';
|
||||||
|
|
||||||
static const String roleTypes = '/role/types';
|
static const String roleTypes = '/role/types';
|
||||||
static const String permission = '/permission/{roleUuid}';
|
static const String permission = '/permission/{roleUuid}';
|
||||||
@ -107,13 +130,16 @@ abstract class ApiEndpoints {
|
|||||||
static const String getUserById = '/projects/{projectId}/user/{userUuid}';
|
static const String getUserById = '/projects/{projectId}/user/{userUuid}';
|
||||||
static const String editUser = '/invite-user/{inviteUserUuid}';
|
static const String editUser = '/invite-user/{inviteUserUuid}';
|
||||||
static const String deleteUser = '/invite-user/{inviteUserUuid}';
|
static const String deleteUser = '/invite-user/{inviteUserUuid}';
|
||||||
static const String changeUserStatus = '/invite-user/{invitedUserUuid}/disable';
|
static const String changeUserStatus =
|
||||||
|
'/invite-user/{invitedUserUuid}/disable';
|
||||||
static const String terms = '/terms';
|
static const String terms = '/terms';
|
||||||
static const String policy = '/policy';
|
static const String policy = '/policy';
|
||||||
static const String userAgreements = '/user/agreements/web/{userUuid}';
|
static const String userAgreements = '/user/agreements/web/{userUuid}';
|
||||||
static const String triggerScene = '/scene/tap-to-run/{sceneId}/trigger';
|
static const String triggerScene = '/scene/tap-to-run/{sceneId}/trigger';
|
||||||
static const String updateAutomationStatus =
|
static const String updateAutomationStatus =
|
||||||
'/projects/{projectId}/automations/{automationId}';
|
'/projects/{projectId}/automations/{automationId}';
|
||||||
static const String getUnitAutomation =
|
static const String getUnitAutomation =
|
||||||
'/projects/{projectId}/communities/{communityId}/spaces/{unitUuid}/automations';
|
'/projects/{projectId}/communities/{communityId}/spaces/{unitUuid}/automations';
|
||||||
|
static const String spaceOnlyWithDevices =
|
||||||
|
'/projects/{projectId}/communities/{communityId}/spaces?onlyWithDevices=true';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user