mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Merge branch 'dev' into link_space_model_spaces
This commit is contained in:
@ -56,24 +56,6 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
|||||||
children: [
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
// Checkbox with independent state management
|
|
||||||
Checkbox(
|
|
||||||
value: false,
|
|
||||||
onChanged: (bool? value) {
|
|
||||||
setState(() {});
|
|
||||||
},
|
|
||||||
side: WidgetStateBorderSide.resolveWith((states) {
|
|
||||||
return const BorderSide(color: ColorsManager.grayBorder);
|
|
||||||
}),
|
|
||||||
fillColor: WidgetStateProperty.resolveWith((states) {
|
|
||||||
if (states.contains(WidgetState.selected)) {
|
|
||||||
return ColorsManager.grayBorder;
|
|
||||||
} else {
|
|
||||||
return ColorsManager.checkBoxFillColor;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
checkColor: ColorsManager.whiteColors,
|
|
||||||
),
|
|
||||||
// Expand/collapse icon, now wrapped in a GestureDetector for specific onTap
|
// Expand/collapse icon, now wrapped in a GestureDetector for specific onTap
|
||||||
if (widget.children != null && widget.children!.isNotEmpty)
|
if (widget.children != null && widget.children!.isNotEmpty)
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
@ -84,7 +66,9 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
child: Icon(
|
child: Icon(
|
||||||
_isExpanded ? Icons.keyboard_arrow_down : Icons.keyboard_arrow_right,
|
_isExpanded
|
||||||
|
? Icons.keyboard_arrow_down
|
||||||
|
: Icons.keyboard_arrow_right,
|
||||||
color: ColorsManager.lightGrayColor,
|
color: ColorsManager.lightGrayColor,
|
||||||
size: 16.0, // Adjusted size for better alignment
|
size: 16.0, // Adjusted size for better alignment
|
||||||
),
|
),
|
||||||
@ -101,8 +85,10 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
|||||||
_capitalizeFirstLetter(widget.title),
|
_capitalizeFirstLetter(widget.title),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: widget.isSelected
|
color: widget.isSelected
|
||||||
? ColorsManager.blackColor // Change color to black when selected
|
? ColorsManager
|
||||||
: ColorsManager.lightGrayColor, // Gray when not selected
|
.blackColor // Change color to black when selected
|
||||||
|
: ColorsManager
|
||||||
|
.lightGrayColor, // Gray when not selected
|
||||||
fontWeight: FontWeight.w400,
|
fontWeight: FontWeight.w400,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -111,7 +97,9 @@ class CustomExpansionTileState extends State<CustomExpansionTile> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
// The expanded section (children) that shows when the tile is expanded
|
// The expanded section (children) that shows when the tile is expanded
|
||||||
if (_isExpanded && widget.children != null && widget.children!.isNotEmpty)
|
if (_isExpanded &&
|
||||||
|
widget.children != null &&
|
||||||
|
widget.children!.isNotEmpty)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.only(left: 48.0), // Indented children
|
padding: const EdgeInsets.only(left: 48.0), // Indented children
|
||||||
child: Column(
|
child: Column(
|
||||||
|
@ -8,9 +8,6 @@ import 'package:syncrow_web/pages/common/hour_picker_dialog.dart';
|
|||||||
import 'package:syncrow_web/services/access_mang_api.dart';
|
import 'package:syncrow_web/services/access_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/app_enum.dart';
|
import 'package:syncrow_web/utils/constants/app_enum.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';
|
|
||||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||||
|
|
||||||
class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
class AccessBloc extends Bloc<AccessEvent, AccessState> {
|
||||||
|
@ -16,6 +16,33 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
on<SearchQueryEvent>(_onSearch);
|
on<SearchQueryEvent>(_onSearch);
|
||||||
on<ClearAllData>(_clearAllData);
|
on<ClearAllData>(_clearAllData);
|
||||||
on<ClearCachedData>(_clearCachedData);
|
on<ClearCachedData>(_clearCachedData);
|
||||||
|
on<OnCommunityAdded>(_onCommunityAdded);
|
||||||
|
on<OnCommunityUpdated>(_onCommunityUpdate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onCommunityUpdate(
|
||||||
|
OnCommunityUpdated event,
|
||||||
|
Emitter<SpaceTreeState> emit,
|
||||||
|
) async {
|
||||||
|
emit(SpaceTreeLoadingState());
|
||||||
|
|
||||||
|
try {
|
||||||
|
final updatedCommunity = event.updatedCommunity;
|
||||||
|
final updatedCommunities =
|
||||||
|
List<CommunityModel>.from(state.communityList);
|
||||||
|
|
||||||
|
final index = updatedCommunities
|
||||||
|
.indexWhere((community) => community.uuid == updatedCommunity.uuid);
|
||||||
|
|
||||||
|
if (index != -1) {
|
||||||
|
updatedCommunities[index] = updatedCommunity;
|
||||||
|
emit(state.copyWith(communitiesList: updatedCommunities));
|
||||||
|
} else {
|
||||||
|
emit(SpaceTreeErrorState('Community not found in the list.'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(SpaceTreeErrorState('Error updating community: $e'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_fetchSpaces(InitialEvent event, Emitter<SpaceTreeState> emit) async {
|
_fetchSpaces(InitialEvent event, Emitter<SpaceTreeState> emit) async {
|
||||||
@ -28,8 +55,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
communities.map((community) async {
|
communities.map((community) async {
|
||||||
List<SpaceModel> spaces =
|
List<SpaceModel> spaces = await CommunitySpaceManagementApi()
|
||||||
await CommunitySpaceManagementApi().getSpaceHierarchy(community.uuid, projectUuid);
|
.getSpaceHierarchy(community.uuid, projectUuid);
|
||||||
|
|
||||||
return CommunityModel(
|
return CommunityModel(
|
||||||
uuid: community.uuid,
|
uuid: community.uuid,
|
||||||
@ -44,15 +71,27 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
communitiesList: updatedCommunities, expandedCommunity: [], expandedSpaces: []));
|
communitiesList: updatedCommunities,
|
||||||
|
expandedCommunity: [],
|
||||||
|
expandedSpaces: []));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceTreeErrorState('Error loading communities and spaces: $e'));
|
emit(SpaceTreeErrorState('Error loading communities and spaces: $e'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCommunityExpanded(OnCommunityExpanded event, Emitter<SpaceTreeState> emit) async {
|
void _onCommunityAdded(
|
||||||
|
OnCommunityAdded event, Emitter<SpaceTreeState> emit) async {
|
||||||
|
final updatedCommunities = List<CommunityModel>.from(state.communityList);
|
||||||
|
updatedCommunities.add(event.newCommunity);
|
||||||
|
|
||||||
|
emit(state.copyWith(communitiesList: updatedCommunities));
|
||||||
|
}
|
||||||
|
|
||||||
|
_onCommunityExpanded(
|
||||||
|
OnCommunityExpanded event, Emitter<SpaceTreeState> emit) async {
|
||||||
try {
|
try {
|
||||||
List<String> updatedExpandedCommunityList = List.from(state.expandedCommunities);
|
List<String> updatedExpandedCommunityList =
|
||||||
|
List.from(state.expandedCommunities);
|
||||||
|
|
||||||
if (updatedExpandedCommunityList.contains(event.communityId)) {
|
if (updatedExpandedCommunityList.contains(event.communityId)) {
|
||||||
updatedExpandedCommunityList.remove(event.communityId);
|
updatedExpandedCommunityList.remove(event.communityId);
|
||||||
@ -84,14 +123,19 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onCommunitySelected(OnCommunitySelected event, Emitter<SpaceTreeState> emit) async {
|
_onCommunitySelected(
|
||||||
|
OnCommunitySelected event, Emitter<SpaceTreeState> emit) async {
|
||||||
try {
|
try {
|
||||||
List<String> updatedSelectedCommunities =
|
List<String> updatedSelectedCommunities =
|
||||||
List.from(state.selectedCommunities.toSet().toList());
|
List.from(state.selectedCommunities.toSet().toList());
|
||||||
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
List<String> updatedSelectedSpaces =
|
||||||
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
List.from(state.selectedSpaces.toSet().toList());
|
||||||
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
|
List<String> updatedSoldChecks =
|
||||||
List<String> selectedSpacesInCommunity = communityAndSpaces[event.communityId] ?? [];
|
List.from(state.soldCheck.toSet().toList());
|
||||||
|
Map<String, List<String>> communityAndSpaces =
|
||||||
|
Map.from(state.selectedCommunityAndSpaces);
|
||||||
|
List<String> selectedSpacesInCommunity =
|
||||||
|
communityAndSpaces[event.communityId] ?? [];
|
||||||
|
|
||||||
List<String> childrenIds = _getAllChildIds(event.children);
|
List<String> childrenIds = _getAllChildIds(event.children);
|
||||||
|
|
||||||
@ -124,11 +168,15 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
try {
|
try {
|
||||||
List<String> updatedSelectedCommunities =
|
List<String> updatedSelectedCommunities =
|
||||||
List.from(state.selectedCommunities.toSet().toList());
|
List.from(state.selectedCommunities.toSet().toList());
|
||||||
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
List<String> updatedSelectedSpaces =
|
||||||
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
List.from(state.selectedSpaces.toSet().toList());
|
||||||
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
|
List<String> updatedSoldChecks =
|
||||||
|
List.from(state.soldCheck.toSet().toList());
|
||||||
|
Map<String, List<String>> communityAndSpaces =
|
||||||
|
Map.from(state.selectedCommunityAndSpaces);
|
||||||
|
|
||||||
List<String> selectedSpacesInCommunity = communityAndSpaces[event.communityModel.uuid] ?? [];
|
List<String> selectedSpacesInCommunity =
|
||||||
|
communityAndSpaces[event.communityModel.uuid] ?? [];
|
||||||
|
|
||||||
List<String> childrenIds = _getAllChildIds(event.children);
|
List<String> childrenIds = _getAllChildIds(event.children);
|
||||||
bool isChildSelected = false;
|
bool isChildSelected = false;
|
||||||
@ -151,9 +199,11 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
selectedSpacesInCommunity.addAll(childrenIds);
|
selectedSpacesInCommunity.addAll(childrenIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> spaces = _getThePathToChild(event.communityModel.uuid, event.spaceId);
|
List<String> spaces =
|
||||||
|
_getThePathToChild(event.communityModel.uuid, event.spaceId);
|
||||||
for (String space in spaces) {
|
for (String space in spaces) {
|
||||||
if (!updatedSelectedSpaces.contains(space) && !updatedSoldChecks.contains(space)) {
|
if (!updatedSelectedSpaces.contains(space) &&
|
||||||
|
!updatedSoldChecks.contains(space)) {
|
||||||
updatedSoldChecks.add(space);
|
updatedSoldChecks.add(space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,7 +226,9 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
updatedSoldChecks.remove(event.spaceId);
|
updatedSoldChecks.remove(event.spaceId);
|
||||||
|
|
||||||
List<String> parents =
|
List<String> parents =
|
||||||
_getThePathToChild(event.communityModel.uuid, event.spaceId).toSet().toList();
|
_getThePathToChild(event.communityModel.uuid, event.spaceId)
|
||||||
|
.toSet()
|
||||||
|
.toList();
|
||||||
|
|
||||||
if (updatedSelectedSpaces.isEmpty) {
|
if (updatedSelectedSpaces.isEmpty) {
|
||||||
updatedSoldChecks.removeWhere(parents.contains);
|
updatedSoldChecks.removeWhere(parents.contains);
|
||||||
@ -184,7 +236,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
} else {
|
} else {
|
||||||
// Check if any parent has selected children
|
// Check if any parent has selected children
|
||||||
for (String space in parents) {
|
for (String space in parents) {
|
||||||
if (!_noChildrenSelected(event.communityModel, space, updatedSelectedSpaces, parents)) {
|
if (!_noChildrenSelected(
|
||||||
|
event.communityModel, space, updatedSelectedSpaces, parents)) {
|
||||||
updatedSoldChecks.remove(space);
|
updatedSoldChecks.remove(space);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -209,8 +262,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_noChildrenSelected(
|
_noChildrenSelected(CommunityModel community, String spaceId,
|
||||||
CommunityModel community, String spaceId, List<String> selectedSpaces, List<String> parents) {
|
List<String> selectedSpaces, List<String> parents) {
|
||||||
if (selectedSpaces.contains(spaceId)) {
|
if (selectedSpaces.contains(spaceId)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -237,10 +290,11 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
|
|
||||||
// Filter communities and expand only those that match the query
|
// Filter communities and expand only those that match the query
|
||||||
filteredCommunity = communities.where((community) {
|
filteredCommunity = communities.where((community) {
|
||||||
final containsQueryInCommunity =
|
final containsQueryInCommunity = community.name
|
||||||
community.name.toLowerCase().contains(event.searchQuery.toLowerCase());
|
.toLowerCase()
|
||||||
final containsQueryInSpaces =
|
.contains(event.searchQuery.toLowerCase());
|
||||||
community.spaces.any((space) => _containsQuery(space, event.searchQuery.toLowerCase()));
|
final containsQueryInSpaces = community.spaces.any(
|
||||||
|
(space) => _containsQuery(space, event.searchQuery.toLowerCase()));
|
||||||
|
|
||||||
return containsQueryInCommunity || containsQueryInSpaces;
|
return containsQueryInCommunity || containsQueryInSpaces;
|
||||||
}).toList();
|
}).toList();
|
||||||
@ -293,8 +347,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
// Helper function to determine if any space or its children match the search query
|
// Helper function to determine if any space or its children match the search query
|
||||||
bool _containsQuery(SpaceModel space, String query) {
|
bool _containsQuery(SpaceModel space, String query) {
|
||||||
final matchesSpace = space.name.toLowerCase().contains(query);
|
final matchesSpace = space.name.toLowerCase().contains(query);
|
||||||
final matchesChildren =
|
final matchesChildren = space.children.any((child) =>
|
||||||
space.children.any((child) => _containsQuery(child, query)); // Recursive check for children
|
_containsQuery(child, query)); // Recursive check for children
|
||||||
|
|
||||||
return matchesSpace || matchesChildren;
|
return matchesSpace || matchesChildren;
|
||||||
}
|
}
|
||||||
@ -317,8 +371,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _anySpacesSelectedInCommunity(
|
bool _anySpacesSelectedInCommunity(CommunityModel community,
|
||||||
CommunityModel community, List<String> selectedSpaces, List<String> partialCheckedList) {
|
List<String> selectedSpaces, List<String> partialCheckedList) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
List<String> ids = _getAllChildIds(community.spaces);
|
List<String> ids = _getAllChildIds(community.spaces);
|
||||||
for (var id in ids) {
|
for (var id in ids) {
|
||||||
@ -347,7 +401,8 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> _getAllParentsIds(SpaceModel child, String spaceId, List<String> listIds) {
|
List<String> _getAllParentsIds(
|
||||||
|
SpaceModel child, String spaceId, List<String> listIds) {
|
||||||
List<String> ids = listIds;
|
List<String> ids = listIds;
|
||||||
|
|
||||||
ids.add(child.uuid ?? '');
|
ids.add(child.uuid ?? '');
|
||||||
|
@ -69,6 +69,23 @@ class SearchQueryEvent extends SpaceTreeEvent {
|
|||||||
List<Object> get props => [searchQuery];
|
List<Object> get props => [searchQuery];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class OnCommunityAdded extends SpaceTreeEvent {
|
||||||
|
final CommunityModel newCommunity;
|
||||||
|
const OnCommunityAdded(this.newCommunity);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [newCommunity];
|
||||||
|
}
|
||||||
|
|
||||||
|
class OnCommunityUpdated extends SpaceTreeEvent {
|
||||||
|
final CommunityModel updatedCommunity;
|
||||||
|
const OnCommunityUpdated(this.updatedCommunity);
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [updatedCommunity];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ClearAllData extends SpaceTreeEvent {}
|
class ClearAllData extends SpaceTreeEvent {}
|
||||||
|
|
||||||
class ClearCachedData extends SpaceTreeEvent {}
|
class ClearCachedData extends SpaceTreeEvent {}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import 'dart:developer';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_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/product_model.dart';
|
||||||
@ -17,10 +17,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_updat
|
|||||||
import 'package:syncrow_web/services/product_api.dart';
|
import 'package:syncrow_web/services/product_api.dart';
|
||||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
import 'package:syncrow_web/utils/constants/action_enum.dart' as custom_action;
|
||||||
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';
|
|
||||||
|
|
||||||
class SpaceManagementBloc
|
class SpaceManagementBloc
|
||||||
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
extends Bloc<SpaceManagementEvent, SpaceManagementState> {
|
||||||
@ -29,11 +26,16 @@ class SpaceManagementBloc
|
|||||||
final SpaceModelManagementApi _spaceModelApi;
|
final SpaceModelManagementApi _spaceModelApi;
|
||||||
|
|
||||||
List<ProductModel>? _cachedProducts;
|
List<ProductModel>? _cachedProducts;
|
||||||
|
List<SpaceTemplateModel>? _cachedSpaceModels;
|
||||||
|
final SpaceTreeBloc _spaceTreeBloc;
|
||||||
|
|
||||||
SpaceManagementBloc(this._api, this._productApi, this._spaceModelApi)
|
SpaceManagementBloc(
|
||||||
: super(SpaceManagementInitial()) {
|
this._api,
|
||||||
|
this._productApi,
|
||||||
|
this._spaceModelApi,
|
||||||
|
this._spaceTreeBloc,
|
||||||
|
) : super(SpaceManagementInitial()) {
|
||||||
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
on<LoadCommunityAndSpacesEvent>(_onLoadCommunityAndSpaces);
|
||||||
on<UpdateSpacePositionEvent>(_onUpdateSpacePosition);
|
|
||||||
on<CreateCommunityEvent>(_onCreateCommunity);
|
on<CreateCommunityEvent>(_onCreateCommunity);
|
||||||
on<SelectCommunityEvent>(_onSelectCommunity);
|
on<SelectCommunityEvent>(_onSelectCommunity);
|
||||||
on<DeleteCommunityEvent>(_onCommunityDelete);
|
on<DeleteCommunityEvent>(_onCommunityDelete);
|
||||||
@ -44,18 +46,94 @@ class SpaceManagementBloc
|
|||||||
on<NewCommunityEvent>(_onNewCommunity);
|
on<NewCommunityEvent>(_onNewCommunity);
|
||||||
on<BlankStateEvent>(_onBlankState);
|
on<BlankStateEvent>(_onBlankState);
|
||||||
on<SpaceModelLoadEvent>(_onLoadSpaceModel);
|
on<SpaceModelLoadEvent>(_onLoadSpaceModel);
|
||||||
|
on<UpdateSpaceModelCache>(_updateSpaceModelCache);
|
||||||
|
on<DeleteSpaceModelFromCache>(_deleteSpaceModelFromCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _logEvent(String eventName) {
|
Future<void> _updateSpaceModelCache(
|
||||||
log('Event Triggered: $eventName');
|
UpdateSpaceModelCache event, Emitter<SpaceManagementState> emit) async {
|
||||||
|
if (_cachedSpaceModels != null) {
|
||||||
|
_cachedSpaceModels = _cachedSpaceModels!.map((model) {
|
||||||
|
return model.uuid == event.updatedModel.uuid
|
||||||
|
? event.updatedModel
|
||||||
|
: model;
|
||||||
|
}).toList();
|
||||||
|
} else {
|
||||||
|
_cachedSpaceModels = await fetchSpaceModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(SpaceModelLoaded(
|
||||||
|
communities: state is SpaceManagementLoaded
|
||||||
|
? (state as SpaceManagementLoaded).communities
|
||||||
|
: [],
|
||||||
|
products: _cachedProducts ?? [],
|
||||||
|
spaceModels: List.from(_cachedSpaceModels ?? []),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void _deleteSpaceModelFromCache(DeleteSpaceModelFromCache event,
|
||||||
|
Emitter<SpaceManagementState> emit) async {
|
||||||
|
if (_cachedSpaceModels != null) {
|
||||||
|
_cachedSpaceModels = _cachedSpaceModels!
|
||||||
|
.where((model) => model.uuid != event.deletedUuid)
|
||||||
|
.toList();
|
||||||
|
} else {
|
||||||
|
_cachedSpaceModels = await fetchSpaceModels();
|
||||||
|
}
|
||||||
|
|
||||||
|
emit(SpaceModelLoaded(
|
||||||
|
communities: state is SpaceManagementLoaded
|
||||||
|
? (state as SpaceManagementLoaded).communities
|
||||||
|
: [],
|
||||||
|
products: _cachedProducts ?? [],
|
||||||
|
spaceModels: List.from(_cachedSpaceModels ?? []),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateCachedSpaceModels(List<SpaceTemplateModel> updatedModels) {
|
||||||
|
_cachedSpaceModels = List.from(updatedModels);
|
||||||
|
}
|
||||||
|
|
||||||
|
void addToCachedSpaceModels(SpaceTemplateModel newModel) {
|
||||||
|
_cachedSpaceModels?.add(newModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<SpaceTemplateModel>> fetchSpaceModels() async {
|
||||||
|
try {
|
||||||
|
if (_cachedSpaceModels != null) {
|
||||||
|
return _cachedSpaceModels!;
|
||||||
|
}
|
||||||
|
|
||||||
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
|
||||||
|
List<SpaceTemplateModel> allSpaceModels = [];
|
||||||
|
|
||||||
|
bool hasNext = true;
|
||||||
|
int page = 1;
|
||||||
|
|
||||||
|
while (hasNext) {
|
||||||
|
final spaceModels = await _spaceModelApi.listSpaceModels(
|
||||||
|
page: page, projectId: projectUuid);
|
||||||
|
if (spaceModels.isNotEmpty) {
|
||||||
|
allSpaceModels.addAll(spaceModels);
|
||||||
|
page++;
|
||||||
|
} else {
|
||||||
|
hasNext = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_cachedSpaceModels = allSpaceModels;
|
||||||
|
|
||||||
|
return allSpaceModels;
|
||||||
|
} catch (e) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUpdateCommunity(
|
void _onUpdateCommunity(
|
||||||
UpdateCommunityEvent event,
|
UpdateCommunityEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
_logEvent('UpdateCommunityEvent');
|
|
||||||
|
|
||||||
final previousState = state;
|
final previousState = state;
|
||||||
try {
|
try {
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
@ -70,11 +148,13 @@ class SpaceManagementBloc
|
|||||||
for (var community in updatedCommunities) {
|
for (var community in updatedCommunities) {
|
||||||
if (community.uuid == event.communityUuid) {
|
if (community.uuid == event.communityUuid) {
|
||||||
community.name = event.name;
|
community.name = event.name;
|
||||||
|
_spaceTreeBloc.add(OnCommunityAdded(community));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var prevSpaceModels = await fetchSpaceModels(previousState);
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
|
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
@ -91,46 +171,6 @@ class SpaceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List<SpaceTemplateModel>> fetchSpaceModels(
|
|
||||||
SpaceManagementState previousState) async {
|
|
||||||
try {
|
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
|
||||||
|
|
||||||
List<SpaceTemplateModel> allSpaces = [];
|
|
||||||
List<SpaceTemplateModel> prevSpaceModels = [];
|
|
||||||
|
|
||||||
if (previousState is SpaceManagementLoaded ||
|
|
||||||
previousState is BlankState) {
|
|
||||||
prevSpaceModels = List<SpaceTemplateModel>.from(
|
|
||||||
(previousState as dynamic).spaceModels ?? [],
|
|
||||||
);
|
|
||||||
allSpaces.addAll(prevSpaceModels);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (prevSpaceModels.isEmpty) {
|
|
||||||
bool hasNext = true;
|
|
||||||
int page = 1;
|
|
||||||
|
|
||||||
while (hasNext) {
|
|
||||||
final spaces = await _spaceModelApi.listSpaceModels(
|
|
||||||
page: page, projectId: projectUuid);
|
|
||||||
if (spaces.isNotEmpty) {
|
|
||||||
allSpaces.addAll(spaces);
|
|
||||||
page++;
|
|
||||||
} else {
|
|
||||||
hasNext = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
prevSpaceModels = await _spaceModelApi.listSpaceModels(
|
|
||||||
page: 1, projectId: projectUuid);
|
|
||||||
}
|
|
||||||
|
|
||||||
return allSpaces;
|
|
||||||
} catch (e) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void _onloadProducts() async {
|
void _onloadProducts() async {
|
||||||
if (_cachedProducts == null) {
|
if (_cachedProducts == null) {
|
||||||
final products = await _productApi.fetchProducts();
|
final products = await _productApi.fetchProducts();
|
||||||
@ -168,7 +208,7 @@ class SpaceManagementBloc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var prevSpaceModels = await fetchSpaceModels(previousState);
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
|
|
||||||
emit(BlankState(
|
emit(BlankState(
|
||||||
communities: event.communities,
|
communities: event.communities,
|
||||||
@ -185,8 +225,10 @@ class SpaceManagementBloc
|
|||||||
try {
|
try {
|
||||||
final previousState = state;
|
final previousState = state;
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||||
|
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc);
|
||||||
|
|
||||||
var prevSpaceModels = await fetchSpaceModels(previousState);
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
|
|
||||||
if (previousState is SpaceManagementLoaded ||
|
if (previousState is SpaceManagementLoaded ||
|
||||||
previousState is BlankState) {
|
previousState is BlankState) {
|
||||||
@ -199,25 +241,31 @@ class SpaceManagementBloc
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final communities = await _api.fetchCommunities(projectUuid);
|
if (communities.isEmpty) {
|
||||||
final updatedCommunities =
|
communities = await _api.fetchCommunities(projectUuid);
|
||||||
await Future.wait(communities.map((community) async {
|
|
||||||
final spaces = await _fetchSpacesForCommunity(community.uuid);
|
|
||||||
|
|
||||||
return CommunityModel(
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
uuid: community.uuid,
|
communities.map((community) async {
|
||||||
createdAt: community.createdAt,
|
List<SpaceModel> spaces =
|
||||||
updatedAt: community.updatedAt,
|
await _fetchSpacesForCommunity(community.uuid);
|
||||||
name: community.name,
|
return CommunityModel(
|
||||||
description: community.description,
|
uuid: community.uuid,
|
||||||
spaces: spaces,
|
createdAt: community.createdAt,
|
||||||
region: community.region,
|
updatedAt: community.updatedAt,
|
||||||
|
name: community.name,
|
||||||
|
description: community.description,
|
||||||
|
spaces: spaces,
|
||||||
|
region: community.region,
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
);
|
);
|
||||||
}));
|
|
||||||
|
communities = updatedCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
emit(BlankState(
|
emit(BlankState(
|
||||||
spaceModels: prevSpaceModels,
|
spaceModels: prevSpaceModels,
|
||||||
communities: updatedCommunities,
|
communities: communities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
));
|
));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -229,41 +277,39 @@ class SpaceManagementBloc
|
|||||||
LoadCommunityAndSpacesEvent event,
|
LoadCommunityAndSpacesEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
_logEvent('LoadCommunityAndSpacesEvent');
|
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||||
|
_onloadProducts();
|
||||||
|
|
||||||
var prevState = state;
|
// Wait until `communityList` is loaded
|
||||||
emit(SpaceManagementLoading());
|
List<CommunityModel> communities = await _waitForCommunityList(spaceBloc);
|
||||||
try {
|
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
|
||||||
|
|
||||||
_onloadProducts();
|
// Fetch space models after communities are available
|
||||||
List<CommunityModel> communities =
|
final prevSpaceModels = await fetchSpaceModels();
|
||||||
await _api.fetchCommunities(projectUuid);
|
emit(SpaceManagementLoaded(
|
||||||
|
communities: communities,
|
||||||
|
products: _cachedProducts ?? [],
|
||||||
|
spaceModels: prevSpaceModels,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
Future<List<CommunityModel>> _waitForCommunityList(
|
||||||
communities.map((community) async {
|
SpaceTreeBloc spaceBloc) async {
|
||||||
List<SpaceModel> spaces =
|
// Check if communityList is already populated
|
||||||
await _fetchSpacesForCommunity(community.uuid);
|
if (spaceBloc.state.communityList.isNotEmpty) {
|
||||||
return CommunityModel(
|
return spaceBloc.state.communityList;
|
||||||
uuid: community.uuid,
|
|
||||||
createdAt: community.createdAt,
|
|
||||||
updatedAt: community.updatedAt,
|
|
||||||
name: community.name,
|
|
||||||
description: community.description,
|
|
||||||
spaces: spaces, // New spaces list
|
|
||||||
region: community.region,
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
);
|
|
||||||
|
|
||||||
final prevSpaceModels = await fetchSpaceModels(prevState);
|
|
||||||
emit(SpaceManagementLoaded(
|
|
||||||
communities: updatedCommunities,
|
|
||||||
products: _cachedProducts ?? [],
|
|
||||||
spaceModels: prevSpaceModels));
|
|
||||||
} catch (e) {
|
|
||||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final completer = Completer<List<CommunityModel>>();
|
||||||
|
final subscription = spaceBloc.stream.listen((state) {
|
||||||
|
if (state.communityList.isNotEmpty) {
|
||||||
|
completer.complete(state.communityList);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Return the list once available, then cancel the listener
|
||||||
|
final communities = await completer.future;
|
||||||
|
await subscription.cancel();
|
||||||
|
return communities;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onCommunityDelete(
|
void _onCommunityDelete(
|
||||||
@ -277,7 +323,7 @@ class SpaceManagementBloc
|
|||||||
final success =
|
final success =
|
||||||
await _api.deleteCommunity(event.communityUuid, projectUuid);
|
await _api.deleteCommunity(event.communityUuid, projectUuid);
|
||||||
if (success) {
|
if (success) {
|
||||||
add(LoadCommunityAndSpacesEvent());
|
// add(LoadCommunityAndSpacesEvent());
|
||||||
} else {
|
} else {
|
||||||
emit(const SpaceManagementError('Failed to delete the community.'));
|
emit(const SpaceManagementError('Failed to delete the community.'));
|
||||||
}
|
}
|
||||||
@ -287,11 +333,6 @@ class SpaceManagementBloc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onUpdateSpacePosition(
|
|
||||||
UpdateSpacePositionEvent event,
|
|
||||||
Emitter<SpaceManagementState> emit,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
void _onCreateCommunity(
|
void _onCreateCommunity(
|
||||||
CreateCommunityEvent event,
|
CreateCommunityEvent event,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
@ -304,7 +345,7 @@ class SpaceManagementBloc
|
|||||||
|
|
||||||
CommunityModel? newCommunity = await _api.createCommunity(
|
CommunityModel? newCommunity = await _api.createCommunity(
|
||||||
event.name, event.description, projectUuid);
|
event.name, event.description, projectUuid);
|
||||||
var prevSpaceModels = await fetchSpaceModels(previousState);
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
|
|
||||||
if (newCommunity != null) {
|
if (newCommunity != null) {
|
||||||
if (previousState is SpaceManagementLoaded ||
|
if (previousState is SpaceManagementLoaded ||
|
||||||
@ -313,6 +354,8 @@ class SpaceManagementBloc
|
|||||||
(previousState as dynamic).communities,
|
(previousState as dynamic).communities,
|
||||||
);
|
);
|
||||||
final updatedCommunities = prevCommunities..add(newCommunity);
|
final updatedCommunities = prevCommunities..add(newCommunity);
|
||||||
|
_spaceTreeBloc.add(OnCommunityAdded(newCommunity));
|
||||||
|
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
spaceModels: prevSpaceModels,
|
spaceModels: prevSpaceModels,
|
||||||
communities: updatedCommunities,
|
communities: updatedCommunities,
|
||||||
@ -407,8 +450,6 @@ class SpaceManagementBloc
|
|||||||
event.communityUuid,
|
event.communityUuid,
|
||||||
emit,
|
emit,
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
add(LoadCommunityAndSpacesEvent());
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error saving spaces: $e'));
|
emit(SpaceManagementError('Error saving spaces: $e'));
|
||||||
@ -425,13 +466,15 @@ class SpaceManagementBloc
|
|||||||
String communityUuid,
|
String communityUuid,
|
||||||
Emitter<SpaceManagementState> emit,
|
Emitter<SpaceManagementState> emit,
|
||||||
) async {
|
) async {
|
||||||
var prevSpaceModels = await fetchSpaceModels(previousState);
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
|
|
||||||
final communities = List<CommunityModel>.from(previousState.communities);
|
final communities = List<CommunityModel>.from(previousState.communities);
|
||||||
|
|
||||||
for (var community in communities) {
|
for (var community in communities) {
|
||||||
if (community.uuid == communityUuid) {
|
if (community.uuid == communityUuid) {
|
||||||
community.spaces = allSpaces;
|
community.spaces = allSpaces;
|
||||||
|
_spaceTreeBloc.add(OnCommunityUpdated(community));
|
||||||
|
|
||||||
emit(SpaceManagementLoaded(
|
emit(SpaceManagementLoaded(
|
||||||
communities: communities,
|
communities: communities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
@ -483,13 +526,15 @@ class SpaceManagementBloc
|
|||||||
.any((subspace) => subspace.uuid == prevSubspace.uuid);
|
.any((subspace) => subspace.uuid == prevSubspace.uuid);
|
||||||
if (!existsInNew) {
|
if (!existsInNew) {
|
||||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||||
action: Action.delete, uuid: prevSubspace.uuid));
|
action: custom_action.Action.delete,
|
||||||
|
uuid: prevSubspace.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (prevSubspaces != null && newSubspaces == null) {
|
} else if (prevSubspaces != null && newSubspaces == null) {
|
||||||
for (var prevSubspace in prevSubspaces) {
|
for (var prevSubspace in prevSubspaces) {
|
||||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||||
action: Action.delete, uuid: prevSubspace.uuid));
|
action: custom_action.Action.delete,
|
||||||
|
uuid: prevSubspace.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -502,14 +547,14 @@ class SpaceManagementBloc
|
|||||||
if (newSubspace.tags != null) {
|
if (newSubspace.tags != null) {
|
||||||
for (var tag in newSubspace.tags!) {
|
for (var tag in newSubspace.tags!) {
|
||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.add,
|
action: custom_action.Action.add,
|
||||||
uuid: tag.uuid == '' ? null : tag.uuid,
|
uuid: tag.uuid == '' ? null : tag.uuid,
|
||||||
tag: tag.tag,
|
tag: tag.tag,
|
||||||
productUuid: tag.product?.uuid));
|
productUuid: tag.product?.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||||
action: Action.add,
|
action: custom_action.Action.add,
|
||||||
subspaceName: newSubspace.subspaceName,
|
subspaceName: newSubspace.subspaceName,
|
||||||
tags: tagUpdates));
|
tags: tagUpdates));
|
||||||
}
|
}
|
||||||
@ -528,7 +573,7 @@ class SpaceManagementBloc
|
|||||||
final List<TagModelUpdate> tagSubspaceUpdates =
|
final List<TagModelUpdate> tagSubspaceUpdates =
|
||||||
processTagUpdates(prevSubspace.tags, newSubspace.tags);
|
processTagUpdates(prevSubspace.tags, newSubspace.tags);
|
||||||
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
subspaceUpdates.add(UpdateSubspaceTemplateModel(
|
||||||
action: Action.update,
|
action: custom_action.Action.update,
|
||||||
uuid: newSubspace.uuid,
|
uuid: newSubspace.uuid,
|
||||||
subspaceName: newSubspace.subspaceName,
|
subspaceName: newSubspace.subspaceName,
|
||||||
tags: tagSubspaceUpdates));
|
tags: tagSubspaceUpdates));
|
||||||
@ -615,35 +660,42 @@ class SpaceManagementBloc
|
|||||||
void _onLoadSpaceModel(
|
void _onLoadSpaceModel(
|
||||||
SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
|
SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
|
||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var prevState = state;
|
var prevState = state;
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||||
|
List<CommunityModel> communities = spaceBloc.state.communityList;
|
||||||
|
|
||||||
List<CommunityModel> communities =
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
await _api.fetchCommunities(projectUuid);
|
|
||||||
|
|
||||||
List<CommunityModel> updatedCommunities = await Future.wait(
|
if (communities.isEmpty) {
|
||||||
communities.map((community) async {
|
communities = await _api.fetchCommunities(projectUuid);
|
||||||
List<SpaceModel> spaces =
|
|
||||||
await _fetchSpacesForCommunity(community.uuid);
|
|
||||||
return CommunityModel(
|
|
||||||
uuid: community.uuid,
|
|
||||||
createdAt: community.createdAt,
|
|
||||||
updatedAt: community.updatedAt,
|
|
||||||
name: community.name,
|
|
||||||
description: community.description,
|
|
||||||
spaces: spaces, // New spaces list
|
|
||||||
region: community.region,
|
|
||||||
);
|
|
||||||
}).toList(),
|
|
||||||
);
|
|
||||||
|
|
||||||
var prevSpaceModels = await fetchSpaceModels(prevState);
|
List<CommunityModel> updatedCommunities = await Future.wait(
|
||||||
|
communities.map((community) async {
|
||||||
|
List<SpaceModel> spaces =
|
||||||
|
await _fetchSpacesForCommunity(community.uuid);
|
||||||
|
return CommunityModel(
|
||||||
|
uuid: community.uuid,
|
||||||
|
createdAt: community.createdAt,
|
||||||
|
updatedAt: community.updatedAt,
|
||||||
|
name: community.name,
|
||||||
|
description: community.description,
|
||||||
|
spaces: spaces,
|
||||||
|
region: community.region,
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
);
|
||||||
|
|
||||||
|
communities = updatedCommunities;
|
||||||
|
}
|
||||||
|
|
||||||
emit(SpaceModelLoaded(
|
emit(SpaceModelLoaded(
|
||||||
communities: updatedCommunities,
|
communities: communities,
|
||||||
products: _cachedProducts ?? [],
|
products: _cachedProducts ?? [],
|
||||||
spaceModels: prevSpaceModels));
|
spaceModels: prevSpaceModels,
|
||||||
|
));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
emit(SpaceManagementError('Error loading communities and spaces: $e'));
|
||||||
}
|
}
|
||||||
@ -659,7 +711,7 @@ class SpaceManagementBloc
|
|||||||
if (prevTags == null && newTags != null) {
|
if (prevTags == null && newTags != null) {
|
||||||
for (var newTag in newTags) {
|
for (var newTag in newTags) {
|
||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.add,
|
action: custom_action.Action.add,
|
||||||
tag: newTag.tag,
|
tag: newTag.tag,
|
||||||
uuid: newTag.uuid,
|
uuid: newTag.uuid,
|
||||||
productUuid: newTag.product?.uuid,
|
productUuid: newTag.product?.uuid,
|
||||||
@ -675,14 +727,14 @@ class SpaceManagementBloc
|
|||||||
final existsInNew =
|
final existsInNew =
|
||||||
newTags.any((newTag) => newTag.uuid == prevTag.uuid);
|
newTags.any((newTag) => newTag.uuid == prevTag.uuid);
|
||||||
if (!existsInNew) {
|
if (!existsInNew) {
|
||||||
tagUpdates
|
tagUpdates.add(TagModelUpdate(
|
||||||
.add(TagModelUpdate(action: Action.delete, uuid: prevTag.uuid));
|
action: custom_action.Action.delete, uuid: prevTag.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (prevTags != null && newTags == null) {
|
} else if (prevTags != null && newTags == null) {
|
||||||
for (var prevTag in prevTags) {
|
for (var prevTag in prevTags) {
|
||||||
tagUpdates
|
tagUpdates.add(TagModelUpdate(
|
||||||
.add(TagModelUpdate(action: Action.delete, uuid: prevTag.uuid));
|
action: custom_action.Action.delete, uuid: prevTag.uuid));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -695,7 +747,7 @@ class SpaceManagementBloc
|
|||||||
if ((newTag.uuid == null || !prevTagUuids.contains(newTag.uuid)) &&
|
if ((newTag.uuid == null || !prevTagUuids.contains(newTag.uuid)) &&
|
||||||
!processedTags.contains(newTag.tag)) {
|
!processedTags.contains(newTag.tag)) {
|
||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.add,
|
action: custom_action.Action.add,
|
||||||
tag: newTag.tag,
|
tag: newTag.tag,
|
||||||
uuid: newTag.uuid == '' ? null : newTag.uuid,
|
uuid: newTag.uuid == '' ? null : newTag.uuid,
|
||||||
productUuid: newTag.product?.uuid));
|
productUuid: newTag.product?.uuid));
|
||||||
@ -712,7 +764,7 @@ class SpaceManagementBloc
|
|||||||
final newTag = newTagMap[prevTag.uuid];
|
final newTag = newTagMap[prevTag.uuid];
|
||||||
if (newTag != null) {
|
if (newTag != null) {
|
||||||
tagUpdates.add(TagModelUpdate(
|
tagUpdates.add(TagModelUpdate(
|
||||||
action: Action.update,
|
action: custom_action.Action.update,
|
||||||
uuid: newTag.uuid,
|
uuid: newTag.uuid,
|
||||||
tag: newTag.tag,
|
tag: newTag.tag,
|
||||||
));
|
));
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
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'; // Import for Offset
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart'; // Import for Offset
|
||||||
|
|
||||||
abstract class SpaceManagementEvent extends Equatable {
|
abstract class SpaceManagementEvent extends Equatable {
|
||||||
const SpaceManagementEvent();
|
const SpaceManagementEvent();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [];
|
List<Object?> get props => [];
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadCommunityAndSpacesEvent extends SpaceManagementEvent {}
|
class LoadCommunityAndSpacesEvent extends SpaceManagementEvent {
|
||||||
|
final BuildContext context;
|
||||||
|
|
||||||
|
const LoadCommunityAndSpacesEvent(this.context);
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [context];
|
||||||
|
}
|
||||||
|
|
||||||
class DeleteCommunityEvent extends SpaceManagementEvent {
|
class DeleteCommunityEvent extends SpaceManagementEvent {
|
||||||
final String communityUuid;
|
final String communityUuid;
|
||||||
@ -74,14 +81,12 @@ class UpdateSpacePositionEvent extends SpaceManagementEvent {
|
|||||||
class CreateCommunityEvent extends SpaceManagementEvent {
|
class CreateCommunityEvent extends SpaceManagementEvent {
|
||||||
final String name;
|
final String name;
|
||||||
final String description;
|
final String description;
|
||||||
|
final BuildContext context;
|
||||||
|
|
||||||
const CreateCommunityEvent({
|
const CreateCommunityEvent(this.name, this.description, this.context);
|
||||||
required this.name,
|
|
||||||
required this.description,
|
|
||||||
});
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [name, description];
|
List<Object?> get props => [name, description, context];
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateCommunityEvent extends SpaceManagementEvent {
|
class UpdateCommunityEvent extends SpaceManagementEvent {
|
||||||
@ -141,7 +146,28 @@ class LoadSpaceHierarchyEvent extends SpaceManagementEvent {
|
|||||||
List<Object> get props => [communityId];
|
List<Object> get props => [communityId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class BlankStateEvent extends SpaceManagementEvent {
|
||||||
|
final BuildContext context;
|
||||||
|
|
||||||
class BlankStateEvent extends SpaceManagementEvent {}
|
const BlankStateEvent(this.context);
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [context];
|
||||||
|
}
|
||||||
|
|
||||||
class SpaceModelLoadEvent extends SpaceManagementEvent {}
|
class SpaceModelLoadEvent extends SpaceManagementEvent {
|
||||||
|
final BuildContext context;
|
||||||
|
|
||||||
|
const SpaceModelLoadEvent(this.context);
|
||||||
|
@override
|
||||||
|
List<Object?> get props => [context];
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpdateSpaceModelCache extends SpaceManagementEvent {
|
||||||
|
final SpaceTemplateModel updatedModel;
|
||||||
|
UpdateSpaceModelCache(this.updatedModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
class DeleteSpaceModelFromCache extends SpaceManagementEvent {
|
||||||
|
final String deletedUuid;
|
||||||
|
DeleteSpaceModelFromCache(this.deletedUuid);
|
||||||
|
}
|
@ -30,10 +30,6 @@ class SpaceManagementLoaded extends SpaceManagementState {
|
|||||||
this.spaceModels});
|
this.spaceModels});
|
||||||
}
|
}
|
||||||
|
|
||||||
class SpaceModelManagenetLoaded extends SpaceManagementState {
|
|
||||||
SpaceModelManagenetLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
class BlankState extends SpaceManagementState {
|
class BlankState extends SpaceManagementState {
|
||||||
final List<CommunityModel> communities;
|
final List<CommunityModel> communities;
|
||||||
final List<ProductModel> products;
|
final List<ProductModel> products;
|
||||||
@ -75,3 +71,4 @@ class SpaceModelLoaded extends SpaceManagementState {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [communities, products, spaceModels];
|
List<Object> get props => [communities, products, spaceModels];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/navigate_home_grid_view.dart';
|
||||||
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/structure_selector/bloc/center_body_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||||
@ -29,14 +32,15 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
return MultiBlocProvider(
|
return MultiBlocProvider(
|
||||||
providers: [
|
providers: [
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (_) => SpaceManagementBloc(
|
create: (context) => SpaceManagementBloc(
|
||||||
_api,
|
_api,
|
||||||
_productApi,
|
_productApi,
|
||||||
_spaceModelApi,
|
_spaceModelApi,
|
||||||
)..add(LoadCommunityAndSpacesEvent()),
|
BlocProvider.of<SpaceTreeBloc>(context),
|
||||||
|
)..add(LoadCommunityAndSpacesEvent(this.context)),
|
||||||
),
|
),
|
||||||
BlocProvider(
|
BlocProvider(
|
||||||
create: (_) => CenterBodyBloc(),
|
create: (context) => CenterBodyBloc(),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
child: WebScaffold(
|
child: WebScaffold(
|
||||||
@ -60,6 +64,7 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
|||||||
shouldNavigateToSpaceModelPage: false,
|
shouldNavigateToSpaceModelPage: false,
|
||||||
);
|
);
|
||||||
} else if (state is SpaceManagementLoaded) {
|
} else if (state is SpaceManagementLoaded) {
|
||||||
|
|
||||||
return LoadedSpaceView(
|
return LoadedSpaceView(
|
||||||
communities: state.communities,
|
communities: state.communities,
|
||||||
selectedCommunity: state.selectedCommunity,
|
selectedCommunity: state.selectedCommunity,
|
||||||
|
@ -73,17 +73,14 @@ class _BlankCommunityWidgetState extends State<BlankCommunityWidget> {
|
|||||||
context: parentContext,
|
context: parentContext,
|
||||||
builder: (context) => CreateCommunityDialog(
|
builder: (context) => CreateCommunityDialog(
|
||||||
isEditMode: false,
|
isEditMode: false,
|
||||||
existingCommunityNames: widget.communities.map((community) => community.name).toList(),
|
existingCommunityNames:
|
||||||
|
widget.communities.map((community) => community.name).toList(),
|
||||||
onCreateCommunity: (String communityName, String description) {
|
onCreateCommunity: (String communityName, String description) {
|
||||||
parentContext.read<SpaceManagementBloc>().add(
|
parentContext.read<SpaceManagementBloc>().add(
|
||||||
CreateCommunityEvent(
|
CreateCommunityEvent(communityName, description, context),
|
||||||
name: communityName,
|
|
||||||
description: description,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,15 +21,17 @@ class CommunityTile extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CustomExpansionTile(
|
return Padding(
|
||||||
title: title,
|
padding: const EdgeInsets.only(left: 16.0),
|
||||||
initiallyExpanded: isExpanded,
|
child: CustomExpansionTile(
|
||||||
isSelected: isSelected,
|
title: title,
|
||||||
onExpansionChanged: (bool expanded) {
|
initiallyExpanded: isExpanded,
|
||||||
onExpansionChanged(title, expanded);
|
isSelected: isSelected,
|
||||||
},
|
onExpansionChanged: (bool expanded) {
|
||||||
onItemSelected: onItemSelected,
|
onExpansionChanged(title, expanded);
|
||||||
children: children ?? [],
|
},
|
||||||
);
|
onItemSelected: onItemSelected,
|
||||||
|
children: children ?? [],
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,6 +40,7 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
_spaceModels = List.from(widget.spaceModels ?? []);
|
_spaceModels = List.from(widget.spaceModels ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,6 +48,7 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
@override
|
@override
|
||||||
void didUpdateWidget(covariant LoadedSpaceView oldWidget) {
|
void didUpdateWidget(covariant LoadedSpaceView oldWidget) {
|
||||||
super.didUpdateWidget(oldWidget);
|
super.didUpdateWidget(oldWidget);
|
||||||
|
|
||||||
if (widget.spaceModels != oldWidget.spaceModels) {
|
if (widget.spaceModels != oldWidget.spaceModels) {
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
@ -76,29 +78,33 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
clipBehavior: Clip.none,
|
clipBehavior: Clip.none,
|
||||||
children: [
|
children: [
|
||||||
widget.shouldNavigateToSpaceModelPage
|
widget.shouldNavigateToSpaceModelPage
|
||||||
? Row(
|
? _spaceModels.isNotEmpty
|
||||||
children: [
|
? Row(
|
||||||
SizedBox(width: 300, child: SpaceTreeView(onSelect: () {})),
|
children: [
|
||||||
Expanded(
|
SizedBox(
|
||||||
child: BlocProvider(
|
width: 300, child: SpaceTreeView(onSelect: () {})),
|
||||||
create: (context) => SpaceModelBloc(
|
Expanded(
|
||||||
api: SpaceModelManagementApi(),
|
child: BlocProvider(
|
||||||
initialSpaceModels: _spaceModels,
|
create: (context) => SpaceModelBloc(
|
||||||
|
api: SpaceModelManagementApi(),
|
||||||
|
initialSpaceModels: _spaceModels,
|
||||||
|
),
|
||||||
|
child: SpaceModelPage(
|
||||||
|
products: widget.products,
|
||||||
|
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
child: SpaceModelPage(
|
],
|
||||||
products: widget.products,
|
)
|
||||||
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
: const Center(child: CircularProgressIndicator())
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
: Row(
|
: Row(
|
||||||
children: [
|
children: [
|
||||||
SidebarWidget(
|
SidebarWidget(
|
||||||
communities: widget.communities,
|
communities: widget.communities,
|
||||||
selectedSpaceUuid:
|
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
||||||
widget.selectedSpace?.uuid ?? widget.selectedCommunity?.uuid ?? '',
|
widget.selectedCommunity?.uuid ??
|
||||||
|
'',
|
||||||
),
|
),
|
||||||
CommunityStructureArea(
|
CommunityStructureArea(
|
||||||
selectedCommunity: widget.selectedCommunity,
|
selectedCommunity: widget.selectedCommunity,
|
||||||
|
@ -9,9 +9,6 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model
|
|||||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
||||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||||
import 'package:syncrow_web/utils/constants/action_enum.dart';
|
import 'package:syncrow_web/utils/constants/action_enum.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';
|
|
||||||
|
|
||||||
class CreateSpaceModelBloc
|
class CreateSpaceModelBloc
|
||||||
extends Bloc<CreateSpaceModelEvent, CreateSpaceModelState> {
|
extends Bloc<CreateSpaceModelEvent, CreateSpaceModelState> {
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
|
||||||
@ -12,6 +14,8 @@ class SpaceModelBloc extends Bloc<SpaceModelEvent, SpaceModelState> {
|
|||||||
required this.api,
|
required this.api,
|
||||||
required List<SpaceTemplateModel> initialSpaceModels,
|
required List<SpaceTemplateModel> initialSpaceModels,
|
||||||
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
}) : super(SpaceModelLoaded(spaceModels: initialSpaceModels)) {
|
||||||
|
log('Initial Space Models in: ${initialSpaceModels.map((e) => e.toJson()).toList()}');
|
||||||
|
|
||||||
on<CreateSpaceModel>(_onCreateSpaceModel);
|
on<CreateSpaceModel>(_onCreateSpaceModel);
|
||||||
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
on<UpdateSpaceModel>(_onUpdateSpaceModel);
|
||||||
on<DeleteSpaceModel>(_onDeleteSpaceModel);
|
on<DeleteSpaceModel>(_onDeleteSpaceModel);
|
||||||
|
@ -2,6 +2,8 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/cancel_button.dart';
|
||||||
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
import 'package:syncrow_web/pages/common/buttons/default_button.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/create_space_model_event.dart';
|
||||||
@ -196,6 +198,12 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
.add(CreateSpaceModel(
|
.add(CreateSpaceModel(
|
||||||
newSpaceModel:
|
newSpaceModel:
|
||||||
newModel));
|
newModel));
|
||||||
|
pageContext!
|
||||||
|
.read<
|
||||||
|
SpaceManagementBloc>()
|
||||||
|
.add(
|
||||||
|
UpdateSpaceModelCache(
|
||||||
|
newModel));
|
||||||
}
|
}
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.pop(); // Close the dialog
|
.pop(); // Close the dialog
|
||||||
@ -241,6 +249,11 @@ class CreateSpaceModelDialog extends StatelessWidget {
|
|||||||
spaceModelUuid:
|
spaceModelUuid:
|
||||||
newModel.uuid ??
|
newModel.uuid ??
|
||||||
''));
|
''));
|
||||||
|
pageContext!
|
||||||
|
.read<
|
||||||
|
SpaceManagementBloc>()
|
||||||
|
.add(UpdateSpaceModelCache(
|
||||||
|
newModel));
|
||||||
}
|
}
|
||||||
Navigator.of(context)
|
Navigator.of(context)
|
||||||
.pop();
|
.pop();
|
||||||
|
@ -4,14 +4,15 @@ import 'package:flutter_svg/svg.dart';
|
|||||||
import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_bloc.dart';
|
import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_event.dart';
|
import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_event.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_state.dart';
|
import 'package:syncrow_web/pages/spaces_management/link_space_model/bloc/link_space_to_model_state.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_bloc.dart';
|
||||||
|
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.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/space_template_model.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/custom_loading_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/custom_loading_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/link_space_model_spaces_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/link_space_model_spaces_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/linking_attention_dialog.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/linking_successful.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/linking_successful.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/overwrite_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/overwrite_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_bloc.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/bloc/space_model_event.dart';
|
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/delete_space_model_dialog.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dialog/delete_space_model_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_product_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_product_widget.dart';
|
||||||
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_room_widget.dart';
|
import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_room_widget.dart';
|
||||||
@ -312,6 +313,10 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
pageContext!.read<SpaceModelBloc>().add(
|
pageContext!.read<SpaceModelBloc>().add(
|
||||||
DeleteSpaceModel(spaceModelUuid: model.uuid ?? ''),
|
DeleteSpaceModel(spaceModelUuid: model.uuid ?? ''),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
pageContext!.read<SpaceManagementBloc>().add(
|
||||||
|
DeleteSpaceModelFromCache(model.uuid ?? ''),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -15,11 +15,11 @@ class CenterBodyWidget extends StatelessWidget {
|
|||||||
context.read<CenterBodyBloc>().add(CommunityStructureSelectedEvent());
|
context.read<CenterBodyBloc>().add(CommunityStructureSelectedEvent());
|
||||||
}
|
}
|
||||||
if (state is CommunityStructureState) {
|
if (state is CommunityStructureState) {
|
||||||
context.read<SpaceManagementBloc>().add(BlankStateEvent());
|
context.read<SpaceManagementBloc>().add(BlankStateEvent(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state is SpaceModelState) {
|
if (state is SpaceModelState) {
|
||||||
context.read<SpaceManagementBloc>().add(SpaceModelLoadEvent());
|
context.read<SpaceManagementBloc>().add(SpaceModelLoadEvent(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
|
Reference in New Issue
Block a user