mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
add tags
This commit is contained in:
@ -24,6 +24,8 @@ class AddDeviceTypeWidget extends StatelessWidget {
|
||||
final String spaceName;
|
||||
final bool isCreate;
|
||||
final Function(List<Tag>, List<SubspaceModel>?)? onSave;
|
||||
final List<Tag> projectTags;
|
||||
|
||||
|
||||
const AddDeviceTypeWidget(
|
||||
{super.key,
|
||||
@ -35,7 +37,8 @@ class AddDeviceTypeWidget extends StatelessWidget {
|
||||
this.allTags,
|
||||
this.spaceTags,
|
||||
this.onSave,
|
||||
required this.spaceName});
|
||||
required this.spaceName,
|
||||
required this.projectTags});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -134,7 +137,8 @@ class AddDeviceTypeWidget extends StatelessWidget {
|
||||
spaceName: spaceName,
|
||||
initialTags: initialTags,
|
||||
title: dialogTitle,
|
||||
onSave: onSave),
|
||||
onSave: onSave,
|
||||
projectTags: projectTags),
|
||||
);
|
||||
}
|
||||
},
|
||||
|
@ -296,11 +296,10 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
// Fetch space models after communities are available
|
||||
final prevSpaceModels = await fetchSpaceModels();
|
||||
emit(SpaceManagementLoaded(
|
||||
communities: communities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: prevSpaceModels,
|
||||
allTags: _cachedTags ?? []
|
||||
));
|
||||
communities: communities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: prevSpaceModels,
|
||||
allTags: _cachedTags ?? []));
|
||||
}
|
||||
|
||||
Future<List<CommunityModel>> _waitForCommunityList(SpaceTreeBloc spaceBloc) async {
|
||||
@ -365,13 +364,13 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
_spaceTreeBloc.add(OnCommunityAdded(newCommunity));
|
||||
|
||||
emit(SpaceManagementLoaded(
|
||||
spaceModels: prevSpaceModels,
|
||||
communities: updatedCommunities,
|
||||
products: _cachedProducts ?? [],
|
||||
selectedCommunity: newCommunity,
|
||||
selectedSpace: null,
|
||||
allTags: _cachedTags ?? [],
|
||||
));
|
||||
spaceModels: prevSpaceModels,
|
||||
communities: updatedCommunities,
|
||||
products: _cachedProducts ?? [],
|
||||
selectedCommunity: newCommunity,
|
||||
selectedSpace: null,
|
||||
allTags: _cachedTags ?? [],
|
||||
));
|
||||
}
|
||||
} else {
|
||||
emit(const SpaceManagementError('Error creating community'));
|
||||
@ -492,7 +491,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
selectedCommunity: community,
|
||||
selectedSpace: null,
|
||||
spaceModels: prevSpaceModels,
|
||||
allTags: _cachedTags ??[]));
|
||||
allTags: _cachedTags ?? []));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -557,7 +556,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
for (var tag in newSubspace.tags!) {
|
||||
tagUpdates.add(TagModelUpdate(
|
||||
action: custom_action.Action.add,
|
||||
uuid: tag.uuid == '' ? null : tag.uuid,
|
||||
newTagUuid: tag.uuid == '' ? null : tag.uuid,
|
||||
tag: tag.tag,
|
||||
productUuid: tag.product?.uuid));
|
||||
}
|
||||
@ -695,11 +694,10 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
}
|
||||
|
||||
emit(SpaceModelLoaded(
|
||||
communities: communities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: prevSpaceModels,
|
||||
allTags: _cachedTags ?? []
|
||||
));
|
||||
communities: communities,
|
||||
products: _cachedProducts ?? [],
|
||||
spaceModels: prevSpaceModels,
|
||||
allTags: _cachedTags ?? []));
|
||||
} catch (e) {
|
||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||
}
|
||||
@ -717,7 +715,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
tagUpdates.add(TagModelUpdate(
|
||||
action: custom_action.Action.add,
|
||||
tag: newTag.tag,
|
||||
uuid: newTag.uuid,
|
||||
newTagUuid: newTag.uuid,
|
||||
productUuid: newTag.product?.uuid,
|
||||
));
|
||||
}
|
||||
@ -750,7 +748,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
tagUpdates.add(TagModelUpdate(
|
||||
action: custom_action.Action.add,
|
||||
tag: newTag.tag,
|
||||
uuid: newTag.uuid == '' ? null : newTag.uuid,
|
||||
newTagUuid: newTag.uuid == '' ? null : newTag.uuid,
|
||||
productUuid: newTag.product?.uuid));
|
||||
processedTags.add(newTag.tag);
|
||||
}
|
||||
@ -767,6 +765,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
tagUpdates.add(TagModelUpdate(
|
||||
action: custom_action.Action.update,
|
||||
uuid: newTag.uuid,
|
||||
newTagUuid: newTag.uuid,
|
||||
tag: newTag.tag,
|
||||
));
|
||||
} else {}
|
||||
|
@ -36,16 +36,17 @@ class CommunityStructureArea extends StatefulWidget {
|
||||
final List<CommunityModel> communities;
|
||||
final List<SpaceModel> spaces;
|
||||
final List<SpaceTemplateModel>? spaceModels;
|
||||
final List<Tag> projectTags;
|
||||
|
||||
CommunityStructureArea({
|
||||
this.selectedCommunity,
|
||||
this.selectedSpace,
|
||||
required this.communities,
|
||||
this.products,
|
||||
required this.spaces,
|
||||
this.onSpaceSelected,
|
||||
this.spaceModels,
|
||||
});
|
||||
CommunityStructureArea(
|
||||
{this.selectedCommunity,
|
||||
this.selectedSpace,
|
||||
required this.communities,
|
||||
this.products,
|
||||
required this.spaces,
|
||||
this.onSpaceSelected,
|
||||
this.spaceModels,
|
||||
required this.projectTags});
|
||||
|
||||
@override
|
||||
_CommunityStructureAreaState createState() => _CommunityStructureAreaState();
|
||||
@ -64,8 +65,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||
connections =
|
||||
widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||
_adjustCanvasSizeForSpaces();
|
||||
_nameController = TextEditingController(
|
||||
text: widget.selectedCommunity?.name ?? '',
|
||||
@ -92,14 +92,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
if (oldWidget.spaces != widget.spaces) {
|
||||
setState(() {
|
||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||
connections =
|
||||
widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||
_adjustCanvasSizeForSpaces();
|
||||
});
|
||||
}
|
||||
|
||||
if (widget.selectedSpace != oldWidget.selectedSpace &&
|
||||
widget.selectedSpace != null) {
|
||||
if (widget.selectedSpace != oldWidget.selectedSpace && widget.selectedSpace != null) {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
_moveToSpace(widget.selectedSpace!);
|
||||
});
|
||||
@ -182,8 +180,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
connection, widget.selectedSpace)
|
||||
? 1.0
|
||||
: 0.3, // Adjust opacity
|
||||
child: CustomPaint(
|
||||
painter: CurvedLinePainter([connection])),
|
||||
child: CustomPaint(painter: CurvedLinePainter([connection])),
|
||||
),
|
||||
for (var entry in spaces.asMap().entries)
|
||||
if (entry.value.status != SpaceStatus.deleted &&
|
||||
@ -193,15 +190,12 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
top: entry.value.position.dy,
|
||||
child: SpaceCardWidget(
|
||||
index: entry.key,
|
||||
onButtonTap: (int index, Offset newPosition,
|
||||
String direction) {
|
||||
_showCreateSpaceDialog(
|
||||
screenSize,
|
||||
position:
|
||||
spaces[index].position + newPosition,
|
||||
parentIndex: index,
|
||||
direction: direction,
|
||||
);
|
||||
onButtonTap: (int index, Offset newPosition, String direction) {
|
||||
_showCreateSpaceDialog(screenSize,
|
||||
position: spaces[index].position + newPosition,
|
||||
parentIndex: index,
|
||||
direction: direction,
|
||||
projectTags: widget.projectTags);
|
||||
},
|
||||
position: entry.value.position,
|
||||
isHovered: entry.value.isHovered,
|
||||
@ -211,9 +205,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
_updateNodePosition(entry.value, newPosition);
|
||||
},
|
||||
buildSpaceContainer: (int index) {
|
||||
final bool isHighlighted =
|
||||
SpaceHelper.isHighlightedSpace(
|
||||
spaces[index], widget.selectedSpace);
|
||||
final bool isHighlighted = SpaceHelper.isHighlightedSpace(
|
||||
spaces[index], widget.selectedSpace);
|
||||
|
||||
return Opacity(
|
||||
opacity: isHighlighted ? 1.0 : 0.3,
|
||||
@ -238,7 +231,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
onTap: () {
|
||||
_showCreateSpaceDialog(screenSize,
|
||||
canvasHeight: canvasHeight,
|
||||
canvasWidth: canvasWidth);
|
||||
canvasWidth: canvasWidth,
|
||||
projectTags: widget.projectTags);
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -292,26 +286,22 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
int? parentIndex,
|
||||
String? direction,
|
||||
double? canvasWidth,
|
||||
double? canvasHeight}) {
|
||||
double? canvasHeight,
|
||||
required List<Tag> projectTags}) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSpaceDialog(
|
||||
products: widget.products,
|
||||
spaceModels: widget.spaceModels,
|
||||
allTags:
|
||||
TagHelper.getAllTagValues(widget.communities, widget.spaceModels),
|
||||
allTags: TagHelper.getAllTagValues(widget.communities, widget.spaceModels),
|
||||
parentSpace: parentIndex != null ? spaces[parentIndex] : null,
|
||||
onCreateSpace: (String name,
|
||||
String icon,
|
||||
List<SelectedProduct> selectedProducts,
|
||||
SpaceTemplateModel? spaceModel,
|
||||
List<SubspaceModel>? subspaces,
|
||||
List<Tag>? tags) {
|
||||
projectTags: projectTags,
|
||||
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts,
|
||||
SpaceTemplateModel? spaceModel, List<SubspaceModel>? subspaces, List<Tag>? tags) {
|
||||
setState(() {
|
||||
// Set the first space in the center or use passed position
|
||||
Offset centerPosition =
|
||||
position ?? ConnectionHelper.getCenterPosition(screenSize);
|
||||
Offset centerPosition = position ?? ConnectionHelper.getCenterPosition(screenSize);
|
||||
SpaceModel newSpace = SpaceModel(
|
||||
name: name,
|
||||
icon: icon,
|
||||
@ -356,21 +346,17 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
spaceModels: widget.spaceModels,
|
||||
name: widget.selectedSpace!.name,
|
||||
icon: widget.selectedSpace!.icon,
|
||||
parentSpace: SpaceHelper.findSpaceByInternalId(
|
||||
widget.selectedSpace?.parent?.internalId, spaces),
|
||||
projectTags: widget.projectTags,
|
||||
parentSpace:
|
||||
SpaceHelper.findSpaceByInternalId(widget.selectedSpace?.parent?.internalId, spaces),
|
||||
editSpace: widget.selectedSpace,
|
||||
currentSpaceModel: widget.selectedSpace?.spaceModel,
|
||||
tags: widget.selectedSpace?.tags,
|
||||
subspaces: widget.selectedSpace?.subspaces,
|
||||
isEdit: true,
|
||||
allTags: TagHelper.getAllTagValues(
|
||||
widget.communities, widget.spaceModels),
|
||||
onCreateSpace: (String name,
|
||||
String icon,
|
||||
List<SelectedProduct> selectedProducts,
|
||||
SpaceTemplateModel? spaceModel,
|
||||
List<SubspaceModel>? subspaces,
|
||||
List<Tag>? tags) {
|
||||
allTags: TagHelper.getAllTagValues(widget.communities, widget.spaceModels),
|
||||
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts,
|
||||
SpaceTemplateModel? spaceModel, List<SubspaceModel>? subspaces, List<Tag>? tags) {
|
||||
setState(() {
|
||||
// Update the space's properties
|
||||
widget.selectedSpace!.name = name;
|
||||
@ -380,8 +366,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
widget.selectedSpace!.tags = tags;
|
||||
|
||||
if (widget.selectedSpace!.status != SpaceStatus.newSpace) {
|
||||
widget.selectedSpace!.status =
|
||||
SpaceStatus.modified; // Mark as modified
|
||||
widget.selectedSpace!.status = SpaceStatus.modified; // Mark as modified
|
||||
}
|
||||
|
||||
for (var space in spaces) {
|
||||
@ -411,8 +396,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
List<SpaceModel> result = [];
|
||||
|
||||
void flatten(SpaceModel space) {
|
||||
if (space.status == SpaceStatus.deleted ||
|
||||
space.status == SpaceStatus.parentDeleted) {
|
||||
if (space.status == SpaceStatus.deleted || space.status == SpaceStatus.parentDeleted) {
|
||||
return;
|
||||
}
|
||||
result.add(space);
|
||||
@ -527,16 +511,13 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
|
||||
void _selectSpace(BuildContext context, SpaceModel space) {
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
SelectSpaceEvent(
|
||||
selectedCommunity: widget.selectedCommunity,
|
||||
selectedSpace: space),
|
||||
SelectSpaceEvent(selectedCommunity: widget.selectedCommunity, selectedSpace: space),
|
||||
);
|
||||
}
|
||||
|
||||
void _deselectSpace(BuildContext context) {
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
SelectSpaceEvent(
|
||||
selectedCommunity: widget.selectedCommunity, selectedSpace: null),
|
||||
SelectSpaceEvent(selectedCommunity: widget.selectedCommunity, selectedSpace: null),
|
||||
);
|
||||
}
|
||||
|
||||
@ -625,19 +606,16 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
const double horizontalGap = 200.0;
|
||||
const double verticalGap = 100.0;
|
||||
|
||||
SpaceModel duplicateRecursive(SpaceModel original, Offset parentPosition,
|
||||
SpaceModel? duplicatedParent) {
|
||||
Offset newPosition =
|
||||
Offset(parentPosition.dx + horizontalGap, original.position.dy);
|
||||
SpaceModel duplicateRecursive(
|
||||
SpaceModel original, Offset parentPosition, SpaceModel? duplicatedParent) {
|
||||
Offset newPosition = Offset(parentPosition.dx + horizontalGap, original.position.dy);
|
||||
|
||||
while (spaces.any((s) =>
|
||||
(s.position - newPosition).distance < horizontalGap &&
|
||||
s.status != SpaceStatus.deleted)) {
|
||||
(s.position - newPosition).distance < horizontalGap && s.status != SpaceStatus.deleted)) {
|
||||
newPosition += Offset(horizontalGap, 0);
|
||||
}
|
||||
|
||||
final duplicatedName =
|
||||
SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||
final duplicatedName = SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||
|
||||
final List<SubspaceModel>? duplicatedSubspaces;
|
||||
final List<Tag>? duplicatedTags;
|
||||
@ -681,8 +659,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
|
||||
if (original.parent != null && duplicatedParent == null) {
|
||||
final originalParent = original.parent!;
|
||||
final duplicatedParent =
|
||||
originalToDuplicate[originalParent] ?? originalParent;
|
||||
final duplicatedParent = originalToDuplicate[originalParent] ?? originalParent;
|
||||
|
||||
final parentConnection = Connection(
|
||||
startSpace: duplicatedParent,
|
||||
@ -698,8 +675,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
|
||||
final childrenWithDownDirection = original.children
|
||||
.where((child) =>
|
||||
child.incomingConnection?.direction == "down" &&
|
||||
child.status != SpaceStatus.deleted)
|
||||
child.incomingConnection?.direction == "down" && child.status != SpaceStatus.deleted)
|
||||
.toList();
|
||||
|
||||
Offset childStartPosition = childrenWithDownDirection.length == 1
|
||||
@ -707,8 +683,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
: newPosition + Offset(0, verticalGap);
|
||||
|
||||
for (final child in original.children) {
|
||||
final isDownDirection =
|
||||
child.incomingConnection?.direction == "down" ?? false;
|
||||
final isDownDirection = child.incomingConnection?.direction == "down" ?? false;
|
||||
|
||||
if (isDownDirection && childrenWithDownDirection.length == 1) {
|
||||
childStartPosition = duplicated.position + Offset(0, verticalGap);
|
||||
@ -716,8 +691,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
childStartPosition = duplicated.position + Offset(horizontalGap, 0);
|
||||
}
|
||||
|
||||
final duplicatedChild =
|
||||
duplicateRecursive(child, childStartPosition, duplicated);
|
||||
final duplicatedChild = duplicateRecursive(child, childStartPosition, duplicated);
|
||||
duplicated.children.add(duplicatedChild);
|
||||
childStartPosition += Offset(0, verticalGap);
|
||||
}
|
||||
@ -728,8 +702,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
if (space.parent == null) {
|
||||
duplicateRecursive(space, space.position, null);
|
||||
} else {
|
||||
final duplicatedParent =
|
||||
originalToDuplicate[space.parent!] ?? space.parent!;
|
||||
final duplicatedParent = originalToDuplicate[space.parent!] ?? space.parent!;
|
||||
duplicateRecursive(space, space.position, duplicatedParent);
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ class CreateSpaceDialog extends StatefulWidget {
|
||||
final List<Tag>? tags;
|
||||
final List<String>? allTags;
|
||||
final SpaceTemplateModel? currentSpaceModel;
|
||||
final List<Tag> projectTags;
|
||||
|
||||
const CreateSpaceDialog(
|
||||
{super.key,
|
||||
@ -57,7 +58,8 @@ class CreateSpaceDialog extends StatefulWidget {
|
||||
this.spaceModels,
|
||||
this.subspaces,
|
||||
this.tags,
|
||||
this.currentSpaceModel});
|
||||
this.currentSpaceModel,
|
||||
required this.projectTags});
|
||||
|
||||
@override
|
||||
CreateSpaceDialogState createState() => CreateSpaceDialogState();
|
||||
@ -80,10 +82,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
super.initState();
|
||||
selectedIcon = widget.icon ?? Assets.location;
|
||||
nameController = TextEditingController(text: widget.name ?? '');
|
||||
selectedProducts =
|
||||
widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||
isOkButtonEnabled =
|
||||
enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||
selectedProducts = widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||
isOkButtonEnabled = enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||
if (widget.currentSpaceModel != null) {
|
||||
subspaces = [];
|
||||
tags = [];
|
||||
@ -96,15 +96,13 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool isSpaceModelDisabled = (tags != null && tags!.isNotEmpty ||
|
||||
subspaces != null && subspaces!.isNotEmpty);
|
||||
bool isSpaceModelDisabled =
|
||||
(tags != null && tags!.isNotEmpty || subspaces != null && subspaces!.isNotEmpty);
|
||||
bool isTagsAndSubspaceModelDisabled = (selectedSpaceModel != null);
|
||||
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
return AlertDialog(
|
||||
title: widget.isEdit
|
||||
? const Text('Edit Space')
|
||||
: const Text('Create New Space'),
|
||||
title: widget.isEdit ? const Text('Edit Space') : const Text('Create New Space'),
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
content: SizedBox(
|
||||
width: screenWidth * 0.5,
|
||||
@ -178,7 +176,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
isNameFieldInvalid = value.isEmpty;
|
||||
|
||||
if (!isNameFieldInvalid) {
|
||||
if (SpaceHelper.isNameConflict(value, widget.parentSpace, widget.editSpace)) {
|
||||
if (SpaceHelper.isNameConflict(
|
||||
value, widget.parentSpace, widget.editSpace)) {
|
||||
isNameFieldExist = true;
|
||||
isOkButtonEnabled = false;
|
||||
} else {
|
||||
@ -245,9 +244,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
onPressed: () {
|
||||
isSpaceModelDisabled
|
||||
? null
|
||||
: _showLinkSpaceModelDialog(context);
|
||||
isSpaceModelDisabled ? null : _showLinkSpaceModelDialog(context);
|
||||
},
|
||||
child: ButtonContentWidget(
|
||||
svgAssets: Assets.link,
|
||||
@ -257,8 +254,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
)
|
||||
: Container(
|
||||
width: screenWidth * 0.25,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 10.0, horizontal: 16.0),
|
||||
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.boxColor,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
@ -273,8 +269,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium!
|
||||
.copyWith(
|
||||
color: ColorsManager.spaceColor),
|
||||
.copyWith(color: ColorsManager.spaceColor),
|
||||
),
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
@ -343,8 +338,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
onPressed: () async {
|
||||
isTagsAndSubspaceModelDisabled
|
||||
? null
|
||||
: _showSubSpaceDialog(context, enteredName,
|
||||
[], false, widget.products, subspaces);
|
||||
: _showSubSpaceDialog(
|
||||
context, enteredName, [], false, widget.products, subspaces);
|
||||
},
|
||||
child: ButtonContentWidget(
|
||||
icon: Icons.add,
|
||||
@ -371,22 +366,16 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
if (subspaces != null)
|
||||
...subspaces!.map((subspace) {
|
||||
return Column(
|
||||
crossAxisAlignment:
|
||||
CrossAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
SubspaceNameDisplayWidget(
|
||||
text: subspace.subspaceName,
|
||||
validateName: (updatedName) {
|
||||
bool nameExists =
|
||||
subspaces!.any((s) {
|
||||
bool isSameId = s.internalId ==
|
||||
subspace.internalId;
|
||||
bool isSameName = s.subspaceName
|
||||
.trim()
|
||||
.toLowerCase() ==
|
||||
updatedName
|
||||
.trim()
|
||||
.toLowerCase();
|
||||
bool nameExists = subspaces!.any((s) {
|
||||
bool isSameId = s.internalId == subspace.internalId;
|
||||
bool isSameName =
|
||||
s.subspaceName.trim().toLowerCase() ==
|
||||
updatedName.trim().toLowerCase();
|
||||
|
||||
return !isSameId && isSameName;
|
||||
});
|
||||
@ -395,8 +384,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
},
|
||||
onNameChanged: (updatedName) {
|
||||
setState(() {
|
||||
subspace.subspaceName =
|
||||
updatedName;
|
||||
subspace.subspaceName = updatedName;
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -405,8 +393,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
}),
|
||||
EditChip(
|
||||
onTap: () async {
|
||||
_showSubSpaceDialog(context, enteredName,
|
||||
[], true, widget.products, subspaces);
|
||||
_showSubSpaceDialog(context, enteredName, [], true,
|
||||
widget.products, subspaces);
|
||||
},
|
||||
)
|
||||
],
|
||||
@ -415,9 +403,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
(tags?.isNotEmpty == true ||
|
||||
subspaces?.any((subspace) =>
|
||||
subspace.tags?.isNotEmpty == true) ==
|
||||
true)
|
||||
subspaces?.any((subspace) => subspace.tags?.isNotEmpty == true) == true)
|
||||
? SizedBox(
|
||||
width: screenWidth * 0.25,
|
||||
child: Container(
|
||||
@ -437,16 +423,14 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
// Combine tags from spaceModel and subspaces
|
||||
...TagHelper.groupTags([
|
||||
...?tags,
|
||||
...?subspaces?.expand(
|
||||
(subspace) => subspace.tags ?? [])
|
||||
...?subspaces?.expand((subspace) => subspace.tags ?? [])
|
||||
]).entries.map(
|
||||
(entry) => Chip(
|
||||
avatar: SizedBox(
|
||||
width: 24,
|
||||
height: 24,
|
||||
child: SvgPicture.asset(
|
||||
entry.key.icon ??
|
||||
'assets/icons/gateway.svg',
|
||||
entry.key.icon ?? 'assets/icons/gateway.svg',
|
||||
fit: BoxFit.contain,
|
||||
),
|
||||
),
|
||||
@ -455,15 +439,11 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodySmall
|
||||
?.copyWith(
|
||||
color: ColorsManager
|
||||
.spaceColor),
|
||||
?.copyWith(color: ColorsManager.spaceColor),
|
||||
),
|
||||
backgroundColor:
|
||||
ColorsManager.whiteColors,
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius:
|
||||
BorderRadius.circular(16),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: const BorderSide(
|
||||
color: ColorsManager.spaceColor,
|
||||
),
|
||||
@ -472,23 +452,21 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
),
|
||||
|
||||
EditChip(onTap: () async {
|
||||
final result = await showDialog(
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (context) => AssignTagDialog(
|
||||
products: widget.products,
|
||||
subspaces: subspaces,
|
||||
allTags: widget.allTags,
|
||||
addedProducts: TagHelper
|
||||
.createInitialSelectedProductsForTags(
|
||||
addedProducts:
|
||||
TagHelper.createInitialSelectedProductsForTags(
|
||||
tags ?? [], subspaces),
|
||||
title: 'Edit Device',
|
||||
initialTags:
|
||||
TagHelper.generateInitialForTags(
|
||||
spaceTags: tags,
|
||||
subspaces: subspaces),
|
||||
initialTags: TagHelper.generateInitialForTags(
|
||||
spaceTags: tags, subspaces: subspaces),
|
||||
spaceName: widget.name ?? '',
|
||||
onSave:
|
||||
(updatedTags, updatedSubspaces) {
|
||||
projectTags: widget.projectTags,
|
||||
onSave: (updatedTags, updatedSubspaces) {
|
||||
setState(() {
|
||||
tags = updatedTags;
|
||||
subspaces = updatedSubspaces;
|
||||
@ -547,25 +525,17 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
String newName = enteredName.isNotEmpty
|
||||
? enteredName
|
||||
: (widget.name ?? '');
|
||||
String newName = enteredName.isNotEmpty ? enteredName : (widget.name ?? '');
|
||||
if (newName.isNotEmpty) {
|
||||
widget.onCreateSpace(
|
||||
newName,
|
||||
selectedIcon,
|
||||
selectedProducts,
|
||||
selectedSpaceModel,
|
||||
subspaces,
|
||||
tags);
|
||||
widget.onCreateSpace(newName, selectedIcon, selectedProducts,
|
||||
selectedSpaceModel, subspaces, tags);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
},
|
||||
borderRadius: 10,
|
||||
backgroundColor: isOkButtonEnabled
|
||||
? ColorsManager.secondaryColor
|
||||
: ColorsManager.grayColor,
|
||||
backgroundColor:
|
||||
isOkButtonEnabled ? ColorsManager.secondaryColor : ColorsManager.grayColor,
|
||||
foregroundColor: ColorsManager.whiteColors,
|
||||
child: const Text('OK'),
|
||||
),
|
||||
@ -592,7 +562,6 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
void _showLinkSpaceModelDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@ -613,13 +582,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showSubSpaceDialog(
|
||||
BuildContext context,
|
||||
String name,
|
||||
final List<Tag>? spaceTags,
|
||||
bool isEdit,
|
||||
List<ProductModel>? products,
|
||||
final List<SubspaceModel>? existingSubSpaces) {
|
||||
void _showSubSpaceDialog(BuildContext context, String name, final List<Tag>? spaceTags,
|
||||
bool isEdit, List<ProductModel>? products, final List<SubspaceModel>? existingSubSpaces) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
@ -634,12 +598,10 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
final List<Tag> tagsToAppendToSpace = [];
|
||||
|
||||
if (slectedSubspaces != null) {
|
||||
final updatedIds =
|
||||
slectedSubspaces.map((s) => s.internalId).toSet();
|
||||
final updatedIds = slectedSubspaces.map((s) => s.internalId).toSet();
|
||||
if (existingSubSpaces != null) {
|
||||
final deletedSubspaces = existingSubSpaces
|
||||
.where((s) => !updatedIds.contains(s.internalId))
|
||||
.toList();
|
||||
final deletedSubspaces =
|
||||
existingSubSpaces.where((s) => !updatedIds.contains(s.internalId)).toList();
|
||||
for (var s in deletedSubspaces) {
|
||||
if (s.tags != null) {
|
||||
tagsToAppendToSpace.addAll(s.tags!);
|
||||
@ -659,20 +621,20 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showTagCreateDialog(BuildContext context, String name, bool isEdit,
|
||||
List<ProductModel>? products) {
|
||||
void _showTagCreateDialog(
|
||||
BuildContext context, String name, bool isEdit, List<ProductModel>? products) {
|
||||
isEdit
|
||||
? showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AssignTagDialog(
|
||||
title: 'Edit Device',
|
||||
addedProducts: TagHelper.createInitialSelectedProductsForTags(
|
||||
tags, subspaces),
|
||||
addedProducts: TagHelper.createInitialSelectedProductsForTags(tags, subspaces),
|
||||
spaceName: name,
|
||||
products: products,
|
||||
subspaces: subspaces,
|
||||
allTags: widget.allTags,
|
||||
projectTags: widget.projectTags,
|
||||
onSave: (selectedSpaceTags, selectedSubspaces) {
|
||||
setState(() {
|
||||
tags = selectedSpaceTags;
|
||||
@ -682,8 +644,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
if (subspaces != null) {
|
||||
for (final subspace in subspaces!) {
|
||||
for (final selectedSubspace in selectedSubspaces) {
|
||||
if (subspace.subspaceName ==
|
||||
selectedSubspace.subspaceName) {
|
||||
if (subspace.subspaceName == selectedSubspace.subspaceName) {
|
||||
subspace.tags = selectedSubspace.tags;
|
||||
}
|
||||
}
|
||||
@ -705,9 +666,9 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
spaceTags: tags,
|
||||
isCreate: true,
|
||||
allTags: widget.allTags,
|
||||
projectTags: widget.projectTags,
|
||||
initialSelectedProducts:
|
||||
TagHelper.createInitialSelectedProductsForTags(
|
||||
tags, subspaces),
|
||||
TagHelper.createInitialSelectedProductsForTags(tags, subspaces),
|
||||
onSave: (selectedSpaceTags, selectedSubspaces) {
|
||||
setState(() {
|
||||
tags = selectedSpaceTags;
|
||||
@ -717,8 +678,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
if (subspaces != null) {
|
||||
for (final subspace in subspaces!) {
|
||||
for (final selectedSubspace in selectedSubspaces) {
|
||||
if (subspace.subspaceName ==
|
||||
selectedSubspace.subspaceName) {
|
||||
if (subspace.subspaceName == selectedSubspace.subspaceName) {
|
||||
subspace.tags = selectedSubspace.tags;
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +114,7 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
products: widget.products,
|
||||
communities: widget.communities,
|
||||
spaceModels: _spaceModels,
|
||||
projectTags: widget.projectTags,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -4,17 +4,16 @@ import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_e
|
||||
import 'package:syncrow_web/pages/spaces_management/assign_tag/bloc/assign_tag_state.dart';
|
||||
|
||||
class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
final List<String> allTags;
|
||||
final List<Tag> projectTags;
|
||||
|
||||
AssignTagBloc(this.allTags) : super(AssignTagInitial()) {
|
||||
AssignTagBloc(this.projectTags) : super(AssignTagInitial()) {
|
||||
on<InitializeTags>((event, emit) {
|
||||
final initialTags = event.initialTags ?? [];
|
||||
|
||||
final existingTagCounts = <String, int>{};
|
||||
for (var tag in initialTags) {
|
||||
if (tag.product != null) {
|
||||
existingTagCounts[tag.product!.uuid] =
|
||||
(existingTagCounts[tag.product!.uuid] ?? 0) + 1;
|
||||
existingTagCounts[tag.product!.uuid] = (existingTagCounts[tag.product!.uuid] ?? 0) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,17 +22,14 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
for (var selectedProduct in event.addedProducts) {
|
||||
final existingCount = existingTagCounts[selectedProduct.productId] ?? 0;
|
||||
|
||||
if (selectedProduct.count == 0 ||
|
||||
selectedProduct.count <= existingCount) {
|
||||
tags.addAll(initialTags
|
||||
.where((tag) => tag.product?.uuid == selectedProduct.productId));
|
||||
if (selectedProduct.count == 0 || selectedProduct.count <= existingCount) {
|
||||
tags.addAll(initialTags.where((tag) => tag.product?.uuid == selectedProduct.productId));
|
||||
continue;
|
||||
}
|
||||
|
||||
final missingCount = selectedProduct.count - existingCount;
|
||||
|
||||
tags.addAll(initialTags
|
||||
.where((tag) => tag.product?.uuid == selectedProduct.productId));
|
||||
tags.addAll(initialTags.where((tag) => tag.product?.uuid == selectedProduct.productId));
|
||||
|
||||
if (missingCount > 0) {
|
||||
tags.addAll(List.generate(
|
||||
@ -47,11 +43,11 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
}
|
||||
}
|
||||
|
||||
final updatedTags = _calculateAvailableTags(allTags, tags);
|
||||
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
||||
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
updatedTags: updatedTags,
|
||||
updatedTags: updatedTags,
|
||||
isSaveEnabled: _validateTags(tags),
|
||||
errorMessage: '',
|
||||
));
|
||||
@ -62,9 +58,16 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
|
||||
if (currentState is AssignTagLoaded && currentState.tags.isNotEmpty) {
|
||||
final tags = List<Tag>.from(currentState.tags);
|
||||
tags[event.index] = tags[event.index].copyWith(tag: event.tag);
|
||||
if (event.index < 0 || event.index >= tags.length) return;
|
||||
|
||||
final updatedTags = _calculateAvailableTags(allTags, tags);
|
||||
tags[event.index] = tags[event.index].copyWith(
|
||||
tag: event.tag.tag,
|
||||
uuid: event.tag.uuid,
|
||||
product: event.tag.product,
|
||||
internalId: event.tag.internalId,
|
||||
location: event.tag.location,
|
||||
);
|
||||
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
||||
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
@ -82,10 +85,9 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
final tags = List<Tag>.from(currentState.tags);
|
||||
|
||||
// Update the location
|
||||
tags[event.index] =
|
||||
tags[event.index].copyWith(location: event.location);
|
||||
tags[event.index] = tags[event.index].copyWith(location: event.location);
|
||||
|
||||
final updatedTags = _calculateAvailableTags(allTags, tags);
|
||||
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
||||
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
@ -104,7 +106,7 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
updatedTags: _calculateAvailableTags(allTags, tags),
|
||||
updatedTags: _calculateAvailableTags(projectTags, tags),
|
||||
isSaveEnabled: _validateTags(tags),
|
||||
errorMessage: _getValidationError(tags),
|
||||
));
|
||||
@ -115,11 +117,10 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
final currentState = state;
|
||||
|
||||
if (currentState is AssignTagLoaded && currentState.tags.isNotEmpty) {
|
||||
final tags = List<Tag>.from(currentState.tags)
|
||||
..remove(event.tagToDelete);
|
||||
final tags = List<Tag>.from(currentState.tags)..remove(event.tagToDelete);
|
||||
|
||||
// Recalculate available tags
|
||||
final updatedTags = _calculateAvailableTags(allTags, tags);
|
||||
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
||||
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
@ -140,10 +141,8 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
|
||||
// Get validation error for duplicate tags
|
||||
String? _getValidationError(List<Tag> tags) {
|
||||
final nonEmptyTags = tags
|
||||
.map((tag) => tag.tag?.trim() ?? '')
|
||||
.where((tag) => tag.isNotEmpty)
|
||||
.toList();
|
||||
final nonEmptyTags =
|
||||
tags.map((tag) => tag.tag?.trim() ?? '').where((tag) => tag.isNotEmpty).toList();
|
||||
|
||||
final duplicateTags = nonEmptyTags
|
||||
.fold<Map<String, int>>({}, (map, tag) {
|
||||
@ -162,14 +161,16 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
return null;
|
||||
}
|
||||
|
||||
List<String> _calculateAvailableTags(List<String> allTags, List<Tag> tags) {
|
||||
final selectedTags = tags
|
||||
List<Tag> _calculateAvailableTags(List<Tag> allTags, List<Tag> selectedTags) {
|
||||
final selectedTagSet = selectedTags
|
||||
.where((tag) => (tag.tag?.trim().isNotEmpty ?? false))
|
||||
.map((tag) => tag.tag!.trim())
|
||||
.toSet();
|
||||
|
||||
final availableTags =
|
||||
allTags.where((tag) => !selectedTags.contains(tag.trim())).toList();
|
||||
final availableTags = allTags
|
||||
.where((tag) => tag.tag != null && !selectedTagSet.contains(tag.tag!.trim()))
|
||||
.toList();
|
||||
|
||||
return availableTags;
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ class InitializeTags extends AssignTagEvent {
|
||||
|
||||
class UpdateTagEvent extends AssignTagEvent {
|
||||
final int index;
|
||||
final String tag;
|
||||
final Tag tag;
|
||||
|
||||
const UpdateTagEvent({required this.index, required this.tag});
|
||||
|
||||
|
@ -5,7 +5,7 @@ abstract class AssignTagState extends Equatable {
|
||||
const AssignTagState();
|
||||
|
||||
@override
|
||||
List<Object> get props => [];
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class AssignTagInitial extends AssignTagState {}
|
||||
@ -14,7 +14,7 @@ class AssignTagLoading extends AssignTagState {}
|
||||
|
||||
class AssignTagLoaded extends AssignTagState {
|
||||
final List<Tag> tags;
|
||||
final List<String> updatedTags;
|
||||
final List<Tag> updatedTags;
|
||||
|
||||
final bool isSaveEnabled;
|
||||
final String? errorMessage;
|
||||
@ -27,8 +27,7 @@ class AssignTagLoaded extends AssignTagState {
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props =>
|
||||
[tags, updatedTags, isSaveEnabled, errorMessage ?? ''];
|
||||
List<Object?> get props => [tags, updatedTags, isSaveEnabled, errorMessage ?? ''];
|
||||
}
|
||||
|
||||
class AssignTagError extends AssignTagState {
|
||||
@ -37,5 +36,5 @@ class AssignTagError extends AssignTagState {
|
||||
const AssignTagError(this.errorMessage);
|
||||
|
||||
@override
|
||||
List<Object> get props => [errorMessage];
|
||||
List<Object?> get props => [errorMessage];
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:syncrow_web/common/dialog_dropdown.dart';
|
||||
import 'package:syncrow_web/common/dialog_textfield_dropdown.dart';
|
||||
import 'package:syncrow_web/common/tag_dialog_textfield_dropdown.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/add_device_type/views/add_device_type_widget.dart';
|
||||
@ -26,6 +26,7 @@ class AssignTagDialog extends StatelessWidget {
|
||||
final String spaceName;
|
||||
final String title;
|
||||
final Function(List<Tag>, List<SubspaceModel>?)? onSave;
|
||||
final List<Tag> projectTags;
|
||||
|
||||
const AssignTagDialog(
|
||||
{Key? key,
|
||||
@ -37,18 +38,17 @@ class AssignTagDialog extends StatelessWidget {
|
||||
this.allTags,
|
||||
required this.spaceName,
|
||||
required this.title,
|
||||
this.onSave})
|
||||
this.onSave,
|
||||
required this.projectTags})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final List<String> locations = (subspaces ?? [])
|
||||
.map((subspace) => subspace.subspaceName)
|
||||
.toList()
|
||||
..add('Main Space');
|
||||
final List<String> locations =
|
||||
(subspaces ?? []).map((subspace) => subspace.subspaceName).toList()..add('Main Space');
|
||||
|
||||
return BlocProvider(
|
||||
create: (_) => AssignTagBloc(allTags ?? [])
|
||||
create: (_) => AssignTagBloc(projectTags)
|
||||
..add(InitializeTags(
|
||||
initialTags: initialTags,
|
||||
addedProducts: addedProducts,
|
||||
@ -70,8 +70,7 @@ class AssignTagDialog extends StatelessWidget {
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
child: DataTable(
|
||||
headingRowColor: WidgetStateProperty.all(
|
||||
ColorsManager.dataHeaderGrey),
|
||||
headingRowColor: WidgetStateProperty.all(ColorsManager.dataHeaderGrey),
|
||||
key: ValueKey(state.tags.length),
|
||||
border: TableBorder.all(
|
||||
color: ColorsManager.dataHeaderGrey,
|
||||
@ -80,22 +79,15 @@ class AssignTagDialog extends StatelessWidget {
|
||||
),
|
||||
columns: [
|
||||
DataColumn(
|
||||
label: Text('#',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
label: Text('#', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
label: Text('Device',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
label: Text('Device', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
numeric: false,
|
||||
label: Text('Tag',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
label: Text('Tag', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
DataColumn(
|
||||
label: Text('Location',
|
||||
style:
|
||||
Theme.of(context).textTheme.bodyMedium)),
|
||||
label:
|
||||
Text('Location', style: Theme.of(context).textTheme.bodyMedium)),
|
||||
],
|
||||
rows: state.tags.isEmpty
|
||||
? [
|
||||
@ -103,12 +95,8 @@ class AssignTagDialog extends StatelessWidget {
|
||||
DataCell(
|
||||
Center(
|
||||
child: Text('No Data Available',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.bodyMedium
|
||||
?.copyWith(
|
||||
color: ColorsManager
|
||||
.lightGrayColor,
|
||||
style: Theme.of(context).textTheme.bodyMedium?.copyWith(
|
||||
color: ColorsManager.lightGrayColor,
|
||||
)),
|
||||
),
|
||||
),
|
||||
@ -126,8 +114,7 @@ class AssignTagDialog extends StatelessWidget {
|
||||
DataCell(Text((index + 1).toString())),
|
||||
DataCell(
|
||||
Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
@ -141,31 +128,25 @@ class AssignTagDialog extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: ColorsManager
|
||||
.lightGrayColor,
|
||||
color: ColorsManager.lightGrayColor,
|
||||
width: 1.0,
|
||||
),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: const Icon(
|
||||
Icons.close,
|
||||
color: ColorsManager
|
||||
.lightGreyColor,
|
||||
color: ColorsManager.lightGreyColor,
|
||||
size: 16,
|
||||
),
|
||||
onPressed: () {
|
||||
context
|
||||
.read<AssignTagBloc>()
|
||||
.add(DeleteTag(
|
||||
tagToDelete: tag,
|
||||
tags: state.tags));
|
||||
context.read<AssignTagBloc>().add(
|
||||
DeleteTag(tagToDelete: tag, tags: state.tags));
|
||||
|
||||
controllers.removeAt(index);
|
||||
},
|
||||
tooltip: 'Delete Tag',
|
||||
padding: EdgeInsets.zero,
|
||||
constraints:
|
||||
const BoxConstraints(),
|
||||
constraints: const BoxConstraints(),
|
||||
),
|
||||
),
|
||||
],
|
||||
@ -173,23 +154,20 @@ class AssignTagDialog extends StatelessWidget {
|
||||
),
|
||||
DataCell(
|
||||
Container(
|
||||
alignment: Alignment
|
||||
.centerLeft, // Align cell content to the left
|
||||
alignment:
|
||||
Alignment.centerLeft, // Align cell content to the left
|
||||
child: SizedBox(
|
||||
width: double
|
||||
.infinity, // Ensure full width for dropdown
|
||||
child: DialogTextfieldDropdown(
|
||||
key: ValueKey(
|
||||
'dropdown_${Uuid().v4()}_${index}'),
|
||||
width: double.infinity,
|
||||
child: TagDialogTextfieldDropdown(
|
||||
key: ValueKey('dropdown_${const Uuid().v4()}_$index'),
|
||||
items: state.updatedTags,
|
||||
initialValue: tag.tag,
|
||||
product: tag.product?.uuid ?? 'Unknown',
|
||||
initialValue: tag,
|
||||
onSelected: (value) {
|
||||
controller.text = value;
|
||||
context
|
||||
.read<AssignTagBloc>()
|
||||
.add(UpdateTagEvent(
|
||||
controller.text = value.tag ?? '';
|
||||
context.read<AssignTagBloc>().add(UpdateTagEvent(
|
||||
index: index,
|
||||
tag: value.trim(),
|
||||
tag: value,
|
||||
));
|
||||
},
|
||||
),
|
||||
@ -201,12 +179,9 @@ class AssignTagDialog extends StatelessWidget {
|
||||
width: double.infinity,
|
||||
child: DialogDropdown(
|
||||
items: locations,
|
||||
selectedValue:
|
||||
tag.location ?? 'Main Space',
|
||||
selectedValue: tag.location ?? 'Main Space',
|
||||
onSelected: (value) {
|
||||
context
|
||||
.read<AssignTagBloc>()
|
||||
.add(UpdateLocation(
|
||||
context.read<AssignTagBloc>().add(UpdateLocation(
|
||||
index: index,
|
||||
location: value,
|
||||
));
|
||||
@ -238,13 +213,11 @@ class AssignTagDialog extends StatelessWidget {
|
||||
label: 'Add New Device',
|
||||
onPressed: () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result =
|
||||
TagHelper.processTags(updatedTags, subspaces);
|
||||
final result = TagHelper.processTags(updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces = List<SubspaceModel>.from(
|
||||
result['subspaces'] as List<dynamic>);
|
||||
final processedTags = result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces =
|
||||
List<SubspaceModel>.from(result['subspaces'] as List<dynamic>);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@ -253,8 +226,9 @@ class AssignTagDialog extends StatelessWidget {
|
||||
builder: (context) => AddDeviceTypeWidget(
|
||||
products: products,
|
||||
subspaces: processedSubspaces,
|
||||
initialSelectedProducts: TagHelper
|
||||
.createInitialSelectedProductsForTags(
|
||||
projectTags: projectTags,
|
||||
initialSelectedProducts:
|
||||
TagHelper.createInitialSelectedProductsForTags(
|
||||
processedTags, processedSubspaces),
|
||||
spaceName: spaceName,
|
||||
spaceTags: processedTags,
|
||||
@ -278,14 +252,11 @@ class AssignTagDialog extends StatelessWidget {
|
||||
onPressed: state.isSaveEnabled
|
||||
? () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result = TagHelper.processTags(
|
||||
updatedTags, subspaces);
|
||||
final result = TagHelper.processTags(updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
final processedTags = result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces =
|
||||
List<SubspaceModel>.from(
|
||||
result['subspaces'] as List<dynamic>);
|
||||
List<SubspaceModel>.from(result['subspaces'] as List<dynamic>);
|
||||
onSave?.call(processedTags, processedSubspaces);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ class AssignTagModelBloc extends Bloc<AssignTagModelEvent, AssignTagModelState>
|
||||
|
||||
AssignTagModelBloc(this.projectTags) : super(AssignTagModelInitial()) {
|
||||
on<InitializeTagModels>((event, emit) {
|
||||
final initialTags = event.initialTags ?? [];
|
||||
final initialTags = event.initialTags;
|
||||
|
||||
final existingTagCounts = <String, int>{};
|
||||
for (var tag in initialTags) {
|
||||
@ -67,7 +67,7 @@ class AssignTagModelBloc extends Bloc<AssignTagModelEvent, AssignTagModelState>
|
||||
location: event.tag.location,
|
||||
);
|
||||
|
||||
final updatedTags = _calculateAvailableTags(projectTags ?? [], tags);
|
||||
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
||||
|
||||
emit(AssignTagModelLoaded(
|
||||
tags: tags,
|
||||
@ -83,12 +83,9 @@ class AssignTagModelBloc extends Bloc<AssignTagModelEvent, AssignTagModelState>
|
||||
|
||||
if (currentState is AssignTagModelLoaded && currentState.tags.isNotEmpty) {
|
||||
final tags = List<Tag>.from(currentState.tags);
|
||||
for (var t in tags) {
|
||||
}
|
||||
// Use copyWith for immutability
|
||||
tags[event.index] = tags[event.index].copyWith(location: event.location);
|
||||
|
||||
|
||||
final updatedTags = _calculateAvailableTags(projectTags, tags);
|
||||
|
||||
emit(AssignTagModelLoaded(
|
||||
|
@ -171,8 +171,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
alignment: Alignment
|
||||
.centerLeft, // Align cell content to the left
|
||||
child: SizedBox(
|
||||
width:
|
||||
double.infinity, // Ensure full width for dropdown
|
||||
width: double.infinity,
|
||||
child: TagDialogTextfieldDropdown(
|
||||
key: ValueKey(
|
||||
'dropdown_${const Uuid().v4()}_$index'),
|
||||
|
Reference in New Issue
Block a user