mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 23:27:25 +00:00
Compare commits
12 Commits
bugfix/sub
...
bugifx/tag
Author | SHA1 | Date | |
---|---|---|---|
c5c5088724 | |||
d1d570b40f | |||
5e5f127a4b | |||
6f51c2d2b6 | |||
72241cba6c | |||
64e3fb7f34 | |||
e6e46be9b4 | |||
91dfd53477 | |||
916b606cb1 | |||
29c444eede | |||
9dd6c9e1e7 | |||
bf5b39e742 |
@ -87,6 +87,7 @@ class SpaceManagementBloc
|
||||
prevSpaceModels = List<SpaceTemplateModel>.from(
|
||||
(previousState as dynamic).spaceModels ?? [],
|
||||
);
|
||||
allSpaces.addAll(prevSpaceModels);
|
||||
}
|
||||
|
||||
if (prevSpaceModels.isEmpty) {
|
||||
@ -179,6 +180,7 @@ class SpaceManagementBloc
|
||||
final updatedCommunities =
|
||||
await Future.wait(communities.map((community) async {
|
||||
final spaces = await _fetchSpacesForCommunity(community.uuid);
|
||||
|
||||
return CommunityModel(
|
||||
uuid: community.uuid,
|
||||
createdAt: community.createdAt,
|
||||
|
@ -95,6 +95,9 @@ class SpaceModel {
|
||||
icon: json['icon'] ?? Assets.location,
|
||||
position: Offset(json['x'] ?? 0, json['y'] ?? 0),
|
||||
isHovered: false,
|
||||
spaceModel: json['spaceModel'] != null
|
||||
? SpaceTemplateModel.fromJson(json['spaceModel'])
|
||||
: null,
|
||||
tags: (json['tags'] as List<dynamic>?)
|
||||
?.where((item) => item is Map<String, dynamic>) // Validate type
|
||||
.map((item) => Tag.fromJson(item as Map<String, dynamic>))
|
||||
|
@ -64,11 +64,11 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||
);
|
||||
} else if (state is SpaceModelLoaded) {
|
||||
return LoadedSpaceView(
|
||||
communities: state.communities,
|
||||
products: state.products,
|
||||
spaceModels: state.spaceModels,
|
||||
shouldNavigateToSpaceModelPage: true,
|
||||
);
|
||||
communities: state.communities,
|
||||
products: state.products,
|
||||
spaceModels: state.spaceModels,
|
||||
shouldNavigateToSpaceModelPage: true,
|
||||
);
|
||||
} else if (state is SpaceManagementError) {
|
||||
return Center(child: Text('Error: ${state.errorMessage}'));
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/curved_li
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/duplicate_process_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_card_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_container_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/connection_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/space_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
@ -130,7 +133,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
communities: widget.communities,
|
||||
communityName: widget.selectedCommunity?.name,
|
||||
community: widget.selectedCommunity,
|
||||
isSave: isSave(spaces),
|
||||
isSave: SpaceHelper.isSave(spaces),
|
||||
isEditingName: isEditingName,
|
||||
nameController: _nameController,
|
||||
onSave: _saveSpaces,
|
||||
@ -175,7 +178,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
children: [
|
||||
for (var connection in connections)
|
||||
Opacity(
|
||||
opacity: _isHighlightedConnection(connection)
|
||||
opacity: ConnectionHelper.isHighlightedConnection(
|
||||
connection, widget.selectedSpace)
|
||||
? 1.0
|
||||
: 0.3, // Adjust opacity
|
||||
child: CustomPaint(
|
||||
@ -195,7 +199,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
screenSize,
|
||||
position:
|
||||
spaces[index].position + newPosition,
|
||||
|
||||
parentIndex: index,
|
||||
direction: direction,
|
||||
);
|
||||
@ -209,7 +212,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
},
|
||||
buildSpaceContainer: (int index) {
|
||||
final bool isHighlighted =
|
||||
_isHighlightedSpace(spaces[index]);
|
||||
SpaceHelper.isHighlightedSpace(
|
||||
spaces[index], widget.selectedSpace);
|
||||
|
||||
return Opacity(
|
||||
opacity: isHighlighted ? 1.0 : 0.3,
|
||||
@ -295,7 +299,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
return CreateSpaceDialog(
|
||||
products: widget.products,
|
||||
spaceModels: widget.spaceModels,
|
||||
allTags: _getAllTagValues(spaces),
|
||||
allTags:
|
||||
TagHelper.getAllTagValues(widget.communities, widget.spaceModels),
|
||||
parentSpace: parentIndex != null ? spaces[parentIndex] : null,
|
||||
onCreateSpace: (String name,
|
||||
String icon,
|
||||
@ -306,7 +311,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
setState(() {
|
||||
// Set the first space in the center or use passed position
|
||||
Offset centerPosition =
|
||||
position ?? _getCenterPosition(screenSize);
|
||||
position ?? ConnectionHelper.getCenterPosition(screenSize);
|
||||
SpaceModel newSpace = SpaceModel(
|
||||
name: name,
|
||||
icon: icon,
|
||||
@ -351,11 +356,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
spaceModels: widget.spaceModels,
|
||||
name: widget.selectedSpace!.name,
|
||||
icon: widget.selectedSpace!.icon,
|
||||
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: _getAllTagValues(spaces),
|
||||
allTags: TagHelper.getAllTagValues(
|
||||
widget.communities, widget.spaceModels),
|
||||
onCreateSpace: (String name,
|
||||
String icon,
|
||||
List<SelectedProduct> selectedProducts,
|
||||
@ -374,6 +383,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
widget.selectedSpace!.status =
|
||||
SpaceStatus.modified; // Mark as modified
|
||||
}
|
||||
|
||||
for (var space in spaces) {
|
||||
if (space.internalId == widget.selectedSpace?.internalId) {
|
||||
space.status = SpaceStatus.modified;
|
||||
space.subspaces = subspaces;
|
||||
space.tags = tags;
|
||||
space.name = name;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
key: Key(widget.selectedSpace!.name),
|
||||
@ -452,7 +470,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
}).toList();
|
||||
|
||||
if (spacesToSave.isEmpty) {
|
||||
debugPrint("No new or modified spaces to save.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -516,17 +533,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
);
|
||||
}
|
||||
|
||||
bool _isHighlightedSpace(SpaceModel space) {
|
||||
final selectedSpace = widget.selectedSpace;
|
||||
if (selectedSpace == null) return true;
|
||||
|
||||
return space == selectedSpace ||
|
||||
selectedSpace.parent?.internalId == space.internalId ||
|
||||
selectedSpace.children
|
||||
?.any((child) => child.internalId == space.internalId) ==
|
||||
true;
|
||||
}
|
||||
|
||||
void _deselectSpace(BuildContext context) {
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
SelectSpaceEvent(
|
||||
@ -534,28 +540,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
);
|
||||
}
|
||||
|
||||
bool _isHighlightedConnection(Connection connection) {
|
||||
if (widget.selectedSpace == null) return true;
|
||||
|
||||
return connection.startSpace == widget.selectedSpace ||
|
||||
connection.endSpace == widget.selectedSpace;
|
||||
}
|
||||
|
||||
Offset _getCenterPosition(Size screenSize) {
|
||||
return Offset(
|
||||
screenSize.width / 2 - 260,
|
||||
screenSize.height / 2 - 200,
|
||||
);
|
||||
}
|
||||
|
||||
bool isSave(List<SpaceModel> spaces) {
|
||||
return spaces.isNotEmpty &&
|
||||
spaces.any((space) =>
|
||||
space.status == SpaceStatus.newSpace ||
|
||||
space.status == SpaceStatus.modified ||
|
||||
space.status == SpaceStatus.deleted);
|
||||
}
|
||||
|
||||
void _onDuplicate(BuildContext parentContext) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
@ -641,17 +625,10 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
const double horizontalGap = 200.0;
|
||||
const double verticalGap = 100.0;
|
||||
|
||||
final Map<String, int> nameCounters = {};
|
||||
|
||||
String _generateCopyName(String originalName) {
|
||||
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
|
||||
nameCounters[baseName] = (nameCounters[baseName] ?? 0) + 1;
|
||||
return "$baseName(${nameCounters[baseName]})";
|
||||
}
|
||||
|
||||
SpaceModel duplicateRecursive(SpaceModel original, Offset parentPosition,
|
||||
SpaceModel? duplicatedParent) {
|
||||
Offset newPosition = parentPosition + Offset(horizontalGap, 0);
|
||||
Offset newPosition =
|
||||
Offset(parentPosition.dx + horizontalGap, original.position.dy);
|
||||
|
||||
while (spaces.any((s) =>
|
||||
(s.position - newPosition).distance < horizontalGap &&
|
||||
@ -659,7 +636,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
newPosition += Offset(horizontalGap, 0);
|
||||
}
|
||||
|
||||
final duplicatedName = _generateCopyName(original.name);
|
||||
final duplicatedName =
|
||||
SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||
|
||||
final duplicated = SpaceModel(
|
||||
name: duplicatedName,
|
||||
@ -684,7 +662,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
final newConnection = Connection(
|
||||
startSpace: duplicatedParent,
|
||||
endSpace: duplicated,
|
||||
direction: "down",
|
||||
direction: original.incomingConnection?.direction ?? 'down',
|
||||
);
|
||||
connections.add(newConnection);
|
||||
duplicated.incomingConnection = newConnection;
|
||||
@ -723,10 +701,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
child.incomingConnection?.direction == "down" ?? false;
|
||||
|
||||
if (isDownDirection && childrenWithDownDirection.length == 1) {
|
||||
// Place the only "down" child vertically aligned with the parent
|
||||
childStartPosition = duplicated.position + Offset(0, verticalGap);
|
||||
} else if (!isDownDirection) {
|
||||
// Position children with other directions horizontally
|
||||
childStartPosition = duplicated.position + Offset(horizontalGap, 0);
|
||||
}
|
||||
|
||||
@ -747,14 +723,4 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
duplicateRecursive(space, space.position, duplicatedParent);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> _getAllTagValues(List<SpaceModel> spaces) {
|
||||
final List<String> allTags = [];
|
||||
for (final space in spaces) {
|
||||
if (space.tags != null) {
|
||||
allTags.addAll(space.listAllTagValues());
|
||||
}
|
||||
}
|
||||
return allTags;
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ class CreateSpaceDialog extends StatefulWidget {
|
||||
final List<SubspaceModel>? subspaces;
|
||||
final List<Tag>? tags;
|
||||
final List<String>? allTags;
|
||||
final SpaceTemplateModel? currentSpaceModel;
|
||||
|
||||
const CreateSpaceDialog(
|
||||
{super.key,
|
||||
@ -54,7 +55,8 @@ class CreateSpaceDialog extends StatefulWidget {
|
||||
this.selectedProducts = const [],
|
||||
this.spaceModels,
|
||||
this.subspaces,
|
||||
this.tags});
|
||||
this.tags,
|
||||
this.currentSpaceModel});
|
||||
|
||||
@override
|
||||
CreateSpaceDialogState createState() => CreateSpaceDialogState();
|
||||
@ -81,8 +83,14 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||
isOkButtonEnabled =
|
||||
enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||
tags = widget.tags ?? [];
|
||||
subspaces = widget.subspaces ?? [];
|
||||
if (widget.currentSpaceModel != null) {
|
||||
subspaces = [];
|
||||
tags = [];
|
||||
} else {
|
||||
tags = widget.tags ?? [];
|
||||
subspaces = widget.subspaces ?? [];
|
||||
}
|
||||
selectedSpaceModel = widget.currentSpaceModel;
|
||||
}
|
||||
|
||||
@override
|
||||
@ -457,7 +465,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
context: context,
|
||||
builder: (context) => AssignTagDialog(
|
||||
products: widget.products,
|
||||
subspaces: widget.subspaces,
|
||||
subspaces: subspaces,
|
||||
allTags: widget.allTags,
|
||||
addedProducts: TagHelper
|
||||
.createInitialSelectedProductsForTags(
|
||||
tags ?? [], subspaces),
|
||||
@ -488,7 +497,6 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
enteredName,
|
||||
widget.isEdit,
|
||||
widget.products,
|
||||
subspaces,
|
||||
);
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
@ -571,12 +579,23 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
}
|
||||
|
||||
bool _isNameConflict(String value) {
|
||||
return (widget.parentSpace?.children.any((child) => child.name == value) ??
|
||||
false) ||
|
||||
(widget.parentSpace?.name == value) ||
|
||||
(widget.editSpace?.parent?.name == value) ||
|
||||
(widget.editSpace?.children.any((child) => child.name == value) ??
|
||||
false);
|
||||
final parentSpace = widget.parentSpace;
|
||||
final editSpace = widget.editSpace;
|
||||
final siblings = parentSpace?.children
|
||||
.where((child) => child.uuid != editSpace?.uuid)
|
||||
.toList() ??
|
||||
[];
|
||||
final siblingConflict = siblings.any((child) => child.name == value);
|
||||
final parentConflict =
|
||||
parentSpace?.name == value && parentSpace?.uuid != editSpace?.uuid;
|
||||
final parentOfEditSpaceConflict = editSpace?.parent?.name == value &&
|
||||
editSpace?.parent?.uuid != editSpace?.uuid;
|
||||
final childConflict =
|
||||
editSpace?.children.any((child) => child.name == value) ?? false;
|
||||
return siblingConflict ||
|
||||
parentConflict ||
|
||||
parentOfEditSpaceConflict ||
|
||||
childConflict;
|
||||
}
|
||||
|
||||
void _showLinkSpaceModelDialog(BuildContext context) {
|
||||
@ -617,9 +636,26 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
products: products,
|
||||
existingSubSpaces: existingSubSpaces,
|
||||
onSave: (slectedSubspaces) {
|
||||
final List<Tag> tagsToAppendToSpace = [];
|
||||
|
||||
if (slectedSubspaces != null) {
|
||||
final updatedIds =
|
||||
slectedSubspaces.map((s) => s.internalId).toSet();
|
||||
if (existingSubSpaces != null) {
|
||||
final deletedSubspaces = existingSubSpaces
|
||||
.where((s) => !updatedIds.contains(s.internalId))
|
||||
.toList();
|
||||
for (var s in deletedSubspaces) {
|
||||
if (s.tags != null) {
|
||||
tagsToAppendToSpace.addAll(s.tags!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (slectedSubspaces != null) {
|
||||
setState(() {
|
||||
subspaces = slectedSubspaces;
|
||||
tags?.addAll(tagsToAppendToSpace);
|
||||
selectedSpaceModel = null;
|
||||
});
|
||||
}
|
||||
@ -629,7 +665,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
}
|
||||
|
||||
void _showTagCreateDialog(BuildContext context, String name, bool isEdit,
|
||||
List<ProductModel>? products, List<SubspaceModel>? subspaces) {
|
||||
List<ProductModel>? products) {
|
||||
isEdit
|
||||
? showDialog(
|
||||
context: context,
|
||||
|
@ -11,7 +11,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/space_tem
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/view/space_model_page.dart';
|
||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||
|
||||
class LoadedSpaceView extends StatelessWidget {
|
||||
class LoadedSpaceView extends StatefulWidget {
|
||||
final List<CommunityModel> communities;
|
||||
final CommunityModel? selectedCommunity;
|
||||
final SpaceModel? selectedSpace;
|
||||
@ -26,41 +26,73 @@ class LoadedSpaceView extends StatelessWidget {
|
||||
this.selectedSpace,
|
||||
this.products,
|
||||
this.spaceModels,
|
||||
required this.shouldNavigateToSpaceModelPage
|
||||
required this.shouldNavigateToSpaceModelPage,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_LoadedSpaceViewState createState() => _LoadedSpaceViewState();
|
||||
}
|
||||
|
||||
class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
late List<SpaceTemplateModel> _spaceModels;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_spaceModels = List.from(widget.spaceModels ?? []);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant LoadedSpaceView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.spaceModels != oldWidget.spaceModels) {
|
||||
setState(() {
|
||||
_spaceModels = List.from(widget.spaceModels ?? []);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onSpaceModelsUpdated(List<SpaceTemplateModel> updatedModels) {
|
||||
if (mounted && updatedModels != _spaceModels) {
|
||||
setState(() {
|
||||
_spaceModels = updatedModels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SidebarWidget(
|
||||
communities: communities,
|
||||
selectedSpaceUuid:
|
||||
selectedSpace?.uuid ?? selectedCommunity?.uuid ?? '',
|
||||
communities: widget.communities,
|
||||
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
||||
widget.selectedCommunity?.uuid ??
|
||||
'',
|
||||
),
|
||||
shouldNavigateToSpaceModelPage
|
||||
widget.shouldNavigateToSpaceModelPage
|
||||
? Expanded(
|
||||
child: BlocProvider(
|
||||
create: (context) => SpaceModelBloc(
|
||||
api: SpaceModelManagementApi(),
|
||||
initialSpaceModels: spaceModels ?? [],
|
||||
initialSpaceModels: _spaceModels,
|
||||
),
|
||||
child: SpaceModelPage(
|
||||
products: products,
|
||||
products: widget.products,
|
||||
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
||||
),
|
||||
),
|
||||
)
|
||||
: CommunityStructureArea(
|
||||
selectedCommunity: selectedCommunity,
|
||||
selectedSpace: selectedSpace,
|
||||
spaces: selectedCommunity?.spaces ?? [],
|
||||
products: products,
|
||||
communities: communities,
|
||||
spaceModels: spaceModels,
|
||||
selectedCommunity: widget.selectedCommunity,
|
||||
selectedSpace: widget.selectedSpace,
|
||||
spaces: widget.selectedCommunity?.spaces ?? [],
|
||||
products: widget.products,
|
||||
communities: widget.communities,
|
||||
spaceModels: _spaceModels,
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -68,13 +100,4 @@ class LoadedSpaceView extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
SpaceModel? findSpaceByUuid(String? uuid, List<CommunityModel> communities) {
|
||||
for (var community in communities) {
|
||||
for (var space in community.spaces) {
|
||||
if (space.uuid == uuid) return space;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
if (currentState is AssignTagLoaded && currentState.tags.isNotEmpty) {
|
||||
final tags = List<Tag>.from(currentState.tags);
|
||||
tags[event.index].tag = event.tag;
|
||||
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
isSaveEnabled: _validateTags(tags),
|
||||
@ -78,6 +79,7 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
isSaveEnabled: _validateTags(tags),
|
||||
errorMessage: _getValidationError(tags),
|
||||
));
|
||||
}
|
||||
});
|
||||
@ -106,12 +108,13 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
emit(AssignTagLoaded(
|
||||
tags: updatedTags,
|
||||
isSaveEnabled: _validateTags(updatedTags),
|
||||
errorMessage: _getValidationError(updatedTags),
|
||||
));
|
||||
} else {
|
||||
emit(const AssignTagLoaded(
|
||||
tags: [],
|
||||
isSaveEnabled: false,
|
||||
));
|
||||
tags: [],
|
||||
isSaveEnabled: false,
|
||||
errorMessage: 'Failed to delete tag'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -125,7 +128,10 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
|
||||
String? _getValidationError(List<Tag> tags) {
|
||||
final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty);
|
||||
if (hasEmptyTag) return 'Tags cannot be empty.';
|
||||
if (hasEmptyTag) {
|
||||
return 'Tags cannot be empty.';
|
||||
}
|
||||
|
||||
final duplicateTags = tags
|
||||
.map((tag) => tag.tag?.trim() ?? '')
|
||||
.fold<Map<String, int>>({}, (map, tag) {
|
||||
|
@ -21,11 +21,11 @@ class AssignTagLoaded extends AssignTagState {
|
||||
const AssignTagLoaded({
|
||||
required this.tags,
|
||||
required this.isSaveEnabled,
|
||||
this.errorMessage,
|
||||
required this.errorMessage,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tags, isSaveEnabled];
|
||||
List<Object> get props => [tags, isSaveEnabled, errorMessage ?? ''];
|
||||
}
|
||||
|
||||
class AssignTagError extends AssignTagState {
|
||||
|
@ -233,11 +233,13 @@ class AssignTagDialog extends StatelessWidget {
|
||||
label: 'Add New Device',
|
||||
onPressed: () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result = processTags(updatedTags, subspaces);
|
||||
final result =
|
||||
TagHelper.processTags(updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces = result['subspaces'];
|
||||
final processedSubspaces = List<SubspaceModel>.from(
|
||||
result['subspaces'] as List<dynamic>);
|
||||
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@ -270,13 +272,14 @@ class AssignTagDialog extends StatelessWidget {
|
||||
onPressed: state.isSaveEnabled
|
||||
? () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result =
|
||||
processTags(updatedTags, subspaces);
|
||||
final result = TagHelper.processTags(
|
||||
updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
final processedSubspaces =
|
||||
result['subspaces'] as List<SubspaceModel>;
|
||||
List<SubspaceModel>.from(
|
||||
result['subspaces'] as List<dynamic>);
|
||||
onSave?.call(processedTags, processedSubspaces);
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
@ -301,115 +304,12 @@ class AssignTagDialog extends StatelessWidget {
|
||||
|
||||
List<String> getAvailableTags(
|
||||
List<String> allTags, List<Tag> currentTags, Tag currentTag) {
|
||||
return allTags
|
||||
.where((tagValue) => !currentTags
|
||||
.where((e) => e != currentTag) // Exclude the current row
|
||||
.map((e) => e.tag)
|
||||
.contains(tagValue))
|
||||
.toList();
|
||||
}
|
||||
|
||||
Map<String, dynamic> processTags(
|
||||
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
|
||||
final modifiedTags = List<Tag>.from(updatedTags);
|
||||
final modifiedSubspaces = List<SubspaceModel>.from(subspaces ?? []);
|
||||
|
||||
if (subspaces != null) {
|
||||
for (var subspace in subspaces) {
|
||||
subspace.tags?.removeWhere(
|
||||
(tag) => !modifiedTags
|
||||
.any((updatedTag) => updatedTag.internalId == tag.internalId),
|
||||
);
|
||||
}
|
||||
}
|
||||
for (var tag in modifiedTags.toList()) {
|
||||
if (modifiedSubspaces.isEmpty) continue;
|
||||
|
||||
final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces);
|
||||
|
||||
if ((tag.location == 'Main Space' || tag.location == null) &&
|
||||
(prevIndice == null ||
|
||||
modifiedSubspaces[prevIndice].subspaceName == 'Main Space')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location == 'Main Space' || tag.location == null) &&
|
||||
prevIndice != null) {
|
||||
modifiedSubspaces[prevIndice]
|
||||
.tags
|
||||
?.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location != 'Main Space' && tag.location != null) &&
|
||||
prevIndice == null) {
|
||||
final newIndex = modifiedSubspaces
|
||||
.indexWhere((subspace) => subspace.subspaceName == tag.location);
|
||||
if (newIndex != -1) {
|
||||
if (modifiedSubspaces[newIndex]
|
||||
.tags
|
||||
?.any((t) => t.internalId == tag.internalId) !=
|
||||
true) {
|
||||
tag.location = modifiedSubspaces[newIndex].subspaceName;
|
||||
modifiedSubspaces[newIndex].tags?.add(tag);
|
||||
}
|
||||
}
|
||||
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location != 'Main Space' && tag.location != null) &&
|
||||
tag.location != modifiedSubspaces[prevIndice!].subspaceName) {
|
||||
modifiedSubspaces[prevIndice]
|
||||
.tags
|
||||
?.removeWhere((t) => t.internalId == tag.internalId);
|
||||
final newIndex = modifiedSubspaces
|
||||
.indexWhere((subspace) => subspace.subspaceName == tag.location);
|
||||
if (newIndex != -1) {
|
||||
if (modifiedSubspaces[newIndex]
|
||||
.tags
|
||||
?.any((t) => t.internalId == tag.internalId) !=
|
||||
true) {
|
||||
tag.location = modifiedSubspaces[newIndex].subspaceName;
|
||||
modifiedSubspaces[newIndex].tags?.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location != 'Main Space' && tag.location != null) &&
|
||||
tag.location == modifiedSubspaces[prevIndice!].subspaceName) {
|
||||
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location == 'Main Space' || tag.location == null) &&
|
||||
prevIndice != null) {
|
||||
modifiedSubspaces[prevIndice]
|
||||
.tags
|
||||
?.removeWhere((t) => t.internalId == tag.internalId);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'updatedTags': modifiedTags,
|
||||
'subspaces': modifiedSubspaces,
|
||||
};
|
||||
}
|
||||
|
||||
int? checkTagExistInSubspace(Tag tag, List<SubspaceModel>? subspaces) {
|
||||
if (subspaces == null) return null;
|
||||
for (int i = 0; i < subspaces.length; i++) {
|
||||
final subspace = subspaces[i];
|
||||
if (subspace.tags == null) continue;
|
||||
for (var t in subspace.tags!) {
|
||||
if (tag.internalId == t.internalId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
List<String> availableTagsForTagModel = TagHelper.getAvailableTags<Tag>(
|
||||
allTags: allTags,
|
||||
currentTags: currentTags,
|
||||
currentTag: currentTag,
|
||||
getTag: (tag) => tag.tag ?? '',
|
||||
);
|
||||
return availableTagsForTagModel;
|
||||
}
|
||||
}
|
||||
|
@ -133,8 +133,9 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
: List.generate(state.tags.length, (index) {
|
||||
final tag = state.tags[index];
|
||||
final controller = controllers[index];
|
||||
final availableTags = getAvailableTags(
|
||||
allTags ?? [], state.tags, tag);
|
||||
final availableTags =
|
||||
TagHelper.getAvailableTagModels(
|
||||
allTags ?? [], state.tags, tag);
|
||||
|
||||
return DataRow(
|
||||
cells: [
|
||||
@ -254,11 +255,15 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
final updatedTags =
|
||||
List<TagModel>.from(state.tags);
|
||||
final result =
|
||||
processTags(updatedTags, subspaces);
|
||||
TagHelper.updateSubspaceTagModels(
|
||||
updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<TagModel>;
|
||||
final processedSubspaces = result['subspaces'];
|
||||
final processedSubspaces =
|
||||
List<SubspaceTemplateModel>.from(
|
||||
result['subspaces'] as List<dynamic>);
|
||||
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@ -305,14 +310,17 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
? () async {
|
||||
final updatedTags =
|
||||
List<TagModel>.from(state.tags);
|
||||
|
||||
final result =
|
||||
processTags(updatedTags, subspaces);
|
||||
TagHelper.updateSubspaceTagModels(
|
||||
updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<TagModel>;
|
||||
final processedSubspaces =
|
||||
result['subspaces']
|
||||
as List<SubspaceTemplateModel>;
|
||||
List<SubspaceTemplateModel>.from(
|
||||
result['subspaces']
|
||||
as List<dynamic>);
|
||||
|
||||
Navigator.of(context)
|
||||
.popUntil((route) => route.isFirst);
|
||||
@ -356,120 +364,4 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
List<String> getAvailableTags(
|
||||
List<String> allTags, List<TagModel> currentTags, TagModel currentTag) {
|
||||
return allTags
|
||||
.where((tagValue) => !currentTags
|
||||
.where((e) => e != currentTag) // Exclude the current row
|
||||
.map((e) => e.tag)
|
||||
.contains(tagValue))
|
||||
.toList();
|
||||
}
|
||||
|
||||
int? checkTagExistInSubspace(
|
||||
TagModel tag, List<SubspaceTemplateModel>? subspaces) {
|
||||
if (subspaces == null) return null;
|
||||
for (int i = 0; i < subspaces.length; i++) {
|
||||
final subspace = subspaces[i];
|
||||
if (subspace.tags == null) continue;
|
||||
for (var t in subspace.tags!) {
|
||||
if (tag.internalId == t.internalId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
Map<String, dynamic> processTags(
|
||||
List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) {
|
||||
final modifiedTags = List<TagModel>.from(updatedTags);
|
||||
final modifiedSubspaces = List<SubspaceTemplateModel>.from(subspaces ?? []);
|
||||
|
||||
if (subspaces != null) {
|
||||
for (var subspace in subspaces) {
|
||||
subspace.tags?.removeWhere(
|
||||
(tag) => !modifiedTags
|
||||
.any((updatedTag) => updatedTag.internalId == tag.internalId),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (var tag in modifiedTags.toList()) {
|
||||
if (modifiedSubspaces.isEmpty) continue;
|
||||
|
||||
final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces);
|
||||
|
||||
if ((tag.location == 'Main Space' || tag.location == null) &&
|
||||
(prevIndice == null ||
|
||||
modifiedSubspaces[prevIndice].subspaceName == 'Main Space')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location == 'Main Space' || tag.location == null) &&
|
||||
prevIndice != null) {
|
||||
modifiedSubspaces[prevIndice]
|
||||
.tags
|
||||
?.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location != 'Main Space' && tag.location != null) &&
|
||||
prevIndice == null) {
|
||||
final newIndex = modifiedSubspaces
|
||||
.indexWhere((subspace) => subspace.subspaceName == tag.location);
|
||||
if (newIndex != -1) {
|
||||
if (modifiedSubspaces[newIndex]
|
||||
.tags
|
||||
?.any((t) => t.internalId == tag.internalId) !=
|
||||
true) {
|
||||
tag.location = modifiedSubspaces[newIndex].subspaceName;
|
||||
modifiedSubspaces[newIndex].tags?.add(tag);
|
||||
}
|
||||
}
|
||||
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location != 'Main Space' && tag.location != null) &&
|
||||
tag.location != modifiedSubspaces[prevIndice!].subspaceName) {
|
||||
modifiedSubspaces[prevIndice]
|
||||
.tags
|
||||
?.removeWhere((t) => t.internalId == tag.internalId);
|
||||
final newIndex = modifiedSubspaces
|
||||
.indexWhere((subspace) => subspace.subspaceName == tag.location);
|
||||
if (newIndex != -1) {
|
||||
if (modifiedSubspaces[newIndex]
|
||||
.tags
|
||||
?.any((t) => t.internalId == tag.internalId) !=
|
||||
true) {
|
||||
tag.location = modifiedSubspaces[newIndex].subspaceName;
|
||||
modifiedSubspaces[newIndex].tags?.add(tag);
|
||||
}
|
||||
}
|
||||
|
||||
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location != 'Main Space' && tag.location != null) &&
|
||||
tag.location == modifiedSubspaces[prevIndice!].subspaceName) {
|
||||
modifiedTags.removeWhere((t) => t.internalId == tag.internalId);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tag.location == 'Main Space' || tag.location == null) &&
|
||||
prevIndice != null) {
|
||||
modifiedSubspaces[prevIndice]
|
||||
.tags
|
||||
?.removeWhere((t) => t.internalId == tag.internalId);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'updatedTags': modifiedTags,
|
||||
'subspaces': modifiedSubspaces,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
21
lib/pages/spaces_management/helper/connection_helper.dart
Normal file
21
lib/pages/spaces_management/helper/connection_helper.dart
Normal file
@ -0,0 +1,21 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/connection_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
|
||||
class ConnectionHelper {
|
||||
static Offset getCenterPosition(Size screenSize) {
|
||||
return Offset(
|
||||
screenSize.width / 2 - 260,
|
||||
screenSize.height / 2 - 200,
|
||||
);
|
||||
}
|
||||
|
||||
static bool isHighlightedConnection(
|
||||
Connection connection, SpaceModel? selectedSpace) {
|
||||
if (selectedSpace == null) return true;
|
||||
|
||||
return connection.startSpace == selectedSpace ||
|
||||
connection.endSpace == selectedSpace;
|
||||
}
|
||||
}
|
61
lib/pages/spaces_management/helper/space_helper.dart
Normal file
61
lib/pages/spaces_management/helper/space_helper.dart
Normal file
@ -0,0 +1,61 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
|
||||
class SpaceHelper {
|
||||
static SpaceModel? findSpaceByUuid(
|
||||
String? uuid, List<CommunityModel> communities) {
|
||||
for (var community in communities) {
|
||||
for (var space in community.spaces) {
|
||||
if (space.uuid == uuid) return space;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static SpaceModel? findSpaceByInternalId(
|
||||
String? internalId, List<SpaceModel> spaces) {
|
||||
if (internalId != null) {
|
||||
for (var space in spaces) {
|
||||
if (space.internalId == internalId) return space;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static String generateUniqueSpaceName(
|
||||
String originalName, List<SpaceModel> spaces) {
|
||||
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
|
||||
int maxNumber = 0;
|
||||
|
||||
for (var space in spaces) {
|
||||
final match = RegExp(r'^(.*?)\((\d+)\)$').firstMatch(space.name);
|
||||
if (match != null && match.group(1)?.trim() == baseName) {
|
||||
int existingNumber = int.parse(match.group(2)!);
|
||||
if (existingNumber > maxNumber) {
|
||||
maxNumber = existingNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "$baseName(${maxNumber + 1})";
|
||||
}
|
||||
|
||||
static bool isSave(List<SpaceModel> spaces) {
|
||||
return spaces.isNotEmpty &&
|
||||
spaces.any((space) =>
|
||||
space.status == SpaceStatus.newSpace ||
|
||||
space.status == SpaceStatus.modified ||
|
||||
space.status == SpaceStatus.deleted);
|
||||
}
|
||||
|
||||
static bool isHighlightedSpace(SpaceModel space, SpaceModel? selectedSpace) {
|
||||
if (selectedSpace == null) return true;
|
||||
|
||||
return space == selectedSpace ||
|
||||
selectedSpace.parent?.internalId == space.internalId ||
|
||||
selectedSpace.children
|
||||
?.any((child) => child.internalId == space.internalId) ==
|
||||
true;
|
||||
}
|
||||
}
|
@ -1,12 +1,147 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/base_tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.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/all_spaces/model/space_model.dart';
|
||||
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/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';
|
||||
|
||||
class TagHelper {
|
||||
static Map<String, dynamic> updateTags<T>({
|
||||
required List<T> updatedTags,
|
||||
required List<dynamic>? subspaces,
|
||||
required String Function(T) getInternalId,
|
||||
required String? Function(T) getLocation,
|
||||
required void Function(T, String) setLocation,
|
||||
required String Function(dynamic) getSubspaceName,
|
||||
required List<T>? Function(dynamic) getSubspaceTags,
|
||||
required void Function(dynamic, List<T>?) setSubspaceTags,
|
||||
required int? Function(T, List<dynamic>) checkTagExistInSubspace,
|
||||
}) {
|
||||
final modifiedTags = List<T>.from(updatedTags);
|
||||
final modifiedSubspaces = List<dynamic>.from(subspaces ?? []);
|
||||
|
||||
if (subspaces != null) {
|
||||
for (var subspace in subspaces) {
|
||||
getSubspaceTags(subspace)?.removeWhere(
|
||||
(tag) => !modifiedTags.any(
|
||||
(updatedTag) => getInternalId(updatedTag) == getInternalId(tag)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (var tag in modifiedTags.toList()) {
|
||||
if (modifiedSubspaces.isEmpty) continue;
|
||||
|
||||
final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces);
|
||||
final tagLocation = getLocation(tag);
|
||||
|
||||
if ((tagLocation == 'Main Space' || tagLocation == null) &&
|
||||
(prevIndice == null ||
|
||||
getSubspaceName(modifiedSubspaces[prevIndice]) == 'Main Space')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tagLocation == 'Main Space' || tagLocation == null) &&
|
||||
prevIndice != null) {
|
||||
getSubspaceTags(modifiedSubspaces[prevIndice])
|
||||
?.removeWhere((t) => getInternalId(t) == getInternalId(tag));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tagLocation != 'Main Space' && tagLocation != null) &&
|
||||
prevIndice == null) {
|
||||
final newIndex = modifiedSubspaces
|
||||
.indexWhere((subspace) => getSubspaceName(subspace) == tagLocation);
|
||||
|
||||
if (newIndex != -1) {
|
||||
if (getSubspaceTags(modifiedSubspaces[newIndex])
|
||||
?.any((t) => getInternalId(t) == getInternalId(tag)) !=
|
||||
true) {
|
||||
setLocation(tag, getSubspaceName(modifiedSubspaces[newIndex]));
|
||||
final subspaceTags =
|
||||
getSubspaceTags(modifiedSubspaces[newIndex]) ?? [];
|
||||
subspaceTags.add(tag);
|
||||
setSubspaceTags(modifiedSubspaces[newIndex], subspaceTags);
|
||||
}
|
||||
}
|
||||
|
||||
modifiedTags.removeWhere((t) => getInternalId(t) == getInternalId(tag));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tagLocation != 'Main Space' && tagLocation != null) &&
|
||||
tagLocation != getSubspaceName(modifiedSubspaces[prevIndice!])) {
|
||||
getSubspaceTags(modifiedSubspaces[prevIndice])
|
||||
?.removeWhere((t) => getInternalId(t) == getInternalId(tag));
|
||||
|
||||
final newIndex = modifiedSubspaces
|
||||
.indexWhere((subspace) => getSubspaceName(subspace) == tagLocation);
|
||||
|
||||
if (newIndex != -1) {
|
||||
if (getSubspaceTags(modifiedSubspaces[newIndex])
|
||||
?.any((t) => getInternalId(t) == getInternalId(tag)) !=
|
||||
true) {
|
||||
setLocation(tag, getSubspaceName(modifiedSubspaces[newIndex]));
|
||||
final subspaceTags =
|
||||
getSubspaceTags(modifiedSubspaces[newIndex]) ?? [];
|
||||
subspaceTags.add(tag);
|
||||
setSubspaceTags(modifiedSubspaces[newIndex], subspaceTags);
|
||||
}
|
||||
}
|
||||
|
||||
modifiedTags.removeWhere((t) => getInternalId(t) == getInternalId(tag));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tagLocation != 'Main Space' && tagLocation != null) &&
|
||||
tagLocation == getSubspaceName(modifiedSubspaces[prevIndice!])) {
|
||||
modifiedTags.removeWhere((t) => getInternalId(t) == getInternalId(tag));
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((tagLocation == 'Main Space' || tagLocation == null) &&
|
||||
prevIndice != null) {
|
||||
getSubspaceTags(modifiedSubspaces[prevIndice])
|
||||
?.removeWhere((t) => getInternalId(t) == getInternalId(tag));
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
'updatedTags': modifiedTags,
|
||||
'subspaces': modifiedSubspaces,
|
||||
};
|
||||
}
|
||||
|
||||
static List<String> getAvailableTags<T>({
|
||||
required List<String> allTags,
|
||||
required List<T> currentTags,
|
||||
required T currentTag,
|
||||
required String? Function(T) getTag, // Allow nullable return type
|
||||
}) {
|
||||
return allTags
|
||||
.where((tagValue) => !currentTags
|
||||
.where((e) => e != currentTag) // Exclude the current row
|
||||
.map((e) => getTag(e) ?? '') // Handle null values gracefully
|
||||
.contains(tagValue))
|
||||
.toList();
|
||||
}
|
||||
|
||||
static List<String> getAvailableTagModels(
|
||||
List<String> allTags, List<TagModel> currentTags, TagModel currentTag) {
|
||||
List<String> availableTagsForTagModel =
|
||||
TagHelper.getAvailableTags<TagModel>(
|
||||
allTags: allTags,
|
||||
currentTags: currentTags,
|
||||
currentTag: currentTag,
|
||||
getTag: (tag) => tag.tag ?? '',
|
||||
);
|
||||
return availableTagsForTagModel;
|
||||
}
|
||||
|
||||
static List<TagModel> generateInitialTags({
|
||||
List<TagModel>? spaceTagModels,
|
||||
List<SubspaceTemplateModel>? subspaces,
|
||||
@ -36,7 +171,7 @@ class TagHelper {
|
||||
return initialTags;
|
||||
}
|
||||
|
||||
static List<Tag> generateInitialForTags({
|
||||
static List<Tag> generateInitialForTags({
|
||||
List<Tag>? spaceTags,
|
||||
List<SubspaceModel>? subspaces,
|
||||
}) {
|
||||
@ -145,4 +280,85 @@ class TagHelper {
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
|
||||
static int? checkTagExistInSubspaceModels(
|
||||
TagModel tag, List<dynamic>? subspaces) {
|
||||
if (subspaces == null) return null;
|
||||
|
||||
for (int i = 0; i < subspaces.length; i++) {
|
||||
final subspace = subspaces[i] as SubspaceTemplateModel; // Explicit cast
|
||||
if (subspace.tags == null) continue;
|
||||
for (var t in subspace.tags!) {
|
||||
if (tag.internalId == t.internalId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Map<String, dynamic> updateSubspaceTagModels(
|
||||
List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) {
|
||||
return TagHelper.updateTags<TagModel>(
|
||||
updatedTags: updatedTags,
|
||||
subspaces: subspaces,
|
||||
getInternalId: (tag) => tag.internalId,
|
||||
getLocation: (tag) => tag.location,
|
||||
setLocation: (tag, location) => tag.location = location,
|
||||
getSubspaceName: (subspace) => subspace.subspaceName,
|
||||
getSubspaceTags: (subspace) => subspace.tags,
|
||||
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
||||
checkTagExistInSubspace: checkTagExistInSubspaceModels,
|
||||
);
|
||||
}
|
||||
|
||||
static int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
|
||||
if (subspaces == null) return null;
|
||||
for (int i = 0; i < subspaces.length; i++) {
|
||||
final subspace = subspaces[i];
|
||||
if (subspace.tags == null) continue;
|
||||
for (var t in subspace.tags!) {
|
||||
if (tag.internalId == t.internalId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Map<String, dynamic> processTags(
|
||||
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
|
||||
return TagHelper.updateTags<Tag>(
|
||||
updatedTags: updatedTags,
|
||||
subspaces: subspaces,
|
||||
getInternalId: (tag) => tag.internalId,
|
||||
getLocation: (tag) => tag.location,
|
||||
setLocation: (tag, location) => tag.location = location,
|
||||
getSubspaceName: (subspace) => subspace.subspaceName,
|
||||
getSubspaceTags: (subspace) => subspace.tags,
|
||||
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
||||
checkTagExistInSubspace: checkTagExistInSubspace,
|
||||
);
|
||||
}
|
||||
|
||||
static List<String> getAllTagValues(
|
||||
List<CommunityModel> communities, List<SpaceTemplateModel>? spaceModels) {
|
||||
final Set<String> allTags = {};
|
||||
|
||||
if (spaceModels != null) {
|
||||
for (var model in spaceModels) {
|
||||
allTags.addAll(model.listAllTagValues());
|
||||
}
|
||||
}
|
||||
|
||||
for (final community in communities) {
|
||||
for (final space in community.spaces) {
|
||||
if (space.tags != null) {
|
||||
allTags.addAll(space.listAllTagValues());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allTags.toList();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:equatable/equatable.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/pages/spaces_management/space_model/models/tag_update_model.dart';
|
||||
|
@ -11,8 +11,10 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class SpaceModelPage extends StatelessWidget {
|
||||
final List<ProductModel>? products;
|
||||
final Function(List<SpaceTemplateModel>)? onSpaceModelsUpdated;
|
||||
|
||||
const SpaceModelPage({Key? key, this.products}) : super(key: key);
|
||||
const SpaceModelPage({Key? key, this.products, this.onSpaceModelsUpdated})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -25,6 +27,10 @@ class SpaceModelPage extends StatelessWidget {
|
||||
final allTagValues = _getAllTagValues(spaceModels);
|
||||
final allSpaceModelNames = _getAllSpaceModelName(spaceModels);
|
||||
|
||||
if (onSpaceModelsUpdated != null) {
|
||||
onSpaceModelsUpdated!(spaceModels);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
body: Padding(
|
||||
|
@ -129,10 +129,16 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
||||
const SizedBox(height: 16),
|
||||
SubspaceModelCreate(
|
||||
subspaces: state.space.subspaceModels ?? [],
|
||||
onSpaceModelUpdate: (updatedSubspaces) {
|
||||
tags: state.space.tags ?? [],
|
||||
onSpaceModelUpdate: (updatedSubspaces,updatedTags) {
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddSubspacesToSpaceTemplate(updatedSubspaces));
|
||||
if(updatedTags!=null){
|
||||
context
|
||||
.read<CreateSpaceModelBloc>()
|
||||
.add(AddTagsToSpaceTemplate(updatedTags));
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
@ -1,6 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/common/edit_chip.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/pages/spaces_management/space_model/widgets/subspace_name_label_widget.dart';
|
||||
@ -8,13 +9,16 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class SubspaceModelCreate extends StatefulWidget {
|
||||
final List<SubspaceTemplateModel> subspaces;
|
||||
final void Function(List<SubspaceTemplateModel> newSubspaces)?
|
||||
final void Function(
|
||||
List<SubspaceTemplateModel> newSubspaces, List<TagModel>? tags)?
|
||||
onSpaceModelUpdate;
|
||||
final List<TagModel> tags;
|
||||
|
||||
const SubspaceModelCreate({
|
||||
Key? key,
|
||||
required this.subspaces,
|
||||
this.onSpaceModelUpdate,
|
||||
required this.tags,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -24,11 +28,13 @@ class SubspaceModelCreate extends StatefulWidget {
|
||||
class _SubspaceModelCreateState extends State<SubspaceModelCreate> {
|
||||
late List<SubspaceTemplateModel> _subspaces;
|
||||
String? errorSubspaceId;
|
||||
late List<TagModel> _tags;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_subspaces = List.from(widget.subspaces);
|
||||
_tags = List.from(widget.tags);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -105,14 +111,26 @@ class _SubspaceModelCreateState extends State<SubspaceModelCreate> {
|
||||
isEdit: true,
|
||||
dialogTitle: dialogTitle,
|
||||
existingSubSpaces: _subspaces,
|
||||
|
||||
onUpdate: (subspaceModels) {
|
||||
final updatedIds = subspaceModels.map((s) => s.internalId).toSet();
|
||||
final deletedSubspaces = _subspaces
|
||||
.where((s) => !updatedIds.contains(s.internalId))
|
||||
.toList();
|
||||
|
||||
final List<TagModel> tagsToAppendToSpace = [];
|
||||
|
||||
for (var s in deletedSubspaces) {
|
||||
if (s.tags != null) {
|
||||
tagsToAppendToSpace.addAll(s.tags!);
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_subspaces = subspaceModels;
|
||||
errorSubspaceId = null;
|
||||
_tags.addAll(tagsToAppendToSpace);
|
||||
});
|
||||
if (widget.onSpaceModelUpdate != null) {
|
||||
widget.onSpaceModelUpdate!(subspaceModels);
|
||||
widget.onSpaceModelUpdate!(subspaceModels, _tags);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
@ -52,6 +52,13 @@ class _SubspaceNameDisplayWidgetState extends State<SubspaceNameDisplayWidget> {
|
||||
|
||||
void _handleValidationAndSave() {
|
||||
final updatedName = _controller.text;
|
||||
|
||||
if (updatedName.isEmpty) {
|
||||
setState(() {
|
||||
errorText = 'Subspace name cannot be empty.';
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (widget.validateName(updatedName)) {
|
||||
setState(() {
|
||||
errorText = null;
|
||||
|
Reference in New Issue
Block a user