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