mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
added internal id for mapping spaces internally
This commit is contained in:
@ -86,7 +86,6 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
// Fetch all communities
|
||||
List<CommunityModel> communities = await _api.fetchCommunities();
|
||||
|
||||
// Use Future.wait to handle async calls within map
|
||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||
communities.map((community) async {
|
||||
List<SpaceModel> spaces = await _api.getSpaceHierarchy(community.uuid);
|
||||
|
@ -3,6 +3,7 @@ import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/connection_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/selected_product_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
enum SpaceStatus { newSpace, modified, unchanged, deleted }
|
||||
|
||||
@ -20,12 +21,14 @@ class SpaceModel {
|
||||
bool isHovered;
|
||||
SpaceStatus status;
|
||||
List<SelectedProduct> selectedProducts;
|
||||
String internalId;
|
||||
|
||||
List<Connection> outgoingConnections = []; // Connections from this space
|
||||
Connection? incomingConnection; // Connections to this space
|
||||
|
||||
SpaceModel({
|
||||
this.uuid,
|
||||
String? internalId,
|
||||
this.spaceTuyaUuid,
|
||||
required this.icon,
|
||||
required this.name,
|
||||
@ -39,25 +42,44 @@ class SpaceModel {
|
||||
this.incomingConnection,
|
||||
this.status = SpaceStatus.unchanged,
|
||||
this.selectedProducts = const [],
|
||||
});
|
||||
}) : internalId = internalId ?? const Uuid().v4();
|
||||
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
// Create SpaceModel instance first
|
||||
final instance = SpaceModel(
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json, {String? parentInternalId}) {
|
||||
final String internalId = json['internalId'] ?? const Uuid().v4();
|
||||
|
||||
final List<SpaceModel> children = json['children'] != null
|
||||
? (json['children'] as List).map((childJson) {
|
||||
return SpaceModel.fromJson(
|
||||
childJson,
|
||||
parentInternalId: internalId,
|
||||
);
|
||||
}).toList()
|
||||
: [];
|
||||
|
||||
return SpaceModel(
|
||||
internalId: internalId,
|
||||
uuid: json['uuid'] ?? '',
|
||||
spaceTuyaUuid: json['spaceTuyaUuid'],
|
||||
name: json['spaceName'],
|
||||
isPrivate: json['isPrivate'] ?? false,
|
||||
invitationCode: json['invitationCode'],
|
||||
parent: json['parent'] != null ? SpaceModel.fromJson(json['parent']) : null,
|
||||
parent: parentInternalId != null
|
||||
? SpaceModel(
|
||||
internalId: parentInternalId,
|
||||
uuid: json['parent']?['uuid'],
|
||||
spaceTuyaUuid: json['parent']?['spaceTuyaUuid'],
|
||||
name: json['parent']?['spaceName'] ?? '',
|
||||
isPrivate: json['parent']?['isPrivate'] ?? false,
|
||||
invitationCode: json['parent']?['invitationCode'],
|
||||
children: [],
|
||||
position: Offset(json['parent']?['x'] ?? 0, json['parent']?['y'] ?? 0),
|
||||
icon: json['parent']?['icon'] ?? Assets.location,
|
||||
)
|
||||
: null,
|
||||
community: json['community'] != null ? CommunityModel.fromJson(json['community']) : null,
|
||||
children: json['children'] != null
|
||||
? (json['children'] as List).map((child) => SpaceModel.fromJson(child)).toList()
|
||||
: [],
|
||||
icon: json['icon'] != null? json['icon'] : Assets.location,
|
||||
position: json['x'] != null && json['y'] != null
|
||||
? Offset(json['x'], json['y'])
|
||||
: const Offset(0, 0),
|
||||
children: children,
|
||||
icon: json['icon'] ?? Assets.location,
|
||||
position: Offset(json['x'] ?? 0, json['y'] ?? 0),
|
||||
isHovered: false,
|
||||
selectedProducts: json['spaceProducts'] != null
|
||||
? (json['spaceProducts'] as List).map((product) {
|
||||
@ -68,21 +90,6 @@ class SpaceModel {
|
||||
}).toList()
|
||||
: [],
|
||||
);
|
||||
|
||||
// Add incomingConnection to the instance after creation
|
||||
if (json['incomingConnections'] != null &&
|
||||
json['incomingConnections'] is List &&
|
||||
(json['incomingConnections'] as List).isNotEmpty &&
|
||||
instance.parent != null) {
|
||||
final conn = json['incomingConnections'][0];
|
||||
instance.incomingConnection = Connection(
|
||||
startSpace: instance.parent ?? instance, // Parent space
|
||||
endSpace: instance, // This space instance
|
||||
direction: conn['direction'],
|
||||
);
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
@ -106,5 +113,4 @@ class SpaceModel {
|
||||
void addOutgoingConnection(Connection connection) {
|
||||
outgoingConnections.add(connection);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,9 +5,7 @@ import 'package:syncrow_web/pages/spaces_management/bloc/space_management_bloc.d
|
||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_state.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/connection_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_data_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/loaded_space_widget.dart';
|
||||
import 'package:syncrow_web/services/product_api.dart';
|
||||
@ -27,10 +25,6 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||
final CommunitySpaceManagementApi _api = CommunitySpaceManagementApi();
|
||||
final ProductApi _productApi = ProductApi();
|
||||
Map<String, List<SpaceModel>> communitySpaces = {};
|
||||
double canvasWidth = 1000;
|
||||
double canvasHeight = 1000;
|
||||
List<SpaceData> spaces = [];
|
||||
List<Connection> connections = [];
|
||||
List<ProductModel> products = [];
|
||||
bool isProductDataLoaded = false;
|
||||
|
||||
|
@ -286,6 +286,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
|
||||
if (parentIndex != null && direction != null) {
|
||||
SpaceModel parentSpace = spaces[parentIndex];
|
||||
parentSpace.internalId = spaces[parentIndex].internalId;
|
||||
newSpace.parent = parentSpace;
|
||||
final newConnection = Connection(
|
||||
startSpace: parentSpace,
|
||||
@ -371,13 +372,11 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
for (var child in parent.children) {
|
||||
if (child.status == SpaceStatus.deleted) continue;
|
||||
|
||||
// Create a connection object
|
||||
connections.add(
|
||||
Connection(
|
||||
startSpace: parent,
|
||||
endSpace: child,
|
||||
direction: child.incomingConnection?.direction ??
|
||||
"down", // Assuming "down" for all direct children
|
||||
direction: child.incomingConnection?.direction ?? "down",
|
||||
),
|
||||
);
|
||||
|
||||
@ -478,11 +477,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
bool _isHighlightedSpace(SpaceModel space) {
|
||||
if (widget.selectedSpace == null) return true;
|
||||
if (space == widget.selectedSpace) return true;
|
||||
if (widget.selectedSpace?.parent?.name == space.name &&
|
||||
widget.selectedSpace?.parent?.position == space.position) return true;
|
||||
if (widget.selectedSpace?.children.contains(space) == true) return true;
|
||||
|
||||
return false; // Otherwise, reduce opacity
|
||||
if (widget.selectedSpace?.parent?.internalId == space.internalId) return true;
|
||||
if (widget.selectedSpace?.children != null) {
|
||||
for (var child in widget.selectedSpace!.children) {
|
||||
if (child.internalId == space.internalId) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void _deselectSpace() {
|
||||
|
Reference in New Issue
Block a user