a
This commit is contained in:
@@ -13,7 +13,11 @@ import 'package:flux/features/tickets/blocs/ticket_form_state.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_model.dart';
|
||||
import 'package:flux/core/widgets/shared_forms/staff_section.dart';
|
||||
import 'package:flux/features/tickets/models/ticket_status_extension.dart';
|
||||
import 'package:flux/features/tickets/ui/ticket_timeline_section.dart';
|
||||
import 'package:flux/features/tickets/utils/ticket_pdf_service.dart';
|
||||
import 'package:flux/features/tracking/blocs/tracking_cubit.dart';
|
||||
import 'package:flux/features/tracking/data/tracking_repository.dart';
|
||||
import 'package:flux/features/tracking/models/tracking_model.dart';
|
||||
import 'package:get_it/get_it.dart';
|
||||
import 'package:printing/printing.dart';
|
||||
|
||||
@@ -409,7 +413,11 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
return Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(child: Column(children: [_cardAnagrafica(ticket)])),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [_cardTimeline(ticket), _cardAnagrafica(ticket)],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
Expanded(
|
||||
child: Column(
|
||||
@@ -441,7 +449,11 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
const SizedBox(width: 24),
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [_cardDettagli(ticket), _cardCosti(ticket)],
|
||||
children: [
|
||||
_cardTimeline(ticket),
|
||||
_cardDettagli(ticket),
|
||||
_cardCosti(ticket),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -451,6 +463,7 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_cardTimeline(ticket),
|
||||
_cardAnagrafica(ticket),
|
||||
_cardDispositivi(ticket),
|
||||
_cardDettagli(ticket),
|
||||
@@ -461,7 +474,7 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// --- LE 5 CARD (MODULARIZZATE E COLORATE) ---
|
||||
// --- LE 6 CARD (MODULARIZZATE E COLORATE) ---
|
||||
|
||||
Widget _cardAnagrafica(TicketModel ticket) {
|
||||
return _buildCard(
|
||||
@@ -781,6 +794,49 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _cardTimeline(TicketModel ticket) {
|
||||
// Se il ticket è nuovo (non ha ancora un ID salvato a DB), nascondiamo la timeline
|
||||
if (ticket.id == null || ticket.id!.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
return _buildCard(
|
||||
title: 'Timeline & Note',
|
||||
icon: Icons.history,
|
||||
themeColor: Colors.blueGrey,
|
||||
children: [
|
||||
BlocProvider(
|
||||
create: (context) => TrackingCubit(
|
||||
repo: GetIt.I.get<TrackingRepository>(),
|
||||
parentId: ticket.id!,
|
||||
parentType: TrackingParentType.ticket,
|
||||
companyId: ticket.companyId,
|
||||
),
|
||||
child: BlocBuilder<TrackingCubit, TrackingState>(
|
||||
builder: (context, state) {
|
||||
if (state.isLoading && state.logs.isEmpty) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
|
||||
return TicketTimelineSection(
|
||||
logs: state.logs,
|
||||
onAddNote: (message, isInternal) {
|
||||
// Recupera l'ID dello staff loggato dal tuo auth state
|
||||
// final currentStaffId = ...
|
||||
context.read<TrackingCubit>().addManualNote(
|
||||
message,
|
||||
isInternal,
|
||||
// staffId: currentStaffId,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// --- WIDGET BASE PER LA CARD ---
|
||||
Widget _buildCard({
|
||||
required String title,
|
||||
|
||||
278
lib/features/tickets/ui/ticket_timeline_section.dart
Normal file
278
lib/features/tickets/ui/ticket_timeline_section.dart
Normal file
@@ -0,0 +1,278 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flux/features/tracking/models/tracking_model.dart';
|
||||
|
||||
class TicketTimelineSection extends StatefulWidget {
|
||||
final List<TrackingModel> logs;
|
||||
final void Function(String message, bool isInternal) onAddNote;
|
||||
|
||||
const TicketTimelineSection({
|
||||
super.key,
|
||||
required this.logs,
|
||||
required this.onAddNote,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TicketTimelineSection> createState() => _TicketTimelineSectionState();
|
||||
}
|
||||
|
||||
class _TicketTimelineSectionState extends State<TicketTimelineSection> {
|
||||
final TextEditingController _textController = TextEditingController();
|
||||
bool _isInternal = true; // Di default blindiamo tutto a uso interno!
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_textController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submitNote() {
|
||||
final text = _textController.text.trim();
|
||||
if (text.isNotEmpty) {
|
||||
widget.onAddNote(text, _isInternal);
|
||||
_textController.clear();
|
||||
// Chiudiamo la tastiera se siamo su mobile
|
||||
FocusScope.of(context).unfocus();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
// --- ZONA INPUT ---
|
||||
Container(
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerHighest.withValues(
|
||||
alpha: 0.3,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: theme.dividerColor),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _textController,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Scrivi un aggiornamento...',
|
||||
border: InputBorder.none,
|
||||
isDense: true,
|
||||
),
|
||||
textInputAction: TextInputAction.send,
|
||||
onSubmitted: (_) => _submitNote(),
|
||||
),
|
||||
),
|
||||
IconButton.filled(
|
||||
onPressed: _submitNote,
|
||||
icon: const Icon(Icons.send, size: 20),
|
||||
tooltip: 'Invia',
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 16),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
_isInternal ? Icons.lock : Icons.public,
|
||||
size: 16,
|
||||
color: _isInternal
|
||||
? Colors.amber.shade700
|
||||
: Colors.green,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_isInternal
|
||||
? 'Nota Interna (Privata)'
|
||||
: 'Visibile al Cliente',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: _isInternal
|
||||
? Colors.amber.shade700
|
||||
: Colors.green,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
Switch(
|
||||
value: _isInternal,
|
||||
activeThumbColor: Colors.amber.shade700,
|
||||
activeTrackColor: Colors.amber,
|
||||
inactiveThumbColor: Colors.green,
|
||||
inactiveTrackColor: Colors.green.withValues(alpha: 0.2),
|
||||
onChanged: (val) {
|
||||
setState(() {
|
||||
_isInternal = val;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// --- TIMELINE SCROLLABILE ---
|
||||
if (widget.logs.isEmpty)
|
||||
const Padding(
|
||||
padding: EdgeInsets.all(32.0),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'Nessun evento registrato.',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
ConstrainedBox(
|
||||
constraints: const BoxConstraints(
|
||||
maxHeight: 400,
|
||||
), // Limite di altezza
|
||||
child: ListView.builder(
|
||||
shrinkWrap: true,
|
||||
itemCount: widget.logs.length,
|
||||
itemBuilder: (context, index) {
|
||||
final log = widget.logs[index];
|
||||
final isLast = index == widget.logs.length - 1;
|
||||
|
||||
return IntrinsicHeight(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// --- LINEA E PALLINO ---
|
||||
SizedBox(
|
||||
width: 30,
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
margin: const EdgeInsets.only(top: 4),
|
||||
width: 14,
|
||||
height: 14,
|
||||
decoration: BoxDecoration(
|
||||
color: _getEventColor(log.eventType),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(
|
||||
color: theme.scaffoldBackgroundColor,
|
||||
width: 2,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (!isLast)
|
||||
Expanded(
|
||||
child: Container(
|
||||
width: 2,
|
||||
color: theme.dividerColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// --- CONTENUTO EVENTO ---
|
||||
Expanded(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text(
|
||||
log.staffName ?? 'Sistema',
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_formatDate(log.createdAt),
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: Colors.grey,
|
||||
),
|
||||
),
|
||||
if (!log.isInternal) ...[
|
||||
const Spacer(),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6,
|
||||
vertical: 2,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.green.withValues(
|
||||
alpha: 0.1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(
|
||||
color: Colors.green.withValues(
|
||||
alpha: 0.3,
|
||||
),
|
||||
),
|
||||
),
|
||||
child: const Text(
|
||||
"PUBBLICO",
|
||||
style: TextStyle(
|
||||
color: Colors.green,
|
||||
fontSize: 9,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(
|
||||
log.message,
|
||||
style: const TextStyle(fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Color _getEventColor(TrackingType type) {
|
||||
switch (type) {
|
||||
case TrackingType.statusChange:
|
||||
return Colors.blue;
|
||||
case TrackingType.assignment:
|
||||
return Colors.purple;
|
||||
case TrackingType.systemAlert:
|
||||
return Colors.redAccent;
|
||||
case TrackingType.customerContact:
|
||||
return Colors.teal;
|
||||
case TrackingType.manualNote:
|
||||
// ignore: unreachable_switch_default
|
||||
default:
|
||||
return Colors.amber.shade600;
|
||||
}
|
||||
}
|
||||
|
||||
String _formatDate(DateTime date) {
|
||||
final day = date.day.toString().padLeft(2, '0');
|
||||
final month = date.month.toString().padLeft(2, '0');
|
||||
final hour = date.hour.toString().padLeft(2, '0');
|
||||
final minute = date.minute.toString().padLeft(2, '0');
|
||||
return "$day/$month - $hour:$minute";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user