From 6f51c2d2b6f5ea8c502f08e4647094893cd6c3a3 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 3 Feb 2025 22:23:53 +0400 Subject: [PATCH] provide all tags on edit space --- .../widgets/community_structure_widget.dart | 64 ++++--------------- .../widgets/dialogs/create_space_dialog.dart | 3 + .../helper/connection_helper.dart | 21 ++++++ .../helper/space_helper.dart | 18 ++++++ .../spaces_management/helper/tag_helper.dart | 24 +++++++ 5 files changed, 78 insertions(+), 52 deletions(-) create mode 100644 lib/pages/spaces_management/helper/connection_helper.dart diff --git a/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart index 795a140f..165ddf34 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart @@ -22,7 +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/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/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/utils/color_manager.dart'; @@ -131,7 +133,7 @@ class _CommunityStructureAreaState extends State { communities: widget.communities, communityName: widget.selectedCommunity?.name, community: widget.selectedCommunity, - isSave: isSave(spaces), + isSave: SpaceHelper.isSave(spaces), isEditingName: isEditingName, nameController: _nameController, onSave: _saveSpaces, @@ -176,7 +178,8 @@ class _CommunityStructureAreaState extends State { children: [ for (var connection in connections) Opacity( - opacity: _isHighlightedConnection(connection) + opacity: ConnectionHelper.isHighlightedConnection( + connection, widget.selectedSpace) ? 1.0 : 0.3, // Adjust opacity child: CustomPaint( @@ -209,7 +212,8 @@ class _CommunityStructureAreaState extends State { }, buildSpaceContainer: (int index) { final bool isHighlighted = - _isHighlightedSpace(spaces[index]); + SpaceHelper.isHighlightedSpace( + spaces[index], widget.selectedSpace); return Opacity( opacity: isHighlighted ? 1.0 : 0.3, @@ -295,7 +299,8 @@ class _CommunityStructureAreaState extends State { return CreateSpaceDialog( products: widget.products, spaceModels: widget.spaceModels, - allTags: _getAllTagValues(spaces), + allTags: + TagHelper.getAllTagValues(widget.communities, widget.spaceModels), parentSpace: parentIndex != null ? spaces[parentIndex] : null, onCreateSpace: (String name, String icon, @@ -306,7 +311,7 @@ class _CommunityStructureAreaState extends State { setState(() { // Set the first space in the center or use passed position Offset centerPosition = - position ?? _getCenterPosition(screenSize); + position ?? ConnectionHelper.getCenterPosition(screenSize); SpaceModel newSpace = SpaceModel( name: name, icon: icon, @@ -358,7 +363,8 @@ class _CommunityStructureAreaState extends State { tags: widget.selectedSpace?.tags, subspaces: widget.selectedSpace?.subspaces, isEdit: true, - allTags: _getAllTagValues(spaces), + allTags: TagHelper.getAllTagValues( + widget.communities, widget.spaceModels), onCreateSpace: (String name, String icon, List selectedProducts, @@ -527,17 +533,6 @@ class _CommunityStructureAreaState extends State { ); } - 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) { context.read().add( SelectSpaceEvent( @@ -545,28 +540,6 @@ class _CommunityStructureAreaState extends State { ); } - 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 spaces) { - return spaces.isNotEmpty && - spaces.any((space) => - space.status == SpaceStatus.newSpace || - space.status == SpaceStatus.modified || - space.status == SpaceStatus.deleted); - } - void _onDuplicate(BuildContext parentContext) { final screenWidth = MediaQuery.of(context).size.width; @@ -652,8 +625,6 @@ class _CommunityStructureAreaState extends State { const double horizontalGap = 200.0; const double verticalGap = 100.0; - final Map nameCounters = {}; - SpaceModel duplicateRecursive(SpaceModel original, Offset parentPosition, SpaceModel? duplicatedParent) { Offset newPosition = parentPosition + Offset(horizontalGap, 0); @@ -729,10 +700,8 @@ class _CommunityStructureAreaState extends State { child.incomingConnection?.direction == "down" ?? false; if (isDownDirection && childrenWithDownDirection.length == 1) { - // Place the only "down" child vertically aligned with the parent childStartPosition = duplicated.position + Offset(0, verticalGap); } else if (!isDownDirection) { - // Position children with other directions horizontally childStartPosition = duplicated.position + Offset(horizontalGap, 0); } @@ -754,13 +723,4 @@ class _CommunityStructureAreaState extends State { } } - List _getAllTagValues(List spaces) { - final List allTags = []; - for (final space in spaces) { - if (space.tags != null) { - allTags.addAll(space.listAllTagValues()); - } - } - return allTags; - } } diff --git a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart index a435a8fc..4e0bc317 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/dialogs/create_space_dialog.dart @@ -461,6 +461,7 @@ class CreateSpaceDialogState extends State { builder: (context) => AssignTagDialog( products: widget.products, subspaces: subspaces, + allTags: widget.allTags, addedProducts: TagHelper .createInitialSelectedProductsForTags( tags ?? [], subspaces), @@ -660,6 +661,8 @@ class CreateSpaceDialogState extends State { void _showTagCreateDialog(BuildContext context, String name, bool isEdit, List? products) { + + print("ada ${widget.allTags}"); isEdit ? showDialog( context: context, diff --git a/lib/pages/spaces_management/helper/connection_helper.dart b/lib/pages/spaces_management/helper/connection_helper.dart new file mode 100644 index 00000000..7de8d80b --- /dev/null +++ b/lib/pages/spaces_management/helper/connection_helper.dart @@ -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; + } +} diff --git a/lib/pages/spaces_management/helper/space_helper.dart b/lib/pages/spaces_management/helper/space_helper.dart index 75aebce9..c316106e 100644 --- a/lib/pages/spaces_management/helper/space_helper.dart +++ b/lib/pages/spaces_management/helper/space_helper.dart @@ -40,4 +40,22 @@ class SpaceHelper { return "$baseName(${maxNumber + 1})"; } + + static bool isSave(List 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; + } } diff --git a/lib/pages/spaces_management/helper/tag_helper.dart b/lib/pages/spaces_management/helper/tag_helper.dart index 757f46e1..9c0299ba 100644 --- a/lib/pages/spaces_management/helper/tag_helper.dart +++ b/lib/pages/spaces_management/helper/tag_helper.dart @@ -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/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/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/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/tag_model.dart'; @@ -337,4 +340,25 @@ class TagHelper { checkTagExistInSubspace: checkTagExistInSubspace, ); } + + static List getAllTagValues( + List communities, List? spaceModels) { + final Set 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(); + } }