mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-26 07:29:41 +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;
|
||||
}
|
||||
}
|
||||
|
110
lib/pages/spaces_management/all_spaces/model/subspace_model.dart
Normal file
110
lib/pages/spaces_management/all_spaces/model/subspace_model.dart
Normal file
@ -0,0 +1,110 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
||||
|
||||
import 'tag.dart';
|
||||
|
||||
class SubspaceModel {
|
||||
final String? uuid;
|
||||
String subspaceName;
|
||||
final bool disabled;
|
||||
List<Tag>? tags;
|
||||
|
||||
SubspaceModel({
|
||||
this.uuid,
|
||||
required this.subspaceName,
|
||||
required this.disabled,
|
||||
this.tags,
|
||||
});
|
||||
|
||||
factory SubspaceModel.fromJson(Map<String, dynamic> json) {
|
||||
return SubspaceModel(
|
||||
uuid: json['uuid'] ?? '',
|
||||
subspaceName: json['subspaceName'] ?? '',
|
||||
disabled: json['disabled'] ?? false,
|
||||
tags: (json['tags'] as List<dynamic>?)
|
||||
?.map((item) => Tag.fromJson(item))
|
||||
.toList() ??
|
||||
[],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'subspaceName': subspaceName,
|
||||
'disabled': disabled,
|
||||
'tags': tags?.map((e) => e.toJson()).toList() ?? [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateSubspaceModel {
|
||||
final String uuid;
|
||||
final Action action;
|
||||
final String? subspaceName;
|
||||
final List<UpdateTag>? tags;
|
||||
UpdateSubspaceModel({
|
||||
required this.action,
|
||||
required this.uuid,
|
||||
this.subspaceName,
|
||||
this.tags,
|
||||
});
|
||||
|
||||
factory UpdateSubspaceModel.fromJson(Map<String, dynamic> json) {
|
||||
return UpdateSubspaceModel(
|
||||
action: ActionExtension.fromValue(json['action']),
|
||||
uuid: json['uuid'] ?? '',
|
||||
subspaceName: json['subspaceName'] ?? '',
|
||||
tags: (json['tags'] as List)
|
||||
.map((item) => UpdateTag.fromJson(item))
|
||||
.toList(),
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'action': action.value,
|
||||
'uuid': uuid,
|
||||
'subspaceName': subspaceName,
|
||||
'tags': tags?.map((e) => e.toJson()).toList() ?? [],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class UpdateTag {
|
||||
final Action action;
|
||||
final String? uuid;
|
||||
final String tag;
|
||||
final bool disabled;
|
||||
final ProductModel? product;
|
||||
|
||||
UpdateTag({
|
||||
required this.action,
|
||||
this.uuid,
|
||||
required this.tag,
|
||||
required this.disabled,
|
||||
this.product,
|
||||
});
|
||||
|
||||
factory UpdateTag.fromJson(Map<String, dynamic> json) {
|
||||
return UpdateTag(
|
||||
action: ActionExtension.fromValue(json['action']),
|
||||
uuid: json['uuid'] ?? '',
|
||||
tag: json['tag'] ?? '',
|
||||
disabled: json['disabled'] ?? false,
|
||||
product: json['product'] != null
|
||||
? ProductModel.fromMap(json['product'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'action': action.value,
|
||||
'uuid': uuid,
|
||||
'tag': tag,
|
||||
'disabled': disabled,
|
||||
'product': product?.toMap(),
|
||||
};
|
||||
}
|
||||
}
|
61
lib/pages/spaces_management/all_spaces/model/tag.dart
Normal file
61
lib/pages/spaces_management/all_spaces/model/tag.dart
Normal file
@ -0,0 +1,61 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
class Tag {
|
||||
String? uuid;
|
||||
String? tag;
|
||||
final ProductModel? product;
|
||||
String internalId;
|
||||
String? location;
|
||||
|
||||
Tag(
|
||||
{this.uuid,
|
||||
required this.tag,
|
||||
this.product,
|
||||
String? internalId,
|
||||
this.location})
|
||||
: internalId = internalId ?? const Uuid().v4();
|
||||
|
||||
factory Tag.fromJson(Map<String, dynamic> json) {
|
||||
final String internalId = json['internalId'] ?? const Uuid().v4();
|
||||
|
||||
return Tag(
|
||||
uuid: json['uuid'] ?? '',
|
||||
internalId: internalId,
|
||||
tag: json['tag'] ?? '',
|
||||
product: json['product'] != null
|
||||
? ProductModel.fromMap(json['product'])
|
||||
: null,
|
||||
);
|
||||
}
|
||||
|
||||
Tag copyWith({
|
||||
String? tag,
|
||||
ProductModel? product,
|
||||
String? location,
|
||||
}) {
|
||||
return Tag(
|
||||
tag: tag ?? this.tag,
|
||||
product: product ?? this.product,
|
||||
location: location ?? this.location,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'uuid': uuid,
|
||||
'tag': tag,
|
||||
'product': product?.toMap(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
extension TagModelExtensions on Tag {
|
||||
TagBodyModel toTagBodyModel() {
|
||||
return TagBodyModel()
|
||||
..uuid = uuid ?? ''
|
||||
..tag = tag ?? ''
|
||||
..productUuid = product?.uuid;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user