push delete automation

This commit is contained in:
ashrafzarkanisala
2024-07-25 00:34:00 +03:00
parent 8a4c5af2e7
commit 3e20ba8f42
6 changed files with 46 additions and 8 deletions

View File

@ -393,8 +393,12 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
emit(DeleteSceneLoading()); emit(DeleteSceneLoading());
try { try {
final response = await SceneApi.deleteScene( final response =
sceneId: event.sceneId, unitUuid: event.unitUuid); sceneType.name == CreateSceneEnum.deviceStatusChanges.name
? await SceneApi.deleteAutomation(
automationId: event.sceneId, unitUuid: event.unitUuid)
: await SceneApi.deleteScene(
sceneId: event.sceneId, unitUuid: event.unitUuid);
if (response == true) { if (response == true) {
emit(const DeleteSceneSuccess(true)); emit(const DeleteSceneSuccess(true));
} else { } else {

View File

@ -5,6 +5,7 @@ import 'package:syncrow_app/features/app_layout/bloc/home_cubit.dart';
import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/create_scene/create_scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart'; import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_bloc.dart';
import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart'; import 'package:syncrow_app/features/scene/bloc/scene_bloc/scene_event.dart';
import 'package:syncrow_app/features/scene/enum/create_scene_enum.dart';
import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart'; import 'package:syncrow_app/features/scene/model/scene_settings_route_arguments.dart';
import 'package:syncrow_app/features/scene/widgets/create_scene_save_button.dart'; import 'package:syncrow_app/features/scene/widgets/create_scene_save_button.dart';
import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart'; import 'package:syncrow_app/features/scene/widgets/if_then_containers/if_container.dart';
@ -27,6 +28,9 @@ class SceneTasksView extends StatelessWidget {
final sceneSettings = ModalRoute.of(context)!.settings.arguments final sceneSettings = ModalRoute.of(context)!.settings.arguments
as SceneSettingsRouteArguments; as SceneSettingsRouteArguments;
final isAutomation =
sceneSettings.sceneType == CreateSceneEnum.deviceStatusChanges.name;
return DefaultScaffold( return DefaultScaffold(
title: sceneSettings.sceneName.isNotEmpty title: sceneSettings.sceneName.isNotEmpty
? sceneSettings.sceneName ? sceneSettings.sceneName
@ -41,7 +45,8 @@ class SceneTasksView extends StatelessWidget {
: () { : () {
context.customBottomSheet( context.customBottomSheet(
child: DeleteBottomSheetContent( child: DeleteBottomSheetContent(
sceneId: sceneSettings.sceneId), sceneId: sceneSettings.sceneId,
isAutomation: isAutomation),
); );
}, },
child: SvgPicture.asset( child: SvgPicture.asset(
@ -95,9 +100,11 @@ class SceneTasksView extends StatelessWidget {
} }
class DeleteBottomSheetContent extends StatelessWidget { class DeleteBottomSheetContent extends StatelessWidget {
const DeleteBottomSheetContent({super.key, required this.sceneId}); const DeleteBottomSheetContent(
{super.key, required this.sceneId, required this.isAutomation});
final String sceneId; final String sceneId;
final bool isAutomation;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -113,6 +120,8 @@ class DeleteBottomSheetContent extends StatelessWidget {
navigateToRoute(context, Routes.homeRoute); navigateToRoute(context, Routes.homeRoute);
BlocProvider.of<SceneBloc>(context).add( BlocProvider.of<SceneBloc>(context).add(
LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)); LoadScenes(HomeCubit.getInstance().selectedSpace!.id!));
BlocProvider.of<SceneBloc>(context).add(LoadAutomation(
HomeCubit.getInstance().selectedSpace!.id!));
} }
} }
}, },
@ -126,7 +135,9 @@ class DeleteBottomSheetContent extends StatelessWidget {
)); ));
}, },
child: SceneListTile( child: SceneListTile(
titleString: StringsManager.deleteScene, titleString: isAutomation
? StringsManager.deleteAutomation
: StringsManager.deleteScene,
leadingWidget: (state is DeleteSceneLoading) leadingWidget: (state is DeleteSceneLoading)
? const SizedBox( ? const SizedBox(
height: 24, height: 24,

View File

@ -28,6 +28,8 @@ class SceneView extends StatelessWidget {
if (state.success) { if (state.success) {
BlocProvider.of<SceneBloc>(context) BlocProvider.of<SceneBloc>(context)
.add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!)); .add(LoadScenes(HomeCubit.getInstance().selectedSpace!.id!));
BlocProvider.of<SceneBloc>(context).add(
LoadAutomation(HomeCubit.getInstance().selectedSpace!.id!));
} }
} }
if (state is CreateSceneWithTasks) { if (state is CreateSceneWithTasks) {

View File

@ -144,18 +144,21 @@ abstract class ApiEndpoints {
static const String getUnitAutomation = '$baseUrl/automation/{unitUuid}'; static const String getUnitAutomation = '$baseUrl/automation/{unitUuid}';
static const String getAutomationDetails = '$baseUrl/automation/details/{automationId}'; static const String getAutomationDetails =
'$baseUrl/automation/details/{automationId}';
/// PUT /// PUT
static const String updateScene = '$baseUrl/scene/tap-to-run/{sceneId}'; static const String updateScene = '$baseUrl/scene/tap-to-run/{sceneId}';
static const String updateAutomation = static const String updateAutomation = '$baseUrl/automation/{automationId}';
'$baseUrl/automation/{automationId}';
/// DELETE /// DELETE
static const String deleteScene = static const String deleteScene =
'$baseUrl/scene/tap-to-run/{unitUuid}/{sceneId}'; '$baseUrl/scene/tap-to-run/{unitUuid}/{sceneId}';
static const String deleteAutomation =
'$baseUrl/automation/{unitUuid}/{automationId}';
//////////////////////Door Lock ////////////////////// //////////////////////Door Lock //////////////////////
//online //online
static const String addTemporaryPassword = static const String addTemporaryPassword =

View File

@ -183,4 +183,21 @@ class SceneApi {
rethrow; rethrow;
} }
} }
// delete automation
static Future<bool> deleteAutomation(
{required String unitUuid, required String automationId}) async {
try {
final response = await _httpService.delete(
path: ApiEndpoints.deleteAutomation
.replaceAll('{automationId}', automationId)
.replaceAll('{unitUuid}', unitUuid),
showServerMessage: false,
expectedResponseModel: (json) => json['statusCode'] == 200,
);
return response;
} catch (e) {
rethrow;
}
}
} }

View File

@ -40,4 +40,5 @@ class StringsManager {
static const String functions = "Functions"; static const String functions = "Functions";
static const String firstLaunch = "firstLaunch"; static const String firstLaunch = "firstLaunch";
static const String deleteScene = 'Delete Scene'; static const String deleteScene = 'Delete Scene';
static const String deleteAutomation = 'Delete Automation';
} }