mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
added subspaces
This commit is contained in:
@ -1,6 +1,8 @@
|
||||
import 'dart:ui';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/connection_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
@ -22,6 +24,8 @@ class SpaceModel {
|
||||
SpaceStatus status;
|
||||
String internalId;
|
||||
SpaceTemplateModel? spaceModel;
|
||||
final List<Tag>? tags;
|
||||
List<SubspaceModel>? subspaces;
|
||||
|
||||
List<Connection> outgoingConnections = []; // Connections from this space
|
||||
Connection? incomingConnection; // Connections to this space
|
||||
@ -42,6 +46,8 @@ class SpaceModel {
|
||||
this.incomingConnection,
|
||||
this.status = SpaceStatus.unchanged,
|
||||
this.spaceModel,
|
||||
this.tags,
|
||||
this.subspaces,
|
||||
}) : internalId = internalId ?? const Uuid().v4();
|
||||
|
||||
factory SpaceModel.fromJson(Map<String, dynamic> json,
|
||||
@ -64,6 +70,11 @@ class SpaceModel {
|
||||
name: json['spaceName'],
|
||||
isPrivate: json['isPrivate'] ?? false,
|
||||
invitationCode: json['invitationCode'],
|
||||
subspaces: (json['subspaces'] as List<dynamic>?)
|
||||
?.where((e) => e is Map<String, dynamic>) // Validate type
|
||||
.map((e) => SubspaceModel.fromJson(e as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
parent: parentInternalId != null
|
||||
? SpaceModel(
|
||||
internalId: parentInternalId,
|
||||
@ -85,6 +96,11 @@ class SpaceModel {
|
||||
icon: json['icon'] ?? Assets.location,
|
||||
position: Offset(json['x'] ?? 0, json['y'] ?? 0),
|
||||
isHovered: false,
|
||||
tags: (json['tags'] as List<dynamic>?)
|
||||
?.where((item) => item is Map<String, dynamic>) // Validate type
|
||||
.map((item) => Tag.fromJson(item as Map<String, dynamic>))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
|
||||
if (json['incomingConnections'] != null &&
|
||||
@ -110,6 +126,7 @@ class SpaceModel {
|
||||
'isPrivate': isPrivate,
|
||||
'invitationCode': invitationCode,
|
||||
'parent': parent?.uuid,
|
||||
'subspaces': subspaces?.map((e) => e.toJson()).toList(),
|
||||
'community': community?.toMap(),
|
||||
'children': children.map((child) => child.toMap()).toList(),
|
||||
'icon': icon,
|
||||
@ -117,6 +134,7 @@ class SpaceModel {
|
||||
'isHovered': isHovered,
|
||||
'outgoingConnections': outgoingConnections.map((c) => c.toMap()).toList(),
|
||||
'incomingConnection': incomingConnection?.toMap(),
|
||||
'tags': tags?.map((e) => e.toJson()).toList(),
|
||||
};
|
||||
}
|
||||
|
||||
@ -124,3 +142,28 @@ class SpaceModel {
|
||||
outgoingConnections.add(connection);
|
||||
}
|
||||
}
|
||||
|
||||
extension SpaceExtensions on SpaceModel {
|
||||
List<String> listAllTagValues() {
|
||||
final List<String> tagValues = [];
|
||||
|
||||
if (tags != null) {
|
||||
tagValues.addAll(
|
||||
tags!.map((tag) => tag.tag ?? '').where((tag) => tag.isNotEmpty));
|
||||
}
|
||||
|
||||
if (subspaces != null) {
|
||||
for (final subspace in subspaces!) {
|
||||
if (subspace.tags != null) {
|
||||
tagValues.addAll(
|
||||
subspace.tags!
|
||||
.map((tag) => tag.tag ?? '')
|
||||
.where((tag) => tag.isNotEmpty),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return tagValues;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user