Compare commits

..

14 Commits

15 changed files with 144 additions and 130 deletions

View File

@ -244,6 +244,7 @@ SOS
SwitchFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
ModeFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
TempSetFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
CurrentTempFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
LevelFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
ChildLockFunction(deviceId: uuid ?? '', deviceName: name ?? ''),
];

View File

@ -29,7 +29,7 @@ class TwoGangSwitchBloc extends Bloc<TwoGangSwitchEvent, TwoGangSwitchState> {
final status =
await DevicesManagementApi().getDeviceStatus(event.deviceId);
deviceStatus = TwoGangStatusModel.fromJson(event.deviceId, status.status);
_listenToChanges(emit);
_listenToChanges(event.deviceId);
emit(TwoGangSwitchStatusLoaded(deviceStatus));
} catch (e) {
emit(TwoGangSwitchError(e.toString()));

View File

@ -30,7 +30,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
var response = await DevicesManagementApi().getDeviceStatus(deviceId);
deviceStatus = WallSensorModel.fromJson(response.status);
emit(WallSensorUpdateState(wallSensorModel: deviceStatus));
_listenToChanges(emit);
_listenToChanges(emit, deviceId);
} catch (e) {
emit(WallSensorFailedState(error: e.toString()));
return;
@ -52,7 +52,7 @@ class WallSensorBloc extends Bloc<WallSensorEvent, WallSensorState> {
}
}
_listenToChanges(Emitter<WallSensorState> emit) {
_listenToChanges(Emitter<WallSensorState> emit, deviceId) {
try {
DatabaseReference ref =
FirebaseDatabase.instance.ref('device-status/$deviceId');

View File

@ -41,6 +41,11 @@ class DeviceDialogHelper {
final deviceSelectedFunctions =
routineBloc.state.selectedFunctions[data['uniqueCustomId']] ?? [];
if (removeComparetors) {
//remove the current temp function in the 'if container'
functions.removeAt(3);
}
switch (productType) {
case 'AC':
return ACHelper.showACFunctionsDialog(context, functions, data['device'],

View File

@ -151,3 +151,32 @@ class ChildLockFunction extends ACFunction {
),
];
}
class CurrentTempFunction extends ACFunction {
final int min;
final int max;
final int step;
CurrentTempFunction({required super.deviceId, required super.deviceName})
: min = -100,
max = 990,
step = 1,
super(
code: 'temp_current',
operationName: 'Current Temperature',
icon: Assets.currentTemp,
);
@override
List<ACOperationalValue> getOperationalValues() {
List<ACOperationalValue> values = [];
for (int temp = min; temp <= max; temp += step) {
values.add(ACOperationalValue(
icon: Assets.currentTemp,
description: "${temp / 10}°C",
value: temp,
));
}
return values;
}
}

View File

@ -329,8 +329,8 @@ class ACHelper {
) {
return Slider(
value: initialValue is int ? initialValue.toDouble() : 200.0,
min: 200,
max: 300,
min: selectCode == 'temp_current' ? -100 : 200,
max: selectCode == 'temp_current' ? 900 : 300,
divisions: 10,
label: '${((initialValue ?? 160) / 10).toInt()}°C',
onChanged: (value) {

View File

@ -33,14 +33,13 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
@override
Widget build(BuildContext context) {
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(
builder: (context, state) {
List<CommunityModel> list =
state.isSearching ? state.filteredCommunity : state.communityList;
return BlocBuilder<SpaceTreeBloc, SpaceTreeState>(builder: (context, state) {
List<CommunityModel> list = state.isSearching ? state.filteredCommunity : state.communityList;
return Container(
height: MediaQuery.sizeOf(context).height,
decoration:
widget.isSide == true ? subSectionContainerDecoration : null,
decoration: widget.isSide == true
? subSectionContainerDecoration.copyWith(color: ColorsManager.whiteColors)
: const BoxDecoration(color: ColorsManager.whiteColors),
child: state is SpaceTreeLoadingState
? const Center(child: CircularProgressIndicator())
: Column(
@ -50,8 +49,7 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
decoration: const BoxDecoration(
color: ColorsManager.circleRolesBackground,
borderRadius: BorderRadius.only(
topRight: Radius.circular(20),
topLeft: Radius.circular(20)),
topRight: Radius.circular(20), topLeft: Radius.circular(20)),
),
child: Padding(
padding: const EdgeInsets.all(8.0),
@ -60,35 +58,27 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: const BorderRadius.all(
Radius.circular(20)),
border: Border.all(
color: ColorsManager.grayBorder)),
borderRadius: const BorderRadius.all(Radius.circular(20)),
border: Border.all(color: ColorsManager.grayBorder)),
child: TextFormField(
style:
const TextStyle(color: Colors.black),
style: const TextStyle(color: Colors.black),
onChanged: (value) {
context
.read<SpaceTreeBloc>()
.add(SearchQueryEvent(value));
context.read<SpaceTreeBloc>().add(SearchQueryEvent(value));
},
decoration: textBoxDecoration(radios: 20)!
.copyWith(
decoration: textBoxDecoration(radios: 20)!.copyWith(
fillColor: Colors.white,
suffixIcon: Padding(
padding:
const EdgeInsets.only(right: 16),
padding: const EdgeInsets.only(right: 16),
child: SvgPicture.asset(
Assets.textFieldSearch,
width: 24,
height: 24,
),
),
hintStyle: context.textTheme.bodyMedium
?.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12,
color: ColorsManager.textGray),
hintStyle: context.textTheme.bodyMedium?.copyWith(
fontWeight: FontWeight.w400,
fontSize: 12,
color: ColorsManager.textGray),
),
),
),
@ -99,9 +89,7 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
)
: CustomSearchBar(
onSearchChanged: (query) {
context
.read<SpaceTreeBloc>()
.add(SearchQueryEvent(query));
context.read<SpaceTreeBloc>().add(SearchQueryEvent(query));
},
),
const SizedBox(height: 16),
@ -117,18 +105,14 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
? Center(
child: Text(
'No results found',
style: Theme.of(context)
.textTheme
.bodySmall!
.copyWith(
style: Theme.of(context).textTheme.bodySmall!.copyWith(
color: ColorsManager.lightGrayColor,
fontWeight: FontWeight.w400,
),
),
)
: Scrollbar(
scrollbarOrientation:
ScrollbarOrientation.left,
scrollbarOrientation: ScrollbarOrientation.left,
thumbVisibility: true,
controller: _scrollController,
child: Padding(
@ -138,39 +122,30 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
shrinkWrap: true,
children: list
.map(
(community) =>
CustomExpansionTileSpaceTree(
(community) => CustomExpansionTileSpaceTree(
title: community.name,
isSelected: state
.selectedCommunities
isSelected: state.selectedCommunities
.contains(community.uuid),
isSoldCheck: state
.selectedCommunities
isSoldCheck: state.selectedCommunities
.contains(community.uuid),
onExpansionChanged: () {
context
.read<SpaceTreeBloc>()
.add(OnCommunityExpanded(
community.uuid));
.add(OnCommunityExpanded(community.uuid));
},
isExpanded: state
.expandedCommunities
isExpanded: state.expandedCommunities
.contains(community.uuid),
onItemSelected: () {
context
.read<SpaceTreeBloc>()
.add(OnCommunitySelected(
community.uuid,
community.spaces));
context.read<SpaceTreeBloc>().add(
OnCommunitySelected(
community.uuid, community.spaces));
widget.onSelect();
},
children:
community.spaces.map((space) {
children: community.spaces.map((space) {
return CustomExpansionTileSpaceTree(
title: space.name,
isExpanded: state
.expandedSpaces
.contains(space.uuid),
isExpanded:
state.expandedSpaces.contains(space.uuid),
onItemSelected: () {
context.read<SpaceTreeBloc>().add(
OnSpaceSelected(community, space.uuid ?? '',
@ -178,20 +153,14 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
widget.onSelect();
},
onExpansionChanged: () {
context
.read<SpaceTreeBloc>()
.add(OnSpaceExpanded(
community.uuid,
space.uuid ?? ''));
context.read<SpaceTreeBloc>().add(
OnSpaceExpanded(
community.uuid, space.uuid ?? ''));
},
isSelected: state
.selectedSpaces
.contains(
space.uuid) ||
state.soldCheck
.contains(space.uuid),
isSoldCheck: state.soldCheck
.contains(space.uuid),
isSelected:
state.selectedSpaces.contains(space.uuid) ||
state.soldCheck.contains(space.uuid),
isSoldCheck: state.soldCheck.contains(space.uuid),
children: _buildNestedSpaces(
context, state, space, community),
);
@ -279,8 +248,8 @@ class _SpaceTreeViewState extends State<SpaceTreeView> {
BuildContext context, SpaceTreeState state, SpaceModel space, CommunityModel community) {
return space.children.map((child) {
return CustomExpansionTileSpaceTree(
isSelected: state.selectedSpaces.contains(child.uuid) ||
state.soldCheck.contains(child.uuid),
isSelected:
state.selectedSpaces.contains(child.uuid) || state.soldCheck.contains(child.uuid),
isSoldCheck: state.soldCheck.contains(child.uuid),
title: child.name,
isExpanded: state.expandedSpaces.contains(child.uuid),

View File

@ -1,4 +1,5 @@
import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
@ -457,7 +458,8 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
emit(SpaceManagementLoading());
try {
final updatedSpaces = await saveSpacesHierarchically(event.spaces, event.communityUuid);
final updatedSpaces =
await saveSpacesHierarchically(event.context, event.spaces, event.communityUuid);
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
@ -508,9 +510,14 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
}
Future<List<SpaceModel>> saveSpacesHierarchically(
List<SpaceModel> spaces, String communityUuid) async {
BuildContext context, List<SpaceModel> spaces, String communityUuid) async {
final orderedSpaces = flattenHierarchy(spaces);
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
var spaceBloc = context.read<SpaceTreeBloc>();
List<CommunityModel> communities = spaceBloc.state.communityList;
CommunityModel? selectedCommunity = communities.firstWhere(
(community) => community.uuid == communityUuid,
);
final parentsToDelete = orderedSpaces.where((space) =>
space.status == SpaceStatus.deleted &&
@ -532,7 +539,13 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
if (space.uuid != null && space.uuid!.isNotEmpty) {
List<TagModelUpdate> tagUpdates = [];
final prevSpace = await _api.getSpace(communityUuid, space.uuid!, projectUuid);
List<SpaceModel> matchedSpaces =
selectedCommunity.spaces.where((space) => space.uuid == space.uuid).toList();
if (matchedSpaces.isEmpty) continue;
final prevSpace = matchedSpaces[0];
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
final List<SubspaceModel>? newSubspaces = space.subspaces;
@ -609,6 +622,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
subspaces: subspaceUpdates,
tags: tagUpdates,
direction: space.incomingConnection?.direction,
spaceModelUuid: space.spaceModel?.uuid,
projectId: projectUuid);
} else {
// Call create if the space does not have a UUID

View File

@ -58,14 +58,16 @@ class CreateSpaceEvent extends SpaceManagementEvent {
class SaveSpacesEvent extends SpaceManagementEvent {
final List<SpaceModel> spaces;
final String communityUuid;
final BuildContext context;
const SaveSpacesEvent({
const SaveSpacesEvent(
this.context, {
required this.spaces,
required this.communityUuid,
});
@override
List<Object> get props => [spaces, communityUuid];
List<Object> get props => [spaces, communityUuid, context];
}
class UpdateSpacePositionEvent extends SpaceManagementEvent {
@ -170,4 +172,4 @@ class UpdateSpaceModelCache extends SpaceManagementEvent {
class DeleteSpaceModelFromCache extends SpaceManagementEvent {
final String deletedUuid;
DeleteSpaceModelFromCache(this.deletedUuid);
}
}

View File

@ -460,6 +460,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
String communityUuid = widget.selectedCommunity!.uuid;
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
context,
spaces: spacesToSave,
communityUuid: communityUuid,
));

View File

@ -28,10 +28,11 @@ class LinkSpaceToModelBloc
try {
BuildContext context = NavigationService.navigatorKey.currentContext!;
var spaceBloc = context.read<SpaceTreeBloc>();
spacesListIds.clear();
for (var communityId in spaceBloc.state.selectedCommunities) {
List<String> spacesList =
spaceBloc.state.selectedCommunityAndSpaces[communityId] ?? [];
spacesListIds = spacesList;
spacesListIds.addAll(spacesList);
}
hasSelectedSpaces =
spaceBloc.state.selectedCommunities.any((communityId) {

View File

@ -18,8 +18,10 @@ import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_room_widget.dart';
import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/constants/assets.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
import 'package:syncrow_web/utils/string_utils.dart';
class SpaceModelCardWidget extends StatelessWidget {
class SpaceModelCardWidget extends StatelessWidget with HelperResponsiveLayout {
final SpaceTemplateModel model;
final BuildContext? pageContext;
final bool topActionsDisabled;
@ -76,14 +78,17 @@ class SpaceModelCardWidget extends StatelessWidget {
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
model.modelName,
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: Colors.black,
fontWeight: FontWeight.bold,
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
Expanded(
child: Text(
StringUtils.capitalizeFirstLetter(model.modelName),
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
color: ColorsManager.blackColor,
fontWeight: FontWeight.bold,
fontSize: isSmallScreenSize(context) ? 13 : 20,
),
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
if (!topActionsDisabled)
Row(
@ -95,15 +100,12 @@ class SpaceModelCardWidget extends StatelessWidget {
builder: (BuildContext dialogContext) {
return BlocProvider<LinkSpaceToModelBloc>(
create: (_) => LinkSpaceToModelBloc(),
child: BlocListener<LinkSpaceToModelBloc,
LinkSpaceToModelState>(
child: BlocListener<LinkSpaceToModelBloc, LinkSpaceToModelState>(
listenWhen: (previous, current) {
return previous != current;
},
listener: (context, state) {
final _bloc =
BlocProvider.of<LinkSpaceToModelBloc>(
context);
final _bloc = BlocProvider.of<LinkSpaceToModelBloc>(context);
if (state is SpaceModelLoading) {
showDialog(
context: context,
@ -111,19 +113,14 @@ class SpaceModelCardWidget extends StatelessWidget {
builder: (BuildContext context) {
return Dialog(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(
20)),
borderRadius: BorderRadius.circular(20)),
elevation: 10,
backgroundColor: Colors.white,
child: Padding(
padding:
const EdgeInsets.symmetric(
vertical: 30,
horizontal: 50),
padding: const EdgeInsets.symmetric(
vertical: 30, horizontal: 50),
child: Column(
mainAxisSize:
MainAxisSize.min,
mainAxisSize: MainAxisSize.min,
children: [
CustomLoadingIndicator(),
],
@ -132,19 +129,14 @@ class SpaceModelCardWidget extends StatelessWidget {
);
},
);
} else if (state
is AlreadyHaveLinkedState) {
} else if (state is AlreadyHaveLinkedState) {
Navigator.of(dialogContext).pop();
showOverwriteDialog(
context, _bloc, model);
} else if (state
is SpaceValidationSuccess) {
showOverwriteDialog(context, _bloc, model);
} else if (state is SpaceValidationSuccess) {
_bloc.add(LinkSpaceModelEvent(
isOverWrite: false,
selectedSpaceMode: model.uuid));
isOverWrite: false, selectedSpaceMode: model.uuid));
Future.delayed(
const Duration(seconds: 1), () {
Future.delayed(const Duration(seconds: 1), () {
Navigator.of(dialogContext).pop();
Navigator.of(dialogContext).pop();
Navigator.of(dialogContext).pop();
@ -152,29 +144,23 @@ class SpaceModelCardWidget extends StatelessWidget {
showDialog(
context: context,
builder:
(BuildContext dialogContext) {
builder: (BuildContext dialogContext) {
return const LinkingSuccessful();
},
).then((v) {
Future.delayed(
const Duration(seconds: 2), () {
Future.delayed(const Duration(seconds: 2), () {
Navigator.of(dialogContext).pop();
});
});
} else if (state
is SpaceModelLinkSuccess) {
} else if (state is SpaceModelLinkSuccess) {
Navigator.of(dialogContext).pop();
Navigator.of(dialogContext).pop();
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext
successDialogContext) {
Future.delayed(
const Duration(seconds: 2), () {
Navigator.of(successDialogContext)
.pop();
builder: (BuildContext successDialogContext) {
Future.delayed(const Duration(seconds: 2), () {
Navigator.of(successDialogContext).pop();
});
return const LinkingSuccessful();
@ -232,8 +218,7 @@ class SpaceModelCardWidget extends StatelessWidget {
),
),
),
if (productTagCount.isNotEmpty &&
model.subspaceModels != null)
if (productTagCount.isNotEmpty && model.subspaceModels != null)
Container(
width: 1.0,
color: ColorsManager.softGray,

View File

@ -6,7 +6,6 @@ import 'package:syncrow_web/pages/routines/models/routine_details_model.dart';
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
import 'package:syncrow_web/services/api/http_service.dart';
import 'package:syncrow_web/utils/constants/api_const.dart';
import 'package:syncrow_web/utils/constants/temp_const.dart';
class SceneApi {
static final HTTPService _httpService = HTTPService();

View File

@ -227,6 +227,7 @@ class CommunitySpaceManagementApi {
required Offset position,
List<TagModelUpdate>? tags,
List<UpdateSubspaceTemplateModel>? subspaces,
String? spaceModelUuid,
required String projectId}) async {
try {
final body = {
@ -238,6 +239,7 @@ class CommunitySpaceManagementApi {
'icon': icon,
'subspace': subspaces,
'tags': tags,
'spaceModelUuid': spaceModelUuid,
};
if (parentId != null) {
body['parentUuid'] = parentId;

View File

@ -0,0 +1,6 @@
class StringUtils {
static String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1);
}
}