mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed issues in create space and duplicate
This commit is contained in:
@ -179,6 +179,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,
|
||||||
@ -313,6 +314,7 @@ class SpaceManagementBloc
|
|||||||
SelectSpaceEvent event,
|
SelectSpaceEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
_handleCommunitySpaceStateUpdate(
|
_handleCommunitySpaceStateUpdate(
|
||||||
emit: emit,
|
emit: emit,
|
||||||
selectedCommunity: event.selectedCommunity,
|
selectedCommunity: event.selectedCommunity,
|
||||||
|
@ -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>))
|
||||||
|
@ -22,6 +22,7 @@ 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/space_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';
|
||||||
|
|
||||||
@ -341,6 +342,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _showEditSpaceDialog() {
|
void _showEditSpaceDialog() {
|
||||||
|
print("parentsdf space is ${widget.selectedSpace?.parent?.name}");
|
||||||
if (widget.selectedSpace != null) {
|
if (widget.selectedSpace != null) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -350,7 +352,10 @@ 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,
|
||||||
@ -650,12 +655,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
|
|
||||||
final Map<String, int> nameCounters = {};
|
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 = parentPosition + Offset(horizontalGap, 0);
|
||||||
@ -666,7 +665,8 @@ 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 duplicated = SpaceModel(
|
final duplicated = SpaceModel(
|
||||||
name: duplicatedName,
|
name: duplicatedName,
|
||||||
|
@ -40,6 +40,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 +55,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();
|
||||||
@ -83,6 +85,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||||
tags = widget.tags ?? [];
|
tags = widget.tags ?? [];
|
||||||
subspaces = widget.subspaces ?? [];
|
subspaces = widget.subspaces ?? [];
|
||||||
|
selectedSpaceModel = widget.currentSpaceModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -570,12 +573,23 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool _isNameConflict(String value) {
|
bool _isNameConflict(String value) {
|
||||||
return (widget.parentSpace?.children.any((child) => child.name == value) ??
|
final parentSpace = widget.parentSpace;
|
||||||
false) ||
|
final editSpace = widget.editSpace;
|
||||||
(widget.parentSpace?.name == value) ||
|
final siblings = parentSpace?.children
|
||||||
(widget.editSpace?.parent?.name == value) ||
|
.where((child) => child.uuid != editSpace?.uuid)
|
||||||
(widget.editSpace?.children.any((child) => child.name == value) ??
|
.toList() ??
|
||||||
false);
|
[];
|
||||||
|
final siblingConflict = siblings.any((child) => child.name == value);
|
||||||
|
final parentConflict =
|
||||||
|
parentSpace?.name == value && parentSpace?.uuid != editSpace?.uuid;
|
||||||
|
final parentOfEditSpaceConflict = editSpace?.parent?.name == value &&
|
||||||
|
editSpace?.parent?.uuid != editSpace?.uuid;
|
||||||
|
final childConflict =
|
||||||
|
editSpace?.children.any((child) => child.name == value) ?? false;
|
||||||
|
return siblingConflict ||
|
||||||
|
parentConflict ||
|
||||||
|
parentOfEditSpaceConflict ||
|
||||||
|
childConflict;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _showLinkSpaceModelDialog(BuildContext context) {
|
void _showLinkSpaceModelDialog(BuildContext context) {
|
||||||
|
@ -39,15 +39,25 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_spaceModels = widget.spaceModels ?? [];
|
_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) {
|
void _onSpaceModelsUpdated(List<SpaceTemplateModel> updatedModels) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
if (mounted && updatedModels != _spaceModels) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_spaceModels = updatedModels;
|
_spaceModels = updatedModels;
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -72,8 +82,7 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
),
|
),
|
||||||
child: SpaceModelPage(
|
child: SpaceModelPage(
|
||||||
products: widget.products,
|
products: widget.products,
|
||||||
onSpaceModelsUpdated:
|
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
||||||
_onSpaceModelsUpdated, // Pass callback
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -91,13 +100,4 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
43
lib/pages/spaces_management/helper/space_helper.dart
Normal file
43
lib/pages/spaces_management/helper/space_helper.dart
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
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})";
|
||||||
|
}
|
||||||
|
}
|
@ -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';
|
||||||
|
Reference in New Issue
Block a user