mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 07:07:19 +00:00
44 lines
1.3 KiB
Dart
44 lines
1.3 KiB
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';
|
|
|
|
class SpaceHelper {
|
|
static SpaceModel? findSpaceByUuid(
|
|
String? uuid, List<CommunityModel> communities) {
|
|
for (var community in communities) {
|
|
for (var space in community.spaces) {
|
|
if (space.uuid == uuid) return space;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
static SpaceModel? findSpaceByInternalId(
|
|
String? internalId, List<SpaceModel> spaces) {
|
|
if (internalId != null) {
|
|
for (var space in spaces) {
|
|
if (space.internalId == internalId) return space;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
static String generateUniqueSpaceName(
|
|
String originalName, List<SpaceModel> spaces) {
|
|
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
|
|
int maxNumber = 0;
|
|
|
|
for (var space in spaces) {
|
|
final match = RegExp(r'^(.*?)\((\d+)\)$').firstMatch(space.name);
|
|
if (match != null && match.group(1)?.trim() == baseName) {
|
|
int existingNumber = int.parse(match.group(2)!);
|
|
if (existingNumber > maxNumber) {
|
|
maxNumber = existingNumber;
|
|
}
|
|
}
|
|
}
|
|
|
|
return "$baseName(${maxNumber + 1})";
|
|
}
|
|
}
|