mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
edit tag model pop up
This commit is contained in:
@ -298,7 +298,23 @@ class AssignTagModelsDialog extends StatelessWidget {
|
|||||||
onPressed: state.isSaveEnabled
|
onPressed: state.isSaveEnabled
|
||||||
? () async {
|
? () async {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
final assignedTags = <TagModel>{};
|
||||||
|
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(
|
await showDialog(
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
context: context,
|
context: context,
|
||||||
|
@ -7,7 +7,7 @@ import 'package:uuid/uuid.dart';
|
|||||||
class SpaceTemplateModel {
|
class SpaceTemplateModel {
|
||||||
final String? uuid;
|
final String? uuid;
|
||||||
String modelName;
|
String modelName;
|
||||||
final List<SubspaceTemplateModel>? subspaceModels;
|
List<SubspaceTemplateModel>? subspaceModels;
|
||||||
final List<TagModel>? tags;
|
final List<TagModel>? tags;
|
||||||
String internalId;
|
String internalId;
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ class SubspaceTemplateModel {
|
|||||||
final String? uuid;
|
final String? uuid;
|
||||||
String subspaceName;
|
String subspaceName;
|
||||||
final bool disabled;
|
final bool disabled;
|
||||||
final List<TagModel>? tags;
|
List<TagModel>? tags;
|
||||||
|
|
||||||
SubspaceTemplateModel({
|
SubspaceTemplateModel({
|
||||||
this.uuid,
|
this.uuid,
|
||||||
|
@ -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_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/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/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/space_model/models/tag_model.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/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/pages/spaces_management/space_model/widgets/subspace_model_create_widget.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
@ -27,9 +27,10 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final screenWidth = MediaQuery.of(context).size.width;
|
final screenWidth = MediaQuery.of(context).size.width;
|
||||||
List<SubspaceTemplateModel>? subspaces = [];
|
List<SubspaceTemplateModel>? subspaces = spaceModel?.subspaceModels ?? [];
|
||||||
final TextEditingController spaceNameController = TextEditingController();
|
final TextEditingController spaceNameController = TextEditingController(
|
||||||
|
text: spaceModel?.modelName ?? '',
|
||||||
|
);
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||||
backgroundColor: ColorsManager.whiteColors,
|
backgroundColor: ColorsManager.whiteColors,
|
||||||
@ -38,7 +39,7 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
child: BlocProvider(
|
child: BlocProvider(
|
||||||
create: (_) {
|
create: (_) {
|
||||||
final bloc = CreateSpaceModelBloc();
|
final bloc = CreateSpaceModelBloc();
|
||||||
if (spaceModel != null) {
|
if (spaceModel != null) {
|
||||||
bloc.add(UpdateSpaceTemplate(spaceModel!));
|
bloc.add(UpdateSpaceTemplate(spaceModel!));
|
||||||
} else {
|
} else {
|
||||||
bloc.add(UpdateSpaceTemplate(SpaceTemplateModel(
|
bloc.add(UpdateSpaceTemplate(SpaceTemplateModel(
|
||||||
@ -86,28 +87,13 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
SubspaceModelCreate(context, subspaces: subspaces),
|
SubspaceModelCreate(context, subspaces: subspaces),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
TextButton(
|
TagChipDisplay(context,
|
||||||
onPressed: () async {
|
screenWidth: screenWidth,
|
||||||
final result = await showDialog<bool>(
|
spaceModel: spaceModel,
|
||||||
barrierDismissible: false,
|
products: products,
|
||||||
context: context,
|
subspaces: subspaces,
|
||||||
builder: (context) => AddDeviceTypeModelWidget(
|
allTags: allTags,
|
||||||
products: products,
|
spaceNameController: spaceNameController),
|
||||||
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',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: screenWidth * 0.25,
|
width: screenWidth * 0.25,
|
||||||
|
@ -54,20 +54,20 @@ class SubspaceModelCreate extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
: SizedBox(
|
: SizedBox(
|
||||||
width: screenWidth * 0.25, // Set the desired width
|
width: screenWidth * 0.25,
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.all(8.0), // Add padding
|
padding: const EdgeInsets.all(8.0),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: ColorsManager.textFieldGreyColor, // Background color
|
color: ColorsManager.textFieldGreyColor,
|
||||||
borderRadius: BorderRadius.circular(15), // Rounded corners
|
borderRadius: BorderRadius.circular(15),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: ColorsManager.textFieldGreyColor, // Border color
|
color: ColorsManager.textFieldGreyColor,
|
||||||
width: 3.0, // Border width
|
width: 3.0, // Border width
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Wrap(
|
child: Wrap(
|
||||||
spacing: 8.0, // Spacing between chips
|
spacing: 8.0,
|
||||||
runSpacing: 8.0, // Spacing between rows of chips
|
runSpacing: 8.0,
|
||||||
children: [
|
children: [
|
||||||
...subspaces.map(
|
...subspaces.map(
|
||||||
(subspace) => Chip(
|
(subspace) => Chip(
|
||||||
|
@ -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<ProductModel>? products;
|
||||||
|
final List<SubspaceTemplateModel>? subspaces;
|
||||||
|
final List<String>? 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<bool>(
|
||||||
|
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<bool>(
|
||||||
|
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<ProductModel, int> _groupTags(List<TagModel> tags) {
|
||||||
|
final Map<ProductModel, int> groupedTags = {};
|
||||||
|
for (var tag in tags) {
|
||||||
|
if (tag.product != null) {
|
||||||
|
groupedTags[tag.product!] = (groupedTags[tag.product!] ?? 0) + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return groupedTags;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user