mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
Merge pull request #82 from SyncrowIOT/SP-951-FE-Link-Space-Model-Pop-Up
added edit space sibling conflict
This commit is contained in:
@ -12,6 +12,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
|||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/create_subspace/views/create_subspace_model_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/create_subspace/views/create_subspace_model_dialog.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/helper/space_helper.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
|
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/link_space_model/view/link_space_model_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/link_space_model/view/link_space_model_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||||
@ -95,6 +96,10 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
bool isSpaceModelDisabled = (tags != null && tags!.isNotEmpty ||
|
||||||
|
subspaces != null && subspaces!.isNotEmpty);
|
||||||
|
bool isTagsAndSubspaceModelDisabled = (selectedSpaceModel != null);
|
||||||
|
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: widget.isEdit
|
title: widget.isEdit
|
||||||
@ -173,7 +178,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
isNameFieldInvalid = value.isEmpty;
|
isNameFieldInvalid = value.isEmpty;
|
||||||
|
|
||||||
if (!isNameFieldInvalid) {
|
if (!isNameFieldInvalid) {
|
||||||
if (_isNameConflict(value)) {
|
if (SpaceHelper.isNameConflict(value, widget.parentSpace, widget.editSpace)) {
|
||||||
isNameFieldExist = true;
|
isNameFieldExist = true;
|
||||||
isOkButtonEnabled = false;
|
isOkButtonEnabled = false;
|
||||||
} else {
|
} else {
|
||||||
@ -240,11 +245,14 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_showLinkSpaceModelDialog(context);
|
isSpaceModelDisabled
|
||||||
|
? null
|
||||||
|
: _showLinkSpaceModelDialog(context);
|
||||||
},
|
},
|
||||||
child: const ButtonContentWidget(
|
child: ButtonContentWidget(
|
||||||
svgAssets: Assets.link,
|
svgAssets: Assets.link,
|
||||||
label: 'Link a space model',
|
label: 'Link a space model',
|
||||||
|
disabled: isSpaceModelDisabled,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: Container(
|
: Container(
|
||||||
@ -333,12 +341,15 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
overlayColor: ColorsManager.transparentColor,
|
overlayColor: ColorsManager.transparentColor,
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
_showSubSpaceDialog(context, enteredName, [],
|
isTagsAndSubspaceModelDisabled
|
||||||
false, widget.products, subspaces);
|
? null
|
||||||
|
: _showSubSpaceDialog(context, enteredName,
|
||||||
|
[], false, widget.products, subspaces);
|
||||||
},
|
},
|
||||||
child: const ButtonContentWidget(
|
child: ButtonContentWidget(
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
label: 'Create Sub Space',
|
label: 'Create Sub Space',
|
||||||
|
disabled: isTagsAndSubspaceModelDisabled,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: SizedBox(
|
: SizedBox(
|
||||||
@ -492,19 +503,22 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
)
|
)
|
||||||
: TextButton(
|
: TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_showTagCreateDialog(
|
isTagsAndSubspaceModelDisabled
|
||||||
context,
|
? null
|
||||||
enteredName,
|
: _showTagCreateDialog(
|
||||||
widget.isEdit,
|
context,
|
||||||
widget.products,
|
enteredName,
|
||||||
);
|
widget.isEdit,
|
||||||
|
widget.products,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
),
|
),
|
||||||
child: const ButtonContentWidget(
|
child: ButtonContentWidget(
|
||||||
icon: Icons.add,
|
icon: Icons.add,
|
||||||
label: 'Add Devices',
|
label: 'Add Devices',
|
||||||
|
disabled: isTagsAndSubspaceModelDisabled,
|
||||||
))
|
))
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -578,26 +592,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _isNameConflict(String value) {
|
|
||||||
final parentSpace = widget.parentSpace;
|
|
||||||
final editSpace = widget.editSpace;
|
|
||||||
final siblings = parentSpace?.children
|
|
||||||
.where((child) => child.uuid != editSpace?.uuid)
|
|
||||||
.toList() ??
|
|
||||||
[];
|
|
||||||
final siblingConflict = siblings.any((child) => child.name == value);
|
|
||||||
final parentConflict =
|
|
||||||
parentSpace?.name == value && parentSpace?.uuid != editSpace?.uuid;
|
|
||||||
final parentOfEditSpaceConflict = editSpace?.parent?.name == value &&
|
|
||||||
editSpace?.parent?.uuid != editSpace?.uuid;
|
|
||||||
final childConflict =
|
|
||||||
editSpace?.children.any((child) => child.name == value) ?? false;
|
|
||||||
return siblingConflict ||
|
|
||||||
parentConflict ||
|
|
||||||
parentOfEditSpaceConflict ||
|
|
||||||
childConflict;
|
|
||||||
}
|
|
||||||
|
|
||||||
void _showLinkSpaceModelDialog(BuildContext context) {
|
void _showLinkSpaceModelDialog(BuildContext context) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -58,4 +58,37 @@ class SpaceHelper {
|
|||||||
?.any((child) => child.internalId == space.internalId) ==
|
?.any((child) => child.internalId == space.internalId) ==
|
||||||
true;
|
true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool isNameConflict(
|
||||||
|
String value, SpaceModel? parentSpace, SpaceModel? editSpace) {
|
||||||
|
final siblings = parentSpace?.children
|
||||||
|
.where((child) => child.internalId != editSpace?.internalId)
|
||||||
|
.toList() ??
|
||||||
|
[];
|
||||||
|
|
||||||
|
final editSiblings = editSpace?.parent?.children
|
||||||
|
.where((child) => child.internalId != editSpace.internalId)
|
||||||
|
.toList() ??
|
||||||
|
[];
|
||||||
|
|
||||||
|
final editSiblingConflict =
|
||||||
|
editSiblings.any((child) => child.name == value);
|
||||||
|
|
||||||
|
final siblingConflict = siblings.any((child) => child.name == value);
|
||||||
|
|
||||||
|
final parentConflict = parentSpace?.name == value &&
|
||||||
|
parentSpace?.internalId != editSpace?.internalId;
|
||||||
|
|
||||||
|
final parentOfEditSpaceConflict = editSpace?.parent?.name == value &&
|
||||||
|
editSpace?.parent?.internalId != editSpace?.internalId;
|
||||||
|
|
||||||
|
final childConflict =
|
||||||
|
editSpace?.children.any((child) => child.name == value) ?? false;
|
||||||
|
|
||||||
|
return siblingConflict ||
|
||||||
|
parentConflict ||
|
||||||
|
editSiblingConflict ||
|
||||||
|
parentOfEditSpaceConflict ||
|
||||||
|
childConflict;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,55 +6,64 @@ class ButtonContentWidget extends StatelessWidget {
|
|||||||
final IconData? icon;
|
final IconData? icon;
|
||||||
final String label;
|
final String label;
|
||||||
final String? svgAssets;
|
final String? svgAssets;
|
||||||
|
final bool disabled;
|
||||||
|
|
||||||
const ButtonContentWidget(
|
const ButtonContentWidget({
|
||||||
{Key? key, this.icon, required this.label, this.svgAssets})
|
Key? key,
|
||||||
: super(key: key);
|
this.icon,
|
||||||
|
required this.label,
|
||||||
|
this.svgAssets,
|
||||||
|
this.disabled = false,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
|
|
||||||
return SizedBox(
|
return Opacity(
|
||||||
width: screenWidth * 0.25,
|
opacity: disabled ? 0.5 : 1.0,
|
||||||
child: Container(
|
child: SizedBox(
|
||||||
decoration: BoxDecoration(
|
width: screenWidth * 0.25,
|
||||||
color: ColorsManager.textFieldGreyColor,
|
child: Container(
|
||||||
border: Border.all(
|
decoration: BoxDecoration(
|
||||||
color: ColorsManager.neutralGray,
|
color: ColorsManager.textFieldGreyColor,
|
||||||
width: 3.0,
|
border: Border.all(
|
||||||
|
color: ColorsManager.neutralGray,
|
||||||
|
width: 3.0,
|
||||||
|
),
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
),
|
),
|
||||||
borderRadius: BorderRadius.circular(20),
|
child: Padding(
|
||||||
),
|
padding:
|
||||||
child: Padding(
|
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
|
||||||
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
|
child: Row(
|
||||||
child: Row(
|
children: [
|
||||||
children: [
|
if (icon != null)
|
||||||
if (icon != null)
|
Icon(
|
||||||
Icon(
|
icon,
|
||||||
icon,
|
color: ColorsManager.spaceColor,
|
||||||
color: ColorsManager.spaceColor,
|
),
|
||||||
),
|
if (svgAssets != null)
|
||||||
if (svgAssets != null)
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.only(left: 6.0),
|
||||||
padding: const EdgeInsets.only(left: 6.0),
|
child: SvgPicture.asset(
|
||||||
child: SvgPicture.asset(
|
svgAssets!,
|
||||||
svgAssets!,
|
width: screenWidth * 0.015, // Adjust icon size
|
||||||
width: screenWidth * 0.015, // Adjust icon size
|
height: screenWidth * 0.015,
|
||||||
height: screenWidth * 0.015,
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
label,
|
||||||
|
style: const TextStyle(
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
],
|
||||||
Expanded(
|
),
|
||||||
child: Text(
|
|
||||||
label,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: ColorsManager.blackColor,
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Reference in New Issue
Block a user