diff --git a/assets/images/delete_space_link_icon.svg b/assets/images/delete_space_link_icon.svg
new file mode 100644
index 00000000..a55d2e04
--- /dev/null
+++ b/assets/images/delete_space_link_icon.svg
@@ -0,0 +1,21 @@
+
diff --git a/assets/images/space_link_icon.svg b/assets/images/space_link_icon.svg
new file mode 100644
index 00000000..f10c57ad
--- /dev/null
+++ b/assets/images/space_link_icon.svg
@@ -0,0 +1,25 @@
+
diff --git a/assets/images/success_icon.svg b/assets/images/success_icon.svg
new file mode 100644
index 00000000..6f5dbf9e
--- /dev/null
+++ b/assets/images/success_icon.svg
@@ -0,0 +1,3 @@
+
diff --git a/lib/common/dialog_textfield_dropdown.dart b/lib/common/tag_dialog_textfield_dropdown.dart
similarity index 75%
rename from lib/common/dialog_textfield_dropdown.dart
rename to lib/common/tag_dialog_textfield_dropdown.dart
index ac88e5dc..219e03ce 100644
--- a/lib/common/dialog_textfield_dropdown.dart
+++ b/lib/common/tag_dialog_textfield_dropdown.dart
@@ -1,35 +1,38 @@
import 'package:flutter/material.dart';
+import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
import 'package:syncrow_web/utils/color_manager.dart';
-class DialogTextfieldDropdown extends StatefulWidget {
- final List items;
- final ValueChanged onSelected;
- final String? initialValue;
+class TagDialogTextfieldDropdown extends StatefulWidget {
+ final List items;
+ final ValueChanged onSelected;
+ final Tag? initialValue;
+ final String product;
- const DialogTextfieldDropdown({
+ const TagDialogTextfieldDropdown({
Key? key,
required this.items,
required this.onSelected,
this.initialValue,
+ required this.product,
}) : super(key: key);
@override
- _DialogTextfieldDropdownState createState() =>
- _DialogTextfieldDropdownState();
+ _DialogTextfieldDropdownState createState() => _DialogTextfieldDropdownState();
}
-class _DialogTextfieldDropdownState extends State {
+class _DialogTextfieldDropdownState extends State {
bool _isOpen = false;
OverlayEntry? _overlayEntry;
final TextEditingController _controller = TextEditingController();
final FocusNode _focusNode = FocusNode();
- List _filteredItems = [];
+ List _filteredItems = [];
@override
void initState() {
super.initState();
- _controller.text = widget.initialValue ?? '';
- _filteredItems = List.from(widget.items);
+ _controller.text = widget.initialValue?.tag ?? '';
+
+ _filterItems();
_focusNode.addListener(() {
if (!_focusNode.hasFocus) {
@@ -38,6 +41,12 @@ class _DialogTextfieldDropdownState extends State {
});
}
+ void _filterItems() {
+ setState(() {
+ _filteredItems = widget.items.where((tag) => tag.product?.uuid == widget.product).toList();
+ });
+ }
+
void _toggleDropdown() {
if (_isOpen) {
_closeDropdown();
@@ -87,7 +96,7 @@ class _DialogTextfieldDropdownState extends State {
shrinkWrap: true,
itemCount: _filteredItems.length,
itemBuilder: (context, index) {
- final item = _filteredItems[index];
+ final tag = _filteredItems[index];
return Container(
decoration: const BoxDecoration(
@@ -99,19 +108,16 @@ class _DialogTextfieldDropdownState extends State {
),
),
child: ListTile(
- title: Text(item,
+ title: Text(tag.tag ?? '',
style: Theme.of(context)
.textTheme
.bodyMedium
- ?.copyWith(
- color: ColorsManager
- .textPrimaryColor)),
+ ?.copyWith(color: ColorsManager.textPrimaryColor)),
onTap: () {
- _controller.text = item;
- widget.onSelected(item);
+ _controller.text = tag.tag ?? '';
+ widget.onSelected(tag);
setState(() {
- _filteredItems
- .remove(item); // Remove selected item
+ _filteredItems.remove(tag);
});
_closeDropdown();
},
@@ -150,11 +156,14 @@ class _DialogTextfieldDropdownState extends State {
controller: _controller,
focusNode: _focusNode,
onFieldSubmitted: (value) {
- widget.onSelected(value);
+ final selectedTag = _filteredItems.firstWhere((tag) => tag.tag == value,
+ orElse: () => Tag(tag: value));
+ widget.onSelected(selectedTag);
_closeDropdown();
},
onTapOutside: (event) {
- widget.onSelected(_controller.text);
+ widget.onSelected(_filteredItems.firstWhere((tag) => tag.tag == _controller.text,
+ orElse: () => Tag(tag: _controller.text)));
_closeDropdown();
},
style: Theme.of(context).textTheme.bodyMedium,
diff --git a/lib/main.dart b/lib/main.dart
index 20b0311e..f2f640e4 100644
--- a/lib/main.dart
+++ b/lib/main.dart
@@ -4,7 +4,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:go_router/go_router.dart';
-import 'package:syncrow_web/firebase_options_dev.dart';
import 'package:syncrow_web/firebase_options_prod.dart';
import 'package:syncrow_web/pages/auth/bloc/auth_bloc.dart';
import 'package:syncrow_web/pages/home/bloc/home_bloc.dart';
diff --git a/lib/pages/access_management/view/access_management.dart b/lib/pages/access_management/view/access_management.dart
index 752b3255..d7c7a9dd 100644
--- a/lib/pages/access_management/view/access_management.dart
+++ b/lib/pages/access_management/view/access_management.dart
@@ -3,7 +3,6 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/access_management/bloc/access_bloc.dart';
import 'package:syncrow_web/pages/access_management/bloc/access_event.dart';
import 'package:syncrow_web/pages/access_management/bloc/access_state.dart';
-import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
import 'package:syncrow_web/pages/common/buttons/search_reset_buttons.dart';
import 'package:syncrow_web/pages/common/custom_table.dart';
diff --git a/lib/pages/auth/bloc/auth_bloc.dart b/lib/pages/auth/bloc/auth_bloc.dart
index b22dae7b..9e0ac2f9 100644
--- a/lib/pages/auth/bloc/auth_bloc.dart
+++ b/lib/pages/auth/bloc/auth_bloc.dart
@@ -15,7 +15,6 @@ import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
import 'package:syncrow_web/services/auth_api.dart';
import 'package:syncrow_web/utils/constants/strings_manager.dart';
import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
-import 'package:syncrow_web/utils/navigation_service.dart';
import 'package:syncrow_web/utils/snack_bar.dart';
class AuthBloc extends Bloc {
diff --git a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart
index e52debb0..7ed3a377 100644
--- a/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart
+++ b/lib/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart
@@ -5,9 +5,6 @@ import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_model.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/services/devices_mang_api.dart';
-import 'package:syncrow_web/utils/constants/strings_manager.dart';
-import 'package:syncrow_web/utils/constants/temp_const.dart';
-import 'package:syncrow_web/utils/helpers/shared_preferences_helper.dart';
part 'device_managment_event.dart';
part 'device_managment_state.dart';
diff --git a/lib/pages/device_managment/all_devices/view/device_managment_page.dart b/lib/pages/device_managment/all_devices/view/device_managment_page.dart
index 81a21046..45af9751 100644
--- a/lib/pages/device_managment/all_devices/view/device_managment_page.dart
+++ b/lib/pages/device_managment/all_devices/view/device_managment_page.dart
@@ -1,6 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/bloc/device_mgmt_bloc/device_managment_bloc.dart';
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_managment_body.dart';
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
diff --git a/lib/pages/spaces_management/add_device_type/views/add_device_type_widget.dart b/lib/pages/spaces_management/add_device_type/views/add_device_type_widget.dart
index 1930963b..ede6afb9 100644
--- a/lib/pages/spaces_management/add_device_type/views/add_device_type_widget.dart
+++ b/lib/pages/spaces_management/add_device_type/views/add_device_type_widget.dart
@@ -24,6 +24,8 @@ class AddDeviceTypeWidget extends StatelessWidget {
final String spaceName;
final bool isCreate;
final Function(List, List?)? onSave;
+ final List 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),
);
}
},
diff --git a/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart b/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart
index 49fa5d72..47fa5508 100644
--- a/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart
+++ b/lib/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart
@@ -19,8 +19,7 @@ import 'package:syncrow_web/services/space_mana_api.dart';
import 'package:syncrow_web/services/space_model_mang_api.dart';
import 'package:syncrow_web/utils/constants/action_enum.dart' as custom_action;
-class SpaceManagementBloc
- extends Bloc {
+class SpaceManagementBloc extends Bloc {
final CommunitySpaceManagementApi _api;
final ProductApi _productApi;
final SpaceModelManagementApi _spaceModelApi;
@@ -28,6 +27,7 @@ class SpaceManagementBloc
List? _cachedProducts;
List? _cachedSpaceModels;
final SpaceTreeBloc _spaceTreeBloc;
+ List? _cachedTags;
SpaceManagementBloc(
this._api,
@@ -54,40 +54,38 @@ class SpaceManagementBloc
UpdateSpaceModelCache event, Emitter emit) async {
if (_cachedSpaceModels != null) {
_cachedSpaceModels = _cachedSpaceModels!.map((model) {
- return model.uuid == event.updatedModel.uuid
- ? event.updatedModel
- : model;
+ return model.uuid == event.updatedModel.uuid ? event.updatedModel : model;
}).toList();
} else {
_cachedSpaceModels = await fetchSpaceModels();
}
+ await fetchTags();
+
emit(SpaceModelLoaded(
- communities: state is SpaceManagementLoaded
- ? (state as SpaceManagementLoaded).communities
- : [],
- products: _cachedProducts ?? [],
- spaceModels: List.from(_cachedSpaceModels ?? []),
- ));
+ communities:
+ state is SpaceManagementLoaded ? (state as SpaceManagementLoaded).communities : [],
+ products: _cachedProducts ?? [],
+ spaceModels: List.from(_cachedSpaceModels ?? []),
+ allTags: _cachedTags ?? []));
}
- void _deleteSpaceModelFromCache(DeleteSpaceModelFromCache event,
- Emitter emit) async {
+ void _deleteSpaceModelFromCache(
+ DeleteSpaceModelFromCache event, Emitter emit) async {
if (_cachedSpaceModels != null) {
- _cachedSpaceModels = _cachedSpaceModels!
- .where((model) => model.uuid != event.deletedUuid)
- .toList();
+ _cachedSpaceModels =
+ _cachedSpaceModels!.where((model) => model.uuid != event.deletedUuid).toList();
} else {
_cachedSpaceModels = await fetchSpaceModels();
}
+ await fetchTags();
emit(SpaceModelLoaded(
- communities: state is SpaceManagementLoaded
- ? (state as SpaceManagementLoaded).communities
- : [],
- products: _cachedProducts ?? [],
- spaceModels: List.from(_cachedSpaceModels ?? []),
- ));
+ communities:
+ state is SpaceManagementLoaded ? (state as SpaceManagementLoaded).communities : [],
+ products: _cachedProducts ?? [],
+ spaceModels: List.from(_cachedSpaceModels ?? []),
+ allTags: _cachedTags ?? []));
}
void updateCachedSpaceModels(List updatedModels) {
@@ -112,8 +110,8 @@ class SpaceManagementBloc
int page = 1;
while (hasNext) {
- final spaceModels = await _spaceModelApi.listSpaceModels(
- page: page, projectId: projectUuid);
+ final spaceModels =
+ await _spaceModelApi.listSpaceModels(page: page, projectId: projectUuid);
if (spaceModels.isNotEmpty) {
allSpaceModels.addAll(spaceModels);
page++;
@@ -130,6 +128,20 @@ class SpaceManagementBloc
}
}
+ Future> fetchTags() async {
+ try {
+ if (_cachedTags != null) {
+ return _cachedTags!;
+ }
+ final projectUuid = await ProjectManager.getProjectUUID() ?? '';
+ final allTags = await _spaceModelApi.listTags(projectId: projectUuid);
+ _cachedTags = allTags;
+ return allTags;
+ } catch (e) {
+ return [];
+ }
+ }
+
void _onUpdateCommunity(
UpdateCommunityEvent event,
Emitter emit,
@@ -137,14 +149,13 @@ class SpaceManagementBloc
final previousState = state;
try {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
+ await fetchTags();
emit(SpaceManagementLoading());
- final success = await _api.updateCommunity(
- event.communityUuid, event.name, projectUuid);
+ final success = await _api.updateCommunity(event.communityUuid, event.name, projectUuid);
if (success) {
if (previousState is SpaceManagementLoaded) {
- final updatedCommunities =
- List.from(previousState.communities);
+ final updatedCommunities = List.from(previousState.communities);
for (var community in updatedCommunities) {
if (community.uuid == event.communityUuid) {
community.name = event.name;
@@ -157,11 +168,11 @@ class SpaceManagementBloc
var prevSpaceModels = await fetchSpaceModels();
emit(SpaceManagementLoaded(
- communities: updatedCommunities,
- products: previousState.products,
- selectedCommunity: previousState.selectedCommunity,
- spaceModels: prevSpaceModels,
- ));
+ communities: updatedCommunities,
+ products: previousState.products,
+ selectedCommunity: previousState.selectedCommunity,
+ spaceModels: prevSpaceModels,
+ allTags: _cachedTags ?? []));
}
} else {
emit(const SpaceManagementError('Failed to update the community.'));
@@ -189,8 +200,7 @@ class SpaceManagementBloc
}
}
- Future> _fetchSpacesForCommunity(
- String communityUuid) async {
+ Future> _fetchSpacesForCommunity(String communityUuid) async {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
return await _api.getSpaceHierarchy(communityUuid, projectUuid);
@@ -201,7 +211,7 @@ class SpaceManagementBloc
Emitter emit,
) async {
try {
- final previousState = state;
+ await fetchTags();
if (event.communities.isEmpty) {
emit(const SpaceManagementError('No communities provided.'));
@@ -211,33 +221,33 @@ class SpaceManagementBloc
var prevSpaceModels = await fetchSpaceModels();
emit(BlankState(
- communities: event.communities,
- products: _cachedProducts ?? [],
- spaceModels: prevSpaceModels,
- ));
+ communities: event.communities,
+ products: _cachedProducts ?? [],
+ spaceModels: prevSpaceModels,
+ allTags: _cachedTags ?? []));
} catch (error) {
emit(SpaceManagementError('Error loading communities: $error'));
}
}
- Future _onBlankState(
- BlankStateEvent event, Emitter emit) async {
+ Future _onBlankState(BlankStateEvent event, Emitter emit) async {
try {
final previousState = state;
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
var spaceBloc = event.context.read();
List communities = await _waitForCommunityList(spaceBloc);
+ await fetchSpaceModels();
+ await fetchTags();
var prevSpaceModels = await fetchSpaceModels();
- if (previousState is SpaceManagementLoaded ||
- previousState is BlankState) {
+ if (previousState is SpaceManagementLoaded || previousState is BlankState) {
final prevCommunities = (previousState as dynamic).communities ?? [];
emit(BlankState(
- communities: List.from(prevCommunities),
- products: _cachedProducts ?? [],
- spaceModels: prevSpaceModels,
- ));
+ communities: List.from(prevCommunities),
+ products: _cachedProducts ?? [],
+ spaceModels: prevSpaceModels,
+ allTags: _cachedTags ?? []));
return;
}
@@ -246,8 +256,7 @@ class SpaceManagementBloc
List updatedCommunities = await Future.wait(
communities.map((community) async {
- List spaces =
- await _fetchSpacesForCommunity(community.uuid);
+ List spaces = await _fetchSpacesForCommunity(community.uuid);
return CommunityModel(
uuid: community.uuid,
createdAt: community.createdAt,
@@ -267,6 +276,7 @@ class SpaceManagementBloc
spaceModels: prevSpaceModels,
communities: communities,
products: _cachedProducts ?? [],
+ allTags: _cachedTags ?? [],
));
} catch (error) {
emit(SpaceManagementError('Error loading communities: $error'));
@@ -279,21 +289,20 @@ class SpaceManagementBloc
) async {
var spaceBloc = event.context.read();
_onloadProducts();
-
+ await fetchTags();
// Wait until `communityList` is loaded
List communities = await _waitForCommunityList(spaceBloc);
// Fetch space models after communities are available
final prevSpaceModels = await fetchSpaceModels();
emit(SpaceManagementLoaded(
- communities: communities,
- products: _cachedProducts ?? [],
- spaceModels: prevSpaceModels,
- ));
+ communities: communities,
+ products: _cachedProducts ?? [],
+ spaceModels: prevSpaceModels,
+ allTags: _cachedTags ?? []));
}
- Future> _waitForCommunityList(
- SpaceTreeBloc spaceBloc) async {
+ Future> _waitForCommunityList(SpaceTreeBloc spaceBloc) async {
// Check if communityList is already populated
if (spaceBloc.state.communityList.isNotEmpty) {
return spaceBloc.state.communityList;
@@ -320,8 +329,7 @@ class SpaceManagementBloc
emit(SpaceManagementLoading());
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
- final success =
- await _api.deleteCommunity(event.communityUuid, projectUuid);
+ final success = await _api.deleteCommunity(event.communityUuid, projectUuid);
if (success) {
// add(LoadCommunityAndSpacesEvent());
} else {
@@ -342,14 +350,13 @@ class SpaceManagementBloc
try {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
-
- CommunityModel? newCommunity = await _api.createCommunity(
- event.name, event.description, projectUuid);
+ await fetchTags();
+ CommunityModel? newCommunity =
+ await _api.createCommunity(event.name, event.description, projectUuid);
var prevSpaceModels = await fetchSpaceModels();
if (newCommunity != null) {
- if (previousState is SpaceManagementLoaded ||
- previousState is BlankState) {
+ if (previousState is SpaceManagementLoaded || previousState is BlankState) {
final prevCommunities = List.from(
(previousState as dynamic).communities,
);
@@ -357,11 +364,13 @@ class SpaceManagementBloc
_spaceTreeBloc.add(OnCommunityAdded(newCommunity));
emit(SpaceManagementLoaded(
- spaceModels: prevSpaceModels,
- communities: updatedCommunities,
- products: _cachedProducts ?? [],
- selectedCommunity: newCommunity,
- selectedSpace: null));
+ spaceModels: prevSpaceModels,
+ communities: updatedCommunities,
+ products: _cachedProducts ?? [],
+ selectedCommunity: newCommunity,
+ selectedSpace: null,
+ allTags: _cachedTags ?? [],
+ ));
}
} else {
emit(const SpaceManagementError('Error creating community'));
@@ -401,11 +410,12 @@ class SpaceManagementBloc
required Emitter emit,
CommunityModel? selectedCommunity,
SpaceModel? selectedSpace,
- }) {
+ }) async {
final previousState = state;
emit(SpaceManagementLoading());
try {
+ await fetchTags();
if (previousState is SpaceManagementLoaded ||
previousState is BlankState ||
previousState is SpaceModelLoaded) {
@@ -421,7 +431,8 @@ class SpaceManagementBloc
products: _cachedProducts ?? [],
selectedCommunity: selectedCommunity,
selectedSpace: selectedSpace,
- spaceModels: spaceModels));
+ spaceModels: spaceModels,
+ allTags: _cachedTags ?? []));
}
} catch (e) {
emit(SpaceManagementError('Error updating state: $e'));
@@ -436,8 +447,7 @@ class SpaceManagementBloc
emit(SpaceManagementLoading());
try {
- final updatedSpaces =
- await saveSpacesHierarchically(event.spaces, event.communityUuid);
+ final updatedSpaces = await saveSpacesHierarchically(event.spaces, event.communityUuid);
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
@@ -467,20 +477,21 @@ class SpaceManagementBloc
Emitter emit,
) async {
var prevSpaceModels = await fetchSpaceModels();
-
+ await fetchTags();
final communities = List.from(previousState.communities);
for (var community in communities) {
if (community.uuid == communityUuid) {
community.spaces = allSpaces;
- _spaceTreeBloc.add(OnCommunityUpdated(community));
+ _spaceTreeBloc.add(InitialEvent());
emit(SpaceManagementLoaded(
communities: communities,
products: _cachedProducts ?? [],
selectedCommunity: community,
selectedSpace: null,
- spaceModels: prevSpaceModels));
+ spaceModels: prevSpaceModels,
+ allTags: _cachedTags ?? []));
return;
}
}
@@ -511,8 +522,7 @@ class SpaceManagementBloc
if (space.uuid != null && space.uuid!.isNotEmpty) {
List tagUpdates = [];
- final prevSpace =
- await _api.getSpace(communityUuid, space.uuid!, projectUuid);
+ final prevSpace = await _api.getSpace(communityUuid, space.uuid!, projectUuid);
final List subspaceUpdates = [];
final List? prevSubspaces = prevSpace?.subspaces;
final List? newSubspaces = space.subspaces;
@@ -522,19 +532,17 @@ class SpaceManagementBloc
if (prevSubspaces != null || newSubspaces != null) {
if (prevSubspaces != null && newSubspaces != null) {
for (var prevSubspace in prevSubspaces) {
- final existsInNew = newSubspaces
- .any((subspace) => subspace.uuid == prevSubspace.uuid);
+ final existsInNew =
+ newSubspaces.any((subspace) => subspace.uuid == prevSubspace.uuid);
if (!existsInNew) {
subspaceUpdates.add(UpdateSubspaceTemplateModel(
- action: custom_action.Action.delete,
- uuid: prevSubspace.uuid));
+ action: custom_action.Action.delete, uuid: prevSubspace.uuid));
}
}
} else if (prevSubspaces != null && newSubspaces == null) {
for (var prevSubspace in prevSubspaces) {
subspaceUpdates.add(UpdateSubspaceTemplateModel(
- action: custom_action.Action.delete,
- uuid: prevSubspace.uuid));
+ action: custom_action.Action.delete, uuid: prevSubspace.uuid));
}
}
@@ -548,7 +556,7 @@ class SpaceManagementBloc
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));
}
@@ -562,9 +570,7 @@ class SpaceManagementBloc
}
if (prevSubspaces != null && newSubspaces != null) {
- final newSubspaceMap = {
- for (var subspace in newSubspaces) subspace.uuid: subspace
- };
+ final newSubspaceMap = {for (var subspace in newSubspaces) subspace.uuid: subspace};
for (var prevSubspace in prevSubspaces) {
final newSubspace = newSubspaceMap[prevSubspace.uuid];
@@ -601,10 +607,8 @@ class SpaceManagementBloc
: [];
final createSubspaceBodyModels = space.subspaces?.map((subspace) {
- final tagBodyModels = subspace.tags
- ?.map((tag) => tag.toCreateTagBodyModel())
- .toList() ??
- [];
+ final tagBodyModels =
+ subspace.tags?.map((tag) => tag.toCreateTagBodyModel()).toList() ?? [];
return CreateSubspaceModel()
..subspaceName = subspace.subspaceName
..tags = tagBodyModels;
@@ -657,12 +661,11 @@ class SpaceManagementBloc
return result.toList(); // Convert back to a list
}
- void _onLoadSpaceModel(
- SpaceModelLoadEvent event, Emitter emit) async {
+ void _onLoadSpaceModel(SpaceModelLoadEvent event, Emitter emit) async {
emit(SpaceManagementLoading());
try {
- var prevState = state;
+ await fetchTags();
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
var spaceBloc = event.context.read();
List communities = spaceBloc.state.communityList;
@@ -674,8 +677,7 @@ class SpaceManagementBloc
List updatedCommunities = await Future.wait(
communities.map((community) async {
- List spaces =
- await _fetchSpacesForCommunity(community.uuid);
+ List spaces = await _fetchSpacesForCommunity(community.uuid);
return CommunityModel(
uuid: community.uuid,
createdAt: community.createdAt,
@@ -692,10 +694,10 @@ class SpaceManagementBloc
}
emit(SpaceModelLoaded(
- communities: communities,
- products: _cachedProducts ?? [],
- spaceModels: prevSpaceModels,
- ));
+ communities: communities,
+ products: _cachedProducts ?? [],
+ spaceModels: prevSpaceModels,
+ allTags: _cachedTags ?? []));
} catch (e) {
emit(SpaceManagementError('Error loading communities and spaces: $e'));
}
@@ -713,7 +715,7 @@ class SpaceManagementBloc
tagUpdates.add(TagModelUpdate(
action: custom_action.Action.add,
tag: newTag.tag,
- uuid: newTag.uuid,
+ newTagUuid: newTag.uuid,
productUuid: newTag.product?.uuid,
));
}
@@ -724,17 +726,14 @@ class SpaceManagementBloc
// Case 1: Tags deleted
if (prevTags != null && newTags != null) {
for (var prevTag in prevTags) {
- final existsInNew =
- newTags.any((newTag) => newTag.uuid == prevTag.uuid);
+ final existsInNew = newTags.any((newTag) => newTag.uuid == prevTag.uuid);
if (!existsInNew) {
- tagUpdates.add(TagModelUpdate(
- action: custom_action.Action.delete, uuid: prevTag.uuid));
+ tagUpdates.add(TagModelUpdate(action: custom_action.Action.delete, uuid: prevTag.uuid));
}
}
} else if (prevTags != null && newTags == null) {
for (var prevTag in prevTags) {
- tagUpdates.add(TagModelUpdate(
- action: custom_action.Action.delete, uuid: prevTag.uuid));
+ tagUpdates.add(TagModelUpdate(action: custom_action.Action.delete, uuid: prevTag.uuid));
}
}
@@ -749,7 +748,7 @@ class SpaceManagementBloc
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);
}
@@ -766,6 +765,7 @@ class SpaceManagementBloc
tagUpdates.add(TagModelUpdate(
action: custom_action.Action.update,
uuid: newTag.uuid,
+ newTagUuid: newTag.uuid,
tag: newTag.tag,
));
} else {}
diff --git a/lib/pages/spaces_management/all_spaces/bloc/space_management_state.dart b/lib/pages/spaces_management/all_spaces/bloc/space_management_state.dart
index 674fce4c..3efa7c00 100644
--- a/lib/pages/spaces_management/all_spaces/bloc/space_management_state.dart
+++ b/lib/pages/spaces_management/all_spaces/bloc/space_management_state.dart
@@ -2,6 +2,7 @@ import 'package:equatable/equatable.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/space_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';
abstract class SpaceManagementState extends Equatable {
@@ -21,22 +22,25 @@ class SpaceManagementLoaded extends SpaceManagementState {
CommunityModel? selectedCommunity;
SpaceModel? selectedSpace;
List? spaceModels;
+ List allTags;
SpaceManagementLoaded(
{required this.communities,
required this.products,
this.selectedCommunity,
this.selectedSpace,
- this.spaceModels});
+ this.spaceModels,
+ required this.allTags});
}
class BlankState extends SpaceManagementState {
final List communities;
final List products;
List? spaceModels;
+ final List allTags;
BlankState(
- {required this.communities, required this.products, this.spaceModels});
+ {required this.communities, required this.products, this.spaceModels, required this.allTags});
}
class SpaceCreationSuccess extends SpaceManagementState {
@@ -61,14 +65,14 @@ class SpaceModelLoaded extends SpaceManagementState {
List spaceModels;
final List products;
final List communities;
+ final List allTags;
- SpaceModelLoaded({
- required this.communities,
- required this.products,
- required this.spaceModels,
- });
+ SpaceModelLoaded(
+ {required this.communities,
+ required this.products,
+ required this.spaceModels,
+ required this.allTags});
@override
- List