mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
fixed page load for space
This commit is contained in:
@ -3,7 +3,7 @@ import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/connection_model.dart';
|
||||
|
||||
class SpaceModel {
|
||||
final String? uuid;
|
||||
String? uuid;
|
||||
final String? icon;
|
||||
final String? spaceTuyaUuid;
|
||||
final String name;
|
||||
@ -16,24 +16,25 @@ class SpaceModel {
|
||||
bool isHovered;
|
||||
|
||||
List<Connection> outgoingConnections = []; // Connections from this space
|
||||
List<Connection> incomingConnections = []; // Connections to this space
|
||||
Connection? incomingConnection; // Connections to this space
|
||||
|
||||
SpaceModel({
|
||||
this.uuid,
|
||||
this.spaceTuyaUuid,
|
||||
required this.icon,
|
||||
required this.name,
|
||||
required this.isPrivate,
|
||||
this.invitationCode,
|
||||
this.parent,
|
||||
this.community,
|
||||
required this.children,
|
||||
required this.position,
|
||||
this.isHovered = false,
|
||||
});
|
||||
SpaceModel(
|
||||
{this.uuid,
|
||||
this.spaceTuyaUuid,
|
||||
required this.icon,
|
||||
required this.name,
|
||||
required this.isPrivate,
|
||||
this.invitationCode,
|
||||
this.parent,
|
||||
this.community,
|
||||
required this.children,
|
||||
required this.position,
|
||||
this.isHovered = false,
|
||||
this.incomingConnection});
|
||||
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json) {
|
||||
return SpaceModel(
|
||||
// Create SpaceModel instance first
|
||||
final instance = SpaceModel(
|
||||
uuid: json['uuid'] ?? '',
|
||||
spaceTuyaUuid: json['spaceTuyaUuid'],
|
||||
name: json['spaceName'],
|
||||
@ -45,11 +46,38 @@ class SpaceModel {
|
||||
? (json['children'] as List).map((child) => SpaceModel.fromJson(child)).toList()
|
||||
: [],
|
||||
icon: json['icon'] as String?,
|
||||
position: json['position'] != null
|
||||
? Offset(json['position']['dx'], json['position']['dy'])
|
||||
position: json['x'] != null && json['y'] != null
|
||||
? Offset(json['x'], json['y'])
|
||||
: const Offset(0, 0),
|
||||
isHovered: false,
|
||||
);
|
||||
|
||||
// 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;
|
||||
}
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
SpaceModel {
|
||||
uuid: $uuid,
|
||||
name: $name,
|
||||
isPrivate: $isPrivate,
|
||||
position: {dx: ${position.dx}, dy: ${position.dy}},
|
||||
parentUuid: ${parent?.uuid},
|
||||
children: ${children.map((child) => child.name).toList()},
|
||||
isHovered: $isHovered
|
||||
}''';
|
||||
}
|
||||
|
||||
Map<String, dynamic> toMap() {
|
||||
@ -66,15 +94,11 @@ class SpaceModel {
|
||||
'position': {'dx': position.dx, 'dy': position.dy},
|
||||
'isHovered': isHovered,
|
||||
'outgoingConnections': outgoingConnections.map((c) => c.toMap()).toList(),
|
||||
'incomingConnections': incomingConnections.map((c) => c.toMap()).toList(),
|
||||
'incomingConnection': incomingConnection?.toMap(),
|
||||
};
|
||||
}
|
||||
|
||||
void addOutgoingConnection(Connection connection) {
|
||||
outgoingConnections.add(connection);
|
||||
}
|
||||
|
||||
void addIncomingConnection(Connection connection) {
|
||||
incomingConnections.add(connection);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user