diff --git a/lib/pages/spaces_management/all_spaces/model/tag.dart b/lib/pages/spaces_management/all_spaces/model/tag.dart index c0f21325..8959986c 100644 --- a/lib/pages/spaces_management/all_spaces/model/tag.dart +++ b/lib/pages/spaces_management/all_spaces/model/tag.dart @@ -26,9 +26,7 @@ class Tag extends BaseTag { uuid: json['uuid'] ?? '', internalId: internalId, tag: json['name'] ?? '', - product: json['product'] != null - ? ProductModel.fromMap(json['product']) - : null, + product: json['product'] != null ? ProductModel.fromMap(json['product']) : null, ); } @@ -41,7 +39,7 @@ class Tag extends BaseTag { String? internalId, }) { return Tag( - uuid: uuid, + uuid: uuid ?? this.uuid, tag: tag ?? this.tag, product: product ?? this.product, location: location ?? this.location, @@ -61,7 +59,7 @@ class Tag extends BaseTag { extension TagModelExtensions on Tag { TagBodyModel toTagBodyModel() { return TagBodyModel() - ..uuid = uuid + ..uuid = uuid ..tag = tag ?? '' ..productUuid = product?.uuid; } diff --git a/lib/pages/spaces_management/assign_tag_models/bloc/assign_tag_model_bloc.dart b/lib/pages/spaces_management/assign_tag_models/bloc/assign_tag_model_bloc.dart index 92699559..51b89859 100644 --- a/lib/pages/spaces_management/assign_tag_models/bloc/assign_tag_model_bloc.dart +++ b/lib/pages/spaces_management/assign_tag_models/bloc/assign_tag_model_bloc.dart @@ -83,10 +83,12 @@ class AssignTagModelBloc extends Bloc if (currentState is AssignTagModelLoaded && currentState.tags.isNotEmpty) { final tags = List.from(currentState.tags); - + for (var t in tags) { + } // Use copyWith for immutability tags[event.index] = tags[event.index].copyWith(location: event.location); + final updatedTags = _calculateAvailableTags(projectTags, tags); emit(AssignTagModelLoaded( diff --git a/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart b/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart index df978a6e..c9d0b57a 100644 --- a/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart +++ b/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart @@ -57,7 +57,7 @@ class AssignTagModelsDialog extends StatelessWidget { (subspaces ?? []).map((subspace) => subspace.subspaceName).toList()..add('Main Space'); return BlocProvider( - create: (_) => AssignTagModelBloc( projectTags) + create: (_) => AssignTagModelBloc(projectTags) ..add(InitializeTagModels( initialTags: initialTags, addedProducts: addedProducts, diff --git a/lib/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart b/lib/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart index d6801b95..5428c343 100644 --- a/lib/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart +++ b/lib/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart @@ -248,7 +248,7 @@ class CreateSpaceModelBloc for (var tag in newSubspace.tags!) { tagUpdates.add(TagModelUpdate( action: Action.add, - uuid: tag.uuid == '' ? null : tag.uuid, + newTagUuid: tag.uuid == '' ? null : tag.uuid, tag: tag.tag, productUuid: tag.product?.uuid)); } @@ -315,7 +315,7 @@ class CreateSpaceModelBloc tagUpdates.add(TagModelUpdate( action: Action.add, tag: newTag.tag, - uuid: newTag.uuid, + newTagUuid: newTag.uuid, productUuid: newTag.product?.uuid, )); } @@ -351,7 +351,7 @@ class CreateSpaceModelBloc tagUpdates.add(TagModelUpdate( action: Action.add, tag: newTag.tag, - uuid: newTag.uuid == '' ? null : newTag.uuid, + newTagUuid: newTag.uuid == '' ? null : newTag.uuid, productUuid: newTag.product?.uuid)); processedTags.add(newTag.tag); } @@ -367,7 +367,8 @@ class CreateSpaceModelBloc if (newTag != null) { tagUpdates.add(TagModelUpdate( action: Action.update, - uuid: newTag.uuid, + uuid: prevTag.uuid, + newTagUuid: newTag.uuid, tag: newTag.tag, )); } else {} diff --git a/lib/pages/spaces_management/space_model/bloc/space_model_bloc.dart b/lib/pages/spaces_management/space_model/bloc/space_model_bloc.dart index ed6ffa71..d94751d9 100644 --- a/lib/pages/spaces_management/space_model/bloc/space_model_bloc.dart +++ b/lib/pages/spaces_management/space_model/bloc/space_model_bloc.dart @@ -14,28 +14,23 @@ class SpaceModelBloc extends Bloc { required this.api, required List initialSpaceModels, }) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) { - log('Initial Space Models in: ${initialSpaceModels.map((e) => e.toJson()).toList()}'); - on(_onCreateSpaceModel); on(_onUpdateSpaceModel); on(_onDeleteSpaceModel); } - Future _onCreateSpaceModel( - CreateSpaceModel event, Emitter emit) async { + Future _onCreateSpaceModel(CreateSpaceModel event, Emitter emit) async { final currentState = state; if (currentState is SpaceModelLoaded) { try { final projectUuid = await ProjectManager.getProjectUUID() ?? ''; - final newSpaceModel = await api.getSpaceModel( - event.newSpaceModel.uuid ?? '', projectUuid); + final newSpaceModel = await api.getSpaceModel(event.newSpaceModel.uuid ?? '', projectUuid); if (newSpaceModel != null) { - final updatedSpaceModels = - List.from(currentState.spaceModels) - ..add(newSpaceModel); + final updatedSpaceModels = List.from(currentState.spaceModels) + ..add(newSpaceModel); emit(SpaceModelLoaded(spaceModels: updatedSpaceModels)); } } catch (e) { @@ -44,15 +39,13 @@ class SpaceModelBloc extends Bloc { } } - Future _onUpdateSpaceModel( - UpdateSpaceModel event, Emitter emit) async { + Future _onUpdateSpaceModel(UpdateSpaceModel event, Emitter emit) async { final currentState = state; if (currentState is SpaceModelLoaded) { try { final projectUuid = await ProjectManager.getProjectUUID() ?? ''; - final newSpaceModel = - await api.getSpaceModel(event.spaceModelUuid, projectUuid); + final newSpaceModel = await api.getSpaceModel(event.spaceModelUuid, projectUuid); if (newSpaceModel != null) { final updatedSpaceModels = currentState.spaceModels.map((model) { return model.uuid == event.spaceModelUuid ? newSpaceModel : model; @@ -65,16 +58,14 @@ class SpaceModelBloc extends Bloc { } } - Future _onDeleteSpaceModel( - DeleteSpaceModel event, Emitter emit) async { + Future _onDeleteSpaceModel(DeleteSpaceModel event, Emitter emit) async { final currentState = state; if (currentState is SpaceModelLoaded) { try { final projectUuid = await ProjectManager.getProjectUUID() ?? ''; - final deletedSuccessfully = - await api.deleteSpaceModel(event.spaceModelUuid, projectUuid); + final deletedSuccessfully = await api.deleteSpaceModel(event.spaceModelUuid, projectUuid); if (deletedSuccessfully) { final updatedSpaceModels = currentState.spaceModels diff --git a/lib/pages/spaces_management/space_model/models/tag_body_model.dart b/lib/pages/spaces_management/space_model/models/tag_body_model.dart index d66e2884..49947831 100644 --- a/lib/pages/spaces_management/space_model/models/tag_body_model.dart +++ b/lib/pages/spaces_management/space_model/models/tag_body_model.dart @@ -4,7 +4,7 @@ class CreateTagBodyModel { Map toJson() { return { - 'tag': tag, + 'name': tag, 'productUuid': productUuid, }; } diff --git a/lib/pages/spaces_management/space_model/models/tag_update_model.dart b/lib/pages/spaces_management/space_model/models/tag_update_model.dart index c7190dc8..c2177058 100644 --- a/lib/pages/spaces_management/space_model/models/tag_update_model.dart +++ b/lib/pages/spaces_management/space_model/models/tag_update_model.dart @@ -5,12 +5,14 @@ class TagModelUpdate { final String? uuid; final String? tag; final String? productUuid; + final String? newTagUuid; TagModelUpdate({ required this.action, this.uuid, this.tag, this.productUuid, + this.newTagUuid, }); factory TagModelUpdate.fromJson(Map json) { @@ -26,9 +28,10 @@ class TagModelUpdate { Map toJson() { return { 'action': action.value, - 'uuid': uuid, // Nullable field - 'tag': tag, + 'tagUuid': uuid, + 'name': tag, 'productUuid': productUuid, + 'newTagUuid': newTagUuid }; } }