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

@ -1,20 +1,19 @@
import 'dart:async';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:syncrow_web/pages/common/bloc/project_manager.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_bloc.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_event.dart';
import 'package:syncrow_web/pages/space_tree/bloc/space_tree_state.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_state.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/community_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/create_subspace_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/product_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/space_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_event.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/bloc/space_management_state.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/subspace_model.dart';
import 'package:syncrow_web/pages/spaces_management/all_spaces/model/tag.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/space_template_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_body_model.dart';
import 'package:syncrow_web/pages/spaces_management/space_model/models/tag_update_model.dart';
import 'package:syncrow_web/services/product_api.dart';
import 'package:syncrow_web/services/space_mana_api.dart';
@ -57,10 +56,10 @@ class SpaceManagementBloc
UpdateSpaceModelCache event, Emitter<SpaceManagementState> emit) async {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
List<SpaceTemplateModel> allSpaceModels = [];
final allSpaceModels = <SpaceTemplateModel>[];
bool hasNext = true;
int page = 1;
var hasNext = true;
var page = 1;
while (hasNext) {
final spaceModels = await _spaceModelApi.listSpaceModels(
@ -85,7 +84,7 @@ class SpaceManagementBloc
allTags: _cachedTags ?? []));
}
void _deleteSpaceModelFromCache(DeleteSpaceModelFromCache event,
Future<void> _deleteSpaceModelFromCache(DeleteSpaceModelFromCache event,
Emitter<SpaceManagementState> emit) async {
if (_cachedSpaceModels != null) {
_cachedSpaceModels = _cachedSpaceModels!
@ -121,10 +120,10 @@ class SpaceManagementBloc
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
List<SpaceTemplateModel> allSpaceModels = [];
final allSpaceModels = <SpaceTemplateModel>[];
bool hasNext = true;
int page = 1;
var hasNext = true;
var page = 1;
while (hasNext) {
final spaceModels = await _spaceModelApi.listSpaceModels(
@ -159,7 +158,7 @@ class SpaceManagementBloc
}
}
void _onUpdateCommunity(
Future<void> _onUpdateCommunity(
UpdateCommunityEvent event,
Emitter<SpaceManagementState> emit,
) async {
@ -175,7 +174,7 @@ class SpaceManagementBloc
if (previousState is SpaceManagementLoaded) {
final updatedCommunities =
List<CommunityModel>.from(previousState.communities);
for (var community in updatedCommunities) {
for (final community in updatedCommunities) {
if (community.uuid == event.communityUuid) {
community.name = event.name;
_spaceTreeBloc.add(OnCommunityAdded(community));
@ -184,7 +183,7 @@ class SpaceManagementBloc
}
}
var prevSpaceModels = await fetchSpaceModels();
final prevSpaceModels = await fetchSpaceModels();
emit(SpaceManagementLoaded(
communities: updatedCommunities,
@ -201,14 +200,14 @@ class SpaceManagementBloc
}
}
void _onloadProducts() async {
Future<void> _onloadProducts() async {
if (_cachedProducts == null) {
final products = await _productApi.fetchProducts();
_cachedProducts = products;
}
}
void _onFetchProducts(
Future<void> _onFetchProducts(
FetchProductsEvent event,
Emitter<SpaceManagementState> emit,
) async {
@ -223,7 +222,7 @@ class SpaceManagementBloc
String communityUuid) async {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
return await _api.getSpaceHierarchy(communityUuid, projectUuid);
return _api.getSpaceHierarchy(communityUuid, projectUuid);
}
Future<void> _onNewCommunity(
@ -238,7 +237,7 @@ class SpaceManagementBloc
return;
}
var prevSpaceModels = await fetchSpaceModels();
final prevSpaceModels = await fetchSpaceModels();
emit(BlankState(
communities: event.communities,
@ -255,15 +254,15 @@ class SpaceManagementBloc
try {
final previousState = state;
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
var spaceBloc = event.context.read<SpaceTreeBloc>();
var spaceTreeState = event.context.read<SpaceTreeBloc>().state;
final spaceBloc = event.context.read<SpaceTreeBloc>();
final spaceTreeState = event.context.read<SpaceTreeBloc>().state;
List<CommunityModel> communities =
final communities =
await _waitForCommunityList(spaceBloc, spaceTreeState);
await fetchSpaceModels();
// await fetchTags();
var prevSpaceModels = await fetchSpaceModels();
final prevSpaceModels = await fetchSpaceModels();
if (previousState is SpaceManagementLoaded ||
previousState is BlankState) {
@ -287,18 +286,17 @@ class SpaceManagementBloc
}
}
void _onLoadCommunityAndSpaces(
Future<void> _onLoadCommunityAndSpaces(
LoadCommunityAndSpacesEvent event,
Emitter<SpaceManagementState> emit,
) async {
var spaceTreeState = event.context.read<SpaceTreeBloc>().state;
var spaceBloc = event.context.read<SpaceTreeBloc>();
final spaceTreeState = event.context.read<SpaceTreeBloc>().state;
final spaceBloc = event.context.read<SpaceTreeBloc>();
_onloadProducts();
await fetchTags();
// Wait until `communityList` is loaded
List<CommunityModel> communities =
await _waitForCommunityList(spaceBloc, spaceTreeState);
final communities = await _waitForCommunityList(spaceBloc, spaceTreeState);
// Fetch space models after communities are available
final prevSpaceModels = await fetchSpaceModels();
@ -344,7 +342,7 @@ class SpaceManagementBloc
}
}
void _onCommunityDelete(
Future<void> _onCommunityDelete(
DeleteCommunityEvent event,
Emitter<SpaceManagementState> emit,
) async {
@ -365,7 +363,7 @@ class SpaceManagementBloc
}
}
void _onCreateCommunity(
Future<void> _onCreateCommunity(
CreateCommunityEvent event,
Emitter<SpaceManagementState> emit,
) async {
@ -375,9 +373,9 @@ class SpaceManagementBloc
try {
final projectUuid = await ProjectManager.getProjectUUID() ?? '';
await fetchTags();
CommunityModel? newCommunity = await _api.createCommunity(
final newCommunity = await _api.createCommunity(
event.name, event.description, projectUuid);
var prevSpaceModels = await fetchSpaceModels();
final prevSpaceModels = await fetchSpaceModels();
if (newCommunity != null) {
if (previousState is SpaceManagementLoaded ||
@ -405,7 +403,7 @@ class SpaceManagementBloc
}
}
void _onSelectCommunity(
Future<void> _onSelectCommunity(
SelectCommunityEvent event,
Emitter<SpaceManagementState> emit,
) async {
@ -431,7 +429,7 @@ class SpaceManagementBloc
);
}
void _handleCommunitySpaceStateUpdate({
Future<void> _handleCommunitySpaceStateUpdate({
required Emitter<SpaceManagementState> emit,
CommunityModel? selectedCommunity,
SpaceModel? selectedSpace,
@ -464,7 +462,7 @@ class SpaceManagementBloc
}
}
void _onSaveSpaces(
Future<void> _onSaveSpaces(
SaveSpacesEvent event,
Emitter<SpaceManagementState> emit,
) async {
@ -494,9 +492,9 @@ class SpaceManagementBloc
event.spaces.removeWhere(
(space) => space.status == SpaceStatus.deleted,
);
event.spaces.forEach(
(space) => space.status = SpaceStatus.unchanged,
);
for (final space in event.spaces) {
space.status = SpaceStatus.unchanged;
}
}
} catch (e) {
// emit(SpaceManagementError('Error saving spaces: $e'));
@ -515,7 +513,7 @@ class SpaceManagementBloc
Emitter<SpaceManagementState> emit,
) async {
try {
var prevSpaceModels = await fetchSpaceModels();
final prevSpaceModels = await fetchSpaceModels();
await fetchTags();
@ -523,7 +521,7 @@ class SpaceManagementBloc
? spaceTreeState.filteredCommunity
: spaceTreeState.communityList;
for (var community in communities) {
for (final community in communities) {
if (community.uuid == communityUuid) {
community.spaces = allSpaces;
_spaceTreeBloc.add(InitialEvent());
@ -540,7 +538,7 @@ class SpaceManagementBloc
}
}
emit(previousState);
} catch (e, stackTrace) {
} catch (e) {
emit(previousState);
// rethrow;
}
@ -577,36 +575,36 @@ class SpaceManagementBloc
space.status == SpaceStatus.deleted &&
(space.parent == null || space.parent?.status != SpaceStatus.deleted));
for (var parent in parentsToDelete) {
for (final parent in parentsToDelete) {
try {
if (parent.uuid != null) {
await _api.deleteSpace(communityUuid, parent.uuid!, projectUuid);
}
} catch (e) {}
}
orderedSpaces.removeWhere((space) => parentsToDelete.contains(space));
orderedSpaces.removeWhere(parentsToDelete.contains);
for (var space in orderedSpaces) {
for (final space in orderedSpaces) {
try {
if (space.uuid != null && space.uuid!.isNotEmpty) {
List<TagModelUpdate> tagUpdates = [];
var tagUpdates = <TagModelUpdate>[];
List<SpaceModel> matchedSpaces =
final matchedSpaces =
findMatchingSpaces(selectedCommunity.spaces, space.uuid!);
if (matchedSpaces.isEmpty) continue;
final prevSpace = matchedSpaces.elementAtOrNull(0);
final List<UpdateSubspaceTemplateModel> subspaceUpdates = [];
final List<SubspaceModel>? prevSubspaces = prevSpace?.subspaces;
final List<SubspaceModel>? newSubspaces = space.subspaces;
final subspaceUpdates = <UpdateSubspaceTemplateModel>[];
final prevSubspaces = prevSpace?.subspaces;
final newSubspaces = space.subspaces;
tagUpdates = processTagUpdates(prevSpace?.tags, space.tags);
if (prevSubspaces != null || newSubspaces != null) {
if (prevSubspaces != null && newSubspaces != null) {
for (var prevSubspace in prevSubspaces) {
for (final prevSubspace in prevSubspaces) {
final existsInNew = newSubspaces
.any((subspace) => subspace.uuid == prevSubspace.uuid);
if (!existsInNew) {
@ -616,7 +614,7 @@ class SpaceManagementBloc
}
}
} else if (prevSubspaces != null && newSubspaces == null) {
for (var prevSubspace in prevSubspaces) {
for (final prevSubspace in prevSubspaces) {
subspaceUpdates.add(UpdateSubspaceTemplateModel(
action: custom_action.Action.delete,
uuid: prevSubspace.uuid));
@ -624,13 +622,13 @@ class SpaceManagementBloc
}
if (newSubspaces != null) {
for (var newSubspace in newSubspaces) {
for (final newSubspace in newSubspaces) {
// Tag without UUID
if ((newSubspace.uuid == null || newSubspace.uuid!.isEmpty)) {
final List<TagModelUpdate> tagUpdates = [];
if (newSubspace.uuid == null || newSubspace.uuid!.isEmpty) {
final tagUpdates = <TagModelUpdate>[];
if (newSubspace.tags != null) {
for (var tag in newSubspace.tags!) {
for (final tag in newSubspace.tags!) {
tagUpdates.add(TagModelUpdate(
action: custom_action.Action.add,
newTagUuid: tag.uuid == '' ? null : tag.uuid,
@ -648,14 +646,14 @@ class SpaceManagementBloc
if (prevSubspaces != null && newSubspaces != null) {
final newSubspaceMap = {
for (var subspace in newSubspaces) subspace.uuid: subspace
for (final subspace in newSubspaces) subspace.uuid: subspace
};
for (var prevSubspace in prevSubspaces) {
for (final prevSubspace in prevSubspaces) {
final newSubspace = newSubspaceMap[prevSubspace.uuid];
if (newSubspace != null) {
final List<TagModelUpdate> tagSubspaceUpdates =
final tagSubspaceUpdates =
processTagUpdates(prevSubspace.tags, newSubspace.tags);
subspaceUpdates.add(UpdateSubspaceTemplateModel(
action: custom_action.Action.update,
@ -669,7 +667,7 @@ class SpaceManagementBloc
final response = await _api.updateSpace(
communityId: communityUuid,
spaceId: space.uuid!,
spaceId: space.uuid,
name: space.name,
parentId: space.parent?.uuid,
isPrivate: space.isPrivate,
@ -683,7 +681,7 @@ class SpaceManagementBloc
projectId: projectUuid);
} else {
// Call create if the space does not have a UUID
List<CreateTagBodyModel> tagBodyModels = space.tags != null
var tagBodyModels = space.tags != null
? space.tags!.map((tag) => tag.toCreateTagBodyModel()).toList()
: [];
@ -731,17 +729,17 @@ class SpaceManagementBloc
void visit(SpaceModel space) {
if (!result.contains(space)) {
result.add(space);
for (var child in spaces.where((s) => s.parent == space)) {
for (final child in spaces.where((s) => s.parent == space)) {
visit(child);
}
}
}
for (var space in topLevelSpaces) {
for (final space in topLevelSpaces) {
visit(space);
}
for (var space in spaces) {
for (final space in spaces) {
if (!result.contains(space)) {
result.add(space);
}
@ -749,7 +747,7 @@ class SpaceManagementBloc
return result.toList(); // Convert back to a list
}
void _onLoadSpaceModel(
Future<void> _onLoadSpaceModel(
SpaceModelLoadEvent event, Emitter<SpaceManagementState> emit) async {
emit(SpaceManagementLoading());
@ -760,9 +758,9 @@ class SpaceManagementBloc
? spaceTreeState.filteredCommunity
: spaceTreeState.communityList;
List<CommunityModel> communities = filteredCommunities;
final communities = filteredCommunities;
var prevSpaceModels = await fetchSpaceModels();
final prevSpaceModels = await fetchSpaceModels();
emit(SpaceModelLoaded(
communities: communities,
@ -778,11 +776,11 @@ class SpaceManagementBloc
List<Tag>? prevTags,
List<Tag>? newTags,
) {
final List<TagModelUpdate> tagUpdates = [];
final tagUpdates = <TagModelUpdate>[];
final processedTags = <String?>{};
if (prevTags == null && newTags != null) {
for (var newTag in newTags) {
for (final newTag in newTags) {
tagUpdates.add(TagModelUpdate(
action: custom_action.Action.add,
tag: newTag.tag,
@ -796,7 +794,7 @@ class SpaceManagementBloc
if (newTags != null || prevTags != null) {
// Case 1: Tags deleted
if (prevTags != null && newTags != null) {
for (var prevTag in prevTags) {
for (final prevTag in prevTags) {
final existsInNew =
newTags.any((newTag) => newTag.uuid == prevTag.uuid);
if (!existsInNew) {
@ -805,7 +803,7 @@ class SpaceManagementBloc
}
}
} else if (prevTags != null && newTags == null) {
for (var prevTag in prevTags) {
for (final prevTag in prevTags) {
tagUpdates.add(TagModelUpdate(
action: custom_action.Action.delete, uuid: prevTag.uuid));
}
@ -815,7 +813,7 @@ class SpaceManagementBloc
if (newTags != null) {
final prevTagUuids = prevTags?.map((t) => t.uuid).toSet() ?? {};
for (var newTag in newTags) {
for (final newTag in newTags) {
// Tag without UUID
if ((newTag.uuid == null || !prevTagUuids.contains(newTag.uuid)) &&
!processedTags.contains(newTag.tag)) {
@ -831,9 +829,9 @@ class SpaceManagementBloc
// Case 3: Tags updated
if (prevTags != null && newTags != null) {
final newTagMap = {for (var tag in newTags) tag.uuid: tag};
final newTagMap = {for (final tag in newTags) tag.uuid: tag};
for (var prevTag in prevTags) {
for (final prevTag in prevTags) {
final newTag = newTagMap[prevTag.uuid];
if (newTag != null) {
tagUpdates.add(TagModelUpdate(
@ -852,9 +850,9 @@ class SpaceManagementBloc
List<SpaceModel> findMatchingSpaces(
List<SpaceModel> spaces, String targetUuid) {
List<SpaceModel> matched = [];
final matched = <SpaceModel>[];
for (var space in spaces) {
for (final space in spaces) {
if (space.uuid == targetUuid) {
matched.add(space);
}

View File

@ -166,10 +166,10 @@ class SpaceModelLoadEvent extends SpaceManagementEvent {
class UpdateSpaceModelCache extends SpaceManagementEvent {
final SpaceTemplateModel updatedModel;
UpdateSpaceModelCache(this.updatedModel);
const UpdateSpaceModelCache(this.updatedModel);
}
class DeleteSpaceModelFromCache extends SpaceManagementEvent {
final String deletedUuid;
DeleteSpaceModelFromCache(this.deletedUuid);
const DeleteSpaceModelFromCache(this.deletedUuid);
}

View File

@ -40,7 +40,10 @@ class BlankState extends SpaceManagementState {
final List<Tag> allTags;
BlankState(
{required this.communities, required this.products, this.spaceModels, required this.allTags});
{required this.communities,
required this.products,
this.spaceModels,
required this.allTags});
}
class SpaceCreationSuccess extends SpaceManagementState {