feat: Geutebruck GeViScope/GeViSoft Action Mapping System - MVP
This MVP release provides a complete full-stack solution for managing action mappings in Geutebruck's GeViScope and GeViSoft video surveillance systems. ## Features ### Flutter Web Application (Port 8081) - Modern, responsive UI for managing action mappings - Action picker dialog with full parameter configuration - Support for both GSC (GeViScope) and G-Core server actions - Consistent UI for input and output actions with edit/delete capabilities - Real-time action mapping creation, editing, and deletion - Server categorization (GSC: prefix for GeViScope, G-Core: prefix for G-Core servers) ### FastAPI REST Backend (Port 8000) - RESTful API for action mapping CRUD operations - Action template service with comprehensive action catalog (247 actions) - Server management (G-Core and GeViScope servers) - Configuration tree reading and writing - JWT authentication with role-based access control - PostgreSQL database integration ### C# SDK Bridge (gRPC, Port 50051) - Native integration with GeViSoft SDK (GeViProcAPINET_4_0.dll) - Action mapping creation with correct binary format - Support for GSC and G-Core action types - Proper Camera parameter inclusion in action strings (fixes CrossSwitch bug) - Action ID lookup table with server-specific action IDs - Configuration reading/writing via SetupClient ## Bug Fixes - **CrossSwitch Bug**: GSC and G-Core actions now correctly display camera/PTZ head parameters in GeViSet - Action strings now include Camera parameter: `@ PanLeft (Comment: "", Camera: 101028)` - Proper filter flags and VideoInput=0 for action mappings - Correct action ID assignment (4198 for GSC, 9294 for G-Core PanLeft) ## Technical Stack - **Frontend**: Flutter Web, Dart, Dio HTTP client - **Backend**: Python FastAPI, PostgreSQL, Redis - **SDK Bridge**: C# .NET 8.0, gRPC, GeViSoft SDK - **Authentication**: JWT tokens - **Configuration**: GeViSoft .set files (binary format) ## Credentials - GeViSoft/GeViScope: username=sysadmin, password=masterkey - Default admin: username=admin, password=admin123 ## Deployment All services run on localhost: - Flutter Web: http://localhost:8081 - FastAPI: http://localhost:8000 - SDK Bridge gRPC: localhost:50051 - GeViServer: localhost (default port) Generated with Claude Code (https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,193 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'action_mapping_event.dart';
|
||||
import 'action_mapping_state.dart';
|
||||
import '../../../domain/repositories/action_mapping_repository.dart';
|
||||
import '../../../data/services/sync_service.dart';
|
||||
|
||||
class ActionMappingBloc extends Bloc<ActionMappingEvent, ActionMappingState> {
|
||||
final ActionMappingRepository actionMappingRepository;
|
||||
|
||||
ActionMappingBloc({required this.actionMappingRepository})
|
||||
: super(const ActionMappingInitial()) {
|
||||
on<LoadActionMappings>(_onLoadActionMappings);
|
||||
on<SearchActionMappings>(_onSearchActionMappings);
|
||||
on<CreateActionMappingEvent>(_onCreateActionMapping);
|
||||
on<UpdateActionMappingEvent>(_onUpdateActionMapping);
|
||||
on<DeleteActionMappingEvent>(_onDeleteActionMapping);
|
||||
on<SyncActionMappingsEvent>(_onSyncActionMappings);
|
||||
on<DownloadActionMappingsEvent>(_onDownloadActionMappings);
|
||||
on<CheckDirtyCountEvent>(_onCheckDirtyCount);
|
||||
}
|
||||
|
||||
Future<void> _onLoadActionMappings(
|
||||
LoadActionMappings event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
emit(const ActionMappingLoading());
|
||||
|
||||
final result = await actionMappingRepository.getAllActionMappings();
|
||||
final dirtyCountResult = await actionMappingRepository.getDirtyCount();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(mappings) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ActionMappingLoaded(mappings, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onSearchActionMappings(
|
||||
SearchActionMappings event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
emit(const ActionMappingLoading());
|
||||
|
||||
final result = await actionMappingRepository.searchActionMappings(event.query);
|
||||
final dirtyCountResult = await actionMappingRepository.getDirtyCount();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(mappings) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ActionMappingLoaded(mappings, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onCreateActionMapping(
|
||||
CreateActionMappingEvent event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
emit(const ActionMappingLoading());
|
||||
|
||||
final result = await actionMappingRepository.createActionMapping(event.mapping);
|
||||
|
||||
await result.fold(
|
||||
(failure) async => emit(ActionMappingError(failure.message)),
|
||||
(_) async {
|
||||
// Reload action mappings first
|
||||
final mappingsResult = await actionMappingRepository.getAllActionMappings();
|
||||
final dirtyCountResult = await actionMappingRepository.getDirtyCount();
|
||||
|
||||
mappingsResult.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(mappings) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ActionMappingLoaded(mappings, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onUpdateActionMapping(
|
||||
UpdateActionMappingEvent event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
emit(const ActionMappingLoading());
|
||||
|
||||
final result = await actionMappingRepository.updateActionMapping(event.mapping);
|
||||
|
||||
await result.fold(
|
||||
(failure) async => emit(ActionMappingError(failure.message)),
|
||||
(_) async {
|
||||
// Reload action mappings first
|
||||
final mappingsResult = await actionMappingRepository.getAllActionMappings();
|
||||
final dirtyCountResult = await actionMappingRepository.getDirtyCount();
|
||||
|
||||
mappingsResult.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(mappings) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ActionMappingLoaded(mappings, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onDeleteActionMapping(
|
||||
DeleteActionMappingEvent event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
emit(const ActionMappingLoading());
|
||||
|
||||
final result = await actionMappingRepository.deleteActionMapping(event.id);
|
||||
|
||||
await result.fold(
|
||||
(failure) async => emit(ActionMappingError(failure.message)),
|
||||
(_) async {
|
||||
// Reload action mappings first
|
||||
final mappingsResult = await actionMappingRepository.getAllActionMappings();
|
||||
final dirtyCountResult = await actionMappingRepository.getDirtyCount();
|
||||
|
||||
mappingsResult.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(mappings) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ActionMappingLoaded(mappings, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onSyncActionMappings(
|
||||
SyncActionMappingsEvent event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
emit(const ActionMappingSyncing());
|
||||
|
||||
final result = await actionMappingRepository.syncToServer();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(syncResult) {
|
||||
if (syncResult.status == SyncStatus.success) {
|
||||
emit(ActionMappingSyncSuccess(
|
||||
syncResult.message ?? 'Sync completed',
|
||||
syncResult.syncedCount ?? 0,
|
||||
));
|
||||
// Reload action mappings after sync
|
||||
add(const LoadActionMappings());
|
||||
} else if (syncResult.status == SyncStatus.error) {
|
||||
emit(ActionMappingError(syncResult.message ?? 'Sync failed'));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onDownloadActionMappings(
|
||||
DownloadActionMappingsEvent event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
emit(const ActionMappingDownloading());
|
||||
|
||||
final result = await actionMappingRepository.downloadFromServer();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(count) {
|
||||
emit(ActionMappingOperationSuccess('Downloaded $count action mappings from server'));
|
||||
// Reload action mappings after download
|
||||
add(const LoadActionMappings());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onCheckDirtyCount(
|
||||
CheckDirtyCountEvent event,
|
||||
Emitter<ActionMappingState> emit,
|
||||
) async {
|
||||
final result = await actionMappingRepository.getDirtyCount();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ActionMappingError(failure.message)),
|
||||
(count) {
|
||||
// Just trigger a reload which will include the dirty count
|
||||
add(const LoadActionMappings());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../domain/entities/action_mapping.dart';
|
||||
|
||||
abstract class ActionMappingEvent extends Equatable {
|
||||
const ActionMappingEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class LoadActionMappings extends ActionMappingEvent {
|
||||
const LoadActionMappings();
|
||||
}
|
||||
|
||||
class SearchActionMappings extends ActionMappingEvent {
|
||||
final String query;
|
||||
|
||||
const SearchActionMappings(this.query);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [query];
|
||||
}
|
||||
|
||||
class CreateActionMappingEvent extends ActionMappingEvent {
|
||||
final ActionMapping mapping;
|
||||
|
||||
const CreateActionMappingEvent(this.mapping);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mapping];
|
||||
}
|
||||
|
||||
class UpdateActionMappingEvent extends ActionMappingEvent {
|
||||
final ActionMapping mapping;
|
||||
|
||||
const UpdateActionMappingEvent(this.mapping);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mapping];
|
||||
}
|
||||
|
||||
class DeleteActionMappingEvent extends ActionMappingEvent {
|
||||
final String id;
|
||||
|
||||
const DeleteActionMappingEvent(this.id);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id];
|
||||
}
|
||||
|
||||
class SyncActionMappingsEvent extends ActionMappingEvent {
|
||||
const SyncActionMappingsEvent();
|
||||
}
|
||||
|
||||
class DownloadActionMappingsEvent extends ActionMappingEvent {
|
||||
const DownloadActionMappingsEvent();
|
||||
}
|
||||
|
||||
class CheckDirtyCountEvent extends ActionMappingEvent {
|
||||
const CheckDirtyCountEvent();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../domain/entities/action_mapping.dart';
|
||||
|
||||
abstract class ActionMappingState extends Equatable {
|
||||
const ActionMappingState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ActionMappingInitial extends ActionMappingState {
|
||||
const ActionMappingInitial();
|
||||
}
|
||||
|
||||
class ActionMappingLoading extends ActionMappingState {
|
||||
const ActionMappingLoading();
|
||||
}
|
||||
|
||||
class ActionMappingLoaded extends ActionMappingState {
|
||||
final List<ActionMapping> mappings;
|
||||
final int dirtyCount;
|
||||
|
||||
const ActionMappingLoaded(this.mappings, {this.dirtyCount = 0});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [mappings, dirtyCount];
|
||||
}
|
||||
|
||||
class ActionMappingOperationSuccess extends ActionMappingState {
|
||||
final String message;
|
||||
|
||||
const ActionMappingOperationSuccess(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ActionMappingError extends ActionMappingState {
|
||||
final String message;
|
||||
|
||||
const ActionMappingError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ActionMappingSyncing extends ActionMappingState {
|
||||
final String message;
|
||||
|
||||
const ActionMappingSyncing({this.message = 'Syncing changes...'});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ActionMappingSyncSuccess extends ActionMappingState {
|
||||
final String message;
|
||||
final int syncedCount;
|
||||
|
||||
const ActionMappingSyncSuccess(this.message, this.syncedCount);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message, syncedCount];
|
||||
}
|
||||
|
||||
class ActionMappingDownloading extends ActionMappingState {
|
||||
const ActionMappingDownloading();
|
||||
}
|
||||
67
geutebruck_app/lib/presentation/blocs/auth/auth_bloc.dart
Normal file
67
geutebruck_app/lib/presentation/blocs/auth/auth_bloc.dart
Normal file
@@ -0,0 +1,67 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'auth_event.dart';
|
||||
import 'auth_state.dart';
|
||||
import '../../../domain/use_cases/auth/login.dart';
|
||||
import '../../../domain/repositories/auth_repository.dart';
|
||||
|
||||
class AuthBloc extends Bloc<AuthEvent, AuthState> {
|
||||
final Login loginUseCase;
|
||||
final AuthRepository authRepository;
|
||||
|
||||
AuthBloc({
|
||||
required this.loginUseCase,
|
||||
required this.authRepository,
|
||||
}) : super(const AuthInitial()) {
|
||||
on<LoginRequested>(_onLoginRequested);
|
||||
on<LogoutRequested>(_onLogoutRequested);
|
||||
on<CheckAuthStatus>(_onCheckAuthStatus);
|
||||
}
|
||||
|
||||
Future<void> _onLoginRequested(
|
||||
LoginRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
emit(const AuthLoading());
|
||||
|
||||
final result = await loginUseCase(event.username, event.password);
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(AuthError(failure.message)),
|
||||
(user) => emit(Authenticated(user)),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onLogoutRequested(
|
||||
LogoutRequested event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
emit(const AuthLoading());
|
||||
|
||||
final result = await authRepository.logout();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(AuthError(failure.message)),
|
||||
(_) => emit(const Unauthenticated()),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onCheckAuthStatus(
|
||||
CheckAuthStatus event,
|
||||
Emitter<AuthState> emit,
|
||||
) async {
|
||||
emit(const AuthLoading());
|
||||
|
||||
final result = await authRepository.getCurrentUser();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(const Unauthenticated()),
|
||||
(user) {
|
||||
if (user != null) {
|
||||
emit(Authenticated(user));
|
||||
} else {
|
||||
emit(const Unauthenticated());
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
29
geutebruck_app/lib/presentation/blocs/auth/auth_event.dart
Normal file
29
geutebruck_app/lib/presentation/blocs/auth/auth_event.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
|
||||
abstract class AuthEvent extends Equatable {
|
||||
const AuthEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class LoginRequested extends AuthEvent {
|
||||
final String username;
|
||||
final String password;
|
||||
|
||||
const LoginRequested({
|
||||
required this.username,
|
||||
required this.password,
|
||||
});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [username, password];
|
||||
}
|
||||
|
||||
class LogoutRequested extends AuthEvent {
|
||||
const LogoutRequested();
|
||||
}
|
||||
|
||||
class CheckAuthStatus extends AuthEvent {
|
||||
const CheckAuthStatus();
|
||||
}
|
||||
39
geutebruck_app/lib/presentation/blocs/auth/auth_state.dart
Normal file
39
geutebruck_app/lib/presentation/blocs/auth/auth_state.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../domain/entities/user.dart';
|
||||
|
||||
abstract class AuthState extends Equatable {
|
||||
const AuthState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class AuthInitial extends AuthState {
|
||||
const AuthInitial();
|
||||
}
|
||||
|
||||
class AuthLoading extends AuthState {
|
||||
const AuthLoading();
|
||||
}
|
||||
|
||||
class Authenticated extends AuthState {
|
||||
final User user;
|
||||
|
||||
const Authenticated(this.user);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [user];
|
||||
}
|
||||
|
||||
class Unauthenticated extends AuthState {
|
||||
const Unauthenticated();
|
||||
}
|
||||
|
||||
class AuthError extends AuthState {
|
||||
final String message;
|
||||
|
||||
const AuthError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
211
geutebruck_app/lib/presentation/blocs/server/server_bloc.dart
Normal file
211
geutebruck_app/lib/presentation/blocs/server/server_bloc.dart
Normal file
@@ -0,0 +1,211 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'server_event.dart';
|
||||
import 'server_state.dart';
|
||||
import '../../../domain/repositories/server_repository.dart';
|
||||
import '../../../data/services/sync_service.dart';
|
||||
|
||||
class ServerBloc extends Bloc<ServerEvent, ServerState> {
|
||||
final ServerRepository serverRepository;
|
||||
|
||||
ServerBloc({required this.serverRepository}) : super(const ServerInitial()) {
|
||||
on<LoadServers>(_onLoadServers);
|
||||
on<LoadGCoreServers>(_onLoadGCoreServers);
|
||||
on<LoadGeViScopeServers>(_onLoadGeViScopeServers);
|
||||
on<CreateServerEvent>(_onCreateServer);
|
||||
on<UpdateServerEvent>(_onUpdateServer);
|
||||
on<DeleteServerEvent>(_onDeleteServer);
|
||||
on<SyncServersEvent>(_onSyncServers);
|
||||
on<DownloadServersEvent>(_onDownloadServers);
|
||||
on<CheckDirtyCountEvent>(_onCheckDirtyCount);
|
||||
}
|
||||
|
||||
Future<void> _onLoadServers(
|
||||
LoadServers event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerLoading());
|
||||
|
||||
final result = await serverRepository.getAllServers();
|
||||
final dirtyCountResult = await serverRepository.getDirtyCount();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(servers) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ServerLoaded(servers, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onLoadGCoreServers(
|
||||
LoadGCoreServers event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerLoading());
|
||||
|
||||
final result = await serverRepository.getGCoreServers();
|
||||
final dirtyCountResult = await serverRepository.getDirtyCount();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(servers) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ServerLoaded(servers, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onLoadGeViScopeServers(
|
||||
LoadGeViScopeServers event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerLoading());
|
||||
|
||||
final result = await serverRepository.getGeViScopeServers();
|
||||
final dirtyCountResult = await serverRepository.getDirtyCount();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(servers) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ServerLoaded(servers, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onCreateServer(
|
||||
CreateServerEvent event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerLoading());
|
||||
|
||||
final result = await serverRepository.createServer(event.server);
|
||||
|
||||
await result.fold(
|
||||
(failure) async => emit(ServerError(failure.message)),
|
||||
(_) async {
|
||||
// Reload servers first
|
||||
final serversResult = await serverRepository.getAllServers();
|
||||
final dirtyCountResult = await serverRepository.getDirtyCount();
|
||||
|
||||
serversResult.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(servers) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ServerLoaded(servers, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onUpdateServer(
|
||||
UpdateServerEvent event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerLoading());
|
||||
|
||||
final result = await serverRepository.updateServer(event.server);
|
||||
|
||||
await result.fold(
|
||||
(failure) async => emit(ServerError(failure.message)),
|
||||
(_) async {
|
||||
// Reload servers first
|
||||
final serversResult = await serverRepository.getAllServers();
|
||||
final dirtyCountResult = await serverRepository.getDirtyCount();
|
||||
|
||||
serversResult.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(servers) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ServerLoaded(servers, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onDeleteServer(
|
||||
DeleteServerEvent event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerLoading());
|
||||
|
||||
final result = await serverRepository.deleteServer(event.id, event.type);
|
||||
|
||||
await result.fold(
|
||||
(failure) async => emit(ServerError(failure.message)),
|
||||
(_) async {
|
||||
// Reload servers first
|
||||
final serversResult = await serverRepository.getAllServers();
|
||||
final dirtyCountResult = await serverRepository.getDirtyCount();
|
||||
|
||||
serversResult.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(servers) {
|
||||
final dirtyCount = dirtyCountResult.fold((_) => 0, (count) => count);
|
||||
emit(ServerLoaded(servers, dirtyCount: dirtyCount));
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onSyncServers(
|
||||
SyncServersEvent event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerSyncing());
|
||||
|
||||
final result = await serverRepository.syncToServer();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(syncResult) {
|
||||
if (syncResult.status == SyncStatus.success) {
|
||||
emit(ServerSyncSuccess(
|
||||
syncResult.message ?? 'Sync completed',
|
||||
syncResult.syncedCount ?? 0,
|
||||
));
|
||||
// Reload servers after sync
|
||||
add(const LoadServers());
|
||||
} else if (syncResult.status == SyncStatus.error) {
|
||||
emit(ServerError(syncResult.message ?? 'Sync failed'));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onDownloadServers(
|
||||
DownloadServersEvent event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
emit(const ServerDownloading());
|
||||
|
||||
final result = await serverRepository.downloadFromServer();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(count) {
|
||||
emit(ServerOperationSuccess('Downloaded $count servers from server'));
|
||||
// Reload servers after download
|
||||
add(const LoadServers());
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onCheckDirtyCount(
|
||||
CheckDirtyCountEvent event,
|
||||
Emitter<ServerState> emit,
|
||||
) async {
|
||||
final result = await serverRepository.getDirtyCount();
|
||||
|
||||
result.fold(
|
||||
(failure) => emit(ServerError(failure.message)),
|
||||
(count) {
|
||||
// Just trigger a reload which will include the dirty count
|
||||
add(const LoadServers());
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../domain/entities/server.dart';
|
||||
|
||||
abstract class ServerEvent extends Equatable {
|
||||
const ServerEvent();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class LoadServers extends ServerEvent {
|
||||
const LoadServers();
|
||||
}
|
||||
|
||||
class LoadGCoreServers extends ServerEvent {
|
||||
const LoadGCoreServers();
|
||||
}
|
||||
|
||||
class LoadGeViScopeServers extends ServerEvent {
|
||||
const LoadGeViScopeServers();
|
||||
}
|
||||
|
||||
class CreateServerEvent extends ServerEvent {
|
||||
final Server server;
|
||||
|
||||
const CreateServerEvent(this.server);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [server];
|
||||
}
|
||||
|
||||
class UpdateServerEvent extends ServerEvent {
|
||||
final Server server;
|
||||
|
||||
const UpdateServerEvent(this.server);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [server];
|
||||
}
|
||||
|
||||
class DeleteServerEvent extends ServerEvent {
|
||||
final String id;
|
||||
final ServerType type;
|
||||
|
||||
const DeleteServerEvent(this.id, this.type);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [id, type];
|
||||
}
|
||||
|
||||
class SyncServersEvent extends ServerEvent {
|
||||
const SyncServersEvent();
|
||||
}
|
||||
|
||||
class DownloadServersEvent extends ServerEvent {
|
||||
const DownloadServersEvent();
|
||||
}
|
||||
|
||||
class CheckDirtyCountEvent extends ServerEvent {
|
||||
const CheckDirtyCountEvent();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import '../../../domain/entities/server.dart';
|
||||
|
||||
abstract class ServerState extends Equatable {
|
||||
const ServerState();
|
||||
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
class ServerInitial extends ServerState {
|
||||
const ServerInitial();
|
||||
}
|
||||
|
||||
class ServerLoading extends ServerState {
|
||||
const ServerLoading();
|
||||
}
|
||||
|
||||
class ServerLoaded extends ServerState {
|
||||
final List<Server> servers;
|
||||
final int dirtyCount;
|
||||
|
||||
const ServerLoaded(this.servers, {this.dirtyCount = 0});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [servers, dirtyCount];
|
||||
}
|
||||
|
||||
class ServerOperationSuccess extends ServerState {
|
||||
final String message;
|
||||
|
||||
const ServerOperationSuccess(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ServerError extends ServerState {
|
||||
final String message;
|
||||
|
||||
const ServerError(this.message);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ServerSyncing extends ServerState {
|
||||
final String message;
|
||||
|
||||
const ServerSyncing({this.message = 'Syncing changes...'});
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message];
|
||||
}
|
||||
|
||||
class ServerSyncSuccess extends ServerState {
|
||||
final String message;
|
||||
final int syncedCount;
|
||||
|
||||
const ServerSyncSuccess(this.message, this.syncedCount);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [message, syncedCount];
|
||||
}
|
||||
|
||||
class ServerDownloading extends ServerState {
|
||||
const ServerDownloading();
|
||||
}
|
||||
Reference in New Issue
Block a user