mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
updated body for update space model
This commit is contained in:
@ -26,9 +26,7 @@ class Tag extends BaseTag {
|
|||||||
uuid: json['uuid'] ?? '',
|
uuid: json['uuid'] ?? '',
|
||||||
internalId: internalId,
|
internalId: internalId,
|
||||||
tag: json['name'] ?? '',
|
tag: json['name'] ?? '',
|
||||||
product: json['product'] != null
|
product: json['product'] != null ? ProductModel.fromMap(json['product']) : null,
|
||||||
? ProductModel.fromMap(json['product'])
|
|
||||||
: null,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -41,7 +39,7 @@ class Tag extends BaseTag {
|
|||||||
String? internalId,
|
String? internalId,
|
||||||
}) {
|
}) {
|
||||||
return Tag(
|
return Tag(
|
||||||
uuid: uuid,
|
uuid: uuid ?? this.uuid,
|
||||||
tag: tag ?? this.tag,
|
tag: tag ?? this.tag,
|
||||||
product: product ?? this.product,
|
product: product ?? this.product,
|
||||||
location: location ?? this.location,
|
location: location ?? this.location,
|
||||||
|
@ -83,10 +83,12 @@ class AssignTagModelBloc extends Bloc<AssignTagModelEvent, AssignTagModelState>
|
|||||||
|
|
||||||
if (currentState is AssignTagModelLoaded && currentState.tags.isNotEmpty) {
|
if (currentState is AssignTagModelLoaded && currentState.tags.isNotEmpty) {
|
||||||
final tags = List<Tag>.from(currentState.tags);
|
final tags = List<Tag>.from(currentState.tags);
|
||||||
|
for (var t in tags) {
|
||||||
|
}
|
||||||
// Use copyWith for immutability
|
// Use copyWith for immutability
|
||||||
tags[event.index] = tags[event.index].copyWith(location: event.location);
|
tags[event.index] = tags[event.index].copyWith(location: event.location);
|
||||||
|
|
||||||
|
|
||||||
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
||||||
|
|
||||||
emit(AssignTagModelLoaded(
|
emit(AssignTagModelLoaded(
|
||||||
|
@ -57,7 +57,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
(subspaces ?? []).map((subspace) => subspace.subspaceName).toList()..add('Main Space');
|
(subspaces ?? []).map((subspace) => subspace.subspaceName).toList()..add('Main Space');
|
||||||
|
|
||||||
return BlocProvider(
|
return BlocProvider(
|
||||||
create: (_) => AssignTagModelBloc( projectTags)
|
create: (_) => AssignTagModelBloc(projectTags)
|
||||||
..add(InitializeTagModels(
|
..add(InitializeTagModels(
|
||||||
initialTags: initialTags,
|
initialTags: initialTags,
|
||||||
addedProducts: addedProducts,
|
addedProducts: addedProducts,
|
||||||
|
@ -248,7 +248,7 @@ class CreateSpaceModelBloc
|
|||||||
for (var tag in newSubspace.tags!) {
|
for (var tag in newSubspace.tags!) {
|
||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.add,
|
action: Action.add,
|
||||||
uuid: tag.uuid == '' ? null : tag.uuid,
|
newTagUuid: tag.uuid == '' ? null : tag.uuid,
|
||||||
tag: tag.tag,
|
tag: tag.tag,
|
||||||
productUuid: tag.product?.uuid));
|
productUuid: tag.product?.uuid));
|
||||||
}
|
}
|
||||||
@ -315,7 +315,7 @@ class CreateSpaceModelBloc
|
|||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.add,
|
action: Action.add,
|
||||||
tag: newTag.tag,
|
tag: newTag.tag,
|
||||||
uuid: newTag.uuid,
|
newTagUuid: newTag.uuid,
|
||||||
productUuid: newTag.product?.uuid,
|
productUuid: newTag.product?.uuid,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@ -351,7 +351,7 @@ class CreateSpaceModelBloc
|
|||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.add,
|
action: Action.add,
|
||||||
tag: newTag.tag,
|
tag: newTag.tag,
|
||||||
uuid: newTag.uuid == '' ? null : newTag.uuid,
|
newTagUuid: newTag.uuid == '' ? null : newTag.uuid,
|
||||||
productUuid: newTag.product?.uuid));
|
productUuid: newTag.product?.uuid));
|
||||||
processedTags.add(newTag.tag);
|
processedTags.add(newTag.tag);
|
||||||
}
|
}
|
||||||
@ -367,7 +367,8 @@ class CreateSpaceModelBloc
|
|||||||
if (newTag != null) {
|
if (newTag != null) {
|
||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.update,
|
action: Action.update,
|
||||||
uuid: newTag.uuid,
|
uuid: prevTag.uuid,
|
||||||
|
newTagUuid: newTag.uuid,
|
||||||
tag: newTag.tag,
|
tag: newTag.tag,
|
||||||
));
|
));
|
||||||
} else {}
|
} else {}
|
||||||
|
@ -14,28 +14,23 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
|||||||
required this.api,
|
required this.api,
|
||||||
required List<SpaceTemplateModel> initialSpaceModels,
|
required List<SpaceTemplateModel> initialSpaceModels,
|
||||||
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
||||||
log('Initial Space Models in: ${initialSpaceModels.map((e) => e.toJson()).toList()}');
|
|
||||||
|
|
||||||
on<CreateSpaceModel>(_onCreateSpaceModel);
|
on<CreateSpaceModel>(_onCreateSpaceModel);
|
||||||
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
||||||
on<DeleteSpaceModel>(_onDeleteSpaceModel);
|
on<DeleteSpaceModel>(_onDeleteSpaceModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onCreateSpaceModel(
|
Future<void> _onCreateSpaceModel(CreateSpaceModel event, Emitter<SpaceModelState> emit) async {
|
||||||
CreateSpaceModel event, Emitter<SpaceModelState> emit) async {
|
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
|
|
||||||
if (currentState is SpaceModelLoaded) {
|
if (currentState is SpaceModelLoaded) {
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
final newSpaceModel = await api.getSpaceModel(
|
final newSpaceModel = await api.getSpaceModel(event.newSpaceModel.uuid ?? '', projectUuid);
|
||||||
event.newSpaceModel.uuid ?? '', projectUuid);
|
|
||||||
|
|
||||||
if (newSpaceModel != null) {
|
if (newSpaceModel != null) {
|
||||||
final updatedSpaceModels =
|
final updatedSpaceModels = List<SpaceTemplateModel>.from(currentState.spaceModels)
|
||||||
List<SpaceTemplateModel>.from(currentState.spaceModels)
|
..add(newSpaceModel);
|
||||||
..add(newSpaceModel);
|
|
||||||
emit(SpaceModelLoaded(spaceModels: updatedSpaceModels));
|
emit(SpaceModelLoaded(spaceModels: updatedSpaceModels));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -44,15 +39,13 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onUpdateSpaceModel(
|
Future<void> _onUpdateSpaceModel(UpdateSpaceModel event, Emitter<SpaceModelState> emit) async {
|
||||||
UpdateSpaceModel event, Emitter<SpaceModelState> emit) async {
|
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
if (currentState is SpaceModelLoaded) {
|
if (currentState is SpaceModelLoaded) {
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
final newSpaceModel =
|
final newSpaceModel = await api.getSpaceModel(event.spaceModelUuid, projectUuid);
|
||||||
await api.getSpaceModel(event.spaceModelUuid, projectUuid);
|
|
||||||
if (newSpaceModel != null) {
|
if (newSpaceModel != null) {
|
||||||
final updatedSpaceModels = currentState.spaceModels.map((model) {
|
final updatedSpaceModels = currentState.spaceModels.map((model) {
|
||||||
return model.uuid == event.spaceModelUuid ? newSpaceModel : model;
|
return model.uuid == event.spaceModelUuid ? newSpaceModel : model;
|
||||||
@ -65,16 +58,14 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onDeleteSpaceModel(
|
Future<void> _onDeleteSpaceModel(DeleteSpaceModel event, Emitter<SpaceModelState> emit) async {
|
||||||
DeleteSpaceModel event, Emitter<SpaceModelState> emit) async {
|
|
||||||
final currentState = state;
|
final currentState = state;
|
||||||
|
|
||||||
if (currentState is SpaceModelLoaded) {
|
if (currentState is SpaceModelLoaded) {
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
final deletedSuccessfully =
|
final deletedSuccessfully = await api.deleteSpaceModel(event.spaceModelUuid, projectUuid);
|
||||||
await api.deleteSpaceModel(event.spaceModelUuid, projectUuid);
|
|
||||||
|
|
||||||
if (deletedSuccessfully) {
|
if (deletedSuccessfully) {
|
||||||
final updatedSpaceModels = currentState.spaceModels
|
final updatedSpaceModels = currentState.spaceModels
|
||||||
|
@ -4,7 +4,7 @@ class CreateTagBodyModel {
|
|||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
'tag': tag,
|
'name': tag,
|
||||||
'productUuid': productUuid,
|
'productUuid': productUuid,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,14 @@ class TagModelUpdate {
|
|||||||
final String? uuid;
|
final String? uuid;
|
||||||
final String? tag;
|
final String? tag;
|
||||||
final String? productUuid;
|
final String? productUuid;
|
||||||
|
final String? newTagUuid;
|
||||||
|
|
||||||
TagModelUpdate({
|
TagModelUpdate({
|
||||||
required this.action,
|
required this.action,
|
||||||
this.uuid,
|
this.uuid,
|
||||||
this.tag,
|
this.tag,
|
||||||
this.productUuid,
|
this.productUuid,
|
||||||
|
this.newTagUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
factory TagModelUpdate.fromJson(Map<String, dynamic> json) {
|
factory TagModelUpdate.fromJson(Map<String, dynamic> json) {
|
||||||
@ -26,9 +28,10 @@ class TagModelUpdate {
|
|||||||
Map<String, dynamic> toJson() {
|
Map<String, dynamic> toJson() {
|
||||||
return {
|
return {
|
||||||
'action': action.value,
|
'action': action.value,
|
||||||
'uuid': uuid, // Nullable field
|
'tagUuid': uuid,
|
||||||
'tag': tag,
|
'name': tag,
|
||||||
'productUuid': productUuid,
|
'productUuid': productUuid,
|
||||||
|
'newTagUuid': newTagUuid
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user