mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-08-25 15:39:41 +00:00
Refactor Space and Tag Models: Removed unused JSON serialization methods from SpaceDetailsModel, ProductAllocation, and Subspace. Updated Tag model to eliminate unnecessary fields. Enhanced UpdateSpaceParam to streamline JSON conversion for subspaces and product allocations, improving data handling during updates.
This commit is contained in:
@ -40,16 +40,6 @@ class SpaceDetailsModel extends Equatable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'spaceName': spaceName,
|
|
||||||
'icon': icon,
|
|
||||||
'productAllocations': productAllocations.map((e) => e.toJson()).toList(),
|
|
||||||
'subspaces': subspaces.map((e) => e.toJson()).toList(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
SpaceDetailsModel copyWith({
|
SpaceDetailsModel copyWith({
|
||||||
String? uuid,
|
String? uuid,
|
||||||
String? spaceName,
|
String? spaceName,
|
||||||
@ -89,14 +79,6 @@ class ProductAllocation extends Equatable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'product': product.toJson(),
|
|
||||||
'tag': tag.toJson(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
ProductAllocation copyWith({
|
ProductAllocation copyWith({
|
||||||
String? uuid,
|
String? uuid,
|
||||||
Product? product,
|
Product? product,
|
||||||
@ -134,14 +116,6 @@ class Subspace extends Equatable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'name': name,
|
|
||||||
'productAllocations': productAllocations.map((e) => e.toJson()).toList(),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
Subspace copyWith({
|
Subspace copyWith({
|
||||||
String? uuid,
|
String? uuid,
|
||||||
String? name,
|
String? name,
|
||||||
|
@ -37,7 +37,7 @@ class _SpaceSubSpacesDialogState extends State<SpaceSubSpacesDialog> {
|
|||||||
..._subspaces,
|
..._subspaces,
|
||||||
Subspace(
|
Subspace(
|
||||||
name: name,
|
name: name,
|
||||||
uuid: const Uuid().v4(),
|
uuid: '${const Uuid().v4()}-NewTag',
|
||||||
productAllocations: const [],
|
productAllocations: const [],
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
@ -3,41 +3,19 @@ import 'package:equatable/equatable.dart';
|
|||||||
class Tag extends Equatable {
|
class Tag extends Equatable {
|
||||||
final String uuid;
|
final String uuid;
|
||||||
final String name;
|
final String name;
|
||||||
final String createdAt;
|
|
||||||
final String updatedAt;
|
|
||||||
|
|
||||||
const Tag({
|
const Tag({
|
||||||
required this.uuid,
|
required this.uuid,
|
||||||
required this.name,
|
required this.name,
|
||||||
required this.createdAt,
|
|
||||||
required this.updatedAt,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
factory Tag.empty() => const Tag(
|
|
||||||
uuid: '',
|
|
||||||
name: '',
|
|
||||||
createdAt: '',
|
|
||||||
updatedAt: '',
|
|
||||||
);
|
|
||||||
|
|
||||||
factory Tag.fromJson(Map<String, dynamic> json) {
|
factory Tag.fromJson(Map<String, dynamic> json) {
|
||||||
return Tag(
|
return Tag(
|
||||||
uuid: json['uuid'] as String,
|
uuid: json['uuid'] as String,
|
||||||
name: json['name'] as String,
|
name: json['name'] as String,
|
||||||
createdAt: json['createdAt'] as String,
|
|
||||||
updatedAt: json['updatedAt'] as String,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
return {
|
|
||||||
'uuid': uuid,
|
|
||||||
'name': name,
|
|
||||||
'createdAt': createdAt,
|
|
||||||
'updatedAt': updatedAt,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [uuid, name, createdAt, updatedAt];
|
List<Object?> get props => [uuid, name];
|
||||||
}
|
}
|
||||||
|
@ -214,9 +214,12 @@ class _AssignTagsDialogState extends State<AssignTagsDialog> {
|
|||||||
for (final product in newProducts) {
|
for (final product in newProducts) {
|
||||||
_space.productAllocations.add(
|
_space.productAllocations.add(
|
||||||
ProductAllocation(
|
ProductAllocation(
|
||||||
uuid: const Uuid().v4(),
|
uuid: '${const Uuid().v4()}-NewProductUuid',
|
||||||
product: product,
|
product: product,
|
||||||
tag: Tag.empty(),
|
tag: Tag(
|
||||||
|
uuid: '${const Uuid().v4()}-NewTag',
|
||||||
|
name: '',
|
||||||
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart';
|
import 'package:syncrow_web/pages/space_management_v2/modules/tags/domain/models/tag.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
import 'package:syncrow_web/utils/extension/build_context_x.dart';
|
||||||
|
import 'package:uuid/uuid.dart';
|
||||||
|
|
||||||
class ProductTagField extends StatefulWidget {
|
class ProductTagField extends StatefulWidget {
|
||||||
final List<Tag> items;
|
final List<Tag> items;
|
||||||
@ -53,13 +54,8 @@ class _ProductTagFieldState extends State<ProductTagField> {
|
|||||||
void _submit(String value) {
|
void _submit(String value) {
|
||||||
final lowerCaseValue = value.toLowerCase();
|
final lowerCaseValue = value.toLowerCase();
|
||||||
final selectedTag = widget.items.firstWhere(
|
final selectedTag = widget.items.firstWhere(
|
||||||
(tag) => tag.name.toLowerCase() == lowerCaseValue,
|
(e) => e.name.toLowerCase() == lowerCaseValue,
|
||||||
orElse: () => Tag(
|
orElse: () => Tag(uuid: '${const Uuid().v4()}-NewTag', name: value),
|
||||||
name: value,
|
|
||||||
uuid: '',
|
|
||||||
createdAt: '',
|
|
||||||
updatedAt: '',
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
widget.onSelected(selectedTag);
|
widget.onSelected(selectedTag);
|
||||||
_closeDropdown();
|
_closeDropdown();
|
||||||
|
@ -19,7 +19,7 @@ class RemoteUpdateSpaceService implements UpdateSpaceService {
|
|||||||
final path = await _makeUrl(param);
|
final path = await _makeUrl(param);
|
||||||
await _httpService.put(
|
await _httpService.put(
|
||||||
path: path,
|
path: path,
|
||||||
body: param.space.toJson(),
|
body: param.toJson(),
|
||||||
expectedResponseModel: (data) {
|
expectedResponseModel: (data) {
|
||||||
final response = data as Map<String, dynamic>;
|
final response = data as Map<String, dynamic>;
|
||||||
final isSuccess = response['success'] as bool;
|
final isSuccess = response['success'] as bool;
|
||||||
|
@ -13,33 +13,29 @@ class UpdateSpaceParam {
|
|||||||
return {
|
return {
|
||||||
'spaceName': space.spaceName,
|
'spaceName': space.spaceName,
|
||||||
'icon': space.icon,
|
'icon': space.icon,
|
||||||
'subspaces': space.subspaces
|
'subspaces': space.subspaces.map((e) => e._toJson()).toList(),
|
||||||
.map(
|
'productAllocations':
|
||||||
(e) => {
|
space.productAllocations.map((e) => e._toJson()).toList(),
|
||||||
'subspaceName': e.name,
|
};
|
||||||
'productAllocations': e.productAllocations
|
}
|
||||||
.map(
|
}
|
||||||
(e) => {
|
|
||||||
'name': e.tag.name,
|
extension _ProductAllocationToJson on ProductAllocation {
|
||||||
'productUuid': e.product.uuid,
|
Map<String, dynamic> _toJson() {
|
||||||
'uuid': e.uuid,
|
final isNewTag = tag.uuid.isEmpty;
|
||||||
},
|
return <String, dynamic>{
|
||||||
)
|
if (isNewTag) 'tagName': tag.name else 'tagUuid': tag.uuid,
|
||||||
.toList(),
|
'productUuid': product.uuid,
|
||||||
'uuid': e.uuid,
|
};
|
||||||
},
|
}
|
||||||
)
|
}
|
||||||
.toList(),
|
|
||||||
'productAllocations': space.productAllocations
|
extension _SubspaceToJson on Subspace {
|
||||||
.map(
|
Map<String, dynamic> _toJson() {
|
||||||
(e) => {
|
final isNewSubspace = uuid.endsWith('-NewTag');
|
||||||
'tagName': e.tag.name,
|
return <String, dynamic>{
|
||||||
'tagUuid': e.tag.uuid,
|
if (isNewSubspace) 'subspaceName': name else 'uuid': uuid,
|
||||||
'productUuid': e.product.uuid,
|
'productAllocations': productAllocations.map((e) => e._toJson()).toList(),
|
||||||
},
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
'spaceModelUuid': space.uuid,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user