feat: GeViScope SDK integration with C# Bridge and Flutter app
- Add GeViScope Bridge (C# .NET 8.0) on port 7720 - Full SDK wrapper for camera control, PTZ, actions/events - 17 REST API endpoints for GeViScope server interaction - Support for MCS (Media Channel Simulator) with 16 test channels - Real-time action/event streaming via PLC callbacks - Add GeViServer Bridge (C# .NET 8.0) on port 7710 - Integration with GeViSoft orchestration layer - Input/output control and event management - Update Python API with new routers - /api/geviscope/* - Proxy to GeViScope Bridge - /api/geviserver/* - Proxy to GeViServer Bridge - /api/excel/* - Excel import functionality - Add Flutter app GeViScope integration - GeViScopeRemoteDataSource with 17 API methods - GeViScopeBloc for state management - GeViScopeScreen with PTZ controls - App drawer navigation to GeViScope - Add SDK documentation (extracted from PDFs) - GeViScope SDK docs (7 parts + action reference) - GeViSoft SDK docs (12 chunks) - Add .mcp.json for Claude Code MCP server config Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'dart:html' as html;
|
||||
import '../../../domain/entities/server.dart';
|
||||
import '../../../data/services/excel_import_service.dart';
|
||||
import '../../../data/data_sources/local/server_local_data_source.dart';
|
||||
import '../../../injection.dart' as di;
|
||||
import '../../blocs/auth/auth_bloc.dart';
|
||||
import '../../blocs/auth/auth_event.dart';
|
||||
import '../../blocs/auth/auth_state.dart';
|
||||
@@ -140,6 +145,147 @@ class _ServersManagementScreenState extends State<ServersManagementScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _importFromExcel() async {
|
||||
print('[Import] Function called');
|
||||
|
||||
try {
|
||||
print('[Import] Creating ExcelImportService...');
|
||||
// Create ExcelImportService with ServerLocalDataSource from DI
|
||||
final localDataSource = di.sl<ServerLocalDataSource>();
|
||||
final excelImportService = ExcelImportService(localDataSource: localDataSource);
|
||||
print('[Import] ExcelImportService created');
|
||||
|
||||
print('[Import] Opening file picker...');
|
||||
|
||||
// Pick Excel file
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['xlsx'],
|
||||
withData: true, // Important for web - loads file data
|
||||
);
|
||||
|
||||
print('[Import] File picker returned');
|
||||
|
||||
if (result == null || result.files.isEmpty) {
|
||||
return; // User cancelled
|
||||
}
|
||||
|
||||
final file = result.files.first;
|
||||
if (file.bytes == null) {
|
||||
throw Exception('Could not read file data');
|
||||
}
|
||||
|
||||
// Show loading dialog
|
||||
if (!mounted) return;
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => const Center(
|
||||
child: Card(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text('Importing servers from Excel...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Parse Excel file via backend API
|
||||
print('[Import] Calling backend API...');
|
||||
final importedServers = await excelImportService.importServersFromExcel(
|
||||
file.bytes!,
|
||||
file.name,
|
||||
);
|
||||
print('[Import] Received ${importedServers.length} servers from API');
|
||||
|
||||
// Get existing servers
|
||||
final bloc = context.read<ServerBloc>();
|
||||
final state = bloc.state;
|
||||
final existingServers = state is ServerLoaded ? state.servers : <Server>[];
|
||||
print('[Import] Found ${existingServers.length} existing servers');
|
||||
|
||||
// Merge: only add new servers
|
||||
final newServers = excelImportService.mergeServers(
|
||||
existing: existingServers,
|
||||
imported: importedServers,
|
||||
);
|
||||
print('[Import] ${newServers.length} new servers to add');
|
||||
|
||||
// Check if there are new servers
|
||||
print('[Import] Import summary: ${importedServers.length} total, ${newServers.length} new');
|
||||
|
||||
if (newServers.isEmpty) {
|
||||
print('[Import] No new servers to add');
|
||||
// Close loading dialog
|
||||
if (mounted) {
|
||||
try {
|
||||
Navigator.of(context).pop();
|
||||
} catch (e) {
|
||||
print('[Import] Error closing dialog: $e');
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
print('[Import] Proceeding with import of ${newServers.length} servers');
|
||||
|
||||
// Save servers directly to storage, bypassing the bloc to avoid triggering rebuilds
|
||||
print('[Import] Saving ${newServers.length} servers directly to storage...');
|
||||
try {
|
||||
await excelImportService.saveImportedServersToStorage(newServers);
|
||||
print('[Import] All servers saved to storage as unsaved changes');
|
||||
} catch (e) {
|
||||
print('[Import] ERROR saving servers to storage: $e');
|
||||
throw Exception('Failed to save servers: $e');
|
||||
}
|
||||
|
||||
// Import complete - reload page
|
||||
print('[Import] Successfully imported ${newServers.length} servers');
|
||||
print('[Import] Servers added as unsaved changes. Use Sync button to upload to GeViServer.');
|
||||
|
||||
// Save redirect path so we return to servers page after reload
|
||||
html.window.localStorage['post_import_redirect'] = '/servers';
|
||||
|
||||
// Brief delay to ensure Hive writes complete
|
||||
await Future.delayed(const Duration(milliseconds: 300));
|
||||
|
||||
print('[Import] Reloading page (auth tokens now persist in localStorage)...');
|
||||
|
||||
// Reload page WITHOUT closing dialog to avoid crash
|
||||
// Auth tokens are now stored in localStorage so you'll stay logged in!
|
||||
html.window.location.reload();
|
||||
} catch (e, stackTrace) {
|
||||
print('[Import] ERROR: $e');
|
||||
print('[Import] Stack trace: $stackTrace');
|
||||
|
||||
// Close loading dialog if open
|
||||
if (mounted) {
|
||||
try {
|
||||
Navigator.of(context, rootNavigator: true).pop();
|
||||
} catch (_) {
|
||||
// Dialog might already be closed
|
||||
}
|
||||
}
|
||||
|
||||
// Show error
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Import failed: $e'),
|
||||
backgroundColor: Colors.red,
|
||||
duration: const Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -194,15 +340,56 @@ class _ServersManagementScreenState extends State<ServersManagementScreen> {
|
||||
);
|
||||
},
|
||||
),
|
||||
// Download/refresh button
|
||||
Builder(
|
||||
builder: (context) => IconButton(
|
||||
icon: const Icon(Icons.cloud_download),
|
||||
onPressed: () {
|
||||
context.read<ServerBloc>().add(const DownloadServersEvent());
|
||||
},
|
||||
tooltip: 'Download latest from server',
|
||||
),
|
||||
// Download/refresh button with confirmation if there are unsaved changes
|
||||
BlocBuilder<ServerBloc, ServerState>(
|
||||
builder: (context, state) {
|
||||
final dirtyCount = state is ServerLoaded ? state.dirtyCount : 0;
|
||||
|
||||
return IconButton(
|
||||
icon: const Icon(Icons.cloud_download),
|
||||
onPressed: () async {
|
||||
// Show confirmation if there are unsaved changes
|
||||
if (dirtyCount > 0) {
|
||||
final confirmed = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: const Text('Discard Changes?'),
|
||||
content: Text(
|
||||
'You have $dirtyCount unsaved change${dirtyCount != 1 ? 's' : ''}. '
|
||||
'Downloading from server will discard all local changes.\n\n'
|
||||
'Do you want to continue?'
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(true),
|
||||
style: FilledButton.styleFrom(
|
||||
backgroundColor: Colors.orange,
|
||||
),
|
||||
child: const Text('Discard & Download'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirmed == true) {
|
||||
if (context.mounted) {
|
||||
context.read<ServerBloc>().add(const DownloadServersEvent());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// No unsaved changes, download directly
|
||||
context.read<ServerBloc>().add(const DownloadServersEvent());
|
||||
}
|
||||
},
|
||||
tooltip: dirtyCount > 0
|
||||
? 'Discard $dirtyCount change${dirtyCount != 1 ? 's' : ''} & download from server'
|
||||
: 'Download latest from server',
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
BlocBuilder<AuthBloc, AuthState>(
|
||||
@@ -278,6 +465,23 @@ class _ServersManagementScreenState extends State<ServersManagementScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 16),
|
||||
OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
print('[Import] Button clicked');
|
||||
try {
|
||||
_importFromExcel();
|
||||
} catch (e, stackTrace) {
|
||||
print('[Import] Button handler error: $e');
|
||||
print('[Import] Button handler stack: $stackTrace');
|
||||
}
|
||||
},
|
||||
icon: const Icon(Icons.upload_file, size: 18),
|
||||
label: const Text('Import Excel'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
_showAddServerDialog(context);
|
||||
|
||||
Reference in New Issue
Block a user