mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
updated subspace edit flow
This commit is contained in:
@ -408,7 +408,9 @@ class SpaceManagementBloc
|
||||
|
||||
Future<List<SpaceModel>> saveSpacesHierarchically(
|
||||
List<SpaceModel> spaces, String communityUuid) async {
|
||||
print("space");
|
||||
final orderedSpaces = flattenHierarchy(spaces);
|
||||
print("parent");
|
||||
|
||||
final parentsToDelete = orderedSpaces.where((space) =>
|
||||
space.status == SpaceStatus.deleted &&
|
||||
@ -420,9 +422,10 @@ class SpaceManagementBloc
|
||||
await _api.deleteSpace(communityUuid, parent.uuid!);
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow; // Decide whether to stop execution or continue
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
orderedSpaces.removeWhere((space) => parentsToDelete.contains(space));
|
||||
|
||||
for (var space in orderedSpaces) {
|
||||
try {
|
||||
|
@ -177,7 +177,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
painter: CurvedLinePainter([connection])),
|
||||
),
|
||||
for (var entry in spaces.asMap().entries)
|
||||
if (entry.value.status != SpaceStatus.deleted ||
|
||||
if (entry.value.status != SpaceStatus.deleted &&
|
||||
entry.value.status != SpaceStatus.parentDeleted)
|
||||
Positioned(
|
||||
left: entry.value.position.dx,
|
||||
@ -301,7 +301,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
List<Tag>? tags) {
|
||||
setState(() {
|
||||
// Set the first space in the center or use passed position
|
||||
|
||||
Offset centerPosition =
|
||||
position ?? _getCenterPosition(screenSize);
|
||||
SpaceModel newSpace = SpaceModel(
|
||||
@ -385,10 +384,10 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
|
||||
void flatten(SpaceModel space) {
|
||||
if (space.status == SpaceStatus.deleted ||
|
||||
space.status == SpaceStatus.parentDeleted) return;
|
||||
|
||||
space.status == SpaceStatus.parentDeleted) {
|
||||
return;
|
||||
}
|
||||
result.add(space);
|
||||
|
||||
for (var child in space.children) {
|
||||
flatten(child);
|
||||
}
|
||||
@ -456,21 +455,17 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
}
|
||||
|
||||
void _onDelete() {
|
||||
if (widget.selectedCommunity != null &&
|
||||
widget.selectedCommunity?.uuid != null &&
|
||||
widget.selectedSpace == null) {
|
||||
context.read<SpaceManagementBloc>().add(DeleteCommunityEvent(
|
||||
communityUuid: widget.selectedCommunity!.uuid,
|
||||
));
|
||||
}
|
||||
if (widget.selectedSpace != null) {
|
||||
setState(() {
|
||||
for (var space in spaces) {
|
||||
if (space.uuid == widget.selectedSpace?.uuid) {
|
||||
if (space.internalId == widget.selectedSpace?.internalId) {
|
||||
space.status = SpaceStatus.deleted;
|
||||
_markChildrenAsDeleted(space);
|
||||
}
|
||||
}
|
||||
for (var space in spaces) {
|
||||
print("space ${space.name} and ${space.status}");
|
||||
}
|
||||
_removeConnectionsForDeletedSpaces();
|
||||
});
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_spac
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/create_space_template_body_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||
@ -204,142 +205,68 @@ class CreateSpaceModelBloc
|
||||
}
|
||||
List<TagModelUpdate> tagUpdates = [];
|
||||
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
|
||||
final List<SubspaceTemplateModel>? prevSubspaces =
|
||||
prevSpaceModel.subspaceModels;
|
||||
final List<SubspaceTemplateModel>? newSubspaces =
|
||||
newSpaceModel.subspaceModels;
|
||||
|
||||
tagUpdates = processTagUpdates(prevSpaceModel.tags, newSpaceModel.tags);
|
||||
|
||||
if (prevSpaceModel.subspaceModels != null) {
|
||||
for (var prevSubspace in prevSpaceModel.subspaceModels!) {
|
||||
if (newSpaceModel.subspaceModels == null) {
|
||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||
action: Action.delete,
|
||||
uuid: prevSubspace.uuid,
|
||||
));
|
||||
continue;
|
||||
if (prevSubspaces != null || newSubspaces != null) {
|
||||
if (prevSubspaces != null && newSubspaces != null) {
|
||||
for (var prevSubspace in prevSubspaces!) {
|
||||
final existsInNew = newSubspaces!
|
||||
.any((newTag) => newTag.uuid == prevSubspace.uuid);
|
||||
if (!existsInNew) {
|
||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||
action: Action.delete, uuid: prevSubspace.uuid));
|
||||
}
|
||||
}
|
||||
|
||||
final subspaceExistsInNew = newSpaceModel.subspaceModels!
|
||||
.any((newSubspace) => newSubspace.uuid == prevSubspace.uuid);
|
||||
if (!subspaceExistsInNew) {
|
||||
} else if (prevSubspaces != null && newSubspaces == null) {
|
||||
for (var prevSubspace in prevSubspaces) {
|
||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||
action: Action.delete,
|
||||
uuid: prevSubspace.uuid,
|
||||
));
|
||||
action: Action.delete, uuid: prevSubspace.uuid));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newSpaceModel.subspaceModels != null) {
|
||||
for (var newSubspaceModel in newSpaceModel.subspaceModels!) {
|
||||
if (newSubspaceModel.uuid == null ||
|
||||
newSubspaceModel.uuid!.isEmpty) {
|
||||
final List<TagModelUpdate> tagUpdatesInSubspace = [];
|
||||
if (newSubspaces != null) {
|
||||
for (var newSubspace in newSubspaces!) {
|
||||
// Tag without UUID
|
||||
if ((newSubspace.uuid == null || newSubspace.uuid!.isEmpty)) {
|
||||
final List<TagModelUpdate> tagUpdates = [];
|
||||
|
||||
if (newSubspaceModel.tags != null) {
|
||||
for (var tag in newSubspaceModel.tags!) {
|
||||
tagUpdatesInSubspace.add(TagModelUpdate(
|
||||
if (newSubspace.tags != null) {
|
||||
for (var tag in newSubspace.tags!) {
|
||||
tagUpdates.add(TagModelUpdate(
|
||||
action: Action.add,
|
||||
tag: tag.tag,
|
||||
productUuid: tag.product?.uuid));
|
||||
}
|
||||
}
|
||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||
action: Action.add,
|
||||
uuid: tag.uuid,
|
||||
tag: tag.tag,
|
||||
productUuid: tag.product?.uuid,
|
||||
));
|
||||
}
|
||||
subspaceName: newSubspace.subspaceName,
|
||||
tags: tagUpdates));
|
||||
}
|
||||
|
||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||
action: Action.add,
|
||||
subspaceName: newSubspaceModel.subspaceName,
|
||||
tags: tagUpdatesInSubspace,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (newSpaceModel.subspaceModels != null &&
|
||||
prevSpaceModel.subspaceModels != null) {
|
||||
final prevSubspaceMap = {
|
||||
for (var subspace in prevSpaceModel.subspaceModels!)
|
||||
subspace.uuid: subspace
|
||||
};
|
||||
if (prevSubspaces != null && newSubspaces != null) {
|
||||
final newSubspaceMap = {
|
||||
for (var subspace in newSubspaces!) subspace.uuid: subspace
|
||||
};
|
||||
|
||||
for (var newSubspace in newSpaceModel.subspaceModels!) {
|
||||
if (newSubspace.uuid != null &&
|
||||
prevSubspaceMap.containsKey(newSubspace.uuid)) {
|
||||
final prevSubspace = prevSubspaceMap[newSubspace.uuid]!;
|
||||
|
||||
// Check if modelName has changed
|
||||
if (newSubspace.subspaceName != prevSubspace.subspaceName) {
|
||||
for (var prevSubspace in prevSubspaces!) {
|
||||
final newSubspace = newSubspaceMap[prevSubspace.uuid];
|
||||
if (newSubspace != null) {
|
||||
final List<TagModelUpdate> tagSubspaceUpdates =
|
||||
processTagUpdates(prevSubspace.tags, newSubspace.tags);
|
||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||
action: Action.update,
|
||||
uuid: newSubspace.uuid,
|
||||
subspaceName: newSubspace.subspaceName,
|
||||
));
|
||||
}
|
||||
|
||||
// Compare tags within the subspace
|
||||
final List<TagModelUpdate> tagUpdatesInSubspace = [];
|
||||
if (prevSubspace.tags != null && newSubspace.tags != null) {
|
||||
final prevTagMap = {
|
||||
for (var tag in prevSubspace.tags!) tag.uuid: tag
|
||||
};
|
||||
|
||||
// Check for deleted tags
|
||||
for (var prevTag in prevSubspace.tags!) {
|
||||
if (!newSubspace.tags!
|
||||
.any((newTag) => newTag.uuid == prevTag.uuid)) {
|
||||
tagUpdatesInSubspace.add(TagModelUpdate(
|
||||
action: Action.delete,
|
||||
uuid: prevTag.uuid,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Check for added tags, including those without a UUID
|
||||
for (var newTag in newSubspace.tags!) {
|
||||
if (newTag.uuid == null || newTag.uuid!.isEmpty) {
|
||||
// Add new tag without UUID
|
||||
tagUpdatesInSubspace.add(TagModelUpdate(
|
||||
action: Action.add,
|
||||
uuid: null, // or generate a new UUID if required
|
||||
tag: newTag.tag,
|
||||
productUuid: newTag.product?.uuid,
|
||||
));
|
||||
} else if (!prevSubspace.tags!
|
||||
.any((prevTag) => prevTag.uuid == newTag.uuid)) {
|
||||
// Add new tag with UUID
|
||||
tagUpdatesInSubspace.add(TagModelUpdate(
|
||||
action: Action.add,
|
||||
uuid: newTag.uuid,
|
||||
tag: newTag.tag,
|
||||
productUuid: newTag.product?.uuid,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
// Check for updated tags
|
||||
for (var prevTag in prevSubspace.tags!) {
|
||||
final newTag = newSubspace.tags!.cast<TagModel?>().firstWhere(
|
||||
(tag) => tag?.uuid == prevTag.uuid,
|
||||
orElse: () => null,
|
||||
);
|
||||
if (newTag != null && newTag.tag != prevTag.tag) {
|
||||
tagUpdatesInSubspace.add(TagModelUpdate(
|
||||
action: Action.update,
|
||||
uuid: newTag.uuid,
|
||||
tag: newTag.tag,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add the subspace with updated tags if necessary
|
||||
if (tagUpdatesInSubspace.isNotEmpty) {
|
||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||
action: Action.update,
|
||||
uuid: newSubspace.uuid,
|
||||
subspaceName: newSubspace.subspaceName,
|
||||
tags: tagUpdatesInSubspace,
|
||||
));
|
||||
}
|
||||
action: Action.update,
|
||||
uuid: newSubspace.uuid,
|
||||
subspaceName: newSubspace.subspaceName,
|
||||
tags: tagSubspaceUpdates));
|
||||
} else {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -382,6 +309,11 @@ class CreateSpaceModelBloc
|
||||
.add(TagModelUpdate(action: Action.delete, uuid: prevTag.uuid));
|
||||
}
|
||||
}
|
||||
} else if (prevTags != null && newTags == null) {
|
||||
for (var prevTag in prevTags) {
|
||||
tagUpdates
|
||||
.add(TagModelUpdate(action: Action.delete, uuid: prevTag.uuid));
|
||||
}
|
||||
}
|
||||
|
||||
// Case 2: Tags added
|
||||
|
@ -47,4 +47,9 @@ class CreateSpaceTemplateBodyModel {
|
||||
'subspaceModels': subspaceModels,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return toJson().toString();
|
||||
}
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ class SpaceModelManagementApi {
|
||||
|
||||
Future<String?> updateSpaceModel(
|
||||
CreateSpaceTemplateBodyModel spaceModel, String spaceModelUuid) async {
|
||||
print(spaceModel.toJson().toString());
|
||||
final response = await HTTPService().put(
|
||||
path: ApiEndpoints.updateSpaceModel
|
||||
.replaceAll('{projectId}', TempConst.projectId).replaceAll('{spaceModelUuid}', spaceModelUuid),
|
||||
|
Reference in New Issue
Block a user