formatted all files.

This commit is contained in:
Faris Armoush
2025-06-12 15:33:32 +03:00
parent 29959f567e
commit 04250ebc98
474 changed files with 5425 additions and 4338 deletions

View File

@ -2,18 +2,20 @@ import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_m
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) {
static SpaceModel? findSpaceByUuid(
String? uuid, List<CommunityModel> communities) {
for (final community in communities) {
for (final space in community.spaces) {
if (space.uuid == uuid) return space;
}
}
return null;
}
static SpaceModel? findSpaceByInternalId(String? internalId, List<SpaceModel> spaces) {
static SpaceModel? findSpaceByInternalId(
String? internalId, List<SpaceModel> spaces) {
if (internalId != null) {
for (var space in spaces) {
for (final space in spaces) {
if (space.internalId == internalId) return space;
}
}
@ -21,21 +23,22 @@ class SpaceHelper {
return null;
}
static String generateUniqueSpaceName(String originalName, List<SpaceModel> spaces) {
static String generateUniqueSpaceName(
String originalName, List<SpaceModel> spaces) {
final baseName = originalName.replaceAll(RegExp(r'\(\d+\)$'), '').trim();
int maxNumber = 0;
var maxNumber = 0;
for (var space in spaces) {
for (final 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)!);
final existingNumber = int.parse(match.group(2)!);
if (existingNumber > maxNumber) {
maxNumber = existingNumber;
}
}
}
return "$baseName(${maxNumber + 1})";
return '$baseName(${maxNumber + 1})';
}
static bool isSave(List<SpaceModel> spaces) {
@ -51,10 +54,13 @@ class SpaceHelper {
return space == selectedSpace ||
selectedSpace.parent?.internalId == space.internalId ||
selectedSpace.children?.any((child) => child.internalId == space.internalId) == true;
selectedSpace.children
.any((child) => child.internalId == space.internalId) ==
true;
}
static bool isNameConflict(String value, SpaceModel? parentSpace, SpaceModel? editSpace) {
static bool isNameConflict(
String value, SpaceModel? parentSpace, SpaceModel? editSpace) {
final siblings = parentSpace?.children
.where((child) => child.internalId != editSpace?.internalId)
.toList() ??
@ -65,17 +71,19 @@ class SpaceHelper {
.toList() ??
[];
final editSiblingConflict = editSiblings.any((child) => child.name == value);
final editSiblingConflict =
editSiblings.any((child) => child.name == value);
final siblingConflict = siblings.any((child) => child.name == value);
final parentConflict =
parentSpace?.name == value && parentSpace?.internalId != editSpace?.internalId;
final parentConflict = parentSpace?.name == value &&
parentSpace?.internalId != editSpace?.internalId;
final parentOfEditSpaceConflict =
editSpace?.parent?.name == value && editSpace?.parent?.internalId != editSpace?.internalId;
final parentOfEditSpaceConflict = editSpace?.parent?.name == value &&
editSpace?.parent?.internalId != editSpace?.internalId;
final childConflict = editSpace?.children.any((child) => child.name == value) ?? false;
final childConflict =
editSpace?.children.any((child) => child.name == value) ?? false;
return siblingConflict ||
parentConflict ||

View File

@ -24,7 +24,7 @@ class TagHelper {
final modifiedSubspaces = List<dynamic>.from(subspaces ?? []);
if (subspaces != null) {
for (var subspace in subspaces) {
for (final subspace in subspaces) {
getSubspaceTags(subspace)?.removeWhere(
(tag) => !modifiedTags.any(
(updatedTag) => getInternalId(updatedTag) == getInternalId(tag)),
@ -32,7 +32,7 @@ class TagHelper {
}
}
for (var tag in modifiedTags.toList()) {
for (final tag in modifiedTags.toList()) {
if (modifiedSubspaces.isEmpty) continue;
final prevIndice = checkTagExistInSubspace(tag, modifiedSubspaces);
@ -131,8 +131,7 @@ class TagHelper {
static List<String> getAvailableTagModels(
List<String> allTags, List<Tag> currentTags, Tag currentTag) {
List<String> availableTagsForTagModel =
TagHelper.getAvailableTags<Tag>(
final availableTagsForTagModel = TagHelper.getAvailableTags<Tag>(
allTags: allTags,
currentTags: currentTags,
currentTag: currentTag,
@ -145,14 +144,14 @@ class TagHelper {
List<Tag>? spaceTagModels,
List<SubspaceTemplateModel>? subspaces,
}) {
final List<Tag> initialTags = [];
final initialTags = <Tag>[];
if (spaceTagModels != null) {
initialTags.addAll(spaceTagModels);
}
if (subspaces != null) {
for (var subspace in subspaces) {
for (final subspace in subspaces) {
if (subspace.tags != null) {
initialTags.addAll(
subspace.tags!.map(
@ -174,14 +173,14 @@ class TagHelper {
List<Tag>? spaceTags,
List<SubspaceModel>? subspaces,
}) {
final List<Tag> initialTags = [];
final initialTags = <Tag>[];
if (spaceTags != null) {
initialTags.addAll(spaceTags);
}
if (subspaces != null) {
for (var subspace in subspaces) {
for (final subspace in subspaces) {
if (subspace.tags != null) {
initialTags.addAll(
subspace.tags!.map(
@ -200,8 +199,8 @@ class TagHelper {
}
static Map<ProductModel, int> groupTags(List<BaseTag> tags) {
final Map<ProductModel, int> groupedTags = {};
for (var tag in tags) {
final groupedTags = <ProductModel, int>{};
for (final tag in tags) {
if (tag.product != null) {
final product = tag.product!;
groupedTags[product] = (groupedTags[product] ?? 0) + 1;
@ -212,10 +211,10 @@ class TagHelper {
static List<SelectedProduct> createInitialSelectedProducts(
List<Tag>? tags, List<SubspaceTemplateModel>? subspaces) {
final Map<ProductModel, int> productCounts = {};
final productCounts = <ProductModel, int>{};
if (tags != null) {
for (var tag in tags) {
for (final tag in tags) {
if (tag.product != null) {
productCounts[tag.product!] = (productCounts[tag.product!] ?? 0) + 1;
}
@ -223,9 +222,9 @@ class TagHelper {
}
if (subspaces != null) {
for (var subspace in subspaces) {
for (final subspace in subspaces) {
if (subspace.tags != null) {
for (var tag in subspace.tags!) {
for (final tag in subspace.tags!) {
if (tag.product != null) {
productCounts[tag.product!] =
(productCounts[tag.product!] ?? 0) + 1;
@ -247,10 +246,10 @@ class TagHelper {
static List<SelectedProduct> createInitialSelectedProductsForTags(
List<Tag>? tags, List<SubspaceModel>? subspaces) {
final Map<ProductModel, int> productCounts = {};
final productCounts = <ProductModel, int>{};
if (tags != null) {
for (var tag in tags) {
for (final tag in tags) {
if (tag.product != null) {
productCounts[tag.product!] = (productCounts[tag.product!] ?? 0) + 1;
}
@ -258,9 +257,9 @@ class TagHelper {
}
if (subspaces != null) {
for (var subspace in subspaces) {
for (final subspace in subspaces) {
if (subspace.tags != null) {
for (var tag in subspace.tags!) {
for (final tag in subspace.tags!) {
if (tag.product != null) {
productCounts[tag.product!] =
(productCounts[tag.product!] ?? 0) + 1;
@ -280,14 +279,13 @@ class TagHelper {
.toList();
}
static int? checkTagExistInSubspaceModels(
Tag tag, List<dynamic>? subspaces) {
static int? checkTagExistInSubspaceModels(Tag tag, List<dynamic>? subspaces) {
if (subspaces == null) return null;
for (int i = 0; i < subspaces.length; i++) {
for (var i = 0; i < subspaces.length; i++) {
final subspace = subspaces[i] as SubspaceTemplateModel; // Explicit cast
if (subspace.tags == null) continue;
for (var t in subspace.tags!) {
for (final t in subspace.tags!) {
if (tag.internalId == t.internalId) {
return i;
}
@ -314,11 +312,11 @@ class TagHelper {
final processedSubspaces =
List<SubspaceTemplateModel>.from(result['subspaces'] as List<dynamic>);
for (var subspace in processedSubspaces) {
for (final subspace in processedSubspaces) {
final subspaceTags = subspace.tags;
if (subspaceTags != null) {
for (int i = 0; i < subspaceTags.length; i++) {
for (var i = 0; i < subspaceTags.length; i++) {
final tag = subspaceTags[i];
// Find the updated tag inside processedTags
@ -341,10 +339,10 @@ class TagHelper {
static int? checkTagExistInSubspace(Tag tag, List<dynamic>? subspaces) {
if (subspaces == null) return null;
for (int i = 0; i < subspaces.length; i++) {
for (var i = 0; i < subspaces.length; i++) {
final subspace = subspaces[i];
if (subspace.tags == null) continue;
for (var t in subspace.tags!) {
for (final t in subspace.tags!) {
if (tag.internalId == t.internalId) {
return i;
}
@ -371,11 +369,11 @@ class TagHelper {
final processedSubspaces =
List<SubspaceModel>.from(result['subspaces'] as List<dynamic>);
for (var subspace in processedSubspaces) {
for (final subspace in processedSubspaces) {
final subspaceTags = subspace.tags;
if (subspaceTags != null) {
for (int i = 0; i < subspaceTags.length; i++) {
for (var i = 0; i < subspaceTags.length; i++) {
final tag = subspaceTags[i];
final changedTag = updatedTags.firstWhere(
@ -397,10 +395,10 @@ class TagHelper {
static List<String> getAllTagValues(
List<CommunityModel> communities, List<SpaceTemplateModel>? spaceModels) {
final Set<String> allTags = {};
final allTags = <String>{};
if (spaceModels != null) {
for (var model in spaceModels) {
for (final model in spaceModels) {
allTags.addAll(model.listAllTagValues());
}
}