Compare commits

..

19 Commits

Author SHA1 Message Date
af4c0f84cb fixed assign tag issue 2025-02-05 11:15:38 +04:00
c2b77ad1fc fixed issue on duplicate 2025-02-05 11:15:25 +04:00
d5fcbe2601 added edit space sibling conflict 2025-02-04 14:15:39 +04:00
1fa33a271f added disabled space model button on adding tags and subspace, vice versa 2025-02-04 13:46:11 +04:00
09e2564183 add disabled state to ButtonContentWidget, When disabled, the entire button becomes opaque 2025-02-04 13:29:09 +04:00
5dee6c2842 Merge pull request #81 from SyncrowIOT/bugifx/tag-validation
Bugifx/tag-validation
2025-02-04 12:36:15 +04:00
c5c5088724 removed logs 2025-02-04 11:38:11 +04:00
d1d570b40f Fixed issue in loading space model 2025-02-04 11:36:26 +04:00
a43ff3c07d Merge pull request #80 from SyncrowIOT/side_tree
Side tree
2025-02-04 01:56:52 +03:00
572520eed5 Fixed issues 2025-02-04 01:54:18 +03:00
5e5f127a4b duplicate should be in same vertical offset 2025-02-04 00:12:20 +04:00
6f51c2d2b6 provide all tags on edit space 2025-02-03 22:23:53 +04:00
a18e8443d0 Merge pull request #77 from SyncrowIOT/web_bugs_fixes
Fix bugs related to the user table, privacy policy, and table filter.
2025-02-03 14:39:38 +03:00
72241cba6c added error validation 2025-02-03 14:47:05 +04:00
506531e16a Fetch devices based on selection 2025-02-03 11:15:36 +03:00
ab3edbaf57 Merge pull request #79 from SyncrowIOT/bugfix/fix-duplicate-space
Bugfix/fix-duplicate-space
2025-02-02 23:39:37 +04:00
64e3fb7f34 removed print 2025-02-02 23:38:04 +04:00
e6e46be9b4 fixed issues in create space and duplicate 2025-02-02 23:16:34 +04:00
91dfd53477 fixed issue in creating space 2025-02-02 21:02:58 +04:00
27 changed files with 478 additions and 239 deletions

View File

@ -1,6 +1,8 @@
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.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/models/devices_model.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/services/devices_mang_api.dart'; import 'package:syncrow_web/services/devices_mang_api.dart';
part 'device_managment_event.dart'; part 'device_managment_event.dart';
@ -32,7 +34,20 @@ class DeviceManagementBloc extends Bloc<DeviceManagementEvent, DeviceManagementS
Future<void> _onFetchDevices(FetchDevices event, Emitter<DeviceManagementState> emit) async { Future<void> _onFetchDevices(FetchDevices event, Emitter<DeviceManagementState> emit) async {
emit(DeviceManagementLoading()); emit(DeviceManagementLoading());
try { try {
final devices = await DevicesManagementApi().fetchDevices(event.communityId, event.spaceId); List<AllDevicesModel> devices = [];
_devices.clear();
var spaceBloc = event.context.read<SpaceTreeBloc>();
if (spaceBloc.state.selectedCommunities.isEmpty) {
devices = await DevicesManagementApi().fetchDevices('', '');
} else {
for (var community in spaceBloc.state.selectedCommunities) {
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
for (var space in spacesList) {
devices.addAll(await DevicesManagementApi().fetchDevices(community, space));
}
}
}
_selectedDevices.clear(); _selectedDevices.clear();
_devices = devices; _devices = devices;
_filteredDevices = devices; _filteredDevices = devices;

View File

@ -8,12 +8,13 @@ abstract class DeviceManagementEvent extends Equatable {
} }
class FetchDevices extends DeviceManagementEvent { class FetchDevices extends DeviceManagementEvent {
final String communityId; // final Map<String, List<String>> selectedCommunitiesSpaces;
final String spaceId; // final String spaceId;
final BuildContext context;
const FetchDevices(this.communityId, this.spaceId); const FetchDevices(this.context);
@override @override
List<Object?> get props => [communityId, spaceId]; List<Object?> get props => [context];
} }
class FilterDevices extends DeviceManagementEvent { class FilterDevices extends DeviceManagementEvent {

View File

@ -19,7 +19,7 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
return MultiBlocProvider( return MultiBlocProvider(
providers: [ providers: [
BlocProvider( BlocProvider(
create: (context) => DeviceManagementBloc()..add(const FetchDevices('', '')), create: (context) => DeviceManagementBloc()..add(FetchDevices(context)),
), ),
], ],
child: WebScaffold( child: WebScaffold(

View File

@ -8,6 +8,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_search_filters.dart'; import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_search_filters.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart'; import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart';
import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart'; import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart'; import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
import 'package:syncrow_web/utils/format_date_time.dart'; import 'package:syncrow_web/utils/format_date_time.dart';
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart'; import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
@ -62,11 +63,10 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
return Row( return Row(
children: [ children: [
const Expanded( Expanded(child: SpaceTreeView(
child: SpaceTreeView( onSelect: () {
// onSelectAction: (String communityId, String spaceId) { context.read<DeviceManagementBloc>().add(FetchDevices(context));
// context.read<DeviceManagementBloc>().add(FetchDevices(communityId, spaceId)); },
// },
)), )),
Expanded( Expanded(
flex: 3, flex: 3,

View File

@ -85,7 +85,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters> with HelperRe
productNameController.clear(); productNameController.clear();
context.read<DeviceManagementBloc>() context.read<DeviceManagementBloc>()
..add(ResetFilters()) ..add(ResetFilters())
..add(const FetchDevices('', '')); ..add(FetchDevices(context));
}, },
); );
} }

View File

@ -816,7 +816,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
FutureOr<void> _fetchDevices(FetchDevicesInRoutine event, Emitter<RoutineState> emit) async { FutureOr<void> _fetchDevices(FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
emit(state.copyWith(isLoading: true)); emit(state.copyWith(isLoading: true));
try { try {
final devices = await DevicesManagementApi().fetchDevices(communityId, spaceId); final devices = await DevicesManagementApi().fetchDevices('', '');
emit(state.copyWith(isLoading: false, devices: devices)); emit(state.copyWith(isLoading: false, devices: devices));
} catch (e) { } catch (e) {

View File

@ -32,7 +32,7 @@ class _RoutinesViewState extends State<RoutinesView> {
} }
return Row( return Row(
children: [ children: [
const Expanded( Expanded(
child: child:
// SideSpacesView( // SideSpacesView(
// onSelectAction: (String communityId, String spaceId) { // onSelectAction: (String communityId, String spaceId) {
@ -41,7 +41,9 @@ class _RoutinesViewState extends State<RoutinesView> {
// // ..add(LoadAutomation(spaceId)); // // ..add(LoadAutomation(spaceId));
// }, // },
// ) // )
SpaceTreeView()), SpaceTreeView(
onSelect: () {},
)),
Expanded( Expanded(
flex: 3, flex: 3,
child: Padding( child: Padding(

View File

@ -6,8 +6,8 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
import 'package:syncrow_web/services/space_mana_api.dart'; import 'package:syncrow_web/services/space_mana_api.dart';
class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> { class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
String selectedCommunityId = ''; String selectedCommunityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
String selectedSpaceId = ''; String selectedSpaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
SpaceTreeBloc() : super(const SpaceTreeState()) { SpaceTreeBloc() : super(const SpaceTreeState()) {
on<InitialEvent>(_fetchSpaces); on<InitialEvent>(_fetchSpaces);
@ -87,6 +87,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
List.from(state.selectedCommunities.toSet().toList()); List.from(state.selectedCommunities.toSet().toList());
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList()); List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList()); List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
List<String> childrenIds = _getAllChildIds(event.children); List<String> childrenIds = _getAllChildIds(event.children);
@ -101,10 +102,13 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
updatedSoldChecks.removeWhere(childrenIds.contains); updatedSoldChecks.removeWhere(childrenIds.contains);
} }
communityAndSpaces[event.communityId] = updatedSelectedSpaces;
emit(state.copyWith( emit(state.copyWith(
selectedCommunities: updatedSelectedCommunities, selectedCommunities: updatedSelectedCommunities,
selectedSpaces: updatedSelectedSpaces, selectedSpaces: updatedSelectedSpaces,
soldCheck: updatedSoldChecks)); soldCheck: updatedSoldChecks,
selectedCommunityAndSpaces: communityAndSpaces));
} catch (e) { } catch (e) {
emit(const SpaceTreeErrorState('Something went wrong')); emit(const SpaceTreeErrorState('Something went wrong'));
} }
@ -116,6 +120,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
List.from(state.selectedCommunities.toSet().toList()); List.from(state.selectedCommunities.toSet().toList());
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList()); List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList()); List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
List<String> childrenIds = _getAllChildIds(event.children); List<String> childrenIds = _getAllChildIds(event.children);
bool isChildSelected = false; bool isChildSelected = false;
@ -166,10 +171,13 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
} }
} }
communityAndSpaces[event.communityId] = updatedSelectedSpaces;
emit(state.copyWith( emit(state.copyWith(
selectedCommunities: updatedSelectedCommunities, selectedCommunities: updatedSelectedCommunities,
selectedSpaces: updatedSelectedSpaces, selectedSpaces: updatedSelectedSpaces,
soldCheck: updatedSoldChecks)); soldCheck: updatedSoldChecks,
selectedCommunityAndSpaces: communityAndSpaces));
emit(state.copyWith(selectedSpaces: updatedSelectedSpaces)); emit(state.copyWith(selectedSpaces: updatedSelectedSpaces));
} catch (e) { } catch (e) {
emit(const SpaceTreeErrorState('Something went wrong')); emit(const SpaceTreeErrorState('Something went wrong'));

View File

@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
class SpaceTreeState extends Equatable { class SpaceTreeState extends Equatable {
final Map<String, List<String>> selectedCommunityAndSpaces;
final List<CommunityModel> communityList; final List<CommunityModel> communityList;
final List<CommunityModel> filteredCommunity; final List<CommunityModel> filteredCommunity;
final List<String> expandedCommunities; final List<String> expandedCommunities;
@ -19,7 +20,8 @@ class SpaceTreeState extends Equatable {
this.selectedCommunities = const [], this.selectedCommunities = const [],
this.selectedSpaces = const [], this.selectedSpaces = const [],
this.soldCheck = const [], this.soldCheck = const [],
this.isSearching = false}); this.isSearching = false,
this.selectedCommunityAndSpaces = const {}});
SpaceTreeState copyWith( SpaceTreeState copyWith(
{List<CommunityModel>? communitiesList, {List<CommunityModel>? communitiesList,
@ -29,7 +31,8 @@ class SpaceTreeState extends Equatable {
List<String>? selectedCommunities, List<String>? selectedCommunities,
List<String>? selectedSpaces, List<String>? selectedSpaces,
List<String>? soldCheck, List<String>? soldCheck,
bool? isSearching}) { bool? isSearching,
Map<String, List<String>>? selectedCommunityAndSpaces}) {
return SpaceTreeState( return SpaceTreeState(
communityList: communitiesList ?? this.communityList, communityList: communitiesList ?? this.communityList,
filteredCommunity: filteredCommunity ?? this.filteredCommunity, filteredCommunity: filteredCommunity ?? this.filteredCommunity,
@ -38,7 +41,8 @@ class SpaceTreeState extends Equatable {
selectedCommunities: selectedCommunities ?? this.selectedCommunities, selectedCommunities: selectedCommunities ?? this.selectedCommunities,
selectedSpaces: selectedSpaces ?? this.selectedSpaces, selectedSpaces: selectedSpaces ?? this.selectedSpaces,
soldCheck: soldCheck ?? this.soldCheck, soldCheck: soldCheck ?? this.soldCheck,
isSearching: isSearching ?? this.isSearching); isSearching: isSearching ?? this.isSearching,
selectedCommunityAndSpaces: selectedCommunityAndSpaces ?? this.selectedCommunityAndSpaces);
} }
@override @override
@ -50,7 +54,8 @@ class SpaceTreeState extends Equatable {
selectedCommunities, selectedCommunities,
selectedSpaces, selectedSpaces,
soldCheck, soldCheck,
isSearching isSearching,
selectedCommunityAndSpaces
]; ];
} }

View File

@ -11,7 +11,8 @@ import 'package:syncrow_web/utils/color_manager.dart';
import 'package:syncrow_web/utils/style.dart'; import 'package:syncrow_web/utils/style.dart';
class SpaceTreeView extends StatelessWidget { class SpaceTreeView extends StatelessWidget {
const SpaceTreeView({super.key}); final Function onSelect;
const SpaceTreeView({required this.onSelect, super.key});
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -64,6 +65,8 @@ class SpaceTreeView extends StatelessWidget {
onItemSelected: () { onItemSelected: () {
context.read<SpaceTreeBloc>().add( context.read<SpaceTreeBloc>().add(
OnCommunitySelected(community.uuid, community.spaces)); OnCommunitySelected(community.uuid, community.spaces));
onSelect();
}, },
children: community.spaces.map((space) { children: community.spaces.map((space) {
return CustomExpansionTileSpaceTree( return CustomExpansionTileSpaceTree(
@ -72,6 +75,7 @@ class SpaceTreeView extends StatelessWidget {
onItemSelected: () { onItemSelected: () {
context.read<SpaceTreeBloc>().add(OnSpaceSelected( context.read<SpaceTreeBloc>().add(OnSpaceSelected(
community.uuid, space.uuid ?? '', space.children)); community.uuid, space.uuid ?? '', space.children));
onSelect();
}, },
onExpansionChanged: () { onExpansionChanged: () {
context.read<SpaceTreeBloc>().add( context.read<SpaceTreeBloc>().add(
@ -109,6 +113,7 @@ class SpaceTreeView extends StatelessWidget {
context context
.read<SpaceTreeBloc>() .read<SpaceTreeBloc>()
.add(OnSpaceSelected(communityId, child.uuid ?? '', child.children)); .add(OnSpaceSelected(communityId, child.uuid ?? '', child.children));
onSelect();
}, },
onExpansionChanged: () { onExpansionChanged: () {
context.read<SpaceTreeBloc>().add(OnSpaceExpanded(communityId, child.uuid ?? '')); context.read<SpaceTreeBloc>().add(OnSpaceExpanded(communityId, child.uuid ?? ''));

View File

@ -87,6 +87,7 @@ class SpaceManagementBloc
prevSpaceModels = List<SpaceTemplateModel>.from( prevSpaceModels = List<SpaceTemplateModel>.from(
(previousState as dynamic).spaceModels ?? [], (previousState as dynamic).spaceModels ?? [],
); );
allSpaces.addAll(prevSpaceModels);
} }
if (prevSpaceModels.isEmpty) { if (prevSpaceModels.isEmpty) {
@ -179,6 +180,7 @@ class SpaceManagementBloc
final updatedCommunities = final updatedCommunities =
await Future.wait(communities.map((community) async { await Future.wait(communities.map((community) async {
final spaces = await _fetchSpacesForCommunity(community.uuid); final spaces = await _fetchSpacesForCommunity(community.uuid);
return CommunityModel( return CommunityModel(
uuid: community.uuid, uuid: community.uuid,
createdAt: community.createdAt, createdAt: community.createdAt,

View File

@ -95,6 +95,9 @@ class SpaceModel {
icon: json['icon'] ?? Assets.location, icon: json['icon'] ?? Assets.location,
position: Offset(json['x'] ?? 0, json['y'] ?? 0), position: Offset(json['x'] ?? 0, json['y'] ?? 0),
isHovered: false, isHovered: false,
spaceModel: json['spaceModel'] != null
? SpaceTemplateModel.fromJson(json['spaceModel'])
: null,
tags: (json['tags'] as List<dynamic>?) tags: (json['tags'] as List<dynamic>?)
?.where((item) => item is Map<String, dynamic>) // Validate type ?.where((item) => item is Map<String, dynamic>) // Validate type
.map((item) => Tag.fromJson(item as Map<String, dynamic>)) .map((item) => Tag.fromJson(item as Map<String, dynamic>))

View File

@ -22,6 +22,9 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/curved_li
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/duplicate_process_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/duplicate_process_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_card_widget.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_card_widget.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_container_widget.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_container_widget.dart';
import 'package:syncrow_web/pages/spaces_management/helper/connection_helper.dart';
import 'package:syncrow_web/pages/spaces_management/helper/space_helper.dart';
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/color_manager.dart';
@ -130,7 +133,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
communities: widget.communities, communities: widget.communities,
communityName: widget.selectedCommunity?.name, communityName: widget.selectedCommunity?.name,
community: widget.selectedCommunity, community: widget.selectedCommunity,
isSave: isSave(spaces), isSave: SpaceHelper.isSave(spaces),
isEditingName: isEditingName, isEditingName: isEditingName,
nameController: _nameController, nameController: _nameController,
onSave: _saveSpaces, onSave: _saveSpaces,
@ -175,7 +178,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
children: [ children: [
for (var connection in connections) for (var connection in connections)
Opacity( Opacity(
opacity: _isHighlightedConnection(connection) opacity: ConnectionHelper.isHighlightedConnection(
connection, widget.selectedSpace)
? 1.0 ? 1.0
: 0.3, // Adjust opacity : 0.3, // Adjust opacity
child: CustomPaint( child: CustomPaint(
@ -195,7 +199,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
screenSize, screenSize,
position: position:
spaces[index].position + newPosition, spaces[index].position + newPosition,
parentIndex: index, parentIndex: index,
direction: direction, direction: direction,
); );
@ -209,7 +212,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
}, },
buildSpaceContainer: (int index) { buildSpaceContainer: (int index) {
final bool isHighlighted = final bool isHighlighted =
_isHighlightedSpace(spaces[index]); SpaceHelper.isHighlightedSpace(
spaces[index], widget.selectedSpace);
return Opacity( return Opacity(
opacity: isHighlighted ? 1.0 : 0.3, opacity: isHighlighted ? 1.0 : 0.3,
@ -295,7 +299,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
return CreateSpaceDialog( return CreateSpaceDialog(
products: widget.products, products: widget.products,
spaceModels: widget.spaceModels, spaceModels: widget.spaceModels,
allTags: _getAllTagValues(spaces), allTags:
TagHelper.getAllTagValues(widget.communities, widget.spaceModels),
parentSpace: parentIndex != null ? spaces[parentIndex] : null, parentSpace: parentIndex != null ? spaces[parentIndex] : null,
onCreateSpace: (String name, onCreateSpace: (String name,
String icon, String icon,
@ -306,7 +311,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
setState(() { setState(() {
// Set the first space in the center or use passed position // Set the first space in the center or use passed position
Offset centerPosition = Offset centerPosition =
position ?? _getCenterPosition(screenSize); position ?? ConnectionHelper.getCenterPosition(screenSize);
SpaceModel newSpace = SpaceModel( SpaceModel newSpace = SpaceModel(
name: name, name: name,
icon: icon, icon: icon,
@ -351,11 +356,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
spaceModels: widget.spaceModels, spaceModels: widget.spaceModels,
name: widget.selectedSpace!.name, name: widget.selectedSpace!.name,
icon: widget.selectedSpace!.icon, icon: widget.selectedSpace!.icon,
parentSpace: SpaceHelper.findSpaceByInternalId(
widget.selectedSpace?.parent?.internalId, spaces),
editSpace: widget.selectedSpace, editSpace: widget.selectedSpace,
currentSpaceModel: widget.selectedSpace?.spaceModel,
tags: widget.selectedSpace?.tags, tags: widget.selectedSpace?.tags,
subspaces: widget.selectedSpace?.subspaces, subspaces: widget.selectedSpace?.subspaces,
isEdit: true, isEdit: true,
allTags: _getAllTagValues(spaces), allTags: TagHelper.getAllTagValues(
widget.communities, widget.spaceModels),
onCreateSpace: (String name, onCreateSpace: (String name,
String icon, String icon,
List<SelectedProduct> selectedProducts, List<SelectedProduct> selectedProducts,
@ -374,6 +383,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
widget.selectedSpace!.status = widget.selectedSpace!.status =
SpaceStatus.modified; // Mark as modified SpaceStatus.modified; // Mark as modified
} }
for (var space in spaces) {
if (space.internalId == widget.selectedSpace?.internalId) {
space.status = SpaceStatus.modified;
space.subspaces = subspaces;
space.tags = tags;
space.name = name;
}
}
}); });
}, },
key: Key(widget.selectedSpace!.name), key: Key(widget.selectedSpace!.name),
@ -452,7 +470,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
}).toList(); }).toList();
if (spacesToSave.isEmpty) { if (spacesToSave.isEmpty) {
debugPrint("No new or modified spaces to save.");
return; return;
} }
@ -516,17 +533,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
); );
} }
bool _isHighlightedSpace(SpaceModel space) {
final selectedSpace = widget.selectedSpace;
if (selectedSpace == null) return true;
return space == selectedSpace ||
selectedSpace.parent?.internalId == space.internalId ||
selectedSpace.children
?.any((child) => child.internalId == space.internalId) ==
true;
}
void _deselectSpace(BuildContext context) { void _deselectSpace(BuildContext context) {
context.read<SpaceManagementBloc>().add( context.read<SpaceManagementBloc>().add(
SelectSpaceEvent( SelectSpaceEvent(
@ -534,28 +540,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
); );
} }
bool _isHighlightedConnection(Connection connection) {
if (widget.selectedSpace == null) return true;
return connection.startSpace == widget.selectedSpace ||
connection.endSpace == widget.selectedSpace;
}
Offset _getCenterPosition(Size screenSize) {
return Offset(
screenSize.width / 2 - 260,
screenSize.height / 2 - 200,
);
}
bool isSave(List<SpaceModel> spaces) {
return spaces.isNotEmpty &&
spaces.any((space) =>
space.status == SpaceStatus.newSpace ||
space.status == SpaceStatus.modified ||
space.status == SpaceStatus.deleted);
}
void _onDuplicate(BuildContext parentContext) { void _onDuplicate(BuildContext parentContext) {
final screenWidth = MediaQuery.of(context).size.width; final screenWidth = MediaQuery.of(context).size.width;
@ -641,17 +625,10 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
const double horizontalGap = 200.0; const double horizontalGap = 200.0;
const double verticalGap = 100.0; const double verticalGap = 100.0;
final Map<String, int> nameCounters = {};
String _generateCopyName(String originalName) {
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
nameCounters[baseName] = (nameCounters[baseName] ?? 0) + 1;
return "$baseName(${nameCounters[baseName]})";
}
SpaceModel duplicateRecursive(SpaceModel original, Offset parentPosition, SpaceModel duplicateRecursive(SpaceModel original, Offset parentPosition,
SpaceModel? duplicatedParent) { SpaceModel? duplicatedParent) {
Offset newPosition = parentPosition + Offset(horizontalGap, 0); Offset newPosition =
Offset(parentPosition.dx + horizontalGap, original.position.dy);
while (spaces.any((s) => while (spaces.any((s) =>
(s.position - newPosition).distance < horizontalGap && (s.position - newPosition).distance < horizontalGap &&
@ -659,7 +636,18 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
newPosition += Offset(horizontalGap, 0); newPosition += Offset(horizontalGap, 0);
} }
final duplicatedName = _generateCopyName(original.name); final duplicatedName =
SpaceHelper.generateUniqueSpaceName(original.name, spaces);
final List<SubspaceModel>? duplicatedSubspaces;
final List<Tag>? duplicatedTags;
if (original.spaceModel != null) {
duplicatedTags = [];
duplicatedSubspaces = [];
} else {
duplicatedTags = original.tags;
duplicatedSubspaces = original.subspaces;
}
final duplicated = SpaceModel( final duplicated = SpaceModel(
name: duplicatedName, name: duplicatedName,
@ -670,8 +658,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
status: SpaceStatus.newSpace, status: SpaceStatus.newSpace,
parent: duplicatedParent, parent: duplicatedParent,
spaceModel: original.spaceModel, spaceModel: original.spaceModel,
subspaces: original.subspaces, subspaces: duplicatedSubspaces,
tags: original.tags, tags: duplicatedTags,
); );
originalToDuplicate[original] = duplicated; originalToDuplicate[original] = duplicated;
@ -684,7 +672,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
final newConnection = Connection( final newConnection = Connection(
startSpace: duplicatedParent, startSpace: duplicatedParent,
endSpace: duplicated, endSpace: duplicated,
direction: "down", direction: original.incomingConnection?.direction ?? 'down',
); );
connections.add(newConnection); connections.add(newConnection);
duplicated.incomingConnection = newConnection; duplicated.incomingConnection = newConnection;
@ -723,10 +711,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
child.incomingConnection?.direction == "down" ?? false; child.incomingConnection?.direction == "down" ?? false;
if (isDownDirection && childrenWithDownDirection.length == 1) { if (isDownDirection && childrenWithDownDirection.length == 1) {
// Place the only "down" child vertically aligned with the parent
childStartPosition = duplicated.position + Offset(0, verticalGap); childStartPosition = duplicated.position + Offset(0, verticalGap);
} else if (!isDownDirection) { } else if (!isDownDirection) {
// Position children with other directions horizontally
childStartPosition = duplicated.position + Offset(horizontalGap, 0); childStartPosition = duplicated.position + Offset(horizontalGap, 0);
} }
@ -747,14 +733,4 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
duplicateRecursive(space, space.position, duplicatedParent); duplicateRecursive(space, space.position, duplicatedParent);
} }
} }
List<String> _getAllTagValues(List<SpaceModel> spaces) {
final List<String> allTags = [];
for (final space in spaces) {
if (space.tags != null) {
allTags.addAll(space.listAllTagValues());
}
}
return allTags;
}
} }

View File

@ -12,6 +12,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/create_subspace/views/create_subspace_model_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/create_subspace/views/create_subspace_model_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/helper/space_helper.dart';
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart'; import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
import 'package:syncrow_web/pages/spaces_management/link_space_model/view/link_space_model_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/link_space_model/view/link_space_model_dialog.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
@ -40,6 +41,7 @@ class CreateSpaceDialog extends StatefulWidget {
final List<SubspaceModel>? subspaces; final List<SubspaceModel>? subspaces;
final List<Tag>? tags; final List<Tag>? tags;
final List<String>? allTags; final List<String>? allTags;
final SpaceTemplateModel? currentSpaceModel;
const CreateSpaceDialog( const CreateSpaceDialog(
{super.key, {super.key,
@ -54,7 +56,8 @@ class CreateSpaceDialog extends StatefulWidget {
this.selectedProducts = const [], this.selectedProducts = const [],
this.spaceModels, this.spaceModels,
this.subspaces, this.subspaces,
this.tags}); this.tags,
this.currentSpaceModel});
@override @override
CreateSpaceDialogState createState() => CreateSpaceDialogState(); CreateSpaceDialogState createState() => CreateSpaceDialogState();
@ -81,12 +84,22 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
widget.selectedProducts.isNotEmpty ? widget.selectedProducts : []; widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
isOkButtonEnabled = isOkButtonEnabled =
enteredName.isNotEmpty || nameController.text.isNotEmpty; enteredName.isNotEmpty || nameController.text.isNotEmpty;
if (widget.currentSpaceModel != null) {
subspaces = [];
tags = [];
} else {
tags = widget.tags ?? []; tags = widget.tags ?? [];
subspaces = widget.subspaces ?? []; subspaces = widget.subspaces ?? [];
} }
selectedSpaceModel = widget.currentSpaceModel;
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
bool isSpaceModelDisabled = (tags != null && tags!.isNotEmpty ||
subspaces != null && subspaces!.isNotEmpty);
bool isTagsAndSubspaceModelDisabled = (selectedSpaceModel != null);
final screenWidth = MediaQuery.of(context).size.width; final screenWidth = MediaQuery.of(context).size.width;
return AlertDialog( return AlertDialog(
title: widget.isEdit title: widget.isEdit
@ -165,7 +178,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
isNameFieldInvalid = value.isEmpty; isNameFieldInvalid = value.isEmpty;
if (!isNameFieldInvalid) { if (!isNameFieldInvalid) {
if (_isNameConflict(value)) { if (SpaceHelper.isNameConflict(value, widget.parentSpace, widget.editSpace)) {
isNameFieldExist = true; isNameFieldExist = true;
isOkButtonEnabled = false; isOkButtonEnabled = false;
} else { } else {
@ -232,11 +245,14 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),
onPressed: () { onPressed: () {
_showLinkSpaceModelDialog(context); isSpaceModelDisabled
? null
: _showLinkSpaceModelDialog(context);
}, },
child: const ButtonContentWidget( child: ButtonContentWidget(
svgAssets: Assets.link, svgAssets: Assets.link,
label: 'Link a space model', label: 'Link a space model',
disabled: isSpaceModelDisabled,
), ),
) )
: Container( : Container(
@ -325,12 +341,15 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
overlayColor: ColorsManager.transparentColor, overlayColor: ColorsManager.transparentColor,
), ),
onPressed: () async { onPressed: () async {
_showSubSpaceDialog(context, enteredName, [], isTagsAndSubspaceModelDisabled
false, widget.products, subspaces); ? null
: _showSubSpaceDialog(context, enteredName,
[], false, widget.products, subspaces);
}, },
child: const ButtonContentWidget( child: ButtonContentWidget(
icon: Icons.add, icon: Icons.add,
label: 'Create Sub Space', label: 'Create Sub Space',
disabled: isTagsAndSubspaceModelDisabled,
), ),
) )
: SizedBox( : SizedBox(
@ -457,7 +476,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
context: context, context: context,
builder: (context) => AssignTagDialog( builder: (context) => AssignTagDialog(
products: widget.products, products: widget.products,
subspaces: widget.subspaces, subspaces: subspaces,
allTags: widget.allTags,
addedProducts: TagHelper addedProducts: TagHelper
.createInitialSelectedProductsForTags( .createInitialSelectedProductsForTags(
tags ?? [], subspaces), tags ?? [], subspaces),
@ -483,20 +503,22 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
) )
: TextButton( : TextButton(
onPressed: () { onPressed: () {
_showTagCreateDialog( isTagsAndSubspaceModelDisabled
? null
: _showTagCreateDialog(
context, context,
enteredName, enteredName,
widget.isEdit, widget.isEdit,
widget.products, widget.products,
subspaces,
); );
}, },
style: TextButton.styleFrom( style: TextButton.styleFrom(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
), ),
child: const ButtonContentWidget( child: ButtonContentWidget(
icon: Icons.add, icon: Icons.add,
label: 'Add Devices', label: 'Add Devices',
disabled: isTagsAndSubspaceModelDisabled,
)) ))
], ],
), ),
@ -570,14 +592,6 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
); );
} }
bool _isNameConflict(String value) {
return (widget.parentSpace?.children.any((child) => child.name == value) ??
false) ||
(widget.parentSpace?.name == value) ||
(widget.editSpace?.parent?.name == value) ||
(widget.editSpace?.children.any((child) => child.name == value) ??
false);
}
void _showLinkSpaceModelDialog(BuildContext context) { void _showLinkSpaceModelDialog(BuildContext context) {
showDialog( showDialog(
@ -617,9 +631,26 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
products: products, products: products,
existingSubSpaces: existingSubSpaces, existingSubSpaces: existingSubSpaces,
onSave: (slectedSubspaces) { onSave: (slectedSubspaces) {
final List<Tag> tagsToAppendToSpace = [];
if (slectedSubspaces != null) {
final updatedIds =
slectedSubspaces.map((s) => s.internalId).toSet();
if (existingSubSpaces != null) {
final deletedSubspaces = existingSubSpaces
.where((s) => !updatedIds.contains(s.internalId))
.toList();
for (var s in deletedSubspaces) {
if (s.tags != null) {
tagsToAppendToSpace.addAll(s.tags!);
}
}
}
}
if (slectedSubspaces != null) { if (slectedSubspaces != null) {
setState(() { setState(() {
subspaces = slectedSubspaces; subspaces = slectedSubspaces;
tags?.addAll(tagsToAppendToSpace);
selectedSpaceModel = null; selectedSpaceModel = null;
}); });
} }
@ -629,7 +660,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
} }
void _showTagCreateDialog(BuildContext context, String name, bool isEdit, void _showTagCreateDialog(BuildContext context, String name, bool isEdit,
List<ProductModel>? products, List<SubspaceModel>? subspaces) { List<ProductModel>? products) {
isEdit isEdit
? showDialog( ? showDialog(
context: context, context: context,

View File

@ -11,7 +11,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/space_tem
import 'package:syncrow_web/pages/spaces_management/space_model/view/space_model_page.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/view/space_model_page.dart';
import 'package:syncrow_web/services/space_model_mang_api.dart'; import 'package:syncrow_web/services/space_model_mang_api.dart';
class LoadedSpaceView extends StatelessWidget { class LoadedSpaceView extends StatefulWidget {
final List<CommunityModel> communities; final List<CommunityModel> communities;
final CommunityModel? selectedCommunity; final CommunityModel? selectedCommunity;
final SpaceModel? selectedSpace; final SpaceModel? selectedSpace;
@ -26,41 +26,73 @@ class LoadedSpaceView extends StatelessWidget {
this.selectedSpace, this.selectedSpace,
this.products, this.products,
this.spaceModels, this.spaceModels,
required this.shouldNavigateToSpaceModelPage required this.shouldNavigateToSpaceModelPage,
}); });
@override @override
Widget build(BuildContext context) { _LoadedSpaceViewState createState() => _LoadedSpaceViewState();
}
class _LoadedSpaceViewState extends State<LoadedSpaceView> {
late List<SpaceTemplateModel> _spaceModels;
@override
void initState() {
super.initState();
_spaceModels = List.from(widget.spaceModels ?? []);
}
@override
void didUpdateWidget(covariant LoadedSpaceView oldWidget) {
super.didUpdateWidget(oldWidget);
if (widget.spaceModels != oldWidget.spaceModels) {
setState(() {
_spaceModels = List.from(widget.spaceModels ?? []);
});
}
}
void _onSpaceModelsUpdated(List<SpaceTemplateModel> updatedModels) {
if (mounted && updatedModels != _spaceModels) {
setState(() {
_spaceModels = updatedModels;
});
}
}
@override
Widget build(BuildContext context) {
return Stack( return Stack(
clipBehavior: Clip.none, clipBehavior: Clip.none,
children: [ children: [
Row( Row(
children: [ children: [
SidebarWidget( SidebarWidget(
communities: communities, communities: widget.communities,
selectedSpaceUuid: selectedSpaceUuid: widget.selectedSpace?.uuid ??
selectedSpace?.uuid ?? selectedCommunity?.uuid ?? '', widget.selectedCommunity?.uuid ??
'',
), ),
shouldNavigateToSpaceModelPage widget.shouldNavigateToSpaceModelPage
? Expanded( ? Expanded(
child: BlocProvider( child: BlocProvider(
create: (context) => SpaceModelBloc( create: (context) => SpaceModelBloc(
api: SpaceModelManagementApi(), api: SpaceModelManagementApi(),
initialSpaceModels: spaceModels ?? [], initialSpaceModels: _spaceModels,
), ),
child: SpaceModelPage( child: SpaceModelPage(
products: products, products: widget.products,
onSpaceModelsUpdated: _onSpaceModelsUpdated,
), ),
), ),
) )
: CommunityStructureArea( : CommunityStructureArea(
selectedCommunity: selectedCommunity, selectedCommunity: widget.selectedCommunity,
selectedSpace: selectedSpace, selectedSpace: widget.selectedSpace,
spaces: selectedCommunity?.spaces ?? [], spaces: widget.selectedCommunity?.spaces ?? [],
products: products, products: widget.products,
communities: communities, communities: widget.communities,
spaceModels: spaceModels, spaceModels: _spaceModels,
), ),
], ],
), ),
@ -68,13 +100,4 @@ class LoadedSpaceView extends StatelessWidget {
], ],
); );
} }
SpaceModel? findSpaceByUuid(String? uuid, List<CommunityModel> communities) {
for (var community in communities) {
for (var space in community.spaces) {
if (space.uuid == uuid) return space;
}
}
return null;
}
} }

View File

@ -57,6 +57,7 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
if (currentState is AssignTagLoaded && currentState.tags.isNotEmpty) { if (currentState is AssignTagLoaded && currentState.tags.isNotEmpty) {
final tags = List<Tag>.from(currentState.tags); final tags = List<Tag>.from(currentState.tags);
tags[event.index].tag = event.tag; tags[event.index].tag = event.tag;
emit(AssignTagLoaded( emit(AssignTagLoaded(
tags: tags, tags: tags,
isSaveEnabled: _validateTags(tags), isSaveEnabled: _validateTags(tags),
@ -78,6 +79,7 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
emit(AssignTagLoaded( emit(AssignTagLoaded(
tags: tags, tags: tags,
isSaveEnabled: _validateTags(tags), isSaveEnabled: _validateTags(tags),
errorMessage: _getValidationError(tags),
)); ));
} }
}); });
@ -106,12 +108,13 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
emit(AssignTagLoaded( emit(AssignTagLoaded(
tags: updatedTags, tags: updatedTags,
isSaveEnabled: _validateTags(updatedTags), isSaveEnabled: _validateTags(updatedTags),
errorMessage: _getValidationError(updatedTags),
)); ));
} else { } else {
emit(const AssignTagLoaded( emit(const AssignTagLoaded(
tags: [], tags: [],
isSaveEnabled: false, isSaveEnabled: false,
)); errorMessage: 'Failed to delete tag'));
} }
}); });
} }
@ -125,7 +128,10 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
String? _getValidationError(List<Tag> tags) { String? _getValidationError(List<Tag> tags) {
final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty); final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty);
if (hasEmptyTag) return 'Tags cannot be empty.'; if (hasEmptyTag) {
return 'Tags cannot be empty.';
}
final duplicateTags = tags final duplicateTags = tags
.map((tag) => tag.tag?.trim() ?? '') .map((tag) => tag.tag?.trim() ?? '')
.fold<Map<String, int>>({}, (map, tag) { .fold<Map<String, int>>({}, (map, tag) {

View File

@ -21,11 +21,11 @@ class AssignTagLoaded extends AssignTagState {
const AssignTagLoaded({ const AssignTagLoaded({
required this.tags, required this.tags,
required this.isSaveEnabled, required this.isSaveEnabled,
this.errorMessage, required this.errorMessage,
}); });
@override @override
List<Object> get props => [tags, isSaveEnabled]; List<Object> get props => [tags, isSaveEnabled, errorMessage ?? ''];
} }
class AssignTagError extends AssignTagState { class AssignTagError extends AssignTagState {

View File

@ -71,6 +71,7 @@ class AssignTagDialog extends StatelessWidget {
child: DataTable( child: DataTable(
headingRowColor: WidgetStateProperty.all( headingRowColor: WidgetStateProperty.all(
ColorsManager.dataHeaderGrey), ColorsManager.dataHeaderGrey),
key: ValueKey(state.tags.length),
border: TableBorder.all( border: TableBorder.all(
color: ColorsManager.dataHeaderGrey, color: ColorsManager.dataHeaderGrey,
width: 1, width: 1,
@ -120,6 +121,7 @@ class AssignTagDialog extends StatelessWidget {
final controller = controllers[index]; final controller = controllers[index];
final availableTags = getAvailableTags( final availableTags = getAvailableTags(
allTags ?? [], state.tags, tag); allTags ?? [], state.tags, tag);
return DataRow( return DataRow(
cells: [ cells: [
DataCell(Text((index + 1).toString())), DataCell(Text((index + 1).toString())),
@ -158,6 +160,8 @@ class AssignTagDialog extends StatelessWidget {
.add(DeleteTag( .add(DeleteTag(
tagToDelete: tag, tagToDelete: tag,
tags: state.tags)); tags: state.tags));
controllers.removeAt(index);
}, },
tooltip: 'Delete Tag', tooltip: 'Delete Tag',
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -233,7 +237,8 @@ class AssignTagDialog extends StatelessWidget {
label: 'Add New Device', label: 'Add New Device',
onPressed: () async { onPressed: () async {
final updatedTags = List<Tag>.from(state.tags); final updatedTags = List<Tag>.from(state.tags);
final result = processTags(updatedTags, subspaces); final result =
TagHelper.processTags(updatedTags, subspaces);
final processedTags = final processedTags =
result['updatedTags'] as List<Tag>; result['updatedTags'] as List<Tag>;
@ -254,6 +259,7 @@ class AssignTagDialog extends StatelessWidget {
spaceTags: processedTags, spaceTags: processedTags,
isCreate: false, isCreate: false,
onSave: onSave, onSave: onSave,
allTags: allTags,
), ),
); );
}, },
@ -264,15 +270,15 @@ class AssignTagDialog extends StatelessWidget {
Expanded( Expanded(
child: DefaultButton( child: DefaultButton(
borderRadius: 10, borderRadius: 10,
backgroundColor: state.isSaveEnabled backgroundColor: ColorsManager.secondaryColor,
? ColorsManager.secondaryColor foregroundColor: state.isSaveEnabled
: ColorsManager.grayColor, ? ColorsManager.whiteColors
foregroundColor: ColorsManager.whiteColors, : ColorsManager.whiteColorsWithOpacity,
onPressed: state.isSaveEnabled onPressed: state.isSaveEnabled
? () async { ? () async {
final updatedTags = List<Tag>.from(state.tags); final updatedTags = List<Tag>.from(state.tags);
final result = final result = TagHelper.processTags(
processTags(updatedTags, subspaces); updatedTags, subspaces);
final processedTags = final processedTags =
result['updatedTags'] as List<Tag>; result['updatedTags'] as List<Tag>;
@ -311,33 +317,4 @@ class AssignTagDialog extends StatelessWidget {
); );
return availableTagsForTagModel; return availableTagsForTagModel;
} }
Map<String, dynamic> processTags(
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
return TagHelper.updateTags<Tag>(
updatedTags: updatedTags,
subspaces: subspaces,
getInternalId: (tag) => tag.internalId,
getLocation: (tag) => tag.location,
setLocation: (tag, location) => tag.location = location,
getSubspaceName: (subspace) => subspace.subspaceName,
getSubspaceTags: (subspace) => subspace.tags,
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
checkTagExistInSubspace: checkTagExistInSubspace,
);
}
int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
if (subspaces == null) return null;
for (int i = 0; i < subspaces.length; i++) {
final subspace = subspaces[i];
if (subspace.tags == null) continue;
for (var t in subspace.tags!) {
if (tag.internalId == t.internalId) {
return i;
}
}
}
return null;
}
} }

View File

@ -82,6 +82,7 @@ class AssignTagModelsDialog extends StatelessWidget {
child: DataTable( child: DataTable(
headingRowColor: WidgetStateProperty.all( headingRowColor: WidgetStateProperty.all(
ColorsManager.dataHeaderGrey), ColorsManager.dataHeaderGrey),
key: ValueKey(state.tags.length),
border: TableBorder.all( border: TableBorder.all(
color: ColorsManager.dataHeaderGrey, color: ColorsManager.dataHeaderGrey,
width: 1, width: 1,
@ -176,6 +177,7 @@ class AssignTagModelsDialog extends StatelessWidget {
.add(DeleteTagModel( .add(DeleteTagModel(
tagToDelete: tag, tagToDelete: tag,
tags: state.tags)); tags: state.tags));
controllers.removeAt(index);
}, },
tooltip: 'Delete Tag', tooltip: 'Delete Tag',
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -302,10 +304,10 @@ class AssignTagModelsDialog extends StatelessWidget {
Expanded( Expanded(
child: DefaultButton( child: DefaultButton(
borderRadius: 10, borderRadius: 10,
backgroundColor: state.isSaveEnabled backgroundColor: ColorsManager.secondaryColor,
? ColorsManager.secondaryColor foregroundColor: state.isSaveEnabled
: ColorsManager.grayColor, ? ColorsManager.whiteColors
foregroundColor: ColorsManager.whiteColors, : ColorsManager.whiteColorsWithOpacity,
onPressed: state.isSaveEnabled onPressed: state.isSaveEnabled
? () async { ? () async {
final updatedTags = final updatedTags =

View File

@ -0,0 +1,21 @@
import 'dart:ui';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/connection_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
class ConnectionHelper {
static Offset getCenterPosition(Size screenSize) {
return Offset(
screenSize.width / 2 - 260,
screenSize.height / 2 - 200,
);
}
static bool isHighlightedConnection(
Connection connection, SpaceModel? selectedSpace) {
if (selectedSpace == null) return true;
return connection.startSpace == selectedSpace ||
connection.endSpace == selectedSpace;
}
}

View File

@ -0,0 +1,94 @@
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
class SpaceHelper {
static SpaceModel? findSpaceByUuid(
String? uuid, List<CommunityModel> communities) {
for (var community in communities) {
for (var space in community.spaces) {
if (space.uuid == uuid) return space;
}
}
return null;
}
static SpaceModel? findSpaceByInternalId(
String? internalId, List<SpaceModel> spaces) {
if (internalId != null) {
for (var space in spaces) {
if (space.internalId == internalId) return space;
}
}
return null;
}
static String generateUniqueSpaceName(
String originalName, List<SpaceModel> spaces) {
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
int maxNumber = 0;
for (var space in spaces) {
final match = RegExp(r'^(.*?)\((\d+)\)$').firstMatch(space.name);
if (match != null && match.group(1)?.trim() == baseName) {
int existingNumber = int.parse(match.group(2)!);
if (existingNumber > maxNumber) {
maxNumber = existingNumber;
}
}
}
return "$baseName(${maxNumber + 1})";
}
static bool isSave(List<SpaceModel> spaces) {
return spaces.isNotEmpty &&
spaces.any((space) =>
space.status == SpaceStatus.newSpace ||
space.status == SpaceStatus.modified ||
space.status == SpaceStatus.deleted);
}
static bool isHighlightedSpace(SpaceModel space, SpaceModel? selectedSpace) {
if (selectedSpace == null) return true;
return space == selectedSpace ||
selectedSpace.parent?.internalId == space.internalId ||
selectedSpace.children
?.any((child) => child.internalId == space.internalId) ==
true;
}
static bool isNameConflict(
String value, SpaceModel? parentSpace, SpaceModel? editSpace) {
final siblings = parentSpace?.children
.where((child) => child.internalId != editSpace?.internalId)
.toList() ??
[];
final editSiblings = editSpace?.parent?.children
.where((child) => child.internalId != editSpace.internalId)
.toList() ??
[];
final editSiblingConflict =
editSiblings.any((child) => child.name == value);
final siblingConflict = siblings.any((child) => child.name == value);
final parentConflict = parentSpace?.name == value &&
parentSpace?.internalId != editSpace?.internalId;
final parentOfEditSpaceConflict = editSpace?.parent?.name == value &&
editSpace?.parent?.internalId != editSpace?.internalId;
final childConflict =
editSpace?.children.any((child) => child.name == value) ?? false;
return siblingConflict ||
parentConflict ||
editSiblingConflict ||
parentOfEditSpaceConflict ||
childConflict;
}
}

View File

@ -1,8 +1,11 @@
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/base_tag.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/base_tag.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
@ -278,7 +281,8 @@ class TagHelper {
.toList(); .toList();
} }
static int? checkTagExistInSubspaceModels(TagModel tag, List<dynamic>? subspaces) { static int? checkTagExistInSubspaceModels(
TagModel tag, List<dynamic>? subspaces) {
if (subspaces == null) return null; if (subspaces == null) return null;
for (int i = 0; i < subspaces.length; i++) { for (int i = 0; i < subspaces.length; i++) {
@ -308,4 +312,53 @@ class TagHelper {
); );
} }
static int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
if (subspaces == null) return null;
for (int i = 0; i < subspaces.length; i++) {
final subspace = subspaces[i];
if (subspace.tags == null) continue;
for (var t in subspace.tags!) {
if (tag.internalId == t.internalId) {
return i;
}
}
}
return null;
}
static Map<String, dynamic> processTags(
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
return TagHelper.updateTags<Tag>(
updatedTags: updatedTags,
subspaces: subspaces,
getInternalId: (tag) => tag.internalId,
getLocation: (tag) => tag.location,
setLocation: (tag, location) => tag.location = location,
getSubspaceName: (subspace) => subspace.subspaceName,
getSubspaceTags: (subspace) => subspace.tags,
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
checkTagExistInSubspace: checkTagExistInSubspace,
);
}
static List<String> getAllTagValues(
List<CommunityModel> communities, List<SpaceTemplateModel>? spaceModels) {
final Set<String> allTags = {};
if (spaceModels != null) {
for (var model in spaceModels) {
allTags.addAll(model.listAllTagValues());
}
}
for (final community in communities) {
for (final space in community.spaces) {
if (space.tags != null) {
allTags.addAll(space.listAllTagValues());
}
}
}
return allTags.toList();
}
} }

View File

@ -1,5 +1,4 @@
import 'package:equatable/equatable.dart'; import 'package:equatable/equatable.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';

View File

@ -11,8 +11,10 @@ import 'package:syncrow_web/utils/color_manager.dart';
class SpaceModelPage extends StatelessWidget { class SpaceModelPage extends StatelessWidget {
final List<ProductModel>? products; final List<ProductModel>? products;
final Function(List<SpaceTemplateModel>)? onSpaceModelsUpdated;
const SpaceModelPage({Key? key, this.products}) : super(key: key); const SpaceModelPage({Key? key, this.products, this.onSpaceModelsUpdated})
: super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -25,6 +27,10 @@ class SpaceModelPage extends StatelessWidget {
final allTagValues = _getAllTagValues(spaceModels); final allTagValues = _getAllTagValues(spaceModels);
final allSpaceModelNames = _getAllSpaceModelName(spaceModels); final allSpaceModelNames = _getAllSpaceModelName(spaceModels);
if (onSpaceModelsUpdated != null) {
onSpaceModelsUpdated!(spaceModels);
}
return Scaffold( return Scaffold(
backgroundColor: ColorsManager.whiteColors, backgroundColor: ColorsManager.whiteColors,
body: Padding( body: Padding(

View File

@ -6,16 +6,23 @@ class ButtonContentWidget extends StatelessWidget {
final IconData? icon; final IconData? icon;
final String label; final String label;
final String? svgAssets; final String? svgAssets;
final bool disabled;
const ButtonContentWidget( const ButtonContentWidget({
{Key? key, this.icon, required this.label, this.svgAssets}) Key? key,
: super(key: key); this.icon,
required this.label,
this.svgAssets,
this.disabled = false,
}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width; final screenWidth = MediaQuery.of(context).size.width;
return SizedBox( return Opacity(
opacity: disabled ? 0.5 : 1.0,
child: SizedBox(
width: screenWidth * 0.25, width: screenWidth * 0.25,
child: Container( child: Container(
decoration: BoxDecoration( decoration: BoxDecoration(
@ -27,7 +34,8 @@ class ButtonContentWidget extends StatelessWidget {
borderRadius: BorderRadius.circular(20), borderRadius: BorderRadius.circular(20),
), ),
child: Padding( child: Padding(
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0), padding:
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
child: Row( child: Row(
children: [ children: [
if (icon != null) if (icon != null)
@ -58,6 +66,7 @@ class ButtonContentWidget extends StatelessWidget {
), ),
), ),
), ),
),
); );
} }
} }

View File

@ -23,7 +23,8 @@ class DevicesManagementApi {
: ApiEndpoints.getAllDevices, : ApiEndpoints.getAllDevices,
showServerMessage: true, showServerMessage: true,
expectedResponseModel: (json) { expectedResponseModel: (json) {
List<dynamic> jsonData = json; List<dynamic> jsonData =
communityId.isNotEmpty && spaceId.isNotEmpty ? json['data'] : json;
List<AllDevicesModel> devicesList = jsonData.map((jsonItem) { List<AllDevicesModel> devicesList = jsonData.map((jsonItem) {
return AllDevicesModel.fromJson(jsonItem); return AllDevicesModel.fromJson(jsonItem);
}).toList(); }).toList();