added duplicate

This commit is contained in:
hannathkadher
2025-01-27 00:33:50 +04:00
parent 9167c8da29
commit 4907eebc42
22 changed files with 1025 additions and 455 deletions

View File

@ -10,6 +10,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
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/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/helper/tag_helper.dart';
import 'package:syncrow_web/pages/spaces_management/link_space_model/view/link_space_model_dialog.dart';
@ -409,7 +410,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
_showTagCreateDialog(
context,
enteredName,
widget.isEdit,
widget.products,
subspaces,
);
// Edit action
})
@ -420,7 +423,12 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
: TextButton(
onPressed: () {
_showTagCreateDialog(
context, enteredName, widget.products);
context,
enteredName,
widget.isEdit,
widget.products,
subspaces,
);
},
style: TextButton.styleFrom(
padding: EdgeInsets.zero,
@ -558,85 +566,57 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
);
}
void _showTagCreateDialog(
BuildContext context, String name, List<ProductModel>? products) {
showDialog(
context: context,
builder: (BuildContext context) {
return AddDeviceTypeWidget(
spaceName: name,
products: products,
subspaces: subspaces,
spaceTags: tags,
allTags: [],
initialSelectedProducts:
createInitialSelectedProducts(tags, subspaces),
onSave: (selectedSpaceTags, selectedSubspaces) {
setState(() {
tags = selectedSpaceTags;
selectedSpaceModel = null;
void _showTagCreateDialog(BuildContext context, String name, bool isEdit,
List<ProductModel>? products, List<SubspaceModel>? subspaces) {
isEdit
? showDialog(
context: context,
builder: (BuildContext context) {
return AssignTagDialog(
title: 'Edit Device',
addedProducts: TagHelper.createInitialSelectedProductsForTags(
tags, subspaces),
spaceName: name,
products: products,
subspaces: subspaces,
allTags: [],
onSave: (selectedSpaceTags, selectedSubspaces) {},
);
},
)
: showDialog(
context: context,
builder: (BuildContext context) {
return AddDeviceTypeWidget(
spaceName: name,
products: products,
subspaces: subspaces,
spaceTags: tags,
allTags: [],
initialSelectedProducts:
TagHelper.createInitialSelectedProductsForTags(
tags, subspaces),
onSave: (selectedSpaceTags, selectedSubspaces) {
setState(() {
tags = selectedSpaceTags;
selectedSpaceModel = null;
if (selectedSubspaces != null) {
if (subspaces != null) {
for (final subspace in subspaces!) {
for (final selectedSubspace in selectedSubspaces) {
if (subspace.subspaceName ==
selectedSubspace.subspaceName) {
subspace.tags = selectedSubspace.tags;
if (selectedSubspaces != null) {
if (subspaces != null) {
for (final subspace in subspaces!) {
for (final selectedSubspace in selectedSubspaces) {
if (subspace.subspaceName ==
selectedSubspace.subspaceName) {
subspace.tags = selectedSubspace.tags;
}
}
}
}
}
}
}
}
});
},
);
},
);
}
List<SelectedProduct> createInitialSelectedProducts(
List<Tag>? tags, List<SubspaceModel>? subspaces) {
final Map<ProductModel, int> productCounts = {};
if (tags != null) {
for (var tag in tags) {
if (tag.product != null) {
productCounts[tag.product!] = (productCounts[tag.product!] ?? 0) + 1;
}
}
}
if (subspaces != null) {
for (var subspace in subspaces) {
if (subspace.tags != null) {
for (var tag in subspace.tags!) {
if (tag.product != null) {
productCounts[tag.product!] =
(productCounts[tag.product!] ?? 0) + 1;
}
}
}
}
}
return productCounts.entries
.map((entry) => SelectedProduct(
productId: entry.key.uuid,
count: entry.value,
productName: entry.key.name ?? 'Unnamed',
product: entry.key,
))
.toList();
}
Map<ProductModel, int> _groupTags(List<Tag> 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;
});
},
);
},
);
}
}

View File

@ -0,0 +1,86 @@
import 'package:flutter/material.dart';
import 'package:syncrow_web/utils/color_manager.dart';
class DuplicateProcessDialog extends StatefulWidget {
final VoidCallback onDuplicate;
const DuplicateProcessDialog({required this.onDuplicate, Key? key})
: super(key: key);
@override
_DuplicateProcessDialogState createState() => _DuplicateProcessDialogState();
}
class _DuplicateProcessDialogState extends State<DuplicateProcessDialog> {
bool isDuplicating = true;
@override
void initState() {
super.initState();
_startDuplication();
}
void _startDuplication() async {
WidgetsBinding.instance.addPostFrameCallback((_) {
widget.onDuplicate();
});
await Future.delayed(const Duration(seconds: 2));
setState(() {
isDuplicating = false;
});
await Future.delayed(const Duration(seconds: 2));
if (mounted) {
Navigator.of(context).pop();
}
}
@override
Widget build(BuildContext context) {
final screenWidth = MediaQuery.of(context).size.width;
return AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
content: SizedBox(
width: screenWidth * 0.4,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (isDuplicating) ...[
const CircularProgressIndicator(
color: ColorsManager.vividBlue,
),
const SizedBox(height: 15),
Text(
"Duplicating in progress",
style: Theme.of(context)
.textTheme
.headlineSmall
?.copyWith(color: ColorsManager.primaryColor),
textAlign: TextAlign.center,
),
] else ...[
const Icon(
Icons.check_circle,
color: ColorsManager.vividBlue,
size: 50,
),
const SizedBox(height: 15),
Text(
"Duplicating successful",
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
.headlineSmall
?.copyWith(color: ColorsManager.primaryColor),
),
],
],
),
),
);
}
}