mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 09:45:22 +00:00
push delete automation
This commit is contained in:
@ -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));
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -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 =
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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';
|
||||
}
|
||||
|
Reference in New Issue
Block a user