mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
updated logic of adding tag to subspace
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user