Implementert historikk og manuell timeregistrering
This commit is contained in:
@@ -0,0 +1,297 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import '../../models/time_registration.dart';
|
||||
import '../../providers/time_provider.dart';
|
||||
|
||||
class RegistrationDetailScreen extends ConsumerWidget {
|
||||
final TimeRegistration registration;
|
||||
|
||||
const RegistrationDetailScreen({
|
||||
super.key,
|
||||
required this.registration,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final timeService = ref.read(timeServiceProvider);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Detaljer'),
|
||||
actions: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit),
|
||||
onPressed: () {
|
||||
// TODO: Implementer redigering
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Redigering kommer snart')),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete),
|
||||
onPressed: () async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('Slett registrering?'),
|
||||
content: const Text('Er du sikker på at du vil slette denne registreringen?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, false),
|
||||
child: const Text('Avbryt'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context, true),
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
child: const Text('Slett'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm == true) {
|
||||
try {
|
||||
await timeService.deleteRegistration(registration.id);
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Registrering slettet')),
|
||||
);
|
||||
// Invalidate providers to refresh lists
|
||||
ref.invalidate(todayRegistrationsProvider);
|
||||
}
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Feil: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
body: ListView(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
children: [
|
||||
// Hovedinfo kort
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
_DetailRow(
|
||||
icon: Icons.calendar_today,
|
||||
label: 'Dato',
|
||||
value: DateFormat('EEEE d. MMMM yyyy', 'nb_NO').format(registration.startTime),
|
||||
),
|
||||
const Divider(),
|
||||
_DetailRow(
|
||||
icon: Icons.schedule,
|
||||
label: 'Tidsrom',
|
||||
value: '${DateFormat('HH:mm').format(registration.startTime)} - ${registration.endTime != null ? DateFormat('HH:mm').format(registration.endTime!) : 'Pågår'}',
|
||||
),
|
||||
const Divider(),
|
||||
_DetailRow(
|
||||
icon: Icons.timer,
|
||||
label: 'Varighet',
|
||||
value: registration.endTime != null
|
||||
? '${registration.netWorkMinutes ~/ 60}t ${registration.netWorkMinutes % 60}m'
|
||||
: '...',
|
||||
),
|
||||
const Divider(),
|
||||
_DetailRow(
|
||||
icon: _getIconForType(registration.type),
|
||||
label: 'Type',
|
||||
value: _getTypeDisplayName(registration.type),
|
||||
valueColor: _getColorForType(registration.type),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Prosjekt/Kunde info
|
||||
if (registration.projectId != null || registration.customerId != null)
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
if (registration.customerId != null)
|
||||
_DetailRow(
|
||||
icon: Icons.business,
|
||||
label: 'Kunde',
|
||||
value: registration.customerId!,
|
||||
),
|
||||
if (registration.customerId != null && registration.projectId != null)
|
||||
const Divider(),
|
||||
if (registration.projectId != null)
|
||||
_DetailRow(
|
||||
icon: Icons.folder,
|
||||
label: 'Prosjekt',
|
||||
value: registration.projectId!,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
if (registration.projectId != null || registration.customerId != null)
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Kommentar
|
||||
if (registration.comment != null && registration.comment!.isNotEmpty)
|
||||
Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.comment, size: 20, color: Colors.grey),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'Kommentar',
|
||||
style: Theme.of(context).textTheme.titleSmall?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(registration.comment!),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Avvik
|
||||
if (registration.deviations.isNotEmpty) ...[
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'Avvik',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.red,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
// Her ville vi normalt hentet avviksdetaljer fra Firestore
|
||||
// For nå viser vi bare at det finnes avvik
|
||||
Card(
|
||||
color: Colors.red.shade50,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Row(
|
||||
children: [
|
||||
const Icon(Icons.warning, color: Colors.red),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Denne registreringen har ${registration.deviations.length} registrerte avvik.',
|
||||
style: const TextStyle(color: Colors.red),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Color _getColorForType(RegistrationType type) {
|
||||
switch (type) {
|
||||
case RegistrationType.ordinary:
|
||||
return Colors.blue;
|
||||
case RegistrationType.overtime:
|
||||
return Colors.orange;
|
||||
case RegistrationType.oncall:
|
||||
return Colors.purple;
|
||||
case RegistrationType.travel:
|
||||
return Colors.green;
|
||||
}
|
||||
}
|
||||
|
||||
IconData _getIconForType(RegistrationType type) {
|
||||
switch (type) {
|
||||
case RegistrationType.ordinary:
|
||||
return Icons.work;
|
||||
case RegistrationType.overtime:
|
||||
return Icons.access_time_filled;
|
||||
case RegistrationType.oncall:
|
||||
return Icons.phone_in_talk;
|
||||
case RegistrationType.travel:
|
||||
return Icons.directions_car;
|
||||
}
|
||||
}
|
||||
|
||||
String _getTypeDisplayName(RegistrationType type) {
|
||||
switch (type) {
|
||||
case RegistrationType.ordinary:
|
||||
return 'Ordinær';
|
||||
case RegistrationType.overtime:
|
||||
return 'Overtid';
|
||||
case RegistrationType.oncall:
|
||||
return 'Beredskap';
|
||||
case RegistrationType.travel:
|
||||
return 'Reisetid';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _DetailRow extends StatelessWidget {
|
||||
final IconData icon;
|
||||
final String label;
|
||||
final String value;
|
||||
final Color? valueColor;
|
||||
|
||||
const _DetailRow({
|
||||
required this.icon,
|
||||
required this.label,
|
||||
required this.value,
|
||||
this.valueColor,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 8.0),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 20, color: Colors.grey),
|
||||
const SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
label,
|
||||
style: Theme.of(context).textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
value,
|
||||
style: Theme.of(context).textTheme.bodyLarge?.copyWith(
|
||||
color: valueColor,
|
||||
fontWeight: valueColor != null ? FontWeight.bold : null,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user