updated logic of adding tag to subspace

This commit is contained in:
hannathkadher
2025-01-30 21:15:00 +04:00
parent bf5b39e742
commit 9dd6c9e1e7
2 changed files with 10 additions and 51 deletions

View File

@ -350,6 +350,9 @@ class AssignTagDialog extends StatelessWidget {
.tags .tags
?.any((t) => t.internalId == tag.internalId) != ?.any((t) => t.internalId == tag.internalId) !=
true) { true) {
if (modifiedSubspaces[newIndex].tags == null) {
modifiedSubspaces[newIndex].tags = [];
}
tag.location = modifiedSubspaces[newIndex].subspaceName; tag.location = modifiedSubspaces[newIndex].subspaceName;
modifiedSubspaces[newIndex].tags?.add(tag); modifiedSubspaces[newIndex].tags?.add(tag);
} }

View File

@ -254,7 +254,7 @@ class AssignTagModelsDialog extends StatelessWidget {
final updatedTags = final updatedTags =
List<TagModel>.from(state.tags); List<TagModel>.from(state.tags);
final result = final result =
processTags(updatedTags, subspaces); updateSubspaceTags(updatedTags, subspaces);
final processedTags = final processedTags =
result['updatedTags'] as List<TagModel>; result['updatedTags'] as List<TagModel>;
@ -305,8 +305,9 @@ class AssignTagModelsDialog extends StatelessWidget {
? () async { ? () async {
final updatedTags = final updatedTags =
List<TagModel>.from(state.tags); List<TagModel>.from(state.tags);
final result = final result =
processTags(updatedTags, subspaces); updateSubspaceTags(updatedTags, subspaces);
final processedTags = final processedTags =
result['updatedTags'] as List<TagModel>; result['updatedTags'] as List<TagModel>;
@ -382,7 +383,7 @@ class AssignTagModelsDialog extends StatelessWidget {
return null; return null;
} }
Map<String, dynamic> processTags( Map<String, dynamic> updateSubspaceTags(
List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) { List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) {
final modifiedTags = List<TagModel>.from(updatedTags); final modifiedTags = List<TagModel>.from(updatedTags);
final modifiedSubspaces = List<SubspaceTemplateModel>.from(subspaces ?? []); final modifiedSubspaces = List<SubspaceTemplateModel>.from(subspaces ?? []);
@ -401,29 +402,17 @@ class AssignTagModelsDialog extends StatelessWidget {
final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces); final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces);
if ((tag.location == 'Main Space' || tag.location == null) &&
(prevIndice == null ||
modifiedSubspaces[prevIndice].subspaceName == 'Main Space')) {
continue;
}
if ((tag.location == 'Main Space' || tag.location == null) &&
prevIndice != null) {
modifiedSubspaces[prevIndice]
.tags
?.removeWhere((t) => t.internalId == tag.internalId);
continue;
}
if ((tag.location != 'Main Space' && tag.location != null) && if ((tag.location != 'Main Space' && tag.location != null) &&
prevIndice == null) { prevIndice == null) {
final newIndex = modifiedSubspaces final newIndex = modifiedSubspaces
.indexWhere((subspace) => subspace.subspaceName == tag.location); .indexWhere((subspace) => subspace.subspaceName == tag.location);
if (newIndex != -1) { if (newIndex != -1) {
if (modifiedSubspaces[newIndex] if (modifiedSubspaces[newIndex]
.tags .tags
?.any((t) => t.internalId == tag.internalId) != ?.any((t) => t.internalId == tag.internalId) !=
true) { true) {
modifiedSubspaces[newIndex].tags ??= [];
tag.location = modifiedSubspaces[newIndex].subspaceName; tag.location = modifiedSubspaces[newIndex].subspaceName;
modifiedSubspaces[newIndex].tags?.add(tag); modifiedSubspaces[newIndex].tags?.add(tag);
} }
@ -431,40 +420,6 @@ class AssignTagModelsDialog extends StatelessWidget {
modifiedTags.removeWhere((t) => t.internalId == tag.internalId); modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
continue; continue;
} }
if ((tag.location != 'Main Space' && tag.location != null) &&
tag.location != modifiedSubspaces[prevIndice!].subspaceName) {
modifiedSubspaces[prevIndice]
.tags
?.removeWhere((t) => t.internalId == tag.internalId);
final newIndex = modifiedSubspaces
.indexWhere((subspace) => subspace.subspaceName == tag.location);
if (newIndex != -1) {
if (modifiedSubspaces[newIndex]
.tags
?.any((t) => t.internalId == tag.internalId) !=
true) {
tag.location = modifiedSubspaces[newIndex].subspaceName;
modifiedSubspaces[newIndex].tags?.add(tag);
}
}
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
continue;
}
if ((tag.location != 'Main Space' && tag.location != null) &&
tag.location == modifiedSubspaces[prevIndice!].subspaceName) {
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
continue;
}
if ((tag.location == 'Main Space' || tag.location == null) &&
prevIndice != null) {
modifiedSubspaces[prevIndice]
.tags
?.removeWhere((t) => t.internalId == tag.internalId);
}
} }
return { return {
@ -472,4 +427,5 @@ class AssignTagModelsDialog extends StatelessWidget {
'subspaces': modifiedSubspaces, 'subspaces': modifiedSubspaces,
}; };
} }
} }