diff --git a/lib/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart b/lib/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart new file mode 100644 index 00000000..1c7ab2d0 --- /dev/null +++ b/lib/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart @@ -0,0 +1,126 @@ +import 'package:flutter/material.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_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/utils/color_manager.dart'; + +class AssignTagModelsDialog extends StatefulWidget { + final List? products; + final List? subspaces; + final List? initialTags; + final ValueChanged>? onTagsAssigned; + + const AssignTagModelsDialog({ + Key? key, + required this.products, + required this.subspaces, + this.initialTags, + this.onTagsAssigned, + }) : super(key: key); + + @override + AssignTagModelsDialogState createState() => AssignTagModelsDialogState(); +} + +class AssignTagModelsDialogState extends State { + late List tags; + + @override + void initState() { + super.initState(); + + if (widget.products != null) { + print(widget.products); + tags = []; + } + } + + @override + Widget build(BuildContext context) { + return AlertDialog( + title: const Text('Assign Tags'), + backgroundColor: ColorsManager.whiteColors, + content: SingleChildScrollView( + child: Container( + width: MediaQuery.of(context).size.width * 0.9, + child: DataTable( + columns: const [ + DataColumn(label: Text('#')), + DataColumn(label: Text('Device')), + DataColumn(label: Text('Tag')), + DataColumn(label: Text('Location')), + ], + rows: tags.asMap().entries.map((entry) { + final index = entry.key + 1; + final tagModel = entry.value; + return DataRow(cells: [ + DataCell(Text(index.toString())), + DataCell(Text(tagModel.product?.name ?? 'Unknown')), + DataCell( + DropdownButton( + value: tagModel.tag, + onChanged: (value) { + setState(() { + tagModel.tag = value!; + }); + }, + items: List.generate(10, (index) { + final tag = 'Tag ${index + 1}'; + return DropdownMenuItem(value: tag, child: Text(tag)); + }), + ), + ), + DataCell( + DropdownButton( + value: widget.subspaces + ?.firstWhere( + (subspace) => + subspace.subspaceName == 'ssdsdf', + ) + .subspaceName ?? + 'None', + onChanged: (value) {}, + items: widget.subspaces! + .map((subspace) => DropdownMenuItem( + value: subspace.subspaceName, + child: Text(subspace.subspaceName), + )) + .toList(), + ), + ), + ]); + }).toList(), + ), + ), + ), + actions: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ElevatedButton( + onPressed: () => Navigator.of(context).pop(), + child: const Text('Back'), + style: ElevatedButton.styleFrom( + backgroundColor: ColorsManager.boxColor, + foregroundColor: ColorsManager.blackColor, + ), + ), + ElevatedButton( + onPressed: () { + Navigator.of(context).pop(); + if (widget.onTagsAssigned != null) { + widget.onTagsAssigned!(tags); + } + }, + child: const Text('Save'), + style: ElevatedButton.styleFrom( + backgroundColor: ColorsManager.secondaryColor, + foregroundColor: ColorsManager.whiteColors, + ), + ), + ], + ), + ], + ); + } +} diff --git a/lib/pages/spaces_management/space_model/models/tag_model.dart b/lib/pages/spaces_management/space_model/models/tag_model.dart index 356368fc..a9512107 100644 --- a/lib/pages/spaces_management/space_model/models/tag_model.dart +++ b/lib/pages/spaces_management/space_model/models/tag_model.dart @@ -1,29 +1,20 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; class TagModel { - final String uuid; - final DateTime createdAt; - final DateTime updatedAt; - final String tag; - final bool disabled; + String? uuid; + String tag; final ProductModel? product; TagModel({ - required this.uuid, - required this.createdAt, - required this.updatedAt, + this.uuid, required this.tag, - required this.disabled, this.product, }); factory TagModel.fromJson(Map json) { return TagModel( uuid: json['uuid'] ?? '', - createdAt: DateTime.parse(json['createdAt']), - updatedAt: DateTime.parse(json['updatedAt']), tag: json['tag'] ?? '', - disabled: json['disabled'] ?? false, product: json['product'] != null ? ProductModel.fromMap(json['product']) : null, @@ -33,10 +24,7 @@ class TagModel { Map toJson() { return { 'uuid': uuid, - 'createdAt': createdAt.toIso8601String(), - 'updatedAt': updatedAt.toIso8601String(), 'tag': tag, - 'disabled': disabled, 'product': product?.toMap(), }; } diff --git a/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart b/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart index ab0a0cb0..32828898 100644 --- a/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart +++ b/lib/pages/spaces_management/tag_model/views/add_device_type_model_widget.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/assign_tag_models/views/assign_tag_models_dialog.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart'; import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart'; @@ -31,56 +32,61 @@ class AddDeviceTypeModelWidget extends StatelessWidget { : 3; return BlocProvider( - create: (_) => AddDeviceTypeModelBloc(initialSelectedProducts ?? []), - child: AlertDialog( - title: const Text('Add Devices'), - backgroundColor: ColorsManager.whiteColors, - content: SingleChildScrollView( - child: Container( - width: size.width * 0.9, - height: size.height * 0.65, - color: ColorsManager.textFieldGreyColor, - child: Column( - children: [ - const SizedBox(height: 16), - Expanded( - child: Padding( - padding: const EdgeInsets.symmetric(horizontal: 20.0), - child: ScrollableGridViewWidget( - products: products, crossAxisCount: crossAxisCount), - ), + create: (_) => AddDeviceTypeModelBloc(initialSelectedProducts ?? []), + child: Builder( + builder: (context) => AlertDialog( + title: const Text('Add Devices'), + backgroundColor: ColorsManager.whiteColors, + content: SingleChildScrollView( + child: Container( + width: size.width * 0.9, + height: size.height * 0.65, + color: ColorsManager.textFieldGreyColor, + child: Column( + children: [ + const SizedBox(height: 16), + Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 20.0), + child: ScrollableGridViewWidget( + products: products, crossAxisCount: crossAxisCount), + ), + ), + ], ), - ], - ), - ), - ), - actions: [ - Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ - ActionButton( - label: 'Cancel', - backgroundColor: ColorsManager.boxColor, - foregroundColor: ColorsManager.blackColor, - onPressed: () => Navigator.of(context).pop(), ), - ActionButton( - label: 'Continue', - backgroundColor: ColorsManager.secondaryColor, - foregroundColor: ColorsManager.whiteColors, - onPressed: () { - Navigator.of(context).pop(); - if (onProductsSelected != null) { - final selectedProducts = - context.read().state; - onProductsSelected!(selectedProducts); - } - }, + ), + actions: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + ActionButton( + label: 'Cancel', + backgroundColor: ColorsManager.boxColor, + foregroundColor: ColorsManager.blackColor, + onPressed: () => Navigator.of(context).pop(), + ), + ActionButton( + label: 'Continue', + backgroundColor: ColorsManager.secondaryColor, + foregroundColor: ColorsManager.whiteColors, + onPressed: () async { + print(products); + print("dfsdf"); + await showDialog( + barrierDismissible: false, + context: context, + builder: (context) => AssignTagModelsDialog( + products: products, + subspaces: subspaces, + ), + ); + }, + ), + ], ), ], ), - ], - ), - ); + )); } }