diff --git a/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart b/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart index 72f2b2ee..c2b3ba9b 100644 --- a/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart +++ b/lib/pages/spaces_management/assign_tag_models/views/assign_tag_models_dialog.dart @@ -298,7 +298,23 @@ class AssignTagModelsDialog extends StatelessWidget { onPressed: state.isSaveEnabled ? () async { Navigator.of(context).pop(); + final assignedTags = {}; + for (var tag in state.tags) { + if (tag.location == null || + subspaces == null) { + continue; + } + for (var subspace in subspaces!) { + if (tag.location == subspace.subspaceName) { + subspace.tags ??= []; + subspace.tags!.add(tag); + assignedTags.add(tag); + break; + } + } + } + state.tags.removeWhere(assignedTags.contains); await showDialog( barrierDismissible: false, context: context, diff --git a/lib/pages/spaces_management/space_model/models/space_template_model.dart b/lib/pages/spaces_management/space_model/models/space_template_model.dart index d493fae9..ec2f466f 100644 --- a/lib/pages/spaces_management/space_model/models/space_template_model.dart +++ b/lib/pages/spaces_management/space_model/models/space_template_model.dart @@ -7,7 +7,7 @@ import 'package:uuid/uuid.dart'; class SpaceTemplateModel { final String? uuid; String modelName; - final List? subspaceModels; + List? subspaceModels; final List? tags; String internalId; diff --git a/lib/pages/spaces_management/space_model/models/subspace_template_model.dart b/lib/pages/spaces_management/space_model/models/subspace_template_model.dart index 911494a0..119728db 100644 --- a/lib/pages/spaces_management/space_model/models/subspace_template_model.dart +++ b/lib/pages/spaces_management/space_model/models/subspace_template_model.dart @@ -4,7 +4,7 @@ class SubspaceTemplateModel { final String? uuid; String subspaceName; final bool disabled; - final List? tags; + List? tags; SubspaceTemplateModel({ this.uuid, diff --git a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart index 8b46d50a..93e5a3dc 100644 --- a/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart +++ b/lib/pages/spaces_management/space_model/widgets/dialog/create_space_model_dialog.dart @@ -7,8 +7,8 @@ import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_spac import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_state.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart'; -import 'package:syncrow_web/pages/spaces_management/space_model/widgets/button_content_widget.dart'; -import 'package:syncrow_web/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart'; +import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart'; +import 'package:syncrow_web/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart'; import 'package:syncrow_web/utils/color_manager.dart'; @@ -27,9 +27,10 @@ class CreateSpaceModelDialog extends StatelessWidget { @override Widget build(BuildContext context) { final screenWidth = MediaQuery.of(context).size.width; - List? subspaces = []; - final TextEditingController spaceNameController = TextEditingController(); - + List? subspaces = spaceModel?.subspaceModels ?? []; + final TextEditingController spaceNameController = TextEditingController( + text: spaceModel?.modelName ?? '', + ); return AlertDialog( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)), backgroundColor: ColorsManager.whiteColors, @@ -38,7 +39,7 @@ class CreateSpaceModelDialog extends StatelessWidget { child: BlocProvider( create: (_) { final bloc = CreateSpaceModelBloc(); - if (spaceModel != null) { + if (spaceModel != null) { bloc.add(UpdateSpaceTemplate(spaceModel!)); } else { bloc.add(UpdateSpaceTemplate(SpaceTemplateModel( @@ -86,28 +87,13 @@ class CreateSpaceModelDialog extends StatelessWidget { const SizedBox(height: 16), SubspaceModelCreate(context, subspaces: subspaces), const SizedBox(height: 10), - TextButton( - onPressed: () async { - final result = await showDialog( - barrierDismissible: false, - context: context, - builder: (context) => AddDeviceTypeModelWidget( - products: products, - subspaces: subspaces, - allTags: allTags, - spaceName: spaceNameController.text, - ), - ); - if (result == true) {} - }, - style: TextButton.styleFrom( - padding: EdgeInsets.zero, - ), - child: const ButtonContentWidget( - icon: Icons.add, - label: 'Add Devices', - ), - ), + TagChipDisplay(context, + screenWidth: screenWidth, + spaceModel: spaceModel, + products: products, + subspaces: subspaces, + allTags: allTags, + spaceNameController: spaceNameController), const SizedBox(height: 20), SizedBox( width: screenWidth * 0.25, diff --git a/lib/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart b/lib/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart index 402c2ac1..30b84a4b 100644 --- a/lib/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart +++ b/lib/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart @@ -54,20 +54,20 @@ class SubspaceModelCreate extends StatelessWidget { ), ) : SizedBox( - width: screenWidth * 0.25, // Set the desired width + width: screenWidth * 0.25, child: Container( - padding: const EdgeInsets.all(8.0), // Add padding + padding: const EdgeInsets.all(8.0), decoration: BoxDecoration( - color: ColorsManager.textFieldGreyColor, // Background color - borderRadius: BorderRadius.circular(15), // Rounded corners + color: ColorsManager.textFieldGreyColor, + borderRadius: BorderRadius.circular(15), border: Border.all( - color: ColorsManager.textFieldGreyColor, // Border color + color: ColorsManager.textFieldGreyColor, width: 3.0, // Border width ), ), child: Wrap( - spacing: 8.0, // Spacing between chips - runSpacing: 8.0, // Spacing between rows of chips + spacing: 8.0, + runSpacing: 8.0, children: [ ...subspaces.map( (subspace) => Chip( diff --git a/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart new file mode 100644 index 00000000..00b2d493 --- /dev/null +++ b/lib/pages/spaces_management/space_model/widgets/tag_chips_display_widget.dart @@ -0,0 +1,151 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.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/subspace_template_model.dart'; +import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart'; +import 'package:syncrow_web/pages/spaces_management/space_model/widgets/button_content_widget.dart'; +import 'package:syncrow_web/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart'; +import 'package:syncrow_web/utils/color_manager.dart'; + +class TagChipDisplay extends StatelessWidget { + final double screenWidth; + final SpaceTemplateModel? spaceModel; + final List? products; + final List? subspaces; + final List? allTags; + final TextEditingController spaceNameController; + + const TagChipDisplay( + BuildContext context, { + Key? key, + required this.screenWidth, + required this.spaceModel, + required this.products, + required this.subspaces, + required this.allTags, + required this.spaceNameController, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return (spaceModel?.subspaceModels?.isNotEmpty == true || spaceModel?.tags?.isNotEmpty == true || + spaceModel?.subspaceModels + ?.any((subspace) => subspace.tags?.isNotEmpty == true) == + true) + ? SizedBox( + width: screenWidth * 0.25, + child: Container( + padding: const EdgeInsets.all(8.0), + decoration: BoxDecoration( + color: ColorsManager.textFieldGreyColor, + borderRadius: BorderRadius.circular(15), + border: Border.all( + color: ColorsManager.textFieldGreyColor, + width: 3.0, // Border width + ), + ), + child: Wrap( + spacing: 8.0, + runSpacing: 8.0, + children: [ + // Combine tags from spaceModel and subspaces + ..._groupTags([ + ...?spaceModel?.tags, + ...?spaceModel?.subspaceModels + ?.expand((subspace) => subspace.tags ?? []) + ]).entries.map( + (entry) => Chip( + avatar: SizedBox( + width: 24, + height: 24, + child: SvgPicture.asset( + entry.key.icon ?? + 'assets/default_icon.svg', // Provide a default asset path if null + fit: BoxFit.contain, + ), + ), + label: Text( + 'x${entry.value}', // Show count + style: const TextStyle( + color: ColorsManager.spaceColor, + ), + ), + backgroundColor: + Colors.white, // Chip background color + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(16), // Rounded chip + side: const BorderSide( + color: ColorsManager.spaceColor, // Border color + ), + ), + ), + ), + GestureDetector( + onTap: () async { + await showDialog( + barrierDismissible: false, + context: context, + builder: (context) => AddDeviceTypeModelWidget( + products: products, + subspaces: subspaces, + allTags: allTags, + spaceName: spaceNameController.text, + ), + ); + // Edit action + }, + child: Chip( + label: const Text( + 'Edit', + style: TextStyle( + color: ColorsManager.spaceColor), // Text color + ), + backgroundColor: + Colors.white, // Background color for "Edit" + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), // Rounded chip + side: const BorderSide( + color: ColorsManager.spaceColor), // Border color + ), + ), + ), + ], + ), + ), + ) + : TextButton( + onPressed: () async { + final result = await showDialog( + barrierDismissible: false, + context: context, + builder: (context) => AddDeviceTypeModelWidget( + products: products, + subspaces: subspaces, + allTags: allTags, + spaceName: spaceNameController.text, + ), + ); + if (result == true) {} + }, + style: TextButton.styleFrom( + padding: EdgeInsets.zero, + ), + child: const ButtonContentWidget( + icon: Icons.add, + label: 'Add Devices', + ), + ); + } + + Map _groupTags(List tags) { + final Map groupedTags = {}; + for (var tag in tags) { + if (tag.product != null) { + groupedTags[tag.product!] = (groupedTags[tag.product!] ?? 0) + 1; + } + } + return groupedTags; + } +}