mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
fixed edit dialog
This commit is contained in:
@ -21,6 +21,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
final List<SelectedProduct> addedProducts;
|
||||
final List<String>? allTags;
|
||||
final String spaceName;
|
||||
final String title;
|
||||
|
||||
const AssignTagModelsDialog({
|
||||
Key? key,
|
||||
@ -31,6 +32,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
this.onTagsAssigned,
|
||||
this.allTags,
|
||||
required this.spaceName,
|
||||
required this.title
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -52,7 +54,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
);
|
||||
|
||||
return AlertDialog(
|
||||
title: const Text('Assign Tags'),
|
||||
title: const Text(title),
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
@ -284,7 +286,21 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
Expanded(
|
||||
child: CancelButton(
|
||||
label: 'Cancel',
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => CreateSpaceModelDialog(
|
||||
products: products,
|
||||
allTags: allTags,
|
||||
spaceModel: SpaceTemplateModel(
|
||||
modelName: spaceName,
|
||||
subspaceModels: subspaces,
|
||||
tags: initialTags),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
@ -313,7 +329,6 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
state.tags.removeWhere(assignedTags.contains);
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
|
@ -2,22 +2,36 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_model_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/create_subspace_model/bloc/subspace_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/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/dialog/create_space_model_dialog.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class CreateSubSpaceModelDialog extends StatelessWidget {
|
||||
final bool isEdit;
|
||||
final String dialogTitle;
|
||||
final List<SubspaceTemplateModel>? existingSubSpaces;
|
||||
final String? spaceName;
|
||||
final List<TagModel>? spaceTagModels;
|
||||
final List<String>? allTags;
|
||||
final List<ProductModel>? products;
|
||||
final SpaceTemplateModel? spaceModel;
|
||||
|
||||
const CreateSubSpaceModelDialog({
|
||||
Key? key,
|
||||
required this.isEdit,
|
||||
required this.dialogTitle,
|
||||
this.existingSubSpaces,
|
||||
required this.allTags,
|
||||
required this.spaceName,
|
||||
required this.spaceTagModels,
|
||||
required this.products,
|
||||
required this.spaceModel,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -153,20 +167,49 @@ class CreateSubSpaceModelDialog extends StatelessWidget {
|
||||
Expanded(
|
||||
child: CancelButton(
|
||||
label: 'Cancel',
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
CreateSpaceModelDialog(
|
||||
products: products,
|
||||
allTags: allTags,
|
||||
spaceModel: SpaceTemplateModel(
|
||||
modelName: spaceName ?? '',
|
||||
subspaceModels: existingSubSpaces,
|
||||
tags: spaceTagModels,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: DefaultButton(
|
||||
onPressed: () {
|
||||
onPressed: () async {
|
||||
final subSpaces = context
|
||||
.read<SubSpaceModelBloc>()
|
||||
.state
|
||||
.subSpaces;
|
||||
Navigator.of(context).pop(subSpaces);
|
||||
Navigator.of(context).pop();
|
||||
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) =>
|
||||
CreateSpaceModelDialog(
|
||||
products: products,
|
||||
allTags: allTags,
|
||||
spaceModel: SpaceTemplateModel(
|
||||
modelName: spaceName ?? '',
|
||||
subspaceModels: subSpaces,
|
||||
tags: spaceTagModels,
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
borderRadius: 10,
|
||||
|
@ -29,7 +29,6 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
||||
final SpaceModelManagementApi _spaceModelApi = SpaceModelManagementApi();
|
||||
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
List<SubspaceTemplateModel>? subspaces = spaceModel?.subspaceModels ?? [];
|
||||
final TextEditingController spaceNameController = TextEditingController(
|
||||
text: spaceModel?.modelName ?? '',
|
||||
);
|
||||
@ -104,8 +103,15 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
SubspaceModelCreate(context,
|
||||
subspaces: state.space.subspaceModels ?? []),
|
||||
SubspaceModelCreate(
|
||||
context,
|
||||
subspaces: state.space.subspaceModels ?? [],
|
||||
allTags: allTags,
|
||||
products: products,
|
||||
spaceModel: spaceModel,
|
||||
spaceTagModels: spaceModel?.tags ?? [],
|
||||
spaceNameController: spaceNameController
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
TagChipDisplay(context,
|
||||
screenWidth: screenWidth,
|
||||
|
@ -1,25 +1,34 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.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/create_subspace_model/views/create_subspace_model_dialog.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart';
|
||||
|
||||
class SubspaceModelCreate extends StatelessWidget {
|
||||
final List<SubspaceTemplateModel> subspaces;
|
||||
final TextEditingController spaceNameController;
|
||||
final List<TagModel>? spaceTagModels;
|
||||
final List<String>? allTags;
|
||||
final List<ProductModel>? products;
|
||||
final SpaceTemplateModel? spaceModel;
|
||||
|
||||
const SubspaceModelCreate(
|
||||
BuildContext context, {
|
||||
Key? key,
|
||||
required this.subspaces,
|
||||
this.spaceTagModels,
|
||||
required this.allTags,
|
||||
required this.products,
|
||||
required this.spaceModel,
|
||||
required this.spaceNameController,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
return Container(
|
||||
child: subspaces.isEmpty
|
||||
? TextButton(
|
||||
@ -29,11 +38,16 @@ class SubspaceModelCreate extends StatelessWidget {
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
final result = await showDialog<List<SubspaceTemplateModel>>(
|
||||
await showDialog<List<SubspaceTemplateModel>>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSubSpaceModelDialog(
|
||||
allTags: allTags,
|
||||
spaceName: spaceNameController.text,
|
||||
spaceModel: spaceModel,
|
||||
spaceTagModels: spaceTagModels,
|
||||
products: products,
|
||||
isEdit: true,
|
||||
dialogTitle: subspaces.isEmpty
|
||||
? 'Create Sub-space'
|
||||
@ -42,14 +56,6 @@ class SubspaceModelCreate extends StatelessWidget {
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
subspaces.clear();
|
||||
subspaces.addAll(result);
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(subspaces));
|
||||
}
|
||||
},
|
||||
child: const ButtonContentWidget(
|
||||
icon: Icons.add,
|
||||
@ -90,7 +96,7 @@ class SubspaceModelCreate extends StatelessWidget {
|
||||
),
|
||||
GestureDetector(
|
||||
onTap: () async {
|
||||
final result =
|
||||
Navigator.of(context).pop();
|
||||
await showDialog<List<SubspaceTemplateModel>>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
@ -99,17 +105,14 @@ class SubspaceModelCreate extends StatelessWidget {
|
||||
isEdit: true,
|
||||
dialogTitle: 'Edit Sub-space',
|
||||
existingSubSpaces: subspaces,
|
||||
allTags: allTags,
|
||||
spaceName: spaceNameController.text,
|
||||
spaceTagModels: spaceTagModels,
|
||||
products: products,
|
||||
spaceModel: spaceModel,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
if (result != null) {
|
||||
subspaces.clear();
|
||||
subspaces.addAll(result);
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(subspaces));
|
||||
}
|
||||
},
|
||||
child: Chip(
|
||||
label: const Text(
|
||||
|
@ -30,8 +30,7 @@ class TagChipDisplay extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return (spaceModel?.subspaceModels?.isNotEmpty == true ||
|
||||
spaceModel?.tags?.isNotEmpty == true ||
|
||||
return (spaceModel?.tags?.isNotEmpty == true ||
|
||||
spaceModel?.subspaceModels
|
||||
?.any((subspace) => subspace.tags?.isNotEmpty == true) ==
|
||||
true)
|
||||
@ -160,7 +159,6 @@ class TagChipDisplay extends StatelessWidget {
|
||||
List<TagModel>? tags, List<SubspaceTemplateModel>? subspaces) {
|
||||
final Map<ProductModel, int> productCounts = {};
|
||||
|
||||
// Count products in spaceModel tags
|
||||
if (tags != null) {
|
||||
for (var tag in tags) {
|
||||
if (tag.product != null) {
|
||||
@ -169,7 +167,6 @@ class TagChipDisplay extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// Count products in subspaces
|
||||
if (subspaces != null) {
|
||||
for (var subspace in subspaces) {
|
||||
if (subspace.tags != null) {
|
||||
@ -183,7 +180,6 @@ class TagChipDisplay extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// Create SelectedProduct instances
|
||||
return productCounts.entries
|
||||
.map((entry) => SelectedProduct(
|
||||
productId: entry.key.uuid,
|
||||
|
@ -4,8 +4,10 @@ import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/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/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/dialog/create_space_model_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/tag_model/bloc/add_device_model_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/action_button_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/tag_model/widgets/scrollable_grid_view_widget.dart';
|
||||
@ -70,7 +72,21 @@ class AddDeviceTypeModelWidget extends StatelessWidget {
|
||||
children: [
|
||||
CancelButton(
|
||||
label: 'Cancel',
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
onPressed: () async {
|
||||
Navigator.of(context).pop();
|
||||
await showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => CreateSpaceModelDialog(
|
||||
products: products,
|
||||
allTags: allTags,
|
||||
spaceModel: SpaceTemplateModel(
|
||||
modelName: spaceName,
|
||||
subspaceModels: subspaces,
|
||||
tags: spaceTagModels,
|
||||
)),
|
||||
);
|
||||
},
|
||||
),
|
||||
ActionButton(
|
||||
label: 'Continue',
|
||||
@ -82,6 +98,14 @@ class AddDeviceTypeModelWidget extends StatelessWidget {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
if (currentState.isNotEmpty) {
|
||||
final initialTags = generateInitialTags(
|
||||
spaceTagModels: spaceTagModels,
|
||||
subspaces: subspaces,
|
||||
);
|
||||
|
||||
final dialogTitle = initialTags.isNotEmpty
|
||||
? 'Edit Device'
|
||||
: 'Assign Tags';
|
||||
await showDialog<bool>(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
@ -91,9 +115,8 @@ class AddDeviceTypeModelWidget extends StatelessWidget {
|
||||
addedProducts: currentState,
|
||||
allTags: allTags,
|
||||
spaceName: spaceName,
|
||||
initialTags: generateInitialTags(
|
||||
spaceTagModels: spaceTagModels,
|
||||
subspaces: subspaces),
|
||||
initialTags: initialTags,
|
||||
title: dialogTitle,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user