mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed repeated duplication
This commit is contained in:
@ -414,21 +414,20 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
result.add(space);
|
result.add(space);
|
||||||
idToSpace[space.internalId] = space;
|
idToSpace[space.internalId] = space;
|
||||||
|
|
||||||
for (var child in space.children) {
|
for (var child in space.children) {
|
||||||
flatten(child);
|
flatten(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (var space in spaces) {
|
for (var space in spaces) {
|
||||||
flatten(space);
|
flatten(space);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var space in result) {
|
for (var space in result) {
|
||||||
if (space.parent != null) {
|
if (space.parent != null) {
|
||||||
space.parent = idToSpace[space.parent!.internalId];
|
space.parent = idToSpace[space.parent!.internalId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -704,62 +703,26 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _duplicateSpace(SpaceModel space) {
|
void _duplicateSpace(SpaceModel space) {
|
||||||
final double horizontalGap = 250.0;
|
|
||||||
final double verticalGap = 180.0;
|
|
||||||
final double nodeWidth = 200;
|
|
||||||
final double nodeHeight = 100;
|
|
||||||
final double breathingSpace = 300.0;
|
|
||||||
|
|
||||||
/// Helper to recursively duplicate a node and its children
|
|
||||||
SpaceModel duplicateRecursive(SpaceModel original, SpaceModel? duplicatedParent) {
|
|
||||||
final duplicatedName = SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
|
||||||
final duplicated = SpaceModel(
|
|
||||||
name: duplicatedName,
|
|
||||||
icon: original.icon,
|
|
||||||
position: original.position,
|
|
||||||
isPrivate: original.isPrivate,
|
|
||||||
children: [],
|
|
||||||
status: SpaceStatus.newSpace,
|
|
||||||
parent: duplicatedParent,
|
|
||||||
spaceModel: original.spaceModel,
|
|
||||||
subspaces: original.subspaces,
|
|
||||||
tags: original.tags,
|
|
||||||
);
|
|
||||||
|
|
||||||
spaces.add(duplicated);
|
|
||||||
|
|
||||||
if (duplicatedParent != null) {
|
|
||||||
final newConnection = Connection(
|
|
||||||
startSpace: duplicatedParent,
|
|
||||||
endSpace: duplicated,
|
|
||||||
direction: "down",
|
|
||||||
);
|
|
||||||
connections.add(newConnection);
|
|
||||||
|
|
||||||
duplicated.incomingConnection = newConnection;
|
|
||||||
duplicatedParent.addOutgoingConnection(newConnection);
|
|
||||||
duplicatedParent.children.add(duplicated);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Duplicate its children recursively
|
|
||||||
for (var child in original.children) {
|
|
||||||
duplicateRecursive(child, duplicated);
|
|
||||||
}
|
|
||||||
|
|
||||||
return duplicated;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Actual duplication process
|
|
||||||
setState(() {
|
setState(() {
|
||||||
if (space.parent == null) {
|
SpaceModel? parent = space.parent;
|
||||||
// Duplicating a ROOT node
|
|
||||||
duplicateRecursive(space, null);
|
SpaceModel duplicated = _deepCloneSpaceTree(space, parent: parent);
|
||||||
connections = createConnections(spaces);
|
|
||||||
realignTree();
|
duplicated.position = Offset(space.position.dx + 300, space.position.dy + 100);
|
||||||
} else {
|
List<SpaceModel> duplicatedSubtree = [];
|
||||||
final parent = space.parent!;
|
void collectSubtree(SpaceModel node) {
|
||||||
|
duplicatedSubtree.add(node);
|
||||||
|
for (var child in node.children) {
|
||||||
|
collectSubtree(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
collectSubtree(duplicated);
|
||||||
|
spaces.addAll(duplicatedSubtree);
|
||||||
|
|
||||||
|
if (parent != null) {
|
||||||
|
parent.children.add(duplicated);
|
||||||
|
|
||||||
final duplicated = duplicateRecursive(space, parent);
|
|
||||||
final newConnection = Connection(
|
final newConnection = Connection(
|
||||||
startSpace: parent,
|
startSpace: parent,
|
||||||
endSpace: duplicated,
|
endSpace: duplicated,
|
||||||
@ -768,11 +731,44 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
connections.add(newConnection);
|
connections.add(newConnection);
|
||||||
duplicated.incomingConnection = newConnection;
|
duplicated.incomingConnection = newConnection;
|
||||||
parent.addOutgoingConnection(newConnection);
|
parent.addOutgoingConnection(newConnection);
|
||||||
parent.children.add(duplicated);
|
|
||||||
connections = createConnections(spaces);
|
|
||||||
realignTree();
|
|
||||||
//_realignSubtree(space.parent!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
realignTree();
|
||||||
|
connections = createConnections(spaces);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpaceModel _deepCloneSpaceTree(SpaceModel original, {SpaceModel? parent}) {
|
||||||
|
final duplicatedName = SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||||
|
|
||||||
|
final newSpace = SpaceModel(
|
||||||
|
name: duplicatedName,
|
||||||
|
icon: original.icon,
|
||||||
|
position: original.position,
|
||||||
|
isPrivate: original.isPrivate,
|
||||||
|
children: [],
|
||||||
|
status: SpaceStatus.newSpace,
|
||||||
|
spaceModel: original.spaceModel,
|
||||||
|
subspaces: original.subspaces,
|
||||||
|
tags: original.tags,
|
||||||
|
parent: parent,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (var child in original.children) {
|
||||||
|
final duplicatedChild = _deepCloneSpaceTree(child, parent: newSpace);
|
||||||
|
newSpace.children.add(duplicatedChild);
|
||||||
|
|
||||||
|
final newConnection = Connection(
|
||||||
|
startSpace: newSpace,
|
||||||
|
endSpace: duplicatedChild,
|
||||||
|
direction: "down",
|
||||||
|
);
|
||||||
|
connections.add(newConnection);
|
||||||
|
|
||||||
|
duplicatedChild.incomingConnection = newConnection;
|
||||||
|
newSpace.addOutgoingConnection(newConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newSpace;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user