mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
updating tags inside subspace
This commit is contained in:
@ -299,7 +299,7 @@ class TagHelper {
|
|||||||
|
|
||||||
static Map<String, dynamic> updateSubspaceTagModels(
|
static Map<String, dynamic> updateSubspaceTagModels(
|
||||||
List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) {
|
List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) {
|
||||||
return TagHelper.updateTags<TagModel>(
|
final result = TagHelper.updateTags<TagModel>(
|
||||||
updatedTags: updatedTags,
|
updatedTags: updatedTags,
|
||||||
subspaces: subspaces,
|
subspaces: subspaces,
|
||||||
getInternalId: (tag) => tag.internalId,
|
getInternalId: (tag) => tag.internalId,
|
||||||
@ -310,6 +310,34 @@ class TagHelper {
|
|||||||
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
||||||
checkTagExistInSubspace: checkTagExistInSubspaceModels,
|
checkTagExistInSubspace: checkTagExistInSubspaceModels,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final processedTags = result['updatedTags'] as List<TagModel>;
|
||||||
|
final processedSubspaces =
|
||||||
|
List<SubspaceTemplateModel>.from(result['subspaces'] as List<dynamic>);
|
||||||
|
|
||||||
|
for (var subspace in processedSubspaces) {
|
||||||
|
final subspaceTags = subspace.tags;
|
||||||
|
|
||||||
|
if (subspaceTags != null) {
|
||||||
|
for (int i = 0; i < subspaceTags.length; i++) {
|
||||||
|
final tag = subspaceTags[i];
|
||||||
|
|
||||||
|
// Find the updated tag inside processedTags
|
||||||
|
final changedTag = updatedTags.firstWhere(
|
||||||
|
(t) => t.internalId == tag.internalId,
|
||||||
|
orElse: () => tag,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (changedTag.tag != tag.tag) {
|
||||||
|
subspaceTags[i] = changedTag.copyWith(tag: changedTag.tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subspace.tags = subspaceTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {'updatedTags': processedTags, 'subspaces': processedSubspaces};
|
||||||
}
|
}
|
||||||
|
|
||||||
static int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
|
static int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
|
||||||
@ -328,7 +356,7 @@ class TagHelper {
|
|||||||
|
|
||||||
static Map<String, dynamic> processTags(
|
static Map<String, dynamic> processTags(
|
||||||
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
|
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
|
||||||
return TagHelper.updateTags<Tag>(
|
final result = TagHelper.updateTags<Tag>(
|
||||||
updatedTags: updatedTags,
|
updatedTags: updatedTags,
|
||||||
subspaces: subspaces,
|
subspaces: subspaces,
|
||||||
getInternalId: (tag) => tag.internalId,
|
getInternalId: (tag) => tag.internalId,
|
||||||
@ -339,6 +367,33 @@ class TagHelper {
|
|||||||
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
||||||
checkTagExistInSubspace: checkTagExistInSubspace,
|
checkTagExistInSubspace: checkTagExistInSubspace,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
final processedTags = result['updatedTags'] as List<Tag>;
|
||||||
|
final processedSubspaces =
|
||||||
|
List<SubspaceModel>.from(result['subspaces'] as List<dynamic>);
|
||||||
|
|
||||||
|
for (var subspace in processedSubspaces) {
|
||||||
|
final subspaceTags = subspace.tags;
|
||||||
|
|
||||||
|
if (subspaceTags != null) {
|
||||||
|
for (int i = 0; i < subspaceTags.length; i++) {
|
||||||
|
final tag = subspaceTags[i];
|
||||||
|
|
||||||
|
final changedTag = updatedTags.firstWhere(
|
||||||
|
(t) => t.internalId == tag.internalId,
|
||||||
|
orElse: () => tag,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (changedTag.tag != tag.tag) {
|
||||||
|
subspaceTags[i] = changedTag.copyWith(tag: changedTag.tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
subspace.tags = subspaceTags;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {'updatedTags': processedTags, 'subspaces': processedSubspaces};
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<String> getAllTagValues(
|
static List<String> getAllTagValues(
|
||||||
|
Reference in New Issue
Block a user