mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
add subspace validation
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import 'tag.dart';
|
||||
|
||||
@ -8,19 +9,24 @@ class SubspaceModel {
|
||||
String subspaceName;
|
||||
final bool disabled;
|
||||
List<Tag>? tags;
|
||||
String internalId;
|
||||
|
||||
SubspaceModel({
|
||||
this.uuid,
|
||||
required this.subspaceName,
|
||||
required this.disabled,
|
||||
this.tags,
|
||||
});
|
||||
String? internalId,
|
||||
}) : internalId = internalId ?? const Uuid().v4();
|
||||
|
||||
factory SubspaceModel.fromJson(Map<String, dynamic> json) {
|
||||
final String internalId = json['internalId'] ?? const Uuid().v4();
|
||||
|
||||
return SubspaceModel(
|
||||
uuid: json['uuid'] ?? '',
|
||||
subspaceName: json['subspaceName'] ?? '',
|
||||
disabled: json['disabled'] ?? false,
|
||||
internalId: internalId,
|
||||
tags: (json['tags'] as List<dynamic>?)
|
||||
?.map((item) => Tag.fromJson(item))
|
||||
.toList() ??
|
||||
@ -43,7 +49,7 @@ class UpdateSubspaceModel {
|
||||
final Action action;
|
||||
final String? subspaceName;
|
||||
final List<UpdateTag>? tags;
|
||||
UpdateSubspaceModel({
|
||||
UpdateSubspaceModel({
|
||||
required this.action,
|
||||
required this.uuid,
|
||||
this.subspaceName,
|
||||
@ -107,4 +113,4 @@ class UpdateTag {
|
||||
'product': product?.toMap(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -358,10 +358,21 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
SubspaceNameDisplayWidget(
|
||||
text: subspace.subspaceName,
|
||||
validateName: (updatedName) {
|
||||
return subspaces!.any((s) =>
|
||||
s != subspace &&
|
||||
s.subspaceName ==
|
||||
updatedName);
|
||||
bool nameExists =
|
||||
subspaces!.any((s) {
|
||||
bool isSameId = s.internalId ==
|
||||
subspace.internalId;
|
||||
bool isSameName = s.subspaceName
|
||||
.trim()
|
||||
.toLowerCase() ==
|
||||
updatedName
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
|
||||
return !isSameId && isSameName;
|
||||
});
|
||||
|
||||
return !nameExists;
|
||||
},
|
||||
onNameChanged: (updatedName) {
|
||||
setState(() {
|
||||
|
Reference in New Issue
Block a user