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,7 +393,11 @@ class CreateSceneBloc extends Bloc<CreateSceneEvent, CreateSceneState>
emit(DeleteSceneLoading());
try {
final response = await SceneApi.deleteScene(
final response =
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) {
emit(const DeleteSceneSuccess(true));

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/scene_bloc/scene_bloc.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/widgets/create_scene_save_button.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
as SceneSettingsRouteArguments;
final isAutomation =
sceneSettings.sceneType == CreateSceneEnum.deviceStatusChanges.name;
return DefaultScaffold(
title: sceneSettings.sceneName.isNotEmpty
? sceneSettings.sceneName
@ -41,7 +45,8 @@ class SceneTasksView extends StatelessWidget {
: () {
context.customBottomSheet(
child: DeleteBottomSheetContent(
sceneId: sceneSettings.sceneId),
sceneId: sceneSettings.sceneId,
isAutomation: isAutomation),
);
},
child: SvgPicture.asset(
@ -95,9 +100,11 @@ class SceneTasksView 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 bool isAutomation;
@override
Widget build(BuildContext context) {
@ -113,6 +120,8 @@ class DeleteBottomSheetContent extends StatelessWidget {
navigateToRoute(context, Routes.homeRoute);
BlocProvider.of<SceneBloc>(context).add(
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(
titleString: StringsManager.deleteScene,
titleString: isAutomation
? StringsManager.deleteAutomation
: StringsManager.deleteScene,
leadingWidget: (state is DeleteSceneLoading)
? const SizedBox(
height: 24,

View File

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

View File

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

View File

@ -183,4 +183,21 @@ class SceneApi {
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 firstLaunch = "firstLaunch";
static const String deleteScene = 'Delete Scene';
static const String deleteAutomation = 'Delete Automation';
}