mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
delete Space
This commit is contained in:
9
assets/icons/delete.svg
Normal file
9
assets/icons/delete.svg
Normal file
@ -0,0 +1,9 @@
|
||||
<svg width="16" height="20" viewBox="0 0 16 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M11.807 19.9998H3.50041C2.16417 19.9998 1.08093 18.9165 1.08093 17.5804V4.51562H14.2263V17.5804C14.2263 18.9165 13.1432 19.9998 11.807 19.9998Z" fill="#D8D8D8"/>
|
||||
<path d="M1.08093 4.51562V5.48335H12.3716C12.8168 5.48335 13.178 5.84438 13.178 6.2898V17.3384C13.178 18.2292 12.4558 18.9513 11.565 18.9513H2.45196C2.05416 18.9513 1.67894 18.8547 1.34781 18.6844C1.74913 19.4652 2.56213 19.9998 3.50041 19.9998H11.807C13.1432 19.9998 14.2263 18.9165 14.2263 17.5803V4.51562H1.08093Z" fill="#BABABA"/>
|
||||
<path d="M14.2668 1.77417H10.7439L10.1633 0.612956C9.97426 0.234837 9.59416 0 9.17148 0H6.136C5.71317 0 5.33322 0.234837 5.14416 0.612956L4.56355 1.77417H1.04069C0.595282 1.77417 0.234253 2.1352 0.234253 2.58061V3.70978C0.234253 4.15504 0.595282 4.51622 1.04069 4.51622H14.2668C14.7122 4.51622 15.0732 4.15504 15.0732 3.70978V2.58077C15.0732 2.1352 14.7122 1.77417 14.2668 1.77417ZM5.68509 0.8835C5.771 0.71153 5.94374 0.604869 6.136 0.604869H9.17148C9.3636 0.604869 9.53633 0.71153 9.62224 0.8835L10.0676 1.77417H5.23984L5.68509 0.8835Z" fill="#757575"/>
|
||||
<path d="M14.2668 1.77441H12.9764C13.4218 1.77441 13.783 2.13544 13.783 2.58086V3.71003C13.783 4.15529 13.4218 4.51647 12.9764 4.51647H14.2668C14.7122 4.51647 15.0733 4.15529 15.0733 3.71003V2.58101C15.0733 2.13544 14.7122 1.77441 14.2668 1.77441Z" fill="#595959"/>
|
||||
<path d="M11.3634 17.5C10.918 17.5 10.557 17.139 10.557 16.6935V9.15312C10.557 8.70771 10.918 8.34668 11.3634 8.34668C11.8089 8.34668 12.1699 8.70771 12.1699 9.15312V16.6935C12.1699 17.139 11.8089 17.5 11.3634 17.5Z" fill="#757575"/>
|
||||
<path d="M3.94405 17.5C4.3893 17.5 4.75049 17.139 4.75049 16.6935V9.15312C4.75049 8.70771 4.3893 8.34668 3.94405 8.34668C3.49863 8.34668 3.13745 8.70771 3.13745 9.15312V16.6935C3.13745 17.139 3.49863 17.5 3.94405 17.5Z" fill="#757575"/>
|
||||
<path d="M7.65367 17.5C7.20826 17.5 6.84723 17.139 6.84723 16.6935V9.15312C6.84723 8.70771 7.20826 8.34668 7.65367 8.34668C8.09908 8.34668 8.46011 8.70771 8.46011 9.15312V16.6935C8.46011 17.139 8.09908 17.5 7.65367 17.5Z" fill="#757575"/>
|
||||
</svg>
|
After Width: | Height: | Size: 2.1 KiB |
@ -110,6 +110,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void _onSaveSpaces(
|
||||
SaveSpacesEvent event,
|
||||
Emitter<SpaceManagementState> emit,
|
||||
@ -146,6 +147,7 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
||||
position: space.position,
|
||||
icon: space.icon,
|
||||
direction: space.incomingConnection?.direction,
|
||||
products: space.selectedProducts
|
||||
);
|
||||
} else {
|
||||
// Call create if the space does not have a UUID
|
||||
|
@ -10,4 +10,9 @@ class SelectedProduct {
|
||||
'count': count,
|
||||
};
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SelectedProduct(productId: $productId, count: $count)';
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,14 @@ class SpaceModel {
|
||||
? Offset(json['x'], json['y'])
|
||||
: const Offset(0, 0),
|
||||
isHovered: false,
|
||||
selectedProducts: json['spaceProducts'] != null
|
||||
? (json['spaceProducts'] as List).map((product) {
|
||||
return SelectedProduct(
|
||||
productId: product['product']['uuid'],
|
||||
count: product['productCount'],
|
||||
);
|
||||
}).toList()
|
||||
: [],
|
||||
);
|
||||
|
||||
// Add incomingConnection to the instance after creation
|
||||
@ -97,4 +105,18 @@ class SpaceModel {
|
||||
void addOutgoingConnection(Connection connection) {
|
||||
outgoingConnections.add(connection);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return '''
|
||||
SpaceModel(
|
||||
uuid: $uuid,
|
||||
name: $name,
|
||||
icon: $icon,
|
||||
isPrivate: $isPrivate,
|
||||
position: $position,
|
||||
selectedProducts: $selectedProducts
|
||||
)
|
||||
''';
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:flutter_svg/svg.dart';
|
||||
import 'package:syncrow_web/pages/common/buttons/add_space_button.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_bloc.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/selected_product_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_space_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/create_space_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/curved_line_painter.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/delete_dialogue.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/space_card_widget.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/connection_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/space_container_widget.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
||||
class CommunityStructureArea extends StatefulWidget {
|
||||
final CommunityModel? selectedCommunity;
|
||||
@ -116,6 +119,7 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
return SpaceContainerWidget(
|
||||
index: index,
|
||||
onDoubleTap: () {
|
||||
print(spaces[index].toString());
|
||||
_showEditSpaceDialog(spaces[index]);
|
||||
},
|
||||
icon: spaces[index].icon ?? '',
|
||||
@ -178,23 +182,55 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
),
|
||||
// Show "Save" button only if there are spaces
|
||||
if (spaces.isNotEmpty && widget.selectedCommunity != null)
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
_saveSpaces();
|
||||
},
|
||||
icon: const Icon(Icons.save, size: 18),
|
||||
label: const Text("Save"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: ColorsManager.whiteColors,
|
||||
foregroundColor: Colors.black,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
Row(children: [
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
_saveSpaces();
|
||||
},
|
||||
icon: const Icon(
|
||||
Icons.save,
|
||||
size: 18,
|
||||
color: ColorsManager.spaceColor,
|
||||
),
|
||||
label: const Text("Save"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: ColorsManager.textFieldGreyColor,
|
||||
foregroundColor: ColorsManager.blackColor,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
side: BorderSide(color: Colors.grey.shade300),
|
||||
elevation: 0,
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
|
||||
side: BorderSide(color: Colors.grey.shade300),
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
showDeleteConfirmationDialog(context, () {
|
||||
// Handle the delete action here
|
||||
print("Delete confirmed");
|
||||
Navigator.of(context).pop(); // Close the dialog after confirming
|
||||
}, widget.selectedSpace != null);
|
||||
},
|
||||
icon: SvgPicture.asset(
|
||||
Assets.acFanAuto, // Path to your SVG asset
|
||||
width: 18, // Adjust width as needed
|
||||
height: 18, // Adjust height as needed
|
||||
),
|
||||
label: const Text("Delete"),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: ColorsManager.textFieldGreyColor,
|
||||
foregroundColor: Colors.black,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
|
||||
side: BorderSide(color: ColorsManager.neutralGray),
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
])
|
||||
],
|
||||
),
|
||||
);
|
||||
@ -284,35 +320,35 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showEditSpaceDialog(SpaceModel space) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSpaceDialog(
|
||||
products: widget.products,
|
||||
name: space.name,
|
||||
icon: space.icon,
|
||||
isEdit: true,
|
||||
selectedProducts: space.selectedProducts,
|
||||
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts) {
|
||||
setState(() {
|
||||
// Update the space's properties
|
||||
space.name = name;
|
||||
space.icon = icon;
|
||||
space.selectedProducts = selectedProducts;
|
||||
|
||||
void _showEditSpaceDialog(SpaceModel space) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CreateSpaceDialog(
|
||||
products: widget.products,
|
||||
name: space.name,
|
||||
icon: space.icon,
|
||||
isEdit: true,
|
||||
selectedProducts: space.selectedProducts,
|
||||
onCreateSpace: (String name, String icon, List<SelectedProduct> selectedProducts) {
|
||||
setState(() {
|
||||
// Update the space's properties
|
||||
space.name = name;
|
||||
space.icon = icon;
|
||||
space.selectedProducts = selectedProducts;
|
||||
if (space.status != SpaceStatus.newSpace) {
|
||||
space.status = SpaceStatus.modified; // Mark as modified
|
||||
}
|
||||
});
|
||||
},
|
||||
// Pre-fill the dialog with current space data
|
||||
key: Key(space.name), // Add a unique key to ensure dialog refresh
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
if (space.status != SpaceStatus.newSpace) {
|
||||
space.status = SpaceStatus.modified; // Mark as modified
|
||||
}
|
||||
});
|
||||
},
|
||||
// Pre-fill the dialog with current space data
|
||||
key: Key(space.name), // Add a unique key to ensure dialog refresh
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
void _handleHoverChanged(int index, bool isHovered) {
|
||||
setState(() {
|
||||
spaces[index].isHovered = isHovered;
|
||||
|
@ -369,6 +369,7 @@ class CreateSpaceDialogState extends State<CreateSpaceDialog> {
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
return product.icon ?? Assets.presenceSensor;
|
||||
}
|
||||
|
225
lib/pages/spaces_management/widgets/dialogs/delete_dialogue.dart
Normal file
225
lib/pages/spaces_management/widgets/dialogs/delete_dialogue.dart
Normal file
@ -0,0 +1,225 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
|
||||
void showDeleteConfirmationDialog(BuildContext context, VoidCallback onConfirm, bool isSpace) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false, // Prevent dismissing by tapping outside
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 500, // Set the desired width
|
||||
child: Container(
|
||||
color: ColorsManager.whiteColors,
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Icon
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.warningRed,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Title
|
||||
isSpace
|
||||
? const Text(
|
||||
'Delete Space',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'Delete Community',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// Subtitle
|
||||
isSpace
|
||||
? const Text(
|
||||
'All the data in the space will be lost',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'All the data in the community will be lost',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 20),
|
||||
// Buttons
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Close the first dialog
|
||||
// Trigger the second popup
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: const BorderSide(color: ColorsManager.boxColor), // Black border
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cancel',
|
||||
style: TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Close the first dialog
|
||||
showProcessingPopup(context, isSpace, onConfirm);
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Continue',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void showProcessingPopup(BuildContext context, bool isSpace, VoidCallback onDelete) {
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return Dialog(
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16.0),
|
||||
),
|
||||
child: SizedBox(
|
||||
width: 500,
|
||||
child: Container(
|
||||
color: ColorsManager.whiteColors,
|
||||
padding: const EdgeInsets.all(20.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Icon
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
decoration: BoxDecoration(
|
||||
color: ColorsManager.warningRed,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.close,
|
||||
color: Colors.white,
|
||||
size: 40,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Title
|
||||
isSpace
|
||||
? const Text(
|
||||
'Delete Space',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
)
|
||||
: const Text(
|
||||
'Delete Community',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// Subtitle
|
||||
const Text(
|
||||
'Are you sure you want to Delete?',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
// Buttons (Optional)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
// Trigger the second popup
|
||||
onDelete();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: ColorsManager.warningRed,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
side: const BorderSide(color: ColorsManager.boxColor), // Black border
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Delete',
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop(); // Close the first dialog
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8.0),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
'Cancel',
|
||||
style: TextStyle(color: Colors.black),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
@ -7,7 +7,7 @@ import 'package:syncrow_web/pages/spaces_management/bloc/space_management_event.
|
||||
import 'package:syncrow_web/pages/spaces_management/model/community_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/model/space_model.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/community_tile.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/view/dialogs/create_community_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/dialogs/create_community_dialog.dart';
|
||||
import 'package:syncrow_web/pages/spaces_management/widgets/space_tile_widget.dart';
|
||||
import 'package:syncrow_web/utils/color_manager.dart';
|
||||
import 'package:syncrow_web/utils/constants/assets.dart';
|
||||
|
@ -183,6 +183,7 @@ class CommunitySpaceManagementApi {
|
||||
String? direction,
|
||||
bool isPrivate = false,
|
||||
required Offset position,
|
||||
required List<SelectedProduct> products,
|
||||
}) async {
|
||||
try {
|
||||
final body = {
|
||||
@ -191,7 +192,8 @@ class CommunitySpaceManagementApi {
|
||||
'x': position.dx,
|
||||
'y': position.dy,
|
||||
'direction': direction,
|
||||
'icon': icon
|
||||
'icon': icon,
|
||||
'products': products.map((product) => product.toJson()).toList(),
|
||||
};
|
||||
if (parentId != null) {
|
||||
body['parentUuid'] = parentId;
|
||||
@ -235,7 +237,10 @@ class CommunitySpaceManagementApi {
|
||||
final response = await HTTPService().get(
|
||||
path: ApiEndpoints.getSpaceHierarchy.replaceAll('{communityId}', communityId),
|
||||
expectedResponseModel: (json) {
|
||||
return (json['data'] as List).map((spaceJson) => SpaceModel.fromJson(spaceJson)).toList();
|
||||
final spaceModels =
|
||||
(json['data'] as List).map((spaceJson) => SpaceModel.fromJson(spaceJson)).toList();
|
||||
|
||||
return spaceModels;
|
||||
},
|
||||
);
|
||||
return response;
|
||||
|
@ -234,4 +234,6 @@ class Assets {
|
||||
|
||||
static const String garageDoor = 'assets/icons/garage_opener.svg';
|
||||
static const String doorSensor = 'assets/icons/door_sensor.svg';
|
||||
|
||||
static const String delete = 'assets/icons/delete_svg';
|
||||
}
|
||||
|
Reference in New Issue
Block a user