mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
adjust the canvas if spaces are far positioned
This commit is contained in:
@ -141,29 +141,25 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<SpaceModel> flattenHierarchy(List<SpaceModel> spaces) {
|
List<SpaceModel> flattenHierarchy(List<SpaceModel> spaces) {
|
||||||
final result = <SpaceModel>{}; // Use a Set to avoid duplicates
|
final result = <SpaceModel>{};
|
||||||
|
|
||||||
// Collect all top-level spaces (those without a parent)
|
|
||||||
final topLevelSpaces = spaces.where((space) => space.parent == null);
|
final topLevelSpaces = spaces.where((space) => space.parent == null);
|
||||||
|
|
||||||
void visit(SpaceModel space) {
|
void visit(SpaceModel space) {
|
||||||
if (!result.contains(space)) {
|
if (!result.contains(space)) {
|
||||||
result.add(space); // Add the space
|
result.add(space);
|
||||||
for (var child in spaces.where((s) => s.parent == space)) {
|
for (var child in spaces.where((s) => s.parent == space)) {
|
||||||
visit(child); // Recursively add children based on parent
|
visit(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start with top-level spaces
|
|
||||||
for (var space in topLevelSpaces) {
|
for (var space in topLevelSpaces) {
|
||||||
visit(space);
|
visit(space);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add any spaces that were not part of the hierarchy
|
|
||||||
for (var space in spaces) {
|
for (var space in spaces) {
|
||||||
if (!result.contains(space)) {
|
if (!result.contains(space)) {
|
||||||
result.add(space); // Add standalone or orphan spaces
|
result.add(space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result.toList(); // Convert back to a list
|
return result.toList(); // Convert back to a list
|
||||||
|
@ -38,6 +38,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||||
|
_adjustCanvasSizeForSpaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -48,10 +49,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||||
|
_adjustCanvasSizeForSpaces();
|
||||||
});
|
});
|
||||||
for (var space in spaces) {
|
|
||||||
print('InitState - Space Position ${space.name}: ${space.incomingConnection?.direction}');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +212,18 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _adjustCanvasSizeForSpaces() {
|
||||||
|
for (var space in spaces) {
|
||||||
|
if (space.position.dx >= canvasWidth - 200) {
|
||||||
|
canvasWidth = space.position.dx + 200;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (space.position.dy >= canvasHeight - 200) {
|
||||||
|
canvasHeight = space.position.dy + 200;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void _showCreateSpaceDialog(Size screenSize,
|
void _showCreateSpaceDialog(Size screenSize,
|
||||||
{Offset? position, int? parentIndex, String? direction}) {
|
{Offset? position, int? parentIndex, String? direction}) {
|
||||||
showDialog(
|
showDialog(
|
||||||
@ -323,14 +334,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
List<SpaceModel> spaceList = spaces;
|
List<SpaceModel> spaceList = spaces;
|
||||||
String communityUuid = widget.selectedCommunity!.uuid;
|
String communityUuid = widget.selectedCommunity!.uuid;
|
||||||
|
|
||||||
for (var space in spaceList) {
|
|
||||||
print("Processing space: ${space.name}, UUID: ${space.uuid}");
|
|
||||||
// Example: Log connections
|
|
||||||
print("Parent UUID: ${space.parent?.uuid}");
|
|
||||||
print("Incoming connection: ${space.incomingConnection?.direction}");
|
|
||||||
print("Outgoing connections: ${space.outgoingConnections.map((c) => c.direction).toList()}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dispatch the save event
|
// Dispatch the save event
|
||||||
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
|
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
|
||||||
spaces: spaceList,
|
spaces: spaceList,
|
||||||
|
Reference in New Issue
Block a user