mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
added routines details apis
This commit is contained in:
@ -6,8 +6,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_automation_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/create_scene_and_autoamtion/create_scene_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
import 'package:syncrow_web/pages/routiens/models/device_functions.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/models/routine_details_model.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
|
import 'package:syncrow_web/pages/routiens/models/routine_model.dart';
|
||||||
import 'package:syncrow_web/services/routines_api.dart';
|
import 'package:syncrow_web/services/routines_api.dart';
|
||||||
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
part 'routine_event.dart';
|
part 'routine_event.dart';
|
||||||
part 'routine_state.dart';
|
part 'routine_state.dart';
|
||||||
@ -31,6 +34,9 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
on<CreateAutomationEvent>(_onCreateAutomation);
|
on<CreateAutomationEvent>(_onCreateAutomation);
|
||||||
on<SetRoutineName>(_onSetRoutineName);
|
on<SetRoutineName>(_onSetRoutineName);
|
||||||
on<ResetRoutineState>(_onResetRoutineState);
|
on<ResetRoutineState>(_onResetRoutineState);
|
||||||
|
on<GetSceneDetails>(_onGetSceneDetails);
|
||||||
|
on<GetAutomationDetails>(_onGetAutomationDetails);
|
||||||
|
on<InitializeRoutineState>(_onInitializeRoutineState);
|
||||||
// on<RemoveFunction>(_onRemoveFunction);
|
// on<RemoveFunction>(_onRemoveFunction);
|
||||||
// on<ClearFunctions>(_onClearFunctions);
|
// on<ClearFunctions>(_onClearFunctions);
|
||||||
}
|
}
|
||||||
@ -39,8 +45,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;
|
||||||
@ -49,18 +55,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;
|
||||||
@ -71,22 +80,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);
|
||||||
@ -96,13 +109,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));
|
||||||
@ -111,11 +126,13 @@ 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));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final scenes = await SceneApi.getScenesByUnitId(event.unitId, event.communityId);
|
final scenes =
|
||||||
|
await SceneApi.getScenesByUnitId(event.unitId, event.communityId);
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
scenes: scenes,
|
scenes: scenes,
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
@ -130,7 +147,8 @@ 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));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -158,14 +176,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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +194,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
return actions.first['deviceId'] == 'delay';
|
return actions.first['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 +270,8 @@ 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 {
|
||||||
if (state.routineName == null || state.routineName!.isEmpty) {
|
if (state.routineName == null || state.routineName!.isEmpty) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
@ -349,38 +371,165 @@ 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);
|
||||||
emit(state.copyWith(ifItems: ifItems, selectedFunctions: selectedFunctions));
|
emit(state.copyWith(
|
||||||
|
ifItems: ifItems, selectedFunctions: selectedFunctions));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _changeOperatorOperator(ChangeAutomationOperator event, Emitter<RoutineState> emit) {
|
FutureOr<void> _changeOperatorOperator(
|
||||||
|
ChangeAutomationOperator event, Emitter<RoutineState> emit) {
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
selectedAutomationOperator: event.operator,
|
selectedAutomationOperator: event.operator,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
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(routineName: event.name));
|
emit(state.copyWith(routineName: event.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onGetSceneDetails(
|
||||||
|
GetSceneDetails event, Emitter<RoutineState> emit) async {
|
||||||
|
try {
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: true,
|
||||||
|
isTabToRun: event.isTabToRun,
|
||||||
|
isUpdate: true,
|
||||||
|
sceneId: event.sceneId,
|
||||||
|
isAutomation: false));
|
||||||
|
final sceneDetails = await SceneApi.getSceneDetails(event.sceneId);
|
||||||
|
add(InitializeRoutineState(sceneDetails));
|
||||||
|
} catch (e) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
errorMessage: 'Failed to load scene details',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _onGetAutomationDetails(
|
||||||
|
GetAutomationDetails event, Emitter<RoutineState> emit) async {
|
||||||
|
try {
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: true,
|
||||||
|
isAutomation: event.isAutomation,
|
||||||
|
automationId: event.automationId,
|
||||||
|
isTabToRun: false,
|
||||||
|
isUpdate: true,
|
||||||
|
));
|
||||||
|
final automationDetails =
|
||||||
|
await SceneApi.getAutomationDetails(event.automationId);
|
||||||
|
add(InitializeRoutineState(automationDetails));
|
||||||
|
} catch (e) {
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
errorMessage: 'Failed to load automation details',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onInitializeRoutineState(
|
||||||
|
InitializeRoutineState event, Emitter<RoutineState> emit) {
|
||||||
|
final routineDetails = event.routineDetails;
|
||||||
|
|
||||||
|
// Convert actions to draggable cards for the THEN container
|
||||||
|
final thenItems = routineDetails.actions.map((action) {
|
||||||
|
final Map<String, dynamic> cardData = {
|
||||||
|
'entityId': action.entityId,
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId':
|
||||||
|
action.actionExecutor == 'delay' ? 'delay' : action.entityId,
|
||||||
|
'title': action.actionExecutor == 'delay' ? 'Delay' : 'Device',
|
||||||
|
// fix this
|
||||||
|
'imagePath':
|
||||||
|
action.actionExecutor == 'delay' ? Assets.delay : Assets.logo,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add functions to selectedFunctions
|
||||||
|
if (action.executorProperty != null) {
|
||||||
|
final functions = <DeviceFunctionData>[
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: action.entityId,
|
||||||
|
functionCode: action.executorProperty!.functionCode ?? '',
|
||||||
|
value: action.executorProperty!.functionValue,
|
||||||
|
|
||||||
|
/// fix this
|
||||||
|
operationName: action.executorProperty?.functionCode ?? ''),
|
||||||
|
];
|
||||||
|
state.selectedFunctions[cardData['uniqueCustomId']] = functions;
|
||||||
|
}
|
||||||
|
|
||||||
|
return cardData;
|
||||||
|
}).toList() ??
|
||||||
|
[];
|
||||||
|
|
||||||
|
// Convert conditions to draggable cards for the IF container
|
||||||
|
final ifItems = routineDetails.conditions?.map((condition) {
|
||||||
|
final Map<String, dynamic> cardData = {
|
||||||
|
'entityId': condition.entityId,
|
||||||
|
'uniqueCustomId': const Uuid().v4(),
|
||||||
|
'deviceId': condition.entityId,
|
||||||
|
|
||||||
|
/// fix this
|
||||||
|
'title': 'Device',
|
||||||
|
|
||||||
|
/// fix this
|
||||||
|
'imagePath': Assets.logo,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add functions to selectedFunctions
|
||||||
|
final functions = <DeviceFunctionData>[
|
||||||
|
DeviceFunctionData(
|
||||||
|
entityId: condition.entityId,
|
||||||
|
functionCode: condition.expr.statusCode,
|
||||||
|
value: condition.expr.statusValue,
|
||||||
|
condition: condition.expr.comparator,
|
||||||
|
operationName: condition.expr.comparator,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
state.selectedFunctions[cardData['uniqueCustomId']] = functions;
|
||||||
|
|
||||||
|
return cardData;
|
||||||
|
}).toList() ??
|
||||||
|
[];
|
||||||
|
|
||||||
|
emit(state.copyWith(
|
||||||
|
isLoading: false,
|
||||||
|
routineName: routineDetails.name,
|
||||||
|
selectedIcon: routineDetails.iconId,
|
||||||
|
selectedAutomationOperator: routineDetails.decisionExpr,
|
||||||
|
effectiveTime: routineDetails.effectiveTime,
|
||||||
|
isAutomation: routineDetails.conditions != null,
|
||||||
|
isTabToRun: routineDetails.conditions == null,
|
||||||
|
thenItems: thenItems,
|
||||||
|
ifItems: ifItems,
|
||||||
|
selectedFunctions: Map.from(state.selectedFunctions),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
RoutineState _resetState() {
|
RoutineState _resetState() {
|
||||||
return const RoutineState(
|
return const RoutineState(
|
||||||
ifItems: [],
|
ifItems: [],
|
||||||
@ -402,7 +551,8 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<void> _onResetRoutineState(ResetRoutineState event, Emitter<RoutineState> emit) {
|
FutureOr<void> _onResetRoutineState(
|
||||||
|
ResetRoutineState event, Emitter<RoutineState> emit) {
|
||||||
emit(_resetState());
|
emit(_resetState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,6 +125,39 @@ class SetRoutineName extends RoutineEvent {
|
|||||||
List<Object> get props => [name];
|
List<Object> get props => [name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class GetSceneDetails extends RoutineEvent {
|
||||||
|
final String sceneId;
|
||||||
|
final bool isUpdate;
|
||||||
|
final bool isTabToRun;
|
||||||
|
const GetSceneDetails({
|
||||||
|
required this.sceneId,
|
||||||
|
required this.isUpdate,
|
||||||
|
required this.isTabToRun,
|
||||||
|
});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [sceneId];
|
||||||
|
}
|
||||||
|
|
||||||
|
class GetAutomationDetails extends RoutineEvent {
|
||||||
|
final String automationId;
|
||||||
|
final bool isUpdate;
|
||||||
|
final bool isAutomation;
|
||||||
|
const GetAutomationDetails({
|
||||||
|
required this.automationId,
|
||||||
|
this.isUpdate = false,
|
||||||
|
this.isAutomation = false,
|
||||||
|
});
|
||||||
|
@override
|
||||||
|
List<Object> get props => [automationId];
|
||||||
|
}
|
||||||
|
|
||||||
|
class InitializeRoutineState extends RoutineEvent {
|
||||||
|
final RoutineDetailsModel routineDetails;
|
||||||
|
const InitializeRoutineState(this.routineDetails);
|
||||||
|
@override
|
||||||
|
List<Object> get props => [routineDetails];
|
||||||
|
}
|
||||||
|
|
||||||
class ResetRoutineState extends RoutineEvent {}
|
class ResetRoutineState extends RoutineEvent {}
|
||||||
|
|
||||||
class ClearFunctions extends RoutineEvent {}
|
class ClearFunctions extends RoutineEvent {}
|
||||||
|
@ -18,6 +18,9 @@ class RoutineState extends Equatable {
|
|||||||
final bool isAutomation;
|
final bool isAutomation;
|
||||||
final String selectedAutomationOperator;
|
final String selectedAutomationOperator;
|
||||||
final EffectiveTime? effectiveTime;
|
final EffectiveTime? effectiveTime;
|
||||||
|
final String? sceneId;
|
||||||
|
final String? automationId;
|
||||||
|
final bool? isUpdate;
|
||||||
|
|
||||||
const RoutineState({
|
const RoutineState({
|
||||||
this.ifItems = const [],
|
this.ifItems = const [],
|
||||||
@ -37,6 +40,9 @@ class RoutineState extends Equatable {
|
|||||||
this.isAutomation = false,
|
this.isAutomation = false,
|
||||||
this.selectedAutomationOperator = 'or',
|
this.selectedAutomationOperator = 'or',
|
||||||
this.effectiveTime,
|
this.effectiveTime,
|
||||||
|
this.sceneId,
|
||||||
|
this.automationId,
|
||||||
|
this.isUpdate,
|
||||||
});
|
});
|
||||||
|
|
||||||
RoutineState copyWith({
|
RoutineState copyWith({
|
||||||
@ -56,6 +62,9 @@ class RoutineState extends Equatable {
|
|||||||
bool? isAutomation,
|
bool? isAutomation,
|
||||||
String? selectedAutomationOperator,
|
String? selectedAutomationOperator,
|
||||||
EffectiveTime? effectiveTime,
|
EffectiveTime? effectiveTime,
|
||||||
|
String? sceneId,
|
||||||
|
String? automationId,
|
||||||
|
bool? isUpdate,
|
||||||
}) {
|
}) {
|
||||||
return RoutineState(
|
return RoutineState(
|
||||||
ifItems: ifItems ?? this.ifItems,
|
ifItems: ifItems ?? this.ifItems,
|
||||||
@ -67,13 +76,19 @@ class RoutineState extends Equatable {
|
|||||||
errorMessage: errorMessage ?? this.errorMessage,
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
routineName: routineName ?? this.routineName,
|
routineName: routineName ?? this.routineName,
|
||||||
selectedIcon: selectedIcon ?? this.selectedIcon,
|
selectedIcon: selectedIcon ?? this.selectedIcon,
|
||||||
loadScenesErrorMessage: loadScenesErrorMessage ?? this.loadScenesErrorMessage,
|
loadScenesErrorMessage:
|
||||||
loadAutomationErrorMessage: loadAutomationErrorMessage ?? this.loadAutomationErrorMessage,
|
loadScenesErrorMessage ?? this.loadScenesErrorMessage,
|
||||||
|
loadAutomationErrorMessage:
|
||||||
|
loadAutomationErrorMessage ?? this.loadAutomationErrorMessage,
|
||||||
searchText: searchText ?? this.searchText,
|
searchText: searchText ?? this.searchText,
|
||||||
isTabToRun: isTabToRun ?? this.isTabToRun,
|
isTabToRun: isTabToRun ?? this.isTabToRun,
|
||||||
isAutomation: isAutomation ?? this.isAutomation,
|
isAutomation: isAutomation ?? this.isAutomation,
|
||||||
selectedAutomationOperator: selectedAutomationOperator ?? this.selectedAutomationOperator,
|
selectedAutomationOperator:
|
||||||
|
selectedAutomationOperator ?? this.selectedAutomationOperator,
|
||||||
effectiveTime: effectiveTime ?? this.effectiveTime,
|
effectiveTime: effectiveTime ?? this.effectiveTime,
|
||||||
|
sceneId: sceneId ?? this.sceneId,
|
||||||
|
automationId: automationId ?? this.automationId,
|
||||||
|
isUpdate: isUpdate ?? this.isUpdate,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,6 +109,9 @@ class RoutineState extends Equatable {
|
|||||||
isTabToRun,
|
isTabToRun,
|
||||||
isAutomation,
|
isAutomation,
|
||||||
selectedAutomationOperator,
|
selectedAutomationOperator,
|
||||||
effectiveTime
|
effectiveTime,
|
||||||
|
sceneId,
|
||||||
|
automationId,
|
||||||
|
isUpdate
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,14 @@ class ScenesModel {
|
|||||||
|
|
||||||
String toRawJson() => json.encode(toJson());
|
String toRawJson() => json.encode(toJson());
|
||||||
|
|
||||||
Uint8List get iconInBytes => base64Decode(icon ?? '');
|
Uint8List? get iconInBytes {
|
||||||
|
if (icon == null || icon?.isEmpty == true) return null;
|
||||||
|
try {
|
||||||
|
return base64Decode(icon!);
|
||||||
|
} catch (e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
factory ScenesModel.fromJson(Map<String, dynamic> json,
|
factory ScenesModel.fromJson(Map<String, dynamic> json,
|
||||||
{bool? isAutomation}) {
|
{bool? isAutomation}) {
|
||||||
|
@ -6,8 +6,16 @@ import 'package:syncrow_web/pages/routiens/widgets/then_container.dart';
|
|||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
|
|
||||||
class CreateNewRoutineView extends StatelessWidget {
|
class CreateNewRoutineView extends StatelessWidget {
|
||||||
const CreateNewRoutineView({super.key});
|
final bool isUpdate;
|
||||||
|
final String? routineId;
|
||||||
|
final bool isScene;
|
||||||
|
|
||||||
|
const CreateNewRoutineView({
|
||||||
|
super.key,
|
||||||
|
this.isUpdate = false,
|
||||||
|
this.routineId,
|
||||||
|
this.isScene = true,
|
||||||
|
});
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
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/device_managment/all_devices/bloc/switch_tabs/switch_tabs_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
import 'package:syncrow_web/pages/routiens/bloc/routine_bloc/routine_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/routiens/view/create_new_routine_view.dart';
|
||||||
import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart';
|
import 'package:syncrow_web/pages/routiens/widgets/main_routine_view/routine_view_card.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
@ -85,7 +85,7 @@ class SceneApi {
|
|||||||
|
|
||||||
List<ScenesModel> scenes = [];
|
List<ScenesModel> scenes = [];
|
||||||
for (var scene in scenesJson) {
|
for (var scene in scenesJson) {
|
||||||
scenes.add(ScenesModel.fromJson(scene));
|
scenes.add(ScenesModel.fromJson(scene, isAutomation: false));
|
||||||
}
|
}
|
||||||
return scenes;
|
return scenes;
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user