From a381fd317dde92024a9b1c88d39a5ae288d120c4 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Sun, 12 Jan 2025 12:10:54 +0400 Subject: [PATCH] added space delete --- .../all_spaces/model/space_model.dart | 2 +- .../community_structure_header_widget.dart | 27 ++++++++++++------- .../widgets/community_structure_widget.dart | 16 +++++++---- lib/services/api/http_service.dart | 13 ++++++++- lib/utils/constants/temp_const.dart | 2 +- 5 files changed, 43 insertions(+), 17 deletions(-) diff --git a/lib/pages/spaces_management/all_spaces/model/space_model.dart b/lib/pages/spaces_management/all_spaces/model/space_model.dart index c9393cce..c8da9d9e 100644 --- a/lib/pages/spaces_management/all_spaces/model/space_model.dart +++ b/lib/pages/spaces_management/all_spaces/model/space_model.dart @@ -7,7 +7,7 @@ import 'package:syncrow_web/pages/spaces_management/space_model/models/space_tem import 'package:syncrow_web/utils/constants/assets.dart'; import 'package:uuid/uuid.dart'; -enum SpaceStatus { newSpace, modified, unchanged, deleted } +enum SpaceStatus { newSpace, modified, unchanged, deleted, parentDeleted } class SpaceModel { String? uuid; diff --git a/lib/pages/spaces_management/all_spaces/widgets/community_structure_header_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/community_structure_header_widget.dart index 612f9101..02d3819a 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/community_structure_header_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/community_structure_header_widget.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:syncrow_web/pages/common/buttons/default_button.dart'; import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart'; +import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart'; import 'package:syncrow_web/pages/spaces_management/create_community/view/create_community_dialog.dart'; import 'package:syncrow_web/utils/color_manager.dart'; import 'package:syncrow_web/utils/constants/assets.dart'; @@ -17,6 +18,7 @@ class CommunityStructureHeader extends StatefulWidget { final ValueChanged onNameSubmitted; final List communities; final CommunityModel? community; + final SpaceModel? selectedSpace; const CommunityStructureHeader( {super.key, @@ -29,7 +31,8 @@ class CommunityStructureHeader extends StatefulWidget { required this.onEditName, required this.onNameSubmitted, this.community, - required this.communities}); + required this.communities, + this.selectedSpace}); @override State createState() => @@ -137,10 +140,8 @@ class _CommunityStructureHeaderState extends State { ], ), ), - if (widget.isSave) ...[ - const SizedBox(width: 8), - _buildActionButtons(theme), - ], + const SizedBox(width: 8), + _buildActionButtons(theme), ], ), ], @@ -152,11 +153,19 @@ class _CommunityStructureHeaderState extends State { alignment: WrapAlignment.end, spacing: 10, children: [ + if (widget.isSave) + _buildButton( + label: "Save", + icon: const Icon(Icons.save, + size: 18, color: ColorsManager.spaceColor), + onPressed: widget.onSave, + theme: theme), + if(widget.selectedSpace!= null) _buildButton( - label: "Save", - icon: const Icon(Icons.save, - size: 18, color: ColorsManager.spaceColor), - onPressed: widget.onSave, + label: "Delete", + icon: const Icon(Icons.delete, + size: 18, color: ColorsManager.warningRed), + onPressed: widget.onDelete, theme: theme), ], ); diff --git a/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart b/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart index b7743a01..05a80780 100644 --- a/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart +++ b/lib/pages/spaces_management/all_spaces/widgets/community_structure_widget.dart @@ -131,6 +131,7 @@ class _CommunityStructureAreaState extends State { isEditingName: isEditingName, nameController: _nameController, onSave: _saveSpaces, + selectedSpace: widget.selectedSpace, onDelete: _onDelete, onEditName: () { setState(() { @@ -176,7 +177,8 @@ class _CommunityStructureAreaState extends State { painter: CurvedLinePainter([connection])), ), for (var entry in spaces.asMap().entries) - if (entry.value.status != SpaceStatus.deleted) + if (entry.value.status != SpaceStatus.deleted || + entry.value.status != SpaceStatus.parentDeleted) Positioned( left: entry.value.position.dx, top: entry.value.position.dy, @@ -358,7 +360,7 @@ class _CommunityStructureAreaState extends State { space.name = name; space.icon = icon; space.spaceModel = spaceModel; - space.subspaces= subspaces; + space.subspaces = subspaces; space.tags = tags; if (space.status != SpaceStatus.newSpace) { @@ -382,7 +384,8 @@ class _CommunityStructureAreaState extends State { List result = []; void flatten(SpaceModel space) { - if (space.status == SpaceStatus.deleted) return; + if (space.status == SpaceStatus.deleted || + space.status == SpaceStatus.parentDeleted) return; result.add(space); @@ -475,7 +478,8 @@ class _CommunityStructureAreaState extends State { void _markChildrenAsDeleted(SpaceModel parent) { for (var child in parent.children) { - child.status = SpaceStatus.deleted; + child.status = SpaceStatus.parentDeleted; + _markChildrenAsDeleted(child); } } @@ -483,7 +487,9 @@ class _CommunityStructureAreaState extends State { void _removeConnectionsForDeletedSpaces() { connections.removeWhere((connection) { return connection.startSpace.status == SpaceStatus.deleted || - connection.endSpace.status == SpaceStatus.deleted; + connection.endSpace.status == SpaceStatus.deleted || + connection.startSpace.status == SpaceStatus.parentDeleted || + connection.endSpace.status == SpaceStatus.parentDeleted; }); } diff --git a/lib/services/api/http_service.dart b/lib/services/api/http_service.dart index b75f05cf..324f1938 100644 --- a/lib/services/api/http_service.dart +++ b/lib/services/api/http_service.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:dio/dio.dart'; import 'package:syncrow_web/services/api/http_interceptor.dart'; import 'package:syncrow_web/services/locator.dart'; @@ -121,13 +123,22 @@ class HTTPService { required T Function(dynamic) expectedResponseModel, bool showServerMessage = true, }) async { + log('DELETE Request Initiated', name: 'API DELETE'); + log('Path: $path', name: 'API DELETE'); + if (queryParameters != null) { + log('Query Parameters: $queryParameters', name: 'API DELETE'); + } + try { final response = await client.delete( path, queryParameters: queryParameters, ); + log('Response: ${response.data}', name: 'API DELETE'); return expectedResponseModel(response.data); - } catch (error) { + } catch (error, stackTrace) { + log('Error during DELETE Request: $error', + name: 'API DELETE', error: error, stackTrace: stackTrace); rethrow; } } diff --git a/lib/utils/constants/temp_const.dart b/lib/utils/constants/temp_const.dart index e5847b98..bcd1a1d6 100644 --- a/lib/utils/constants/temp_const.dart +++ b/lib/utils/constants/temp_const.dart @@ -1,3 +1,3 @@ class TempConst { - static const projectId = '0e62577c-06fa-41b9-8a92-99a21fbaf51c'; + static const projectId = '0685c781-df33-4cbf-bf65-9f4e835eb468'; }