mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
@ -1,4 +1,5 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
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/space_tree/bloc/space_tree_bloc.dart';
|
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
|
||||||
@ -457,7 +458,8 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
emit(SpaceManagementLoading());
|
emit(SpaceManagementLoading());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final updatedSpaces = await saveSpacesHierarchically(event.spaces, event.communityUuid);
|
final updatedSpaces =
|
||||||
|
await saveSpacesHierarchically(event.context, event.spaces, event.communityUuid);
|
||||||
|
|
||||||
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
|
final allSpaces = await _fetchSpacesForCommunity(event.communityUuid);
|
||||||
|
|
||||||
@ -508,9 +510,14 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<List<SpaceModel>> saveSpacesHierarchically(
|
Future<List<SpaceModel>> saveSpacesHierarchically(
|
||||||
List<SpaceModel> spaces, String communityUuid) async {
|
BuildContext context, List<SpaceModel> spaces, String communityUuid) async {
|
||||||
final orderedSpaces = flattenHierarchy(spaces);
|
final orderedSpaces = flattenHierarchy(spaces);
|
||||||
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
|
||||||
|
var spaceBloc = context.read<SpaceTreeBloc>();
|
||||||
|
List<CommunityModel> communities = spaceBloc.state.communityList;
|
||||||
|
CommunityModel? selectedCommunity = communities.firstWhere(
|
||||||
|
(community) => community.uuid == communityUuid,
|
||||||
|
);
|
||||||
|
|
||||||
final parentsToDelete = orderedSpaces.where((space) =>
|
final parentsToDelete = orderedSpaces.where((space) =>
|
||||||
space.status == SpaceStatus.deleted &&
|
space.status == SpaceStatus.deleted &&
|
||||||
@ -532,7 +539,13 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
if (space.uuid != null && space.uuid!.isNotEmpty) {
|
if (space.uuid != null && space.uuid!.isNotEmpty) {
|
||||||
List<TagModelUpdate> tagUpdates = [];
|
List<TagModelUpdate> tagUpdates = [];
|
||||||
|
|
||||||
final prevSpace = await _api.getSpace(communityUuid, space.uuid!, projectUuid);
|
List<SpaceModel> matchedSpaces =
|
||||||
|
selectedCommunity.spaces.where((space) => space.uuid == space.uuid).toList();
|
||||||
|
|
||||||
|
if (matchedSpaces.isEmpty) continue;
|
||||||
|
|
||||||
|
final prevSpace = matchedSpaces[0];
|
||||||
|
|
||||||
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
|
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
|
||||||
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
|
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
|
||||||
final List<SubspaceModel>? newSubspaces = space.subspaces;
|
final List<SubspaceModel>? newSubspaces = space.subspaces;
|
||||||
|
@ -58,14 +58,16 @@ class CreateSpaceEvent extends SpaceManagementEvent {
|
|||||||
class SaveSpacesEvent extends SpaceManagementEvent {
|
class SaveSpacesEvent extends SpaceManagementEvent {
|
||||||
final List<SpaceModel> spaces;
|
final List<SpaceModel> spaces;
|
||||||
final String communityUuid;
|
final String communityUuid;
|
||||||
|
final BuildContext context;
|
||||||
|
|
||||||
const SaveSpacesEvent({
|
const SaveSpacesEvent(
|
||||||
|
this.context, {
|
||||||
required this.spaces,
|
required this.spaces,
|
||||||
required this.communityUuid,
|
required this.communityUuid,
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object> get props => [spaces, communityUuid];
|
List<Object> get props => [spaces, communityUuid, context];
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateSpacePositionEvent extends SpaceManagementEvent {
|
class UpdateSpacePositionEvent extends SpaceManagementEvent {
|
||||||
|
@ -460,6 +460,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
String communityUuid = widget.selectedCommunity!.uuid;
|
String communityUuid = widget.selectedCommunity!.uuid;
|
||||||
|
|
||||||
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
|
context.read<SpaceManagementBloc>().add(SaveSpacesEvent(
|
||||||
|
context,
|
||||||
spaces: spacesToSave,
|
spaces: spacesToSave,
|
||||||
communityUuid: communityUuid,
|
communityUuid: communityUuid,
|
||||||
));
|
));
|
||||||
|
@ -18,8 +18,10 @@ import 'package:syncrow_web/pages/spaces_management/space_model/widgets/dynamic_
|
|||||||
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';
|
||||||
import 'package:syncrow_web/utils/color_manager.dart';
|
import 'package:syncrow_web/utils/color_manager.dart';
|
||||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||||
|
import 'package:syncrow_web/utils/helpers/responsice_layout_helper/responsive_layout_helper.dart';
|
||||||
|
import 'package:syncrow_web/utils/string_utils.dart';
|
||||||
|
|
||||||
class SpaceModelCardWidget extends StatelessWidget {
|
class SpaceModelCardWidget extends StatelessWidget with HelperResponsiveLayout {
|
||||||
final SpaceTemplateModel model;
|
final SpaceTemplateModel model;
|
||||||
final BuildContext? pageContext;
|
final BuildContext? pageContext;
|
||||||
final bool topActionsDisabled;
|
final bool topActionsDisabled;
|
||||||
@ -76,15 +78,18 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Expanded(
|
||||||
model.modelName,
|
child: Text(
|
||||||
|
StringUtils.capitalizeFirstLetter(model.modelName),
|
||||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||||
color: Colors.black,
|
color: ColorsManager.blackColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: isSmallScreenSize(context) ? 13 : 20,
|
||||||
),
|
),
|
||||||
maxLines: 1,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
|
),
|
||||||
if (!topActionsDisabled)
|
if (!topActionsDisabled)
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
@ -95,15 +100,12 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
builder: (BuildContext dialogContext) {
|
builder: (BuildContext dialogContext) {
|
||||||
return BlocProvider<LinkSpaceToModelBloc>(
|
return BlocProvider<LinkSpaceToModelBloc>(
|
||||||
create: (_) => LinkSpaceToModelBloc(),
|
create: (_) => LinkSpaceToModelBloc(),
|
||||||
child: BlocListener<LinkSpaceToModelBloc,
|
child: BlocListener<LinkSpaceToModelBloc, LinkSpaceToModelState>(
|
||||||
LinkSpaceToModelState>(
|
|
||||||
listenWhen: (previous, current) {
|
listenWhen: (previous, current) {
|
||||||
return previous != current;
|
return previous != current;
|
||||||
},
|
},
|
||||||
listener: (context, state) {
|
listener: (context, state) {
|
||||||
final _bloc =
|
final _bloc = BlocProvider.of<LinkSpaceToModelBloc>(context);
|
||||||
BlocProvider.of<LinkSpaceToModelBloc>(
|
|
||||||
context);
|
|
||||||
if (state is SpaceModelLoading) {
|
if (state is SpaceModelLoading) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
@ -111,19 +113,14 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
return Dialog(
|
return Dialog(
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius:
|
borderRadius: BorderRadius.circular(20)),
|
||||||
BorderRadius.circular(
|
|
||||||
20)),
|
|
||||||
elevation: 10,
|
elevation: 10,
|
||||||
backgroundColor: Colors.white,
|
backgroundColor: Colors.white,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding:
|
padding: const EdgeInsets.symmetric(
|
||||||
const EdgeInsets.symmetric(
|
vertical: 30, horizontal: 50),
|
||||||
vertical: 30,
|
|
||||||
horizontal: 50),
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize:
|
mainAxisSize: MainAxisSize.min,
|
||||||
MainAxisSize.min,
|
|
||||||
children: [
|
children: [
|
||||||
CustomLoadingIndicator(),
|
CustomLoadingIndicator(),
|
||||||
],
|
],
|
||||||
@ -132,19 +129,14 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else if (state
|
} else if (state is AlreadyHaveLinkedState) {
|
||||||
is AlreadyHaveLinkedState) {
|
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
showOverwriteDialog(
|
showOverwriteDialog(context, _bloc, model);
|
||||||
context, _bloc, model);
|
} else if (state is SpaceValidationSuccess) {
|
||||||
} else if (state
|
|
||||||
is SpaceValidationSuccess) {
|
|
||||||
_bloc.add(LinkSpaceModelEvent(
|
_bloc.add(LinkSpaceModelEvent(
|
||||||
isOverWrite: false,
|
isOverWrite: false, selectedSpaceMode: model.uuid));
|
||||||
selectedSpaceMode: model.uuid));
|
|
||||||
|
|
||||||
Future.delayed(
|
Future.delayed(const Duration(seconds: 1), () {
|
||||||
const Duration(seconds: 1), () {
|
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
@ -152,29 +144,23 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
|
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder:
|
builder: (BuildContext dialogContext) {
|
||||||
(BuildContext dialogContext) {
|
|
||||||
return const LinkingSuccessful();
|
return const LinkingSuccessful();
|
||||||
},
|
},
|
||||||
).then((v) {
|
).then((v) {
|
||||||
Future.delayed(
|
Future.delayed(const Duration(seconds: 2), () {
|
||||||
const Duration(seconds: 2), () {
|
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else if (state
|
} else if (state is SpaceModelLinkSuccess) {
|
||||||
is SpaceModelLinkSuccess) {
|
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
barrierDismissible: false,
|
barrierDismissible: false,
|
||||||
builder: (BuildContext
|
builder: (BuildContext successDialogContext) {
|
||||||
successDialogContext) {
|
Future.delayed(const Duration(seconds: 2), () {
|
||||||
Future.delayed(
|
Navigator.of(successDialogContext).pop();
|
||||||
const Duration(seconds: 2), () {
|
|
||||||
Navigator.of(successDialogContext)
|
|
||||||
.pop();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return const LinkingSuccessful();
|
return const LinkingSuccessful();
|
||||||
@ -232,8 +218,7 @@ class SpaceModelCardWidget extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (productTagCount.isNotEmpty &&
|
if (productTagCount.isNotEmpty && model.subspaceModels != null)
|
||||||
model.subspaceModels != null)
|
|
||||||
Container(
|
Container(
|
||||||
width: 1.0,
|
width: 1.0,
|
||||||
color: ColorsManager.softGray,
|
color: ColorsManager.softGray,
|
||||||
|
@ -6,7 +6,6 @@ import 'package:syncrow_web/pages/routines/models/routine_details_model.dart';
|
|||||||
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
|
import 'package:syncrow_web/pages/routines/models/routine_model.dart';
|
||||||
import 'package:syncrow_web/services/api/http_service.dart';
|
import 'package:syncrow_web/services/api/http_service.dart';
|
||||||
import 'package:syncrow_web/utils/constants/api_const.dart';
|
import 'package:syncrow_web/utils/constants/api_const.dart';
|
||||||
import 'package:syncrow_web/utils/constants/temp_const.dart';
|
|
||||||
|
|
||||||
class SceneApi {
|
class SceneApi {
|
||||||
static final HTTPService _httpService = HTTPService();
|
static final HTTPService _httpService = HTTPService();
|
||||||
|
6
lib/utils/string_utils.dart
Normal file
6
lib/utils/string_utils.dart
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
class StringUtils {
|
||||||
|
static String capitalizeFirstLetter(String text) {
|
||||||
|
if (text.isEmpty) return text;
|
||||||
|
return text[0].toUpperCase() + text.substring(1);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user