mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-08-26 07:29:40 +00:00
changed endpoint for getting automations by space
This commit is contained in:
@ -46,8 +46,11 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
||||
emit(SceneLoading());
|
||||
|
||||
try {
|
||||
Project? project = HomeCubit.getInstance().project;
|
||||
|
||||
if (event.unitId.isNotEmpty) {
|
||||
automationList = await SceneApi.getAutomationByUnitId(event.unitId);
|
||||
automationList = await SceneApi.getAutomationByUnitId(
|
||||
event.unitId, event.communityId, project?.uuid ?? '');
|
||||
emit(SceneLoaded(scenes, automationList));
|
||||
} else {
|
||||
emit(const SceneError(message: 'Unit ID is empty'));
|
||||
@ -96,11 +99,16 @@ class SceneBloc extends Bloc<SceneEvent, SceneState> {
|
||||
));
|
||||
|
||||
try {
|
||||
Project? project = HomeCubit.getInstance().project;
|
||||
|
||||
final success = await SceneApi.updateAutomationStatus(
|
||||
event.automationId, event.automationStatusUpdate);
|
||||
if (success) {
|
||||
automationList = await SceneApi.getAutomationByUnitId(
|
||||
event.automationStatusUpdate.spaceUuid);
|
||||
event.automationStatusUpdate.spaceUuid,
|
||||
event.communityId,
|
||||
project?.uuid ?? ''
|
||||
);
|
||||
newLoadingStates[event.automationId] = false;
|
||||
emit(SceneLoaded(
|
||||
currentState.scenes,
|
||||
|
@ -22,11 +22,13 @@ class LoadScenes extends SceneEvent {
|
||||
|
||||
class LoadAutomation extends SceneEvent {
|
||||
final String unitId;
|
||||
final String communityId;
|
||||
|
||||
const LoadAutomation(this.unitId);
|
||||
|
||||
const LoadAutomation(this.unitId, this.communityId);
|
||||
|
||||
@override
|
||||
List<Object> get props => [unitId];
|
||||
List<Object> get props => [unitId, communityId];
|
||||
}
|
||||
|
||||
class SceneTrigger extends SceneEvent {
|
||||
@ -43,8 +45,9 @@ class SceneTrigger extends SceneEvent {
|
||||
class UpdateAutomationStatus extends SceneEvent {
|
||||
final String automationId;
|
||||
final AutomationStatusUpdate automationStatusUpdate;
|
||||
final String communityId;
|
||||
|
||||
const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId});
|
||||
const UpdateAutomationStatus({required this.automationStatusUpdate, required this.automationId, required this.communityId});
|
||||
|
||||
@override
|
||||
List<Object> get props => [automationStatusUpdate];
|
||||
|
@ -49,7 +49,9 @@ class SceneView extends StatelessWidget {
|
||||
name: '',
|
||||
)),
|
||||
showInDevice: pageType))
|
||||
..add(LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? ''));
|
||||
..add(LoadAutomation(
|
||||
HomeCubit.getInstance().selectedSpace?.id ?? '',
|
||||
HomeCubit.getInstance().selectedSpace?.community.uuid ?? ''));
|
||||
}
|
||||
},
|
||||
child: BlocBuilder<CreateSceneBloc, CreateSceneState>(
|
||||
@ -57,30 +59,37 @@ class SceneView extends StatelessWidget {
|
||||
if (state is DeleteSceneSuccess) {
|
||||
if (state.success) {
|
||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!,
|
||||
HomeCubit.getInstance().selectedSpace!.id,
|
||||
HomeCubit.getInstance().selectedSpace!,
|
||||
showInDevice: pageType));
|
||||
BlocProvider.of<SceneBloc>(context)
|
||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
||||
BlocProvider.of<SceneBloc>(context).add(LoadAutomation(
|
||||
HomeCubit.getInstance().selectedSpace!.id,
|
||||
HomeCubit.getInstance().selectedSpace!.community.uuid));
|
||||
}
|
||||
}
|
||||
if (state is CreateSceneWithTasks) {
|
||||
if (state.success == true) {
|
||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!,
|
||||
HomeCubit.getInstance().selectedSpace!.id,
|
||||
HomeCubit.getInstance().selectedSpace!,
|
||||
showInDevice: pageType));
|
||||
BlocProvider.of<SceneBloc>(context)
|
||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
||||
context.read<SmartSceneSelectBloc>().add(const SmartSceneClearEvent());
|
||||
BlocProvider.of<SceneBloc>(context).add(LoadAutomation(
|
||||
HomeCubit.getInstance().selectedSpace!.id,
|
||||
HomeCubit.getInstance().selectedSpace!.community.uuid));
|
||||
context
|
||||
.read<SmartSceneSelectBloc>()
|
||||
.add(const SmartSceneClearEvent());
|
||||
}
|
||||
}
|
||||
return BlocListener<SceneBloc, SceneState>(
|
||||
listener: (context, state) {
|
||||
if (state is SceneTriggerSuccess) {
|
||||
context.showCustomSnackbar(
|
||||
message: 'Scene ${state.sceneName} triggered successfully!');
|
||||
message:
|
||||
'Scene ${state.sceneName} triggered successfully!');
|
||||
}
|
||||
},
|
||||
child: HomeCubit.getInstance().spaces?.isEmpty ?? true
|
||||
child: HomeCubit.getInstance().spaces.isEmpty
|
||||
? const CreateUnitWidget()
|
||||
: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
@ -114,25 +123,30 @@ class SceneView extends StatelessWidget {
|
||||
child: ListView(
|
||||
children: [
|
||||
Theme(
|
||||
data: ThemeData()
|
||||
.copyWith(dividerColor: Colors.transparent),
|
||||
data: ThemeData().copyWith(
|
||||
dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
tilePadding:
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: 6),
|
||||
initiallyExpanded: true,
|
||||
iconColor: ColorsManager.grayColor,
|
||||
title: const BodyMedium(text: 'Tap to run routines'),
|
||||
title: const BodyMedium(
|
||||
text: 'Tap to run routines'),
|
||||
children: [
|
||||
scenes.isNotEmpty
|
||||
? SceneGrid(
|
||||
scenes: scenes,
|
||||
loadingSceneId: state.loadingSceneId,
|
||||
loadingSceneId:
|
||||
state.loadingSceneId,
|
||||
disablePlayButton: false,
|
||||
loadingStates:
|
||||
state.loadingStates, // Add this line
|
||||
loadingStates: state
|
||||
.loadingStates, // Add this line
|
||||
)
|
||||
: const Center(
|
||||
child: BodyMedium(
|
||||
text: 'No scenes have been added yet',
|
||||
text:
|
||||
'No scenes have been added yet',
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
@ -142,25 +156,30 @@ class SceneView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
Theme(
|
||||
data: ThemeData()
|
||||
.copyWith(dividerColor: Colors.transparent),
|
||||
data: ThemeData().copyWith(
|
||||
dividerColor: Colors.transparent),
|
||||
child: ExpansionTile(
|
||||
initiallyExpanded: true,
|
||||
iconColor: ColorsManager.grayColor,
|
||||
tilePadding: const EdgeInsets.symmetric(horizontal: 6),
|
||||
title: const BodyMedium(text: 'Automation'),
|
||||
tilePadding:
|
||||
const EdgeInsets.symmetric(
|
||||
horizontal: 6),
|
||||
title: const BodyMedium(
|
||||
text: 'Automation'),
|
||||
children: [
|
||||
automationList.isNotEmpty
|
||||
? SceneGrid(
|
||||
scenes: automationList,
|
||||
loadingSceneId: state.loadingSceneId,
|
||||
loadingSceneId:
|
||||
state.loadingSceneId,
|
||||
disablePlayButton: true,
|
||||
loadingStates:
|
||||
state.loadingStates, // Add this line
|
||||
loadingStates: state
|
||||
.loadingStates, // Add this line
|
||||
)
|
||||
: const Center(
|
||||
child: BodyMedium(
|
||||
text: 'No automations have been added yet',
|
||||
text:
|
||||
'No automations have been added yet',
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
|
@ -25,7 +25,7 @@ class DeleteRoutineButton extends StatelessWidget {
|
||||
BlocProvider.of<SceneBloc>(context).add(LoadScenes(
|
||||
HomeCubit.getInstance().selectedSpace!.id, HomeCubit.getInstance().selectedSpace!));
|
||||
BlocProvider.of<SceneBloc>(context)
|
||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id));
|
||||
.add(LoadAutomation(HomeCubit.getInstance().selectedSpace!.id,HomeCubit.getInstance().selectedSpace!.community.uuid));
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -132,6 +132,10 @@ class SceneItem extends StatelessWidget {
|
||||
spaceUuid: HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
.id),
|
||||
communityId: HomeCubit.getInstance()
|
||||
.selectedSpace!
|
||||
.community
|
||||
.uuid,
|
||||
automationId: scene.id));
|
||||
},
|
||||
),
|
||||
|
@ -22,7 +22,7 @@ class SmartEnableAutomation extends StatelessWidget {
|
||||
child: BlocBuilder<SceneBloc, SceneState>(
|
||||
bloc: context.read<SceneBloc>()
|
||||
..add(
|
||||
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '')),
|
||||
LoadAutomation(HomeCubit.getInstance().selectedSpace?.id ?? '',HomeCubit.getInstance().selectedSpace?.community.uuid ?? '')),
|
||||
builder: (context, state) {
|
||||
if (state is SceneLoading) {
|
||||
return const Align(
|
||||
|
@ -153,7 +153,7 @@ abstract class ApiEndpoints {
|
||||
static const String getScene = '/scene/tap-to-run/{sceneId}';
|
||||
static const String getIconScene = '/scene/icon';
|
||||
|
||||
static const String getUnitAutomation = '/automation/{unitUuid}';
|
||||
static const String getUnitAutomation = '/projects/{projectId}/communities/{communityId}/spaces/{unitUuid}/automations';
|
||||
|
||||
static const String getAutomationDetails =
|
||||
'/automation/details/{automationId}';
|
||||
|
@ -78,10 +78,17 @@ class SceneApi {
|
||||
|
||||
//getAutomation
|
||||
|
||||
static Future<List<ScenesModel>> getAutomationByUnitId(String unitId) async {
|
||||
static Future<List<ScenesModel>> getAutomationByUnitId(
|
||||
String unitId,
|
||||
String communityId,
|
||||
String projectId,
|
||||
) async {
|
||||
try {
|
||||
final response = await _httpService.get(
|
||||
path: ApiEndpoints.getUnitAutomation.replaceAll('{unitUuid}', unitId),
|
||||
path: ApiEndpoints.getUnitAutomation
|
||||
.replaceAll('{unitUuid}', unitId)
|
||||
.replaceAll('{communityId}', communityId)
|
||||
.replaceAll('{projectId}', projectId),
|
||||
showServerMessage: false,
|
||||
expectedResponseModel: (json) {
|
||||
List<ScenesModel> scenes = [];
|
||||
|
Reference in New Issue
Block a user