mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-11 15:47:44 +00:00
Compare commits
10 Commits
fix/duplic
...
bugfix/fix
Author | SHA1 | Date | |
---|---|---|---|
acefe6b433 | |||
63bc7a56de | |||
7b3635deae | |||
58755eafe1 | |||
ce225818fb | |||
8762a7aaa8 | |||
8dc833b2c3 | |||
13cef151aa | |||
ab23be9828 | |||
687b68ab22 |
@ -30,8 +30,8 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
final spaceId = result['space'];
|
final spaceId = result['space'];
|
||||||
final bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
final bloc = BlocProvider.of<CreateRoutineBloc>(context);
|
||||||
final routineBloc = context.read<RoutineBloc>();
|
final routineBloc = context.read<RoutineBloc>();
|
||||||
bloc.add(
|
bloc.add(SaveCommunityIdAndSpaceIdEvent(
|
||||||
SaveCommunityIdAndSpaceIdEvent(communityID: communityId, spaceID: spaceId));
|
communityID: communityId, spaceID: spaceId));
|
||||||
await Future.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
routineBloc.add(const CreateNewRoutineViewEvent(createRoutineView: true));
|
routineBloc.add(const CreateNewRoutineViewEvent(createRoutineView: true));
|
||||||
}
|
}
|
||||||
@ -61,6 +61,8 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
width: context.screenWidth,
|
width: context.screenWidth,
|
||||||
child: SingleChildScrollView(
|
child: SingleChildScrollView(
|
||||||
padding: const EdgeInsetsDirectional.all(16),
|
padding: const EdgeInsetsDirectional.all(16),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 20),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
@ -68,7 +70,8 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
"Create New Routines",
|
"Create New Routines",
|
||||||
style: Theme.of(context).textTheme.titleLarge?.copyWith(
|
style:
|
||||||
|
Theme.of(context).textTheme.titleLarge?.copyWith(
|
||||||
color: ColorsManager.grayColor,
|
color: ColorsManager.grayColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@ -92,6 +95,7 @@ class _RoutinesViewState extends State<RoutinesView> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -16,7 +16,8 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
|||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return BlocBuilder<RoutineBloc, RoutineState>(
|
return BlocBuilder<RoutineBloc, RoutineState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state.isLoading) return const Center(child: CircularProgressIndicator());
|
if (state.isLoading)
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@ -40,7 +41,8 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
|||||||
const SizedBox(height: 3),
|
const SizedBox(height: 3),
|
||||||
Visibility(
|
Visibility(
|
||||||
visible: state.automations.isNotEmpty,
|
visible: state.automations.isNotEmpty,
|
||||||
replacement: _buildEmptyState(context, "No automations found"),
|
replacement:
|
||||||
|
_buildEmptyState(context, "No automations found"),
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
child: _buildAutomations(state),
|
child: _buildAutomations(state),
|
||||||
@ -59,7 +61,8 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
|||||||
scrollDirection: Axis.horizontal,
|
scrollDirection: Axis.horizontal,
|
||||||
itemCount: state.automations.length,
|
itemCount: state.automations.length,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final isLoading = state.automations.contains(state.automations[index].id);
|
final isLoading =
|
||||||
|
state.automations.contains(state.automations[index].id);
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
@ -179,11 +182,14 @@ class FetchRoutineScenesAutomation extends StatelessWidget
|
|||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildEmptyState(BuildContext context, String title) {
|
Widget _buildEmptyState(BuildContext context, String title) {
|
||||||
return Text(
|
return Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 100),
|
||||||
|
child: Text(
|
||||||
title,
|
title,
|
||||||
style: context.textTheme.bodyMedium?.copyWith(
|
style: context.textTheme.bodyMedium?.copyWith(
|
||||||
color: ColorsManager.grayColor,
|
color: ColorsManager.grayColor,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,6 +466,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
|
|
||||||
if (previousState is SpaceManagementLoaded) {
|
if (previousState is SpaceManagementLoaded) {
|
||||||
await _updateLoadedState(
|
await _updateLoadedState(
|
||||||
|
event.context,
|
||||||
previousState,
|
previousState,
|
||||||
allSpaces,
|
allSpaces,
|
||||||
event.communityUuid,
|
event.communityUuid,
|
||||||
@ -482,6 +483,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateLoadedState(
|
Future<void> _updateLoadedState(
|
||||||
|
BuildContext context,
|
||||||
SpaceManagementLoaded previousState,
|
SpaceManagementLoaded previousState,
|
||||||
List<SpaceModel> allSpaces,
|
List<SpaceModel> allSpaces,
|
||||||
String communityUuid,
|
String communityUuid,
|
||||||
@ -489,7 +491,10 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
) async {
|
) async {
|
||||||
var prevSpaceModels = await fetchSpaceModels();
|
var prevSpaceModels = await fetchSpaceModels();
|
||||||
await fetchTags();
|
await fetchTags();
|
||||||
final communities = List<CommunityModel>.from(previousState.communities);
|
final spaceTreeState = context.read<SpaceTreeBloc>().state;
|
||||||
|
final communities = spaceTreeState.searchQuery.isNotEmpty
|
||||||
|
? spaceTreeState.filteredCommunity
|
||||||
|
: spaceTreeState.communityList;
|
||||||
|
|
||||||
for (var community in communities) {
|
for (var community in communities) {
|
||||||
if (community.uuid == communityUuid) {
|
if (community.uuid == communityUuid) {
|
||||||
@ -504,6 +509,8 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
spaceModels: prevSpaceModels,
|
spaceModels: prevSpaceModels,
|
||||||
allTags: _cachedTags ?? []));
|
allTags: _cachedTags ?? []));
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
print("Community not found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -634,11 +641,11 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
projectId: projectUuid);
|
projectId: projectUuid);
|
||||||
} else {
|
} else {
|
||||||
// Call create if the space does not have a UUID
|
// Call create if the space does not have a UUID
|
||||||
final List<CreateTagBodyModel> tagBodyModels = space.tags != null
|
List<CreateTagBodyModel> tagBodyModels = space.tags != null
|
||||||
? space.tags!.map((tag) => tag.toCreateTagBodyModel()).toList()
|
? space.tags!.map((tag) => tag.toCreateTagBodyModel()).toList()
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
final createSubspaceBodyModels = space.subspaces?.map((subspace) {
|
var createSubspaceBodyModels = space.subspaces?.map((subspace) {
|
||||||
final tagBodyModels =
|
final tagBodyModels =
|
||||||
subspace.tags?.map((tag) => tag.toCreateTagBodyModel()).toList() ?? [];
|
subspace.tags?.map((tag) => tag.toCreateTagBodyModel()).toList() ?? [];
|
||||||
return CreateSubspaceModel()
|
return CreateSubspaceModel()
|
||||||
@ -647,6 +654,11 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
}).toList() ??
|
}).toList() ??
|
||||||
[];
|
[];
|
||||||
|
|
||||||
|
if (space.spaceModel?.uuid != null) {
|
||||||
|
tagBodyModels = [];
|
||||||
|
createSubspaceBodyModels = [];
|
||||||
|
}
|
||||||
|
|
||||||
final response = await _api.createSpace(
|
final response = await _api.createSpace(
|
||||||
communityId: communityUuid,
|
communityId: communityUuid,
|
||||||
name: space.name,
|
name: space.name,
|
||||||
|
@ -421,7 +421,6 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (var space in spaces) {
|
for (var space in spaces) {
|
||||||
flatten(space);
|
flatten(space);
|
||||||
}
|
}
|
||||||
@ -704,62 +703,26 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _duplicateSpace(SpaceModel space) {
|
void _duplicateSpace(SpaceModel space) {
|
||||||
final double horizontalGap = 250.0;
|
|
||||||
final double verticalGap = 180.0;
|
|
||||||
final double nodeWidth = 200;
|
|
||||||
final double nodeHeight = 100;
|
|
||||||
final double breathingSpace = 300.0;
|
|
||||||
|
|
||||||
/// Helper to recursively duplicate a node and its children
|
|
||||||
SpaceModel duplicateRecursive(SpaceModel original, SpaceModel? duplicatedParent) {
|
|
||||||
final duplicatedName = SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
|
||||||
final duplicated = SpaceModel(
|
|
||||||
name: duplicatedName,
|
|
||||||
icon: original.icon,
|
|
||||||
position: original.position,
|
|
||||||
isPrivate: original.isPrivate,
|
|
||||||
children: [],
|
|
||||||
status: SpaceStatus.newSpace,
|
|
||||||
parent: duplicatedParent,
|
|
||||||
spaceModel: original.spaceModel,
|
|
||||||
subspaces: original.subspaces,
|
|
||||||
tags: original.tags,
|
|
||||||
);
|
|
||||||
|
|
||||||
spaces.add(duplicated);
|
|
||||||
|
|
||||||
if (duplicatedParent != null) {
|
|
||||||
final newConnection = Connection(
|
|
||||||
startSpace: duplicatedParent,
|
|
||||||
endSpace: duplicated,
|
|
||||||
direction: "down",
|
|
||||||
);
|
|
||||||
connections.add(newConnection);
|
|
||||||
|
|
||||||
duplicated.incomingConnection = newConnection;
|
|
||||||
duplicatedParent.addOutgoingConnection(newConnection);
|
|
||||||
duplicatedParent.children.add(duplicated);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Duplicate its children recursively
|
|
||||||
for (var child in original.children) {
|
|
||||||
duplicateRecursive(child, duplicated);
|
|
||||||
}
|
|
||||||
|
|
||||||
return duplicated;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Actual duplication process
|
|
||||||
setState(() {
|
setState(() {
|
||||||
if (space.parent == null) {
|
SpaceModel? parent = space.parent;
|
||||||
// Duplicating a ROOT node
|
|
||||||
duplicateRecursive(space, null);
|
SpaceModel duplicated = _deepCloneSpaceTree(space, parent: parent);
|
||||||
connections = createConnections(spaces);
|
|
||||||
realignTree();
|
duplicated.position = Offset(space.position.dx + 300, space.position.dy + 100);
|
||||||
} else {
|
List<SpaceModel> duplicatedSubtree = [];
|
||||||
final parent = space.parent!;
|
void collectSubtree(SpaceModel node) {
|
||||||
|
duplicatedSubtree.add(node);
|
||||||
|
for (var child in node.children) {
|
||||||
|
collectSubtree(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
collectSubtree(duplicated);
|
||||||
|
spaces.addAll(duplicatedSubtree);
|
||||||
|
|
||||||
|
if (parent != null) {
|
||||||
|
parent.children.add(duplicated);
|
||||||
|
|
||||||
final duplicated = duplicateRecursive(space, parent);
|
|
||||||
final newConnection = Connection(
|
final newConnection = Connection(
|
||||||
startSpace: parent,
|
startSpace: parent,
|
||||||
endSpace: duplicated,
|
endSpace: duplicated,
|
||||||
@ -768,11 +731,44 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
connections.add(newConnection);
|
connections.add(newConnection);
|
||||||
duplicated.incomingConnection = newConnection;
|
duplicated.incomingConnection = newConnection;
|
||||||
parent.addOutgoingConnection(newConnection);
|
parent.addOutgoingConnection(newConnection);
|
||||||
parent.children.add(duplicated);
|
|
||||||
connections = createConnections(spaces);
|
|
||||||
realignTree();
|
|
||||||
//_realignSubtree(space.parent!);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
realignTree();
|
||||||
|
connections = createConnections(spaces);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SpaceModel _deepCloneSpaceTree(SpaceModel original, {SpaceModel? parent}) {
|
||||||
|
final duplicatedName = SpaceHelper.generateUniqueSpaceName(original.name, spaces);
|
||||||
|
|
||||||
|
final newSpace = SpaceModel(
|
||||||
|
name: duplicatedName,
|
||||||
|
icon: original.icon,
|
||||||
|
position: original.position,
|
||||||
|
isPrivate: original.isPrivate,
|
||||||
|
children: [],
|
||||||
|
status: SpaceStatus.newSpace,
|
||||||
|
spaceModel: original.spaceModel,
|
||||||
|
subspaces: original.subspaces,
|
||||||
|
tags: original.tags,
|
||||||
|
parent: parent,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (var child in original.children) {
|
||||||
|
final duplicatedChild = _deepCloneSpaceTree(child, parent: newSpace);
|
||||||
|
newSpace.children.add(duplicatedChild);
|
||||||
|
|
||||||
|
final newConnection = Connection(
|
||||||
|
startSpace: newSpace,
|
||||||
|
endSpace: duplicatedChild,
|
||||||
|
direction: "down",
|
||||||
|
);
|
||||||
|
connections.add(newConnection);
|
||||||
|
|
||||||
|
duplicatedChild.incomingConnection = newConnection;
|
||||||
|
newSpace.addOutgoingConnection(newConnection);
|
||||||
|
}
|
||||||
|
|
||||||
|
return newSpace;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
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/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/bloc/space_tree_event.dart';
|
||||||
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.dart';
|
import 'package:syncrow_web/pages/space_tree/view/space_tree_view.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';
|
||||||
@ -45,7 +46,6 @@ 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 ?? []);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,9 +106,8 @@ class _LoadedSpaceViewState extends State<LoadedSpaceView> {
|
|||||||
children: [
|
children: [
|
||||||
SidebarWidget(
|
SidebarWidget(
|
||||||
communities: widget.communities,
|
communities: widget.communities,
|
||||||
selectedSpaceUuid: widget.selectedSpace?.uuid ??
|
selectedSpaceUuid:
|
||||||
widget.selectedCommunity?.uuid ??
|
widget.selectedSpace?.uuid ?? widget.selectedCommunity?.uuid ?? '',
|
||||||
'',
|
|
||||||
onCreateCommunity: (name, description) {
|
onCreateCommunity: (name, description) {
|
||||||
context.read<SpaceManagementBloc>().add(
|
context.read<SpaceManagementBloc>().add(
|
||||||
CreateCommunityEvent(name, description, context),
|
CreateCommunityEvent(name, description, context),
|
||||||
|
@ -50,6 +50,8 @@ class _SidebarWidgetState extends State<SidebarWidget> {
|
|||||||
_scrollController = ScrollController();
|
_scrollController = ScrollController();
|
||||||
_scrollController.addListener(_onScroll);
|
_scrollController.addListener(_onScroll);
|
||||||
_selectedId = widget.selectedSpaceUuid;
|
_selectedId = widget.selectedSpaceUuid;
|
||||||
|
_searchQuery = '';
|
||||||
|
context.read<SpaceTreeBloc>().add(ClearCachedData());
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onScroll() {
|
void _onScroll() {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
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/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/product_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/tag.dart';
|
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.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_bloc.dart';
|
||||||
@ -27,6 +29,8 @@ class SpaceModelPage extends StatelessWidget {
|
|||||||
return const Center(child: CircularProgressIndicator());
|
return const Center(child: CircularProgressIndicator());
|
||||||
} else if (state is SpaceModelLoaded) {
|
} else if (state is SpaceModelLoaded) {
|
||||||
final spaceModels = state.spaceModels;
|
final spaceModels = state.spaceModels;
|
||||||
|
context.read<SpaceTreeBloc>().add(ClearCachedData());
|
||||||
|
|
||||||
final allTagValues = _getAllTagValues(spaceModels);
|
final allTagValues = _getAllTagValues(spaceModels);
|
||||||
final allSpaceModelNames = _getAllSpaceModelName(spaceModels);
|
final allSpaceModelNames = _getAllSpaceModelName(spaceModels);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user