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