mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
Compare commits
19 Commits
web_bugs_f
...
bugfix/fix
Author | SHA1 | Date | |
---|---|---|---|
af4c0f84cb | |||
c2b77ad1fc | |||
d5fcbe2601 | |||
1fa33a271f | |||
09e2564183 | |||
5dee6c2842 | |||
c5c5088724 | |||
d1d570b40f | |||
a43ff3c07d | |||
572520eed5 | |||
5e5f127a4b | |||
6f51c2d2b6 | |||
a18e8443d0 | |||
72241cba6c | |||
506531e16a | |||
ab3edbaf57 | |||
64e3fb7f34 | |||
e6e46be9b4 | |||
91dfd53477 |
@ -1,6 +1,8 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.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';
|
||||
|
||||
part 'device_managment_event.dart';
|
||||
@ -32,7 +34,20 @@ class DeviceManagementBloc extends Bloc<DeviceManagementEvent, DeviceManagementS
|
||||
Future<void> _onFetchDevices(FetchDevices event, Emitter<DeviceManagementState> emit) async {
|
||||
emit(DeviceManagementLoading());
|
||||
try {
|
||||
final devices = await DevicesManagementApi().fetchDevices(event.communityId, event.spaceId);
|
||||
List<AllDevicesModel> devices = [];
|
||||
_devices.clear();
|
||||
var spaceBloc = event.context.read<SpaceTreeBloc>();
|
||||
if (spaceBloc.state.selectedCommunities.isEmpty) {
|
||||
devices = await DevicesManagementApi().fetchDevices('', '');
|
||||
} else {
|
||||
for (var community in spaceBloc.state.selectedCommunities) {
|
||||
List<String> spacesList = spaceBloc.state.selectedCommunityAndSpaces[community] ?? [];
|
||||
for (var space in spacesList) {
|
||||
devices.addAll(await DevicesManagementApi().fetchDevices(community, space));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_selectedDevices.clear();
|
||||
_devices = devices;
|
||||
_filteredDevices = devices;
|
||||
|
@ -8,12 +8,13 @@ abstract class DeviceManagementEvent extends Equatable {
|
||||
}
|
||||
|
||||
class FetchDevices extends DeviceManagementEvent {
|
||||
final String communityId;
|
||||
final String spaceId;
|
||||
// final Map<String, List<String>> selectedCommunitiesSpaces;
|
||||
// final String spaceId;
|
||||
final BuildContext context;
|
||||
|
||||
const FetchDevices(this.communityId, this.spaceId);
|
||||
const FetchDevices(this.context);
|
||||
@override
|
||||
List<Object?> get props => [communityId, spaceId];
|
||||
List<Object?> get props => [context];
|
||||
}
|
||||
|
||||
class FilterDevices extends DeviceManagementEvent {
|
||||
|
@ -19,7 +19,7 @@ class DeviceManagementPage extends StatelessWidget with HelperResponsiveLayout {
|
||||
return MultiBlocProvider(
|
||||
providers: [
|
||||
BlocProvider(
|
||||
create: (context) => DeviceManagementBloc()..add(const FetchDevices('', '')),
|
||||
create: (context) => DeviceManagementBloc()..add(FetchDevices(context)),
|
||||
),
|
||||
],
|
||||
child: WebScaffold(
|
||||
|
@ -8,6 +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/shared/device_batch_control_dialog.dart';
|
||||
import 'package:syncrow_web/pages/device_managment/shared/device_control_dialog.dart';
|
||||
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.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/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||
@ -62,12 +63,11 @@ class DeviceManagementBody extends StatelessWidget with HelperResponsiveLayout {
|
||||
|
||||
return Row(
|
||||
children: [
|
||||
const Expanded(
|
||||
child: SpaceTreeView(
|
||||
// onSelectAction: (String communityId, String spaceId) {
|
||||
// context.read<DeviceManagementBloc>().add(FetchDevices(communityId, spaceId));
|
||||
// },
|
||||
)),
|
||||
Expanded(child: SpaceTreeView(
|
||||
onSelect: () {
|
||||
context.read<DeviceManagementBloc>().add(FetchDevices(context));
|
||||
},
|
||||
)),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: state is DeviceManagementLoading
|
||||
|
@ -85,7 +85,7 @@ class _DeviceSearchFiltersState extends State<DeviceSearchFilters> with HelperRe
|
||||
productNameController.clear();
|
||||
context.read<DeviceManagementBloc>()
|
||||
..add(ResetFilters())
|
||||
..add(const FetchDevices('', ''));
|
||||
..add(FetchDevices(context));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -816,7 +816,7 @@ class RoutineBloc extends Bloc<RoutineEvent, RoutineState> {
|
||||
FutureOr<void> _fetchDevices(FetchDevicesInRoutine event, Emitter<RoutineState> emit) async {
|
||||
emit(state.copyWith(isLoading: true));
|
||||
try {
|
||||
final devices = await DevicesManagementApi().fetchDevices(communityId, spaceId);
|
||||
final devices = await DevicesManagementApi().fetchDevices('', '');
|
||||
|
||||
emit(state.copyWith(isLoading: false, devices: devices));
|
||||
} catch (e) {
|
||||
|
@ -32,7 +32,7 @@ class _RoutinesViewState extends State<RoutinesView> {
|
||||
}
|
||||
return Row(
|
||||
children: [
|
||||
const Expanded(
|
||||
Expanded(
|
||||
child:
|
||||
// SideSpacesView(
|
||||
// onSelectAction: (String communityId, String spaceId) {
|
||||
@ -41,7 +41,9 @@ class _RoutinesViewState extends State<RoutinesView> {
|
||||
// // ..add(LoadAutomation(spaceId));
|
||||
// },
|
||||
// )
|
||||
SpaceTreeView()),
|
||||
SpaceTreeView(
|
||||
onSelect: () {},
|
||||
)),
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Padding(
|
||||
|
@ -6,8 +6,8 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model
|
||||
import 'package:syncrow_web/services/space_mana_api.dart';
|
||||
|
||||
class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
String selectedCommunityId = '';
|
||||
String selectedSpaceId = '';
|
||||
String selectedCommunityId = 'aff21a57-2f91-4e5c-b99b-0182c3ab65a9';
|
||||
String selectedSpaceId = '25c96044-fadf-44bb-93c7-3c079e527ce6';
|
||||
|
||||
SpaceTreeBloc() : super(const SpaceTreeState()) {
|
||||
on<InitialEvent>(_fetchSpaces);
|
||||
@ -87,6 +87,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
List.from(state.selectedCommunities.toSet().toList());
|
||||
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
||||
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
|
||||
|
||||
List<String> childrenIds = _getAllChildIds(event.children);
|
||||
|
||||
@ -101,10 +102,13 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
updatedSoldChecks.removeWhere(childrenIds.contains);
|
||||
}
|
||||
|
||||
communityAndSpaces[event.communityId] = updatedSelectedSpaces;
|
||||
|
||||
emit(state.copyWith(
|
||||
selectedCommunities: updatedSelectedCommunities,
|
||||
selectedSpaces: updatedSelectedSpaces,
|
||||
soldCheck: updatedSoldChecks));
|
||||
soldCheck: updatedSoldChecks,
|
||||
selectedCommunityAndSpaces: communityAndSpaces));
|
||||
} catch (e) {
|
||||
emit(const SpaceTreeErrorState('Something went wrong'));
|
||||
}
|
||||
@ -116,6 +120,7 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
List.from(state.selectedCommunities.toSet().toList());
|
||||
List<String> updatedSelectedSpaces = List.from(state.selectedSpaces.toSet().toList());
|
||||
List<String> updatedSoldChecks = List.from(state.soldCheck.toSet().toList());
|
||||
Map<String, List<String>> communityAndSpaces = Map.from(state.selectedCommunityAndSpaces);
|
||||
|
||||
List<String> childrenIds = _getAllChildIds(event.children);
|
||||
bool isChildSelected = false;
|
||||
@ -166,10 +171,13 @@ class SpaceTreeBloc extends Bloc<SpaceTreeEvent, SpaceTreeState> {
|
||||
}
|
||||
}
|
||||
|
||||
communityAndSpaces[event.communityId] = updatedSelectedSpaces;
|
||||
|
||||
emit(state.copyWith(
|
||||
selectedCommunities: updatedSelectedCommunities,
|
||||
selectedSpaces: updatedSelectedSpaces,
|
||||
soldCheck: updatedSoldChecks));
|
||||
soldCheck: updatedSoldChecks,
|
||||
selectedCommunityAndSpaces: communityAndSpaces));
|
||||
emit(state.copyWith(selectedSpaces: updatedSelectedSpaces));
|
||||
} catch (e) {
|
||||
emit(const SpaceTreeErrorState('Something went wrong'));
|
||||
|
@ -2,6 +2,7 @@ import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
|
||||
class SpaceTreeState extends Equatable {
|
||||
final Map<String, List<String>> selectedCommunityAndSpaces;
|
||||
final List<CommunityModel> communityList;
|
||||
final List<CommunityModel> filteredCommunity;
|
||||
final List<String> expandedCommunities;
|
||||
@ -19,7 +20,8 @@ class SpaceTreeState extends Equatable {
|
||||
this.selectedCommunities = const [],
|
||||
this.selectedSpaces = const [],
|
||||
this.soldCheck = const [],
|
||||
this.isSearching = false});
|
||||
this.isSearching = false,
|
||||
this.selectedCommunityAndSpaces = const {}});
|
||||
|
||||
SpaceTreeState copyWith(
|
||||
{List<CommunityModel>? communitiesList,
|
||||
@ -29,7 +31,8 @@ class SpaceTreeState extends Equatable {
|
||||
List<String>? selectedCommunities,
|
||||
List<String>? selectedSpaces,
|
||||
List<String>? soldCheck,
|
||||
bool? isSearching}) {
|
||||
bool? isSearching,
|
||||
Map<String, List<String>>? selectedCommunityAndSpaces}) {
|
||||
return SpaceTreeState(
|
||||
communityList: communitiesList ?? this.communityList,
|
||||
filteredCommunity: filteredCommunity ?? this.filteredCommunity,
|
||||
@ -38,7 +41,8 @@ class SpaceTreeState extends Equatable {
|
||||
selectedCommunities: selectedCommunities ?? this.selectedCommunities,
|
||||
selectedSpaces: selectedSpaces ?? this.selectedSpaces,
|
||||
soldCheck: soldCheck ?? this.soldCheck,
|
||||
isSearching: isSearching ?? this.isSearching);
|
||||
isSearching: isSearching ?? this.isSearching,
|
||||
selectedCommunityAndSpaces: selectedCommunityAndSpaces ?? this.selectedCommunityAndSpaces);
|
||||
}
|
||||
|
||||
@override
|
||||
@ -50,7 +54,8 @@ class SpaceTreeState extends Equatable {
|
||||
selectedCommunities,
|
||||
selectedSpaces,
|
||||
soldCheck,
|
||||
isSearching
|
||||
isSearching,
|
||||
selectedCommunityAndSpaces
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,8 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/style.dart';
|
||||
|
||||
class SpaceTreeView extends StatelessWidget {
|
||||
const SpaceTreeView({super.key});
|
||||
final Function onSelect;
|
||||
const SpaceTreeView({required this.onSelect, super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -64,6 +65,8 @@ class SpaceTreeView extends StatelessWidget {
|
||||
onItemSelected: () {
|
||||
context.read<SpaceTreeBloc>().add(
|
||||
OnCommunitySelected(community.uuid, community.spaces));
|
||||
|
||||
onSelect();
|
||||
},
|
||||
children: community.spaces.map((space) {
|
||||
return CustomExpansionTileSpaceTree(
|
||||
@ -72,6 +75,7 @@ class SpaceTreeView extends StatelessWidget {
|
||||
onItemSelected: () {
|
||||
context.read<SpaceTreeBloc>().add(OnSpaceSelected(
|
||||
community.uuid, space.uuid ?? '', space.children));
|
||||
onSelect();
|
||||
},
|
||||
onExpansionChanged: () {
|
||||
context.read<SpaceTreeBloc>().add(
|
||||
@ -109,6 +113,7 @@ class SpaceTreeView extends StatelessWidget {
|
||||
context
|
||||
.read<SpaceTreeBloc>()
|
||||
.add(OnSpaceSelected(communityId, child.uuid ?? '', child.children));
|
||||
onSelect();
|
||||
},
|
||||
onExpansionChanged: () {
|
||||
context.read<SpaceTreeBloc>().add(OnSpaceExpanded(communityId, child.uuid ?? ''));
|
||||
|
@ -87,6 +87,7 @@ class SpaceManagementBloc
|
||||
prevSpaceModels = List<SpaceTemplateModel>.from(
|
||||
(previousState as dynamic).spaceModels ?? [],
|
||||
);
|
||||
allSpaces.addAll(prevSpaceModels);
|
||||
}
|
||||
|
||||
if (prevSpaceModels.isEmpty) {
|
||||
@ -179,6 +180,7 @@ class SpaceManagementBloc
|
||||
final updatedCommunities =
|
||||
await Future.wait(communities.map((community) async {
|
||||
final spaces = await _fetchSpacesForCommunity(community.uuid);
|
||||
|
||||
return CommunityModel(
|
||||
uuid: community.uuid,
|
||||
createdAt: community.createdAt,
|
||||
|
@ -95,6 +95,9 @@ class SpaceModel {
|
||||
icon: json['icon'] ?? Assets.location,
|
||||
position: Offset(json['x'] ?? 0, json['y'] ?? 0),
|
||||
isHovered: false,
|
||||
spaceModel: json['spaceModel'] != null
|
||||
? SpaceTemplateModel.fromJson(json['spaceModel'])
|
||||
: null,
|
||||
tags: (json['tags'] as List<dynamic>?)
|
||||
?.where((item) => item is Map<String, dynamic>) // Validate type
|
||||
.map((item) => Tag.fromJson(item as Map<String, dynamic>))
|
||||
|
@ -64,11 +64,11 @@ class SpaceManagementPageState extends State<SpaceManagementPage> {
|
||||
);
|
||||
} else if (state is SpaceModelLoaded) {
|
||||
return LoadedSpaceView(
|
||||
communities: state.communities,
|
||||
products: state.products,
|
||||
spaceModels: state.spaceModels,
|
||||
shouldNavigateToSpaceModelPage: true,
|
||||
);
|
||||
communities: state.communities,
|
||||
products: state.products,
|
||||
spaceModels: state.spaceModels,
|
||||
shouldNavigateToSpaceModelPage: true,
|
||||
);
|
||||
} else if (state is SpaceManagementError) {
|
||||
return Center(child: Text('Error: ${state.errorMessage}'));
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/curved_li
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/duplicate_process_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_card_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/space_container_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/connection_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/space_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
@ -130,7 +133,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
communities: widget.communities,
|
||||
communityName: widget.selectedCommunity?.name,
|
||||
community: widget.selectedCommunity,
|
||||
isSave: isSave(spaces),
|
||||
isSave: SpaceHelper.isSave(spaces),
|
||||
isEditingName: isEditingName,
|
||||
nameController: _nameController,
|
||||
onSave: _saveSpaces,
|
||||
@ -175,7 +178,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
children: [
|
||||
for (var connection in connections)
|
||||
Opacity(
|
||||
opacity: _isHighlightedConnection(connection)
|
||||
opacity: ConnectionHelper.isHighlightedConnection(
|
||||
connection, widget.selectedSpace)
|
||||
? 1.0
|
||||
: 0.3, // Adjust opacity
|
||||
child: CustomPaint(
|
||||
@ -195,7 +199,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
screenSize,
|
||||
position:
|
||||
spaces[index].position + newPosition,
|
||||
|
||||
parentIndex: index,
|
||||
direction: direction,
|
||||
);
|
||||
@ -209,7 +212,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
},
|
||||
buildSpaceContainer: (int index) {
|
||||
final bool isHighlighted =
|
||||
_isHighlightedSpace(spaces[index]);
|
||||
SpaceHelper.isHighlightedSpace(
|
||||
spaces[index], widget.selectedSpace);
|
||||
|
||||
return Opacity(
|
||||
opacity: isHighlighted ? 1.0 : 0.3,
|
||||
@ -295,7 +299,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
return CreateSpaceDialog(
|
||||
products: widget.products,
|
||||
spaceModels: widget.spaceModels,
|
||||
allTags: _getAllTagValues(spaces),
|
||||
allTags:
|
||||
TagHelper.getAllTagValues(widget.communities, widget.spaceModels),
|
||||
parentSpace: parentIndex != null ? spaces[parentIndex] : null,
|
||||
onCreateSpace: (String name,
|
||||
String icon,
|
||||
@ -306,7 +311,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
setState(() {
|
||||
// Set the first space in the center or use passed position
|
||||
Offset centerPosition =
|
||||
position ?? _getCenterPosition(screenSize);
|
||||
position ?? ConnectionHelper.getCenterPosition(screenSize);
|
||||
SpaceModel newSpace = SpaceModel(
|
||||
name: name,
|
||||
icon: icon,
|
||||
@ -351,11 +356,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
spaceModels: widget.spaceModels,
|
||||
name: widget.selectedSpace!.name,
|
||||
icon: widget.selectedSpace!.icon,
|
||||
parentSpace: SpaceHelper.findSpaceByInternalId(
|
||||
widget.selectedSpace?.parent?.internalId, spaces),
|
||||
editSpace: widget.selectedSpace,
|
||||
currentSpaceModel: widget.selectedSpace?.spaceModel,
|
||||
tags: widget.selectedSpace?.tags,
|
||||
subspaces: widget.selectedSpace?.subspaces,
|
||||
isEdit: true,
|
||||
allTags: _getAllTagValues(spaces),
|
||||
allTags: TagHelper.getAllTagValues(
|
||||
widget.communities, widget.spaceModels),
|
||||
onCreateSpace: (String name,
|
||||
String icon,
|
||||
List<SelectedProduct> selectedProducts,
|
||||
@ -374,6 +383,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
widget.selectedSpace!.status =
|
||||
SpaceStatus.modified; // Mark as modified
|
||||
}
|
||||
|
||||
for (var space in spaces) {
|
||||
if (space.internalId == widget.selectedSpace?.internalId) {
|
||||
space.status = SpaceStatus.modified;
|
||||
space.subspaces = subspaces;
|
||||
space.tags = tags;
|
||||
space.name = name;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
key: Key(widget.selectedSpace!.name),
|
||||
@ -452,7 +470,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
}).toList();
|
||||
|
||||
if (spacesToSave.isEmpty) {
|
||||
debugPrint("No new or modified spaces to save.");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -516,17 +533,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
);
|
||||
}
|
||||
|
||||
bool _isHighlightedSpace(SpaceModel space) {
|
||||
final selectedSpace = widget.selectedSpace;
|
||||
if (selectedSpace == null) return true;
|
||||
|
||||
return space == selectedSpace ||
|
||||
selectedSpace.parent?.internalId == space.internalId ||
|
||||
selectedSpace.children
|
||||
?.any((child) => child.internalId == space.internalId) ==
|
||||
true;
|
||||
}
|
||||
|
||||
void _deselectSpace(BuildContext context) {
|
||||
context.read<SpaceManagementBloc>().add(
|
||||
SelectSpaceEvent(
|
||||
@ -534,28 +540,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
);
|
||||
}
|
||||
|
||||
bool _isHighlightedConnection(Connection connection) {
|
||||
if (widget.selectedSpace == null) return true;
|
||||
|
||||
return connection.startSpace == widget.selectedSpace ||
|
||||
connection.endSpace == widget.selectedSpace;
|
||||
}
|
||||
|
||||
Offset _getCenterPosition(Size screenSize) {
|
||||
return Offset(
|
||||
screenSize.width / 2 - 260,
|
||||
screenSize.height / 2 - 200,
|
||||
);
|
||||
}
|
||||
|
||||
bool isSave(List<SpaceModel> spaces) {
|
||||
return spaces.isNotEmpty &&
|
||||
spaces.any((space) =>
|
||||
space.status == SpaceStatus.newSpace ||
|
||||
space.status == SpaceStatus.modified ||
|
||||
space.status == SpaceStatus.deleted);
|
||||
}
|
||||
|
||||
void _onDuplicate(BuildContext parentContext) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
@ -641,17 +625,10 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
const double horizontalGap = 200.0;
|
||||
const double verticalGap = 100.0;
|
||||
|
||||
final Map<String, int> nameCounters = {};
|
||||
|
||||
String _generateCopyName(String originalName) {
|
||||
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
|
||||
nameCounters[baseName] = (nameCounters[baseName] ?? 0) + 1;
|
||||
return "$baseName(${nameCounters[baseName]})";
|
||||
}
|
||||
|
||||
SpaceModel duplicateRecursive(SpaceModel original, Offset parentPosition,
|
||||
SpaceModel? duplicatedParent) {
|
||||
Offset newPosition = parentPosition + Offset(horizontalGap, 0);
|
||||
Offset newPosition =
|
||||
Offset(parentPosition.dx + horizontalGap, original.position.dy);
|
||||
|
||||
while (spaces.any((s) =>
|
||||
(s.position - newPosition).distance < horizontalGap &&
|
||||
@ -659,7 +636,18 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
newPosition += Offset(horizontalGap, 0);
|
||||
}
|
||||
|
||||
final duplicatedName = _generateCopyName(original.name);
|
||||
final duplicatedName =
|
||||
SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||
|
||||
final List<SubspaceModel>? duplicatedSubspaces;
|
||||
final List<Tag>? duplicatedTags;
|
||||
if (original.spaceModel != null) {
|
||||
duplicatedTags = [];
|
||||
duplicatedSubspaces = [];
|
||||
} else {
|
||||
duplicatedTags = original.tags;
|
||||
duplicatedSubspaces = original.subspaces;
|
||||
}
|
||||
|
||||
final duplicated = SpaceModel(
|
||||
name: duplicatedName,
|
||||
@ -670,8 +658,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
status: SpaceStatus.newSpace,
|
||||
parent: duplicatedParent,
|
||||
spaceModel: original.spaceModel,
|
||||
subspaces: original.subspaces,
|
||||
tags: original.tags,
|
||||
subspaces: duplicatedSubspaces,
|
||||
tags: duplicatedTags,
|
||||
);
|
||||
|
||||
originalToDuplicate[original] = duplicated;
|
||||
@ -684,7 +672,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
final newConnection = Connection(
|
||||
startSpace: duplicatedParent,
|
||||
endSpace: duplicated,
|
||||
direction: "down",
|
||||
direction: original.incomingConnection?.direction ?? 'down',
|
||||
);
|
||||
connections.add(newConnection);
|
||||
duplicated.incomingConnection = newConnection;
|
||||
@ -723,10 +711,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
child.incomingConnection?.direction == "down" ?? false;
|
||||
|
||||
if (isDownDirection && childrenWithDownDirection.length == 1) {
|
||||
// Place the only "down" child vertically aligned with the parent
|
||||
childStartPosition = duplicated.position + Offset(0, verticalGap);
|
||||
} else if (!isDownDirection) {
|
||||
// Position children with other directions horizontally
|
||||
childStartPosition = duplicated.position + Offset(horizontalGap, 0);
|
||||
}
|
||||
|
||||
@ -747,14 +733,4 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
duplicateRecursive(space, space.position, duplicatedParent);
|
||||
}
|
||||
}
|
||||
|
||||
List<String> _getAllTagValues(List<SpaceModel> spaces) {
|
||||
final List<String> allTags = [];
|
||||
for (final space in spaces) {
|
||||
if (space.tags != null) {
|
||||
allTags.addAll(space.listAllTagValues());
|
||||
}
|
||||
}
|
||||
return allTags;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/widgets/dialogs/icon_selection_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/assign_tag/views/assign_tag_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/create_subspace/views/create_subspace_model_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/space_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/helper/tag_helper.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/link_space_model/view/link_space_model_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
@ -40,6 +41,7 @@ class CreateSpaceDialog extends StatefulWidget {
|
||||
final List<SubspaceModel>? subspaces;
|
||||
final List<Tag>? tags;
|
||||
final List<String>? allTags;
|
||||
final SpaceTemplateModel? currentSpaceModel;
|
||||
|
||||
const CreateSpaceDialog(
|
||||
{super.key,
|
||||
@ -54,7 +56,8 @@ class CreateSpaceDialog extends StatefulWidget {
|
||||
this.selectedProducts = const [],
|
||||
this.spaceModels,
|
||||
this.subspaces,
|
||||
this.tags});
|
||||
this.tags,
|
||||
this.currentSpaceModel});
|
||||
|
||||
@override
|
||||
CreateSpaceDialogState createState() => CreateSpaceDialogState();
|
||||
@ -81,12 +84,22 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
widget.selectedProducts.isNotEmpty ? widget.selectedProducts : [];
|
||||
isOkButtonEnabled =
|
||||
enteredName.isNotEmpty || nameController.text.isNotEmpty;
|
||||
tags = widget.tags ?? [];
|
||||
subspaces = widget.subspaces ?? [];
|
||||
if (widget.currentSpaceModel != null) {
|
||||
subspaces = [];
|
||||
tags = [];
|
||||
} else {
|
||||
tags = widget.tags ?? [];
|
||||
subspaces = widget.subspaces ?? [];
|
||||
}
|
||||
selectedSpaceModel = widget.currentSpaceModel;
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
bool isSpaceModelDisabled = (tags != null && tags!.isNotEmpty ||
|
||||
subspaces != null && subspaces!.isNotEmpty);
|
||||
bool isTagsAndSubspaceModelDisabled = (selectedSpaceModel != null);
|
||||
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
return AlertDialog(
|
||||
title: widget.isEdit
|
||||
@ -165,7 +178,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
isNameFieldInvalid = value.isEmpty;
|
||||
|
||||
if (!isNameFieldInvalid) {
|
||||
if (_isNameConflict(value)) {
|
||||
if (SpaceHelper.isNameConflict(value, widget.parentSpace, widget.editSpace)) {
|
||||
isNameFieldExist = true;
|
||||
isOkButtonEnabled = false;
|
||||
} else {
|
||||
@ -232,11 +245,14 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
onPressed: () {
|
||||
_showLinkSpaceModelDialog(context);
|
||||
isSpaceModelDisabled
|
||||
? null
|
||||
: _showLinkSpaceModelDialog(context);
|
||||
},
|
||||
child: const ButtonContentWidget(
|
||||
child: ButtonContentWidget(
|
||||
svgAssets: Assets.link,
|
||||
label: 'Link a space model',
|
||||
disabled: isSpaceModelDisabled,
|
||||
),
|
||||
)
|
||||
: Container(
|
||||
@ -325,12 +341,15 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
overlayColor: ColorsManager.transparentColor,
|
||||
),
|
||||
onPressed: () async {
|
||||
_showSubSpaceDialog(context, enteredName, [],
|
||||
false, widget.products, subspaces);
|
||||
isTagsAndSubspaceModelDisabled
|
||||
? null
|
||||
: _showSubSpaceDialog(context, enteredName,
|
||||
[], false, widget.products, subspaces);
|
||||
},
|
||||
child: const ButtonContentWidget(
|
||||
child: ButtonContentWidget(
|
||||
icon: Icons.add,
|
||||
label: 'Create Sub Space',
|
||||
disabled: isTagsAndSubspaceModelDisabled,
|
||||
),
|
||||
)
|
||||
: SizedBox(
|
||||
@ -457,7 +476,8 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
context: context,
|
||||
builder: (context) => AssignTagDialog(
|
||||
products: widget.products,
|
||||
subspaces: widget.subspaces,
|
||||
subspaces: subspaces,
|
||||
allTags: widget.allTags,
|
||||
addedProducts: TagHelper
|
||||
.createInitialSelectedProductsForTags(
|
||||
tags ?? [], subspaces),
|
||||
@ -483,20 +503,22 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
)
|
||||
: TextButton(
|
||||
onPressed: () {
|
||||
_showTagCreateDialog(
|
||||
context,
|
||||
enteredName,
|
||||
widget.isEdit,
|
||||
widget.products,
|
||||
subspaces,
|
||||
);
|
||||
isTagsAndSubspaceModelDisabled
|
||||
? null
|
||||
: _showTagCreateDialog(
|
||||
context,
|
||||
enteredName,
|
||||
widget.isEdit,
|
||||
widget.products,
|
||||
);
|
||||
},
|
||||
style: TextButton.styleFrom(
|
||||
padding: EdgeInsets.zero,
|
||||
),
|
||||
child: const ButtonContentWidget(
|
||||
child: ButtonContentWidget(
|
||||
icon: Icons.add,
|
||||
label: 'Add Devices',
|
||||
disabled: isTagsAndSubspaceModelDisabled,
|
||||
))
|
||||
],
|
||||
),
|
||||
@ -570,15 +592,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
);
|
||||
}
|
||||
|
||||
bool _isNameConflict(String value) {
|
||||
return (widget.parentSpace?.children.any((child) => child.name == value) ??
|
||||
false) ||
|
||||
(widget.parentSpace?.name == value) ||
|
||||
(widget.editSpace?.parent?.name == value) ||
|
||||
(widget.editSpace?.children.any((child) => child.name == value) ??
|
||||
false);
|
||||
}
|
||||
|
||||
|
||||
void _showLinkSpaceModelDialog(BuildContext context) {
|
||||
showDialog(
|
||||
context: context,
|
||||
@ -617,9 +631,26 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
products: products,
|
||||
existingSubSpaces: existingSubSpaces,
|
||||
onSave: (slectedSubspaces) {
|
||||
final List<Tag> tagsToAppendToSpace = [];
|
||||
|
||||
if (slectedSubspaces != null) {
|
||||
final updatedIds =
|
||||
slectedSubspaces.map((s) => s.internalId).toSet();
|
||||
if (existingSubSpaces != null) {
|
||||
final deletedSubspaces = existingSubSpaces
|
||||
.where((s) => !updatedIds.contains(s.internalId))
|
||||
.toList();
|
||||
for (var s in deletedSubspaces) {
|
||||
if (s.tags != null) {
|
||||
tagsToAppendToSpace.addAll(s.tags!);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (slectedSubspaces != null) {
|
||||
setState(() {
|
||||
subspaces = slectedSubspaces;
|
||||
tags?.addAll(tagsToAppendToSpace);
|
||||
selectedSpaceModel = null;
|
||||
});
|
||||
}
|
||||
@ -629,7 +660,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
}
|
||||
|
||||
void _showTagCreateDialog(BuildContext context, String name, bool isEdit,
|
||||
List<ProductModel>? products, List<SubspaceModel>? subspaces) {
|
||||
List<ProductModel>? products) {
|
||||
isEdit
|
||||
? showDialog(
|
||||
context: context,
|
||||
|
@ -11,7 +11,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/space_tem
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/view/space_model_page.dart';
|
||||
import 'package:syncrow_web/services/space_model_mang_api.dart';
|
||||
|
||||
class LoadedSpaceView extends StatelessWidget {
|
||||
class LoadedSpaceView extends StatefulWidget {
|
||||
final List<CommunityModel> communities;
|
||||
final CommunityModel? selectedCommunity;
|
||||
final SpaceModel? selectedSpace;
|
||||
@ -26,41 +26,73 @@ class LoadedSpaceView extends StatelessWidget {
|
||||
this.selectedSpace,
|
||||
this.products,
|
||||
this.spaceModels,
|
||||
required this.shouldNavigateToSpaceModelPage
|
||||
required this.shouldNavigateToSpaceModelPage,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
_LoadedSpaceViewState createState() => _LoadedSpaceViewState();
|
||||
}
|
||||
|
||||
class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
||||
late List<SpaceTemplateModel> _spaceModels;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_spaceModels = List.from(widget.spaceModels ?? []);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(covariant LoadedSpaceView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (widget.spaceModels != oldWidget.spaceModels) {
|
||||
setState(() {
|
||||
_spaceModels = List.from(widget.spaceModels ?? []);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void _onSpaceModelsUpdated(List<SpaceTemplateModel> updatedModels) {
|
||||
if (mounted && updatedModels != _spaceModels) {
|
||||
setState(() {
|
||||
_spaceModels = updatedModels;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Stack(
|
||||
clipBehavior: Clip.none,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
SidebarWidget(
|
||||
communities: communities,
|
||||
selectedSpaceUuid:
|
||||
selectedSpace?.uuid ?? selectedCommunity?.uuid ?? '',
|
||||
communities: widget.communities,
|
||||
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
||||
widget.selectedCommunity?.uuid ??
|
||||
'',
|
||||
),
|
||||
shouldNavigateToSpaceModelPage
|
||||
widget.shouldNavigateToSpaceModelPage
|
||||
? Expanded(
|
||||
child: BlocProvider(
|
||||
create: (context) => SpaceModelBloc(
|
||||
api: SpaceModelManagementApi(),
|
||||
initialSpaceModels: spaceModels ?? [],
|
||||
initialSpaceModels: _spaceModels,
|
||||
),
|
||||
child: SpaceModelPage(
|
||||
products: products,
|
||||
products: widget.products,
|
||||
onSpaceModelsUpdated: _onSpaceModelsUpdated,
|
||||
),
|
||||
),
|
||||
)
|
||||
: CommunityStructureArea(
|
||||
selectedCommunity: selectedCommunity,
|
||||
selectedSpace: selectedSpace,
|
||||
spaces: selectedCommunity?.spaces ?? [],
|
||||
products: products,
|
||||
communities: communities,
|
||||
spaceModels: spaceModels,
|
||||
selectedCommunity: widget.selectedCommunity,
|
||||
selectedSpace: widget.selectedSpace,
|
||||
spaces: widget.selectedCommunity?.spaces ?? [],
|
||||
products: widget.products,
|
||||
communities: widget.communities,
|
||||
spaceModels: _spaceModels,
|
||||
),
|
||||
],
|
||||
),
|
||||
@ -68,13 +100,4 @@ class LoadedSpaceView extends StatelessWidget {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
SpaceModel? findSpaceByUuid(String? uuid, List<CommunityModel> communities) {
|
||||
for (var community in communities) {
|
||||
for (var space in community.spaces) {
|
||||
if (space.uuid == uuid) return space;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,7 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
if (currentState is AssignTagLoaded && currentState.tags.isNotEmpty) {
|
||||
final tags = List<Tag>.from(currentState.tags);
|
||||
tags[event.index].tag = event.tag;
|
||||
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
isSaveEnabled: _validateTags(tags),
|
||||
@ -78,6 +79,7 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
emit(AssignTagLoaded(
|
||||
tags: tags,
|
||||
isSaveEnabled: _validateTags(tags),
|
||||
errorMessage: _getValidationError(tags),
|
||||
));
|
||||
}
|
||||
});
|
||||
@ -106,12 +108,13 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
emit(AssignTagLoaded(
|
||||
tags: updatedTags,
|
||||
isSaveEnabled: _validateTags(updatedTags),
|
||||
errorMessage: _getValidationError(updatedTags),
|
||||
));
|
||||
} else {
|
||||
emit(const AssignTagLoaded(
|
||||
tags: [],
|
||||
isSaveEnabled: false,
|
||||
));
|
||||
tags: [],
|
||||
isSaveEnabled: false,
|
||||
errorMessage: 'Failed to delete tag'));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -125,7 +128,10 @@ class AssignTagBloc extends Bloc<AssignTagEvent, AssignTagState> {
|
||||
|
||||
String? _getValidationError(List<Tag> tags) {
|
||||
final hasEmptyTag = tags.any((tag) => (tag.tag?.trim() ?? '').isEmpty);
|
||||
if (hasEmptyTag) return 'Tags cannot be empty.';
|
||||
if (hasEmptyTag) {
|
||||
return 'Tags cannot be empty.';
|
||||
}
|
||||
|
||||
final duplicateTags = tags
|
||||
.map((tag) => tag.tag?.trim() ?? '')
|
||||
.fold<Map<String, int>>({}, (map, tag) {
|
||||
|
@ -21,11 +21,11 @@ class AssignTagLoaded extends AssignTagState {
|
||||
const AssignTagLoaded({
|
||||
required this.tags,
|
||||
required this.isSaveEnabled,
|
||||
this.errorMessage,
|
||||
required this.errorMessage,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object> get props => [tags, isSaveEnabled];
|
||||
List<Object> get props => [tags, isSaveEnabled, errorMessage ?? ''];
|
||||
}
|
||||
|
||||
class AssignTagError extends AssignTagState {
|
||||
|
@ -71,6 +71,7 @@ class AssignTagDialog extends StatelessWidget {
|
||||
child: DataTable(
|
||||
headingRowColor: WidgetStateProperty.all(
|
||||
ColorsManager.dataHeaderGrey),
|
||||
key: ValueKey(state.tags.length),
|
||||
border: TableBorder.all(
|
||||
color: ColorsManager.dataHeaderGrey,
|
||||
width: 1,
|
||||
@ -120,6 +121,7 @@ class AssignTagDialog extends StatelessWidget {
|
||||
final controller = controllers[index];
|
||||
final availableTags = getAvailableTags(
|
||||
allTags ?? [], state.tags, tag);
|
||||
|
||||
return DataRow(
|
||||
cells: [
|
||||
DataCell(Text((index + 1).toString())),
|
||||
@ -158,6 +160,8 @@ class AssignTagDialog extends StatelessWidget {
|
||||
.add(DeleteTag(
|
||||
tagToDelete: tag,
|
||||
tags: state.tags));
|
||||
|
||||
controllers.removeAt(index);
|
||||
},
|
||||
tooltip: 'Delete Tag',
|
||||
padding: EdgeInsets.zero,
|
||||
@ -233,7 +237,8 @@ class AssignTagDialog extends StatelessWidget {
|
||||
label: 'Add New Device',
|
||||
onPressed: () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result = processTags(updatedTags, subspaces);
|
||||
final result =
|
||||
TagHelper.processTags(updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
@ -254,6 +259,7 @@ class AssignTagDialog extends StatelessWidget {
|
||||
spaceTags: processedTags,
|
||||
isCreate: false,
|
||||
onSave: onSave,
|
||||
allTags: allTags,
|
||||
),
|
||||
);
|
||||
},
|
||||
@ -264,15 +270,15 @@ class AssignTagDialog extends StatelessWidget {
|
||||
Expanded(
|
||||
child: DefaultButton(
|
||||
borderRadius: 10,
|
||||
backgroundColor: state.isSaveEnabled
|
||||
? ColorsManager.secondaryColor
|
||||
: ColorsManager.grayColor,
|
||||
foregroundColor: ColorsManager.whiteColors,
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
foregroundColor: state.isSaveEnabled
|
||||
? ColorsManager.whiteColors
|
||||
: ColorsManager.whiteColorsWithOpacity,
|
||||
onPressed: state.isSaveEnabled
|
||||
? () async {
|
||||
final updatedTags = List<Tag>.from(state.tags);
|
||||
final result =
|
||||
processTags(updatedTags, subspaces);
|
||||
final result = TagHelper.processTags(
|
||||
updatedTags, subspaces);
|
||||
|
||||
final processedTags =
|
||||
result['updatedTags'] as List<Tag>;
|
||||
@ -311,33 +317,4 @@ class AssignTagDialog extends StatelessWidget {
|
||||
);
|
||||
return availableTagsForTagModel;
|
||||
}
|
||||
|
||||
Map<String, dynamic> processTags(
|
||||
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
|
||||
return TagHelper.updateTags<Tag>(
|
||||
updatedTags: updatedTags,
|
||||
subspaces: subspaces,
|
||||
getInternalId: (tag) => tag.internalId,
|
||||
getLocation: (tag) => tag.location,
|
||||
setLocation: (tag, location) => tag.location = location,
|
||||
getSubspaceName: (subspace) => subspace.subspaceName,
|
||||
getSubspaceTags: (subspace) => subspace.tags,
|
||||
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
||||
checkTagExistInSubspace: checkTagExistInSubspace,
|
||||
);
|
||||
}
|
||||
|
||||
int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
|
||||
if (subspaces == null) return null;
|
||||
for (int i = 0; i < subspaces.length; i++) {
|
||||
final subspace = subspaces[i];
|
||||
if (subspace.tags == null) continue;
|
||||
for (var t in subspace.tags!) {
|
||||
if (tag.internalId == t.internalId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
child: DataTable(
|
||||
headingRowColor: WidgetStateProperty.all(
|
||||
ColorsManager.dataHeaderGrey),
|
||||
key: ValueKey(state.tags.length),
|
||||
border: TableBorder.all(
|
||||
color: ColorsManager.dataHeaderGrey,
|
||||
width: 1,
|
||||
@ -176,6 +177,7 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
.add(DeleteTagModel(
|
||||
tagToDelete: tag,
|
||||
tags: state.tags));
|
||||
controllers.removeAt(index);
|
||||
},
|
||||
tooltip: 'Delete Tag',
|
||||
padding: EdgeInsets.zero,
|
||||
@ -302,10 +304,10 @@ class AssignTagModelsDialog extends StatelessWidget {
|
||||
Expanded(
|
||||
child: DefaultButton(
|
||||
borderRadius: 10,
|
||||
backgroundColor: state.isSaveEnabled
|
||||
? ColorsManager.secondaryColor
|
||||
: ColorsManager.grayColor,
|
||||
foregroundColor: ColorsManager.whiteColors,
|
||||
backgroundColor: ColorsManager.secondaryColor,
|
||||
foregroundColor: state.isSaveEnabled
|
||||
? ColorsManager.whiteColors
|
||||
: ColorsManager.whiteColorsWithOpacity,
|
||||
onPressed: state.isSaveEnabled
|
||||
? () async {
|
||||
final updatedTags =
|
||||
|
21
lib/pages/spaces_management/helper/connection_helper.dart
Normal file
21
lib/pages/spaces_management/helper/connection_helper.dart
Normal file
@ -0,0 +1,21 @@
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/connection_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
|
||||
class ConnectionHelper {
|
||||
static Offset getCenterPosition(Size screenSize) {
|
||||
return Offset(
|
||||
screenSize.width / 2 - 260,
|
||||
screenSize.height / 2 - 200,
|
||||
);
|
||||
}
|
||||
|
||||
static bool isHighlightedConnection(
|
||||
Connection connection, SpaceModel? selectedSpace) {
|
||||
if (selectedSpace == null) return true;
|
||||
|
||||
return connection.startSpace == selectedSpace ||
|
||||
connection.endSpace == selectedSpace;
|
||||
}
|
||||
}
|
94
lib/pages/spaces_management/helper/space_helper.dart
Normal file
94
lib/pages/spaces_management/helper/space_helper.dart
Normal file
@ -0,0 +1,94 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
|
||||
class SpaceHelper {
|
||||
static SpaceModel? findSpaceByUuid(
|
||||
String? uuid, List<CommunityModel> communities) {
|
||||
for (var community in communities) {
|
||||
for (var space in community.spaces) {
|
||||
if (space.uuid == uuid) return space;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static SpaceModel? findSpaceByInternalId(
|
||||
String? internalId, List<SpaceModel> spaces) {
|
||||
if (internalId != null) {
|
||||
for (var space in spaces) {
|
||||
if (space.internalId == internalId) return space;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static String generateUniqueSpaceName(
|
||||
String originalName, List<SpaceModel> spaces) {
|
||||
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
|
||||
int maxNumber = 0;
|
||||
|
||||
for (var space in spaces) {
|
||||
final match = RegExp(r'^(.*?)\((\d+)\)$').firstMatch(space.name);
|
||||
if (match != null && match.group(1)?.trim() == baseName) {
|
||||
int existingNumber = int.parse(match.group(2)!);
|
||||
if (existingNumber > maxNumber) {
|
||||
maxNumber = existingNumber;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "$baseName(${maxNumber + 1})";
|
||||
}
|
||||
|
||||
static bool isSave(List<SpaceModel> spaces) {
|
||||
return spaces.isNotEmpty &&
|
||||
spaces.any((space) =>
|
||||
space.status == SpaceStatus.newSpace ||
|
||||
space.status == SpaceStatus.modified ||
|
||||
space.status == SpaceStatus.deleted);
|
||||
}
|
||||
|
||||
static bool isHighlightedSpace(SpaceModel space, SpaceModel? selectedSpace) {
|
||||
if (selectedSpace == null) return true;
|
||||
|
||||
return space == selectedSpace ||
|
||||
selectedSpace.parent?.internalId == space.internalId ||
|
||||
selectedSpace.children
|
||||
?.any((child) => child.internalId == space.internalId) ==
|
||||
true;
|
||||
}
|
||||
|
||||
static bool isNameConflict(
|
||||
String value, SpaceModel? parentSpace, SpaceModel? editSpace) {
|
||||
final siblings = parentSpace?.children
|
||||
.where((child) => child.internalId != editSpace?.internalId)
|
||||
.toList() ??
|
||||
[];
|
||||
|
||||
final editSiblings = editSpace?.parent?.children
|
||||
.where((child) => child.internalId != editSpace.internalId)
|
||||
.toList() ??
|
||||
[];
|
||||
|
||||
final editSiblingConflict =
|
||||
editSiblings.any((child) => child.name == value);
|
||||
|
||||
final siblingConflict = siblings.any((child) => child.name == value);
|
||||
|
||||
final parentConflict = parentSpace?.name == value &&
|
||||
parentSpace?.internalId != editSpace?.internalId;
|
||||
|
||||
final parentOfEditSpaceConflict = editSpace?.parent?.name == value &&
|
||||
editSpace?.parent?.internalId != editSpace?.internalId;
|
||||
|
||||
final childConflict =
|
||||
editSpace?.children.any((child) => child.name == value) ?? false;
|
||||
|
||||
return siblingConflict ||
|
||||
parentConflict ||
|
||||
editSiblingConflict ||
|
||||
parentOfEditSpaceConflict ||
|
||||
childConflict;
|
||||
}
|
||||
}
|
@ -1,8 +1,11 @@
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/base_tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/selected_product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
|
||||
|
||||
@ -278,7 +281,8 @@ class TagHelper {
|
||||
.toList();
|
||||
}
|
||||
|
||||
static int? checkTagExistInSubspaceModels(TagModel tag, List<dynamic>? subspaces) {
|
||||
static int? checkTagExistInSubspaceModels(
|
||||
TagModel tag, List<dynamic>? subspaces) {
|
||||
if (subspaces == null) return null;
|
||||
|
||||
for (int i = 0; i < subspaces.length; i++) {
|
||||
@ -293,7 +297,7 @@ class TagHelper {
|
||||
return null;
|
||||
}
|
||||
|
||||
static Map<String, dynamic> updateSubspaceTagModels(
|
||||
static Map<String, dynamic> updateSubspaceTagModels(
|
||||
List<TagModel> updatedTags, List<SubspaceTemplateModel>? subspaces) {
|
||||
return TagHelper.updateTags<TagModel>(
|
||||
updatedTags: updatedTags,
|
||||
@ -308,4 +312,53 @@ class TagHelper {
|
||||
);
|
||||
}
|
||||
|
||||
static int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
|
||||
if (subspaces == null) return null;
|
||||
for (int i = 0; i < subspaces.length; i++) {
|
||||
final subspace = subspaces[i];
|
||||
if (subspace.tags == null) continue;
|
||||
for (var t in subspace.tags!) {
|
||||
if (tag.internalId == t.internalId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static Map<String, dynamic> processTags(
|
||||
List<Tag> updatedTags, List<SubspaceModel>? subspaces) {
|
||||
return TagHelper.updateTags<Tag>(
|
||||
updatedTags: updatedTags,
|
||||
subspaces: subspaces,
|
||||
getInternalId: (tag) => tag.internalId,
|
||||
getLocation: (tag) => tag.location,
|
||||
setLocation: (tag, location) => tag.location = location,
|
||||
getSubspaceName: (subspace) => subspace.subspaceName,
|
||||
getSubspaceTags: (subspace) => subspace.tags,
|
||||
setSubspaceTags: (subspace, tags) => subspace.tags = tags,
|
||||
checkTagExistInSubspace: checkTagExistInSubspace,
|
||||
);
|
||||
}
|
||||
|
||||
static List<String> getAllTagValues(
|
||||
List<CommunityModel> communities, List<SpaceTemplateModel>? spaceModels) {
|
||||
final Set<String> allTags = {};
|
||||
|
||||
if (spaceModels != null) {
|
||||
for (var model in spaceModels) {
|
||||
allTags.addAll(model.listAllTagValues());
|
||||
}
|
||||
}
|
||||
|
||||
for (final community in communities) {
|
||||
for (final space in community.spaces) {
|
||||
if (space.tags != null) {
|
||||
allTags.addAll(space.listAllTagValues());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return allTags.toList();
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/subspace_template_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
|
||||
|
@ -11,8 +11,10 @@ import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
class SpaceModelPage extends StatelessWidget {
|
||||
final List<ProductModel>? products;
|
||||
final Function(List<SpaceTemplateModel>)? onSpaceModelsUpdated;
|
||||
|
||||
const SpaceModelPage({Key? key, this.products}) : super(key: key);
|
||||
const SpaceModelPage({Key? key, this.products, this.onSpaceModelsUpdated})
|
||||
: super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -25,6 +27,10 @@ class SpaceModelPage extends StatelessWidget {
|
||||
final allTagValues = _getAllTagValues(spaceModels);
|
||||
final allSpaceModelNames = _getAllSpaceModelName(spaceModels);
|
||||
|
||||
if (onSpaceModelsUpdated != null) {
|
||||
onSpaceModelsUpdated!(spaceModels);
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
body: Padding(
|
||||
|
@ -6,55 +6,64 @@ class ButtonContentWidget extends StatelessWidget {
|
||||
final IconData? icon;
|
||||
final String label;
|
||||
final String? svgAssets;
|
||||
final bool disabled;
|
||||
|
||||
const ButtonContentWidget(
|
||||
{Key? key, this.icon, required this.label, this.svgAssets})
|
||||
: super(key: key);
|
||||
const ButtonContentWidget({
|
||||
Key? key,
|
||||
this.icon,
|
||||
required this.label,
|
||||
this.svgAssets,
|
||||
this.disabled = false,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
|
||||
return SizedBox(
|
||||
width: screenWidth * 0.25,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.textFieldGreyColor,
|
||||
border: Border.all(
|
||||
color: ColorsManager.neutralGray,
|
||||
width: 3.0,
|
||||
return Opacity(
|
||||
opacity: disabled ? 0.5 : 1.0,
|
||||
child: SizedBox(
|
||||
width: screenWidth * 0.25,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.textFieldGreyColor,
|
||||
border: Border.all(
|
||||
color: ColorsManager.neutralGray,
|
||||
width: 3.0,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
if (icon != null)
|
||||
Icon(
|
||||
icon,
|
||||
color: ColorsManager.spaceColor,
|
||||
),
|
||||
if (svgAssets != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6.0),
|
||||
child: SvgPicture.asset(
|
||||
svgAssets!,
|
||||
width: screenWidth * 0.015, // Adjust icon size
|
||||
height: screenWidth * 0.015,
|
||||
child: Padding(
|
||||
padding:
|
||||
const EdgeInsets.symmetric(vertical: 10.0, horizontal: 16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
if (icon != null)
|
||||
Icon(
|
||||
icon,
|
||||
color: ColorsManager.spaceColor,
|
||||
),
|
||||
if (svgAssets != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 6.0),
|
||||
child: SvgPicture.asset(
|
||||
svgAssets!,
|
||||
width: screenWidth * 0.015, // Adjust icon size
|
||||
height: screenWidth * 0.015,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: ColorsManager.blackColor,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
label,
|
||||
style: const TextStyle(
|
||||
color: ColorsManager.blackColor,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -23,7 +23,8 @@ class DevicesManagementApi {
|
||||
: ApiEndpoints.getAllDevices,
|
||||
showServerMessage: true,
|
||||
expectedResponseModel: (json) {
|
||||
List<dynamic> jsonData = json;
|
||||
List<dynamic> jsonData =
|
||||
communityId.isNotEmpty && spaceId.isNotEmpty ? json['data'] : json;
|
||||
List<AllDevicesModel> devicesList = jsonData.map((jsonItem) {
|
||||
return AllDevicesModel.fromJson(jsonItem);
|
||||
}).toList();
|
||||
|
Reference in New Issue
Block a user