mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
updated logic of adding tag to subspace
This commit is contained in:
@ -350,6 +350,9 @@ class AssignTagDialog extends StatelessWidget {
|
||||
.tags
|
||||
?.any((t) => t.internalId == tag.internalId) !=
|
||||
true) {
|
||||
if (modifiedSubspaces[newIndex].tags == null) {
|
||||
modifiedSubspaces[newIndex].tags = [];
|
||||
}
|
||||
tag.location = modifiedSubspaces[newIndex].subspaceName;
|
||||
modifiedSubspaces[newIndex].tags?.add(tag);
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
final updatedTags =
|
||||
List<TagModel>.from(state.tags);
|
||||
final result =
|
||||
processTags(updatedTags, subspaces);
|
||||
updateSubspaceTags(updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<TagModel>;
|
||||
@ -305,8 +305,9 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
? () async {
|
||||
final updatedTags =
|
||||
List<TagModel>.from(state.tags);
|
||||
|
||||
final result =
|
||||
processTags(updatedTags, subspaces);
|
||||
updateSubspaceTags(updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<TagModel>;
|
||||
@ -382,7 +383,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> processTags(
|
||||
Map<String, dynamic> updateSubspaceTags(
|
||||
List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) {
|
||||
final modifiedTags = List<TagModel>.from(updatedTags);
|
||||
final modifiedSubspaces = List<SubspaceTemplateModel>.from(subspaces ?? []);
|
||||
@ -401,29 +402,17 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
|
||||
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) &&
|
||||
prevIndice == null) {
|
||||
final newIndex = modifiedSubspaces
|
||||
.indexWhere((subspace) => subspace.subspaceName == tag.location);
|
||||
|
||||
if (newIndex != -1) {
|
||||
if (modifiedSubspaces[newIndex]
|
||||
.tags
|
||||
?.any((t) => t.internalId == tag.internalId) !=
|
||||
true) {
|
||||
modifiedSubspaces[newIndex].tags ??= [];
|
||||
tag.location = modifiedSubspaces[newIndex].subspaceName;
|
||||
modifiedSubspaces[newIndex].tags?.add(tag);
|
||||
}
|
||||
@ -431,40 +420,6 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
|
||||
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 {
|
||||
@ -472,4 +427,5 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
'subspaces': modifiedSubspaces,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user