feat(app): clean architecture with typed repositories, DTO models and calendar event logos
This commit is contained in:
@@ -4,18 +4,16 @@ import '../../../core/network/api_client.dart';
|
||||
import '../../../core/network/signalr_service.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/widgets/glass_container.dart';
|
||||
import '../../../core/widgets/status_badge.dart';
|
||||
import '../models/admin_update_user_request_dto.dart';
|
||||
import '../models/admin_user_model.dart';
|
||||
import '../bloc/admin_bloc.dart';
|
||||
import '../repositories/admin_repository.dart';
|
||||
import '../widgets/admin_kpi_header.dart';
|
||||
import '../widgets/admin_user_card_item.dart';
|
||||
import '../widgets/create_user_dialog.dart';
|
||||
import '../widgets/edit_user_dialog.dart';
|
||||
|
||||
import '../widgets/system_diagnostics_widget.dart';
|
||||
|
||||
/// Role-Restricted Admin Panel Screen managing users, service settings, and system health.
|
||||
class AdminUsersScreen extends StatelessWidget {
|
||||
final ApiClient apiClient;
|
||||
final SignalRService? signalRService;
|
||||
@@ -102,61 +100,52 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Top Header Ribbon
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.primaryEmerald.withValues(alpha: 0.15),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: AppTheme.primaryEmerald.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Icon(Icons.admin_panel_settings_rounded, color: AppTheme.primaryEmerald, size: 22),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const Text(
|
||||
'Admin Control Panel',
|
||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, letterSpacing: -0.5),
|
||||
),
|
||||
],
|
||||
const Text(
|
||||
'Administration & System',
|
||||
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold, color: Colors.white),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
'Zentrales Management für Nutzer, Mikrodienste & MQTT System-Bus',
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
'Finlytic Admin-Dashboard • Microservices & Benutzer',
|
||||
style: TextStyle(color: AppTheme.textMuted, fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => _openCreateUser(context),
|
||||
icon: const Icon(Icons.person_add_outlined, size: 18),
|
||||
label: const Text('Nutzer Anlegen', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppTheme.primaryEmerald,
|
||||
foregroundColor: Colors.black,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 12),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
onPressed: () => context.read<AdminBloc>().add(FetchAdminUsers()),
|
||||
icon: const Icon(Icons.refresh_rounded, color: Colors.white70),
|
||||
tooltip: 'Neu laden',
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () => _openCreateUser(context),
|
||||
icon: const Icon(Icons.person_add_alt_1_rounded, size: 18),
|
||||
label: const Text('Neuer Benutzer'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppTheme.primaryEmerald,
|
||||
foregroundColor: Colors.black,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// KPI Header Metrics
|
||||
AdminKpiHeader(
|
||||
users: users,
|
||||
signalRService: widget.signalRService,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Tab Selector Ribbon
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.glassSurface,
|
||||
@@ -182,19 +171,12 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Tab Content View
|
||||
Expanded(
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: [
|
||||
// Tab 1: User Management with Filter & Actions
|
||||
_buildUserManagementTab(context, state, users),
|
||||
|
||||
// Tab 2: System Diagnostics & Microservices Health
|
||||
SystemDiagnosticsWidget(
|
||||
signalRService: widget.signalRService,
|
||||
),
|
||||
SystemDiagnosticsWidget(signalRService: widget.signalRService),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -233,7 +215,6 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
);
|
||||
}
|
||||
|
||||
// Apply Search Query & Role Filter
|
||||
final filteredUsers = allUsers.where((u) {
|
||||
final matchesSearch = u.fullName.toLowerCase().contains(_searchQuery.toLowerCase()) ||
|
||||
u.email.toLowerCase().contains(_searchQuery.toLowerCase());
|
||||
@@ -243,7 +224,6 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// Filter Bar (Search Field & Role Filter Chips)
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -292,8 +272,6 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
|
||||
// User Cards List
|
||||
Expanded(
|
||||
child: filteredUsers.isEmpty
|
||||
? Center(
|
||||
@@ -302,10 +280,7 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
children: [
|
||||
Icon(Icons.person_search_outlined, size: 48, color: AppTheme.textMuted),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Keine passenden Benutzer gefunden.',
|
||||
style: TextStyle(color: AppTheme.textMuted, fontSize: 14),
|
||||
),
|
||||
Text('Keine passenden Benutzer gefunden.', style: TextStyle(color: AppTheme.textMuted, fontSize: 14)),
|
||||
],
|
||||
),
|
||||
)
|
||||
@@ -313,95 +288,10 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
itemCount: filteredUsers.length,
|
||||
itemBuilder: (context, index) {
|
||||
final u = filteredUsers[index];
|
||||
final String role = u.role;
|
||||
final bool isActive = u.isActive;
|
||||
|
||||
final Color roleColor = role == 'Admin'
|
||||
? const Color(0xFFA855F7)
|
||||
: role == 'Premium'
|
||||
? AppTheme.primaryEmerald
|
||||
: AppTheme.accentCyan;
|
||||
|
||||
final String initials = _getInitials(u.fullName.isNotEmpty ? u.fullName : u.email);
|
||||
|
||||
return GlassContainer(
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Row(
|
||||
children: [
|
||||
// Avatar Initials Circle
|
||||
Container(
|
||||
width: 42,
|
||||
height: 42,
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
color: roleColor.withValues(alpha: 0.2),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: roleColor, width: 1.5),
|
||||
),
|
||||
child: Text(
|
||||
initials,
|
||||
style: TextStyle(fontWeight: FontWeight.bold, color: roleColor, fontSize: 14),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 14),
|
||||
|
||||
// User Name & Email
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
u.fullName.isNotEmpty ? u.fullName : u.email,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
StatusBadge(label: role, color: roleColor),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Text(
|
||||
u.email,
|
||||
style: TextStyle(fontSize: 12, color: AppTheme.textSecondary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Active/Inactive Quick Switch Toggle
|
||||
Row(
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
isActive ? 'Aktiv' : 'Gesperrt',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isActive ? AppTheme.primaryEmerald : AppTheme.accentRed,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Switch(
|
||||
value: isActive,
|
||||
activeThumbColor: AppTheme.primaryEmerald,
|
||||
onChanged: (val) => _toggleUserActiveStatus(context, u, val),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
IconButton.filledTonal(
|
||||
icon: const Icon(Icons.edit_outlined, size: 18),
|
||||
tooltip: 'Benutzer Bearbeiten',
|
||||
onPressed: () => _openEditUser(context, u),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
return AdminUserCardItem(
|
||||
user: u,
|
||||
onToggleActive: (val) => _toggleUserActiveStatus(context, u, val),
|
||||
onEdit: () => _openEditUser(context, u),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -409,13 +299,4 @@ class _AdminUsersScreenContentState extends State<_AdminUsersScreenContent> with
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String _getInitials(String name) {
|
||||
if (name.isEmpty) return 'U';
|
||||
final parts = name.trim().split(' ');
|
||||
if (parts.length >= 2) {
|
||||
return '${parts[0][0]}${parts[1][0]}'.toUpperCase();
|
||||
}
|
||||
return name.substring(0, name.length >= 2 ? 2 : 1).toUpperCase();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,27 +4,37 @@ import '../../../core/network/api_client.dart';
|
||||
import '../../../core/theme/app_theme.dart';
|
||||
import '../../../core/widgets/glass_container.dart';
|
||||
import '../../../core/widgets/status_badge.dart';
|
||||
import '../models/service_setting_dto.dart';
|
||||
import '../repositories/admin_repository.dart';
|
||||
|
||||
class ServiceDetailScreen extends StatefulWidget {
|
||||
final String serviceName;
|
||||
final ApiClient apiClient;
|
||||
final AdminRepository? repository;
|
||||
|
||||
const ServiceDetailScreen({super.key, required this.serviceName, required this.apiClient});
|
||||
const ServiceDetailScreen({
|
||||
super.key,
|
||||
required this.serviceName,
|
||||
required this.apiClient,
|
||||
this.repository,
|
||||
});
|
||||
|
||||
@override
|
||||
State<ServiceDetailScreen> createState() => _ServiceDetailScreenState();
|
||||
}
|
||||
|
||||
class _ServiceDetailScreenState extends State<ServiceDetailScreen> {
|
||||
late final AdminRepository _repository;
|
||||
bool _isLoading = true;
|
||||
bool _isSaving = false;
|
||||
String _error = '';
|
||||
List<dynamic> _settings = [];
|
||||
List<ServiceSettingDto> _settings = [];
|
||||
final Map<String, TextEditingController> _controllers = {};
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_repository = widget.repository ?? AdminRepository(apiClient: widget.apiClient);
|
||||
_fetchServiceDetails();
|
||||
}
|
||||
|
||||
@@ -38,27 +48,22 @@ class _ServiceDetailScreenState extends State<ServiceDetailScreen> {
|
||||
|
||||
Future<void> _fetchServiceDetails() async {
|
||||
try {
|
||||
final res = await widget.apiClient.get('/api/v1/admin/settings');
|
||||
if (res.statusCode == 200 && res.data != null) {
|
||||
final groupedSettings = res.data as Map<String, dynamic>;
|
||||
final serviceSettings = groupedSettings[widget.serviceName] ?? [];
|
||||
|
||||
setState(() {
|
||||
_settings = serviceSettings;
|
||||
for (var s in _settings) {
|
||||
final key = s['key']?.toString() ?? '';
|
||||
final val = s['value']?.toString() ?? '';
|
||||
if (!_controllers.containsKey(key)) {
|
||||
_controllers[key] = TextEditingController(text: val);
|
||||
} else {
|
||||
_controllers[key]!.text = val;
|
||||
}
|
||||
final groupedSettings = await _repository.fetchSettings();
|
||||
final serviceSettings = groupedSettings[widget.serviceName] ?? [];
|
||||
|
||||
setState(() {
|
||||
_settings = serviceSettings;
|
||||
for (var s in _settings) {
|
||||
final key = s.key;
|
||||
final val = s.value;
|
||||
if (!_controllers.containsKey(key)) {
|
||||
_controllers[key] = TextEditingController(text: val);
|
||||
} else {
|
||||
_controllers[key]!.text = val;
|
||||
}
|
||||
_isLoading = false;
|
||||
});
|
||||
} else {
|
||||
throw Exception('Failed to load settings');
|
||||
}
|
||||
}
|
||||
_isLoading = false;
|
||||
});
|
||||
} catch (e) {
|
||||
setState(() {
|
||||
_error = e.toString();
|
||||
@@ -75,35 +80,28 @@ class _ServiceDetailScreenState extends State<ServiceDetailScreen> {
|
||||
payload[k] = v.text;
|
||||
});
|
||||
|
||||
final res = await widget.apiClient.put(
|
||||
'/api/v1/admin/settings/${widget.serviceName}',
|
||||
data: payload,
|
||||
);
|
||||
await _repository.updateServiceSettings(widget.serviceName, payload);
|
||||
|
||||
if (res.statusCode == 200 || res.statusCode == 204) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
const Icon(Icons.check_circle_outline, color: Colors.black),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Einstellungen für ${widget.serviceName} gespeichert & via MQTT synchronisiert.',
|
||||
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.w600),
|
||||
),
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
const Icon(Icons.check_circle_outline, color: Colors.black),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Einstellungen für ${widget.serviceName} gespeichert & via MQTT synchronisiert.',
|
||||
style: const TextStyle(color: Colors.black, fontWeight: FontWeight.w600),
|
||||
),
|
||||
],
|
||||
),
|
||||
backgroundColor: AppTheme.primaryEmerald,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
throw Exception('Server returned status code ${res.statusCode}');
|
||||
backgroundColor: AppTheme.primaryEmerald,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
@@ -170,8 +168,8 @@ class _ServiceDetailScreenState extends State<ServiceDetailScreen> {
|
||||
const Text('Keine spezifischen Einstellungen gefunden.')
|
||||
else
|
||||
..._settings.map((s) {
|
||||
final key = s['key']?.toString() ?? '';
|
||||
final desc = s['description']?.toString() ?? '';
|
||||
final key = s.key;
|
||||
final desc = s.description;
|
||||
final controller = _controllers[key];
|
||||
if (controller == null) return const SizedBox.shrink();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user