mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
fixed issues in the space tree
This commit is contained in:
@ -8,7 +8,7 @@ import 'package:syncrow_web/pages/device_managment/all_devices/models/devices_mo
|
|||||||
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_search_filters.dart';
|
import 'package:syncrow_web/pages/device_managment/all_devices/widgets/device_search_filters.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/device_batch_control_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart';
|
import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/view/side_tree_view.dart';
|
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
||||||
import 'package:syncrow_web/utils/format_date_time.dart';
|
import 'package:syncrow_web/utils/format_date_time.dart';
|
||||||
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
@ -63,7 +63,7 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
|||||||
return Row(
|
return Row(
|
||||||
children: [
|
children: [
|
||||||
const Expanded(
|
const Expanded(
|
||||||
child: SideTreeView(
|
child: SpaceTreeView(
|
||||||
// onSelectAction: (String communityId, String spaceId) {
|
// onSelectAction: (String communityId, String spaceId) {
|
||||||
// context.read<DeviceManagementBloc>().add(FetchDevices(communityId, spaceId));
|
// context.read<DeviceManagementBloc>().add(FetchDevices(communityId, spaceId));
|
||||||
// },
|
// },
|
||||||
|
@ -5,7 +5,7 @@ import 'package:syncrow_web/pages/routines/view/create_new_routine_view.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart';
|
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/fetch_routine_scenes_automation.dart';
|
||||||
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart';
|
import 'package:syncrow_web/pages/routines/widgets/main_routine_view/routine_view_card.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/view/side_tree_view.dart';
|
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/snack_bar.dart';
|
import 'package:syncrow_web/utils/snack_bar.dart';
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
// // ..add(LoadAutomation(spaceId));
|
// // ..add(LoadAutomation(spaceId));
|
||||||
// },
|
// },
|
||||||
// )
|
// )
|
||||||
SideTreeView()),
|
SpaceTreeView()),
|
||||||
Expanded(
|
Expanded(
|
||||||
flex: 3,
|
flex: 3,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
|
@ -83,9 +83,10 @@ 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.from(state.selectedCommunities);
|
List<String> updatedSelectedCommunities =
|
||||||
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces);
|
List.from(state.selectedCommunities.toSet().toList());
|
||||||
List<String> updatedSoldChecks = List.from(state.soldCheck);
|
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
||||||
|
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||||
|
|
||||||
List<String> childrenIds = _getAllChildIds(event.children);
|
List<String> childrenIds = _getAllChildIds(event.children);
|
||||||
|
|
||||||
@ -111,13 +112,19 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
|
|
||||||
_onSpaceSelected(OnSpaceSelected event, Emitter<SpaceTreeState> emit) async {
|
_onSpaceSelected(OnSpaceSelected event, Emitter<SpaceTreeState> emit) async {
|
||||||
try {
|
try {
|
||||||
List<String> updatedSelectedCommunities = List.from(state.selectedCommunities);
|
List<String> updatedSelectedCommunities =
|
||||||
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces);
|
List.from(state.selectedCommunities.toSet().toList());
|
||||||
List<String> updatedSoldChecks = List.from(state.soldCheck);
|
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
||||||
|
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||||
|
|
||||||
List<String> childrenIds = _getAllChildIds(event.children);
|
List<String> childrenIds = _getAllChildIds(event.children);
|
||||||
|
bool isChildSelected = false;
|
||||||
|
|
||||||
// List<String> childrenIds = _getAllChildSpaceIds(event.communityId);
|
for (String id in childrenIds) {
|
||||||
|
if (updatedSelectedSpaces.contains(id)) {
|
||||||
|
isChildSelected = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!updatedSelectedSpaces.contains(event.spaceId) &&
|
if (!updatedSelectedSpaces.contains(event.spaceId) &&
|
||||||
!updatedSoldChecks.contains(event.spaceId)) {
|
!updatedSoldChecks.contains(event.spaceId)) {
|
||||||
@ -127,20 +134,36 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
if (childrenIds.isNotEmpty) {
|
if (childrenIds.isNotEmpty) {
|
||||||
updatedSelectedSpaces.addAll(childrenIds);
|
updatedSelectedSpaces.addAll(childrenIds);
|
||||||
}
|
}
|
||||||
} else if (!updatedSoldChecks.contains(event.spaceId) && childrenIds.isNotEmpty) {
|
|
||||||
|
List<String> spaces = _getThePathToChild(event.communityId, event.spaceId);
|
||||||
|
for (String space in spaces) {
|
||||||
|
if (!updatedSelectedSpaces.contains(space) && !updatedSoldChecks.contains(space)) {
|
||||||
|
updatedSoldChecks.add(space);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!updatedSoldChecks.contains(event.spaceId) &&
|
||||||
|
childrenIds.isNotEmpty &&
|
||||||
|
isChildSelected) {
|
||||||
// Second click: Unselect space but keep children
|
// Second click: Unselect space but keep children
|
||||||
updatedSelectedSpaces.remove(event.spaceId);
|
updatedSelectedSpaces.remove(event.spaceId);
|
||||||
updatedSoldChecks.add(event.spaceId);
|
updatedSoldChecks.add(event.spaceId);
|
||||||
} else {
|
} else {
|
||||||
// Third click: Unselect space and all its children
|
// Third click: Unselect space and all its children
|
||||||
if (!_anySpacesSelectedInCommunity(event.communityId)) {
|
|
||||||
updatedSelectedCommunities.remove(event.communityId);
|
|
||||||
}
|
|
||||||
updatedSelectedSpaces.remove(event.spaceId);
|
updatedSelectedSpaces.remove(event.spaceId);
|
||||||
if (childrenIds.isNotEmpty) {
|
if (childrenIds.isNotEmpty) {
|
||||||
updatedSelectedSpaces.removeWhere(childrenIds.contains);
|
updatedSelectedSpaces.removeWhere(childrenIds.contains);
|
||||||
|
updatedSoldChecks.removeWhere(childrenIds.contains);
|
||||||
}
|
}
|
||||||
updatedSoldChecks.remove(event.spaceId);
|
updatedSoldChecks.remove(event.spaceId);
|
||||||
|
|
||||||
|
List<String> parents = _getThePathToChild(event.communityId, event.spaceId);
|
||||||
|
if (!_parentSelected(parents, updatedSelectedSpaces)) {
|
||||||
|
updatedSoldChecks.removeWhere(parents.contains);
|
||||||
|
}
|
||||||
|
if (!_anySpacesSelectedInCommunity(
|
||||||
|
event.communityId, updatedSelectedSpaces, updatedSoldChecks)) {
|
||||||
|
updatedSelectedCommunities.remove(event.communityId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit(state.copyWith(
|
emit(state.copyWith(
|
||||||
@ -153,6 +176,15 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_parentSelected(List<String> parents, List<String> selectedSpaces) {
|
||||||
|
for (String space in parents) {
|
||||||
|
if (selectedSpaces.contains(space)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
_onSearch(SearchQueryEvent event, Emitter<SpaceTreeState> emit) async {
|
_onSearch(SearchQueryEvent event, Emitter<SpaceTreeState> emit) async {
|
||||||
try {
|
try {
|
||||||
List<CommunityModel> communities = List.from(state.communityList);
|
List<CommunityModel> communities = List.from(state.communityList);
|
||||||
@ -193,17 +225,59 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _anySpacesSelectedInCommunity(String communityId) {
|
bool _anySpacesSelectedInCommunity(
|
||||||
|
String communityId, List<String> selectedSpaces, List<String> partialCheckedList) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
for (var community in state.communityList) {
|
for (var community in state.communityList) {
|
||||||
if (community.uuid == communityId) {
|
if (community.uuid == communityId) {
|
||||||
List<String> ids = _getAllChildIds(community.spaces);
|
List<String> ids = _getAllChildIds(community.spaces);
|
||||||
for (var id in ids) {
|
for (var id in ids) {
|
||||||
result = state.selectedSpaces.contains(id);
|
result = selectedSpaces.contains(id) || partialCheckedList.contains(id);
|
||||||
break;
|
if (result) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<String> _getThePathToChild(String communityId, String selectedSpaceId) {
|
||||||
|
List<String> ids = [];
|
||||||
|
for (var community in state.communityList) {
|
||||||
|
if (community.uuid == communityId) {
|
||||||
|
for (var space in community.spaces) {
|
||||||
|
List<String> list = [];
|
||||||
|
list.add(space.uuid!);
|
||||||
|
ids = _getAllParentsIds(space, selectedSpaceId, List.from(list));
|
||||||
|
if (ids.isNotEmpty) {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<String> _getAllParentsIds(SpaceModel child, String spaceId, List<String> listIds) {
|
||||||
|
List<String> ids = listIds;
|
||||||
|
|
||||||
|
ids.add(child.uuid ?? '');
|
||||||
|
|
||||||
|
if (child.uuid == spaceId) {
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (child.children.isNotEmpty) {
|
||||||
|
for (var space in child.children) {
|
||||||
|
var result = _getAllParentsIds(space, spaceId, List.from(ids));
|
||||||
|
if (result.isNotEmpty) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ids.removeLast();
|
||||||
|
return [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,8 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
|
|||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/style.dart';
|
import 'package:syncrow_web/utils/style.dart';
|
||||||
|
|
||||||
class SideTreeView extends StatelessWidget {
|
class SpaceTreeView extends StatelessWidget {
|
||||||
const SideTreeView({super.key});
|
const SpaceTreeView({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
Reference in New Issue
Block a user