mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +00:00
fixed edit community
This commit is contained in:
4
assets/icons/edit.svg
Normal file
4
assets/icons/edit.svg
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M8.10573 4.33603C7.94393 4.33603 7.81275 4.4672 7.81275 4.629V8.92602C7.81275 9.19526 7.5937 9.41431 7.32445 9.41431H1.07425C0.805006 9.41431 0.585956 9.19526 0.585956 8.92602V2.67582C0.585956 2.40657 0.805006 2.18752 1.07425 2.18752H5.37127C5.53307 2.18752 5.66425 2.05634 5.66425 1.89454C5.66425 1.73274 5.53307 1.60156 5.37127 1.60156H1.07425C0.48191 1.60156 0 2.08347 0 2.67582V8.92602C0 9.51836 0.48191 10.0003 1.07425 10.0003H7.32445C7.9168 10.0003 8.39871 9.51836 8.39871 8.92602V4.629C8.39871 4.4672 8.26753 4.33603 8.10573 4.33603Z" fill="#999999"/>
|
||||||
|
<path d="M9.8001 0.752358L9.24764 0.199899C8.98113 -0.066633 8.54744 -0.066633 8.28087 0.199899L3.86134 4.61946C3.82044 4.66036 3.79256 4.71245 3.7812 4.76917L3.50496 6.15029C3.48576 6.24634 3.51582 6.34564 3.5851 6.4149C3.64059 6.47039 3.71533 6.50073 3.79225 6.50073C3.81137 6.50073 3.83059 6.49885 3.84969 6.49504L5.23081 6.2188C5.28753 6.20746 5.33963 6.17956 5.38053 6.13867L9.8001 1.71913C9.8001 1.71913 9.80012 1.71913 9.80012 1.71911C10.0666 1.4526 10.0666 1.01891 9.8001 0.752358ZM5.02893 5.66162L4.16574 5.83428L4.3384 4.97109L7.93559 1.37384L8.62616 2.06441L5.02893 5.66162ZM9.38577 1.3048L9.04049 1.65008L8.34992 0.959513L8.69518 0.614248C8.73327 0.576161 8.79523 0.576142 8.83331 0.614229L9.38575 1.16669C9.42386 1.20476 9.42386 1.26673 9.38577 1.3048Z" fill="#999999"/>
|
||||||
|
</svg>
|
After Width: | Height: | Size: 1.4 KiB |
@ -20,6 +20,24 @@ class SpaceManagementBloc extends Bloc<SpaceManagementEvent, SpaceManagementStat
|
|||||||
on<SaveSpacesEvent>(_onSaveSpaces);
|
on<SaveSpacesEvent>(_onSaveSpaces);
|
||||||
on<FetchProductsEvent>(_onFetchProducts);
|
on<FetchProductsEvent>(_onFetchProducts);
|
||||||
on<DeleteCommunityEvent>(_onCommunityDelete);
|
on<DeleteCommunityEvent>(_onCommunityDelete);
|
||||||
|
on<UpdateCommunityEvent>(_onUpdateCommunity);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onUpdateCommunity(
|
||||||
|
UpdateCommunityEvent event,
|
||||||
|
Emitter<SpaceManagementState> emit,
|
||||||
|
) async {
|
||||||
|
try {
|
||||||
|
emit(SpaceManagementLoading());
|
||||||
|
final success = await _api.updateCommunity(event.communityUuid, event.name);
|
||||||
|
if (success) {
|
||||||
|
add(LoadCommunityAndSpacesEvent());
|
||||||
|
} else {
|
||||||
|
emit(const SpaceManagementError('Failed to update the community.'));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
emit(SpaceManagementError('Error updating community: $e'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onFetchProducts(
|
void _onFetchProducts(
|
||||||
|
@ -95,3 +95,16 @@ class LoadSpaceHierarchyEvent extends SpaceManagementEvent {
|
|||||||
@override
|
@override
|
||||||
List<Object> get props => [communityId];
|
List<Object> get props => [communityId];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class UpdateCommunityEvent extends SpaceManagementEvent {
|
||||||
|
final String communityUuid;
|
||||||
|
final String name;
|
||||||
|
|
||||||
|
const UpdateCommunityEvent({
|
||||||
|
required this.communityUuid,
|
||||||
|
required this.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
List<Object> get props => [communityUuid, name];
|
||||||
|
}
|
||||||
|
@ -5,7 +5,7 @@ class CommunityModel {
|
|||||||
final String uuid;
|
final String uuid;
|
||||||
final DateTime createdAt;
|
final DateTime createdAt;
|
||||||
final DateTime updatedAt;
|
final DateTime updatedAt;
|
||||||
final String name;
|
String name;
|
||||||
final String description;
|
final String description;
|
||||||
final RegionModel? region;
|
final RegionModel? region;
|
||||||
List<SpaceModel> spaces;
|
List<SpaceModel> spaces;
|
||||||
@ -27,12 +27,9 @@ class CommunityModel {
|
|||||||
updatedAt: DateTime.parse(json['updatedAt']),
|
updatedAt: DateTime.parse(json['updatedAt']),
|
||||||
name: json['name'],
|
name: json['name'],
|
||||||
description: json['description'],
|
description: json['description'],
|
||||||
region:
|
region: json['region'] != null ? RegionModel.fromJson(json['region']) : null,
|
||||||
json['region'] != null ? RegionModel.fromJson(json['region']) : null,
|
|
||||||
spaces: json['spaces'] != null
|
spaces: json['spaces'] != null
|
||||||
? (json['spaces'] as List)
|
? (json['spaces'] as List).map((space) => SpaceModel.fromJson(space)).toList()
|
||||||
.map((space) => SpaceModel.fromJson(space))
|
|
||||||
.toList()
|
|
||||||
: [],
|
: [],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -45,9 +42,7 @@ class CommunityModel {
|
|||||||
'name': name,
|
'name': name,
|
||||||
'description': description,
|
'description': description,
|
||||||
'region': region?.toJson(),
|
'region': region?.toJson(),
|
||||||
'spaces': spaces
|
'spaces': spaces.map((space) => space.toMap()).toList(), // Convert spaces to Map
|
||||||
.map((space) => space.toMap())
|
|
||||||
.toList(), // Convert spaces to Map
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,8 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
double canvasHeight = 1000;
|
double canvasHeight = 1000;
|
||||||
List<SpaceModel> spaces = [];
|
List<SpaceModel> spaces = [];
|
||||||
List<Connection> connections = [];
|
List<Connection> connections = [];
|
||||||
|
late TextEditingController _nameController;
|
||||||
|
bool isEditingName = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -49,6 +51,15 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
spaces = widget.spaces.isNotEmpty ? flattenSpaces(widget.spaces) : [];
|
||||||
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
connections = widget.spaces.isNotEmpty ? createConnections(widget.spaces) : [];
|
||||||
_adjustCanvasSizeForSpaces();
|
_adjustCanvasSizeForSpaces();
|
||||||
|
_nameController = TextEditingController(
|
||||||
|
text: widget.selectedCommunity?.name ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_nameController.dispose();
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -176,9 +187,59 @@ class _CommunityStructureAreaState extends State<CommunityStructureArea> {
|
|||||||
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
|
||||||
),
|
),
|
||||||
if (widget.selectedCommunity != null)
|
if (widget.selectedCommunity != null)
|
||||||
Text(
|
Row(
|
||||||
widget.selectedCommunity?.name ?? '',
|
children: [
|
||||||
style: const TextStyle(fontSize: 16, color: ColorsManager.blackColor),
|
// Show Text widget when not editing
|
||||||
|
if (!isEditingName)
|
||||||
|
Text(
|
||||||
|
widget.selectedCommunity?.name ?? '',
|
||||||
|
style: const TextStyle(fontSize: 16, color: ColorsManager.blackColor),
|
||||||
|
),
|
||||||
|
if (isEditingName) // Show TextField when editing
|
||||||
|
SizedBox(
|
||||||
|
width: 200, // Adjusted width to make TextField visible
|
||||||
|
child: TextField(
|
||||||
|
controller: _nameController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
border: InputBorder.none,
|
||||||
|
isDense: true, // Reduce the height of the TextField
|
||||||
|
),
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
color: ColorsManager.blackColor,
|
||||||
|
),
|
||||||
|
onSubmitted: (value) {
|
||||||
|
context.read<SpaceManagementBloc>().add(
|
||||||
|
UpdateCommunityEvent(
|
||||||
|
communityUuid: widget.selectedCommunity!.uuid,
|
||||||
|
name: value,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
setState(() {
|
||||||
|
widget.selectedCommunity?.name = value; // Update the name
|
||||||
|
isEditingName = false; // Exit edit mode
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
if (!isEditingName)
|
||||||
|
GestureDetector(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
isEditingName = !isEditingName; // Toggle edit mode
|
||||||
|
});
|
||||||
|
if (isEditingName) {
|
||||||
|
_nameController.text = widget.selectedCommunity?.name ?? ''; // Pre-fill
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: SvgPicture.asset(
|
||||||
|
Assets.iconEdit, // Path to the edit icon SVG asset
|
||||||
|
width: 16,
|
||||||
|
height: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -65,11 +65,13 @@ class CommunitySpaceManagementApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<bool> updateCommunity(String communityId, CommunityModel community) async {
|
Future<bool> updateCommunity(String communityId, String name) async {
|
||||||
try {
|
try {
|
||||||
final response = await HTTPService().put(
|
final response = await HTTPService().put(
|
||||||
path: ApiEndpoints.updateCommunity.replaceAll('{communityId}', communityId),
|
path: ApiEndpoints.updateCommunity.replaceAll('{communityId}', communityId),
|
||||||
body: community.toMap(),
|
body: {
|
||||||
|
'name': name,
|
||||||
|
},
|
||||||
expectedResponseModel: (json) {
|
expectedResponseModel: (json) {
|
||||||
return json['success'] ?? false;
|
return json['success'] ?? false;
|
||||||
},
|
},
|
||||||
|
@ -236,4 +236,5 @@ class Assets {
|
|||||||
static const String doorSensor = 'assets/icons/door_sensor.svg';
|
static const String doorSensor = 'assets/icons/door_sensor.svg';
|
||||||
|
|
||||||
static const String delete = 'assets/icons/delete.svg';
|
static const String delete = 'assets/icons/delete.svg';
|
||||||
|
static const String edit = 'assets/icons/edit.svg';
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user