mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
updated body for update space model
This commit is contained in:
@ -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,
|
||||
|
@ -83,10 +83,12 @@ class AssignTagModelBloc extends Bloc<AssignTagModelEvent, AssignTagModelState>
|
||||
|
||||
if (currentState is AssignTagModelLoaded && currentState.tags.isNotEmpty) {
|
||||
final tags = List<Tag>.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(
|
||||
|
@ -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,
|
||||
|
@ -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 {}
|
||||
|
@ -14,28 +14,23 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
||||
required this.api,
|
||||
required List<SpaceTemplateModel> initialSpaceModels,
|
||||
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
||||
log('Initial Space Models in: ${initialSpaceModels.map((e) => e.toJson()).toList()}');
|
||||
|
||||
on<CreateSpaceModel>(_onCreateSpaceModel);
|
||||
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
||||
on<DeleteSpaceModel>(_onDeleteSpaceModel);
|
||||
}
|
||||
|
||||
Future<void> _onCreateSpaceModel(
|
||||
CreateSpaceModel event, Emitter<SpaceModelState> emit) async {
|
||||
Future<void> _onCreateSpaceModel(CreateSpaceModel event, Emitter<SpaceModelState> 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<SpaceTemplateModel>.from(currentState.spaceModels)
|
||||
..add(newSpaceModel);
|
||||
final updatedSpaceModels = List<SpaceTemplateModel>.from(currentState.spaceModels)
|
||||
..add(newSpaceModel);
|
||||
emit(SpaceModelLoaded(spaceModels: updatedSpaceModels));
|
||||
}
|
||||
} catch (e) {
|
||||
@ -44,15 +39,13 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onUpdateSpaceModel(
|
||||
UpdateSpaceModel event, Emitter<SpaceModelState> emit) async {
|
||||
Future<void> _onUpdateSpaceModel(UpdateSpaceModel event, Emitter<SpaceModelState> 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<SpaceModelEvent, SpaceModelState> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _onDeleteSpaceModel(
|
||||
DeleteSpaceModel event, Emitter<SpaceModelState> emit) async {
|
||||
Future<void> _onDeleteSpaceModel(DeleteSpaceModel event, Emitter<SpaceModelState> 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
|
||||
|
@ -4,7 +4,7 @@ class CreateTagBodyModel {
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'tag': tag,
|
||||
'name': tag,
|
||||
'productUuid': productUuid,
|
||||
};
|
||||
}
|
||||
|
@ -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<String, dynamic> json) {
|
||||
@ -26,9 +28,10 @@ class TagModelUpdate {
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'action': action.value,
|
||||
'uuid': uuid, // Nullable field
|
||||
'tag': tag,
|
||||
'tagUuid': uuid,
|
||||
'name': tag,
|
||||
'productUuid': productUuid,
|
||||
'newTagUuid': newTagUuid
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user