mah....volare
This commit is contained in:
@@ -217,8 +217,6 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
String? reference,
|
String? reference,
|
||||||
String? note,
|
String? note,
|
||||||
String? type,
|
String? type,
|
||||||
String? providerId,
|
|
||||||
String? providerDisplayName,
|
|
||||||
String? subType,
|
String? subType,
|
||||||
String? description,
|
String? description,
|
||||||
DateTime? expirationDate,
|
DateTime? expirationDate,
|
||||||
@@ -248,10 +246,6 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
final updated = current.copyWith(
|
final updated = current.copyWith(
|
||||||
reference: reference ?? current.reference,
|
reference: reference ?? current.reference,
|
||||||
note: note ?? current.note,
|
note: note ?? current.note,
|
||||||
providerId: clearProvider ? null : (providerId ?? current.providerId),
|
|
||||||
providerDisplayName: clearProvider
|
|
||||||
? null
|
|
||||||
: (providerDisplayName ?? current.providerDisplayName),
|
|
||||||
quantity: newQuantity ?? current.quantity,
|
quantity: newQuantity ?? current.quantity,
|
||||||
type: clearType ? null : (type ?? current.type),
|
type: clearType ? null : (type ?? current.type),
|
||||||
description: clearDescription
|
description: clearDescription
|
||||||
@@ -274,6 +268,18 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
emit(state.copyWith(operation: updated));
|
emit(state.copyWith(operation: updated));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateProvider(ProviderModel? newProvider) {
|
||||||
|
final current = state.operation;
|
||||||
|
|
||||||
|
final updatedOperation = current.copyWith(
|
||||||
|
// Se newProvider è null, passiamo una funzione che ritorna null per sbiancare i campi!
|
||||||
|
providerId: () => newProvider?.id,
|
||||||
|
provider: () => newProvider,
|
||||||
|
);
|
||||||
|
|
||||||
|
emit(state.copyWith(operation: updatedOperation));
|
||||||
|
}
|
||||||
|
|
||||||
void updateCustomer(CustomerModel customer) {
|
void updateCustomer(CustomerModel customer) {
|
||||||
final bool isBusiness = customer.isBusiness;
|
final bool isBusiness = customer.isBusiness;
|
||||||
final updatedOperation = state.operation.copyWith(
|
final updatedOperation = state.operation.copyWith(
|
||||||
@@ -293,13 +299,8 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
}) {
|
}) {
|
||||||
// 1. Aggiorniamo il tipo nel modello in canna
|
// 1. Aggiorniamo il tipo nel modello in canna
|
||||||
// (Presumo tu abbia un metodo copyWith o simile)
|
// (Presumo tu abbia un metodo copyWith o simile)
|
||||||
final updatedOp = state.operation.copyWith(type: newType, subType: '');
|
|
||||||
|
|
||||||
// 2. Prepariamoci ad auto-selezionare il provider
|
// 2. LA LOGICA DI DEFAULT
|
||||||
String? newProviderId = updatedOp.providerId;
|
|
||||||
String? newProviderName = updatedOp.providerDisplayName;
|
|
||||||
|
|
||||||
// 3. LA LOGICA DI DEFAULT
|
|
||||||
if (defaultProviderId != null) {
|
if (defaultProviderId != null) {
|
||||||
// Troviamo il provider di default nella lista
|
// Troviamo il provider di default nella lista
|
||||||
final defaultProvider = allProviders
|
final defaultProvider = allProviders
|
||||||
@@ -309,25 +310,13 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
if (defaultProvider != null) {
|
if (defaultProvider != null) {
|
||||||
// Usiamo l'extension appena creata!
|
// Usiamo l'extension appena creata!
|
||||||
if (defaultProvider.supportsOperation(newType)) {
|
if (defaultProvider.supportsOperation(newType)) {
|
||||||
newProviderId = defaultProvider.id;
|
updateProvider(defaultProvider);
|
||||||
newProviderName = defaultProvider.name;
|
|
||||||
} else {
|
} else {
|
||||||
// Se cambi tipo (es. da Mobile a Luce) e il default non lo supporta, sbianchiamo
|
// Se cambi tipo (es. da Mobile a Luce) e il default non lo supporta, sbianchiamo
|
||||||
newProviderId = null;
|
updateProvider(null);
|
||||||
newProviderName = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emettiamo il nuovo stato
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
operation: updatedOp.copyWith(
|
|
||||||
providerId: newProviderId,
|
|
||||||
providerDisplayName: newProviderName,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTypeWithSmartDefaults({
|
void setTypeWithSmartDefaults({
|
||||||
@@ -338,7 +327,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
final currentOp = state.operation;
|
final currentOp = state.operation;
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
// 1. SMART DATES: Calcolo Scadenze Default
|
// 1. SMART DATES: Calcolo Scadenze Default (Invariato)
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
DateTime? defaultDate;
|
DateTime? defaultDate;
|
||||||
final now = DateTime.now();
|
final now = DateTime.now();
|
||||||
@@ -354,28 +343,19 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
// 2. SMART PROVIDER: Filtro e Auto-Selezione
|
// 2. SMART PROVIDER: Filtro e Auto-Selezione ad Oggetti
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
String? newProviderId = currentOp.providerId;
|
// Pescatore direttamente l'oggetto dal modello corrente
|
||||||
String? newProviderName = currentOp.providerDisplayName;
|
ProviderModel? targetProvider = currentOp.provider;
|
||||||
|
|
||||||
// A) Il provider attuale è ancora compatibile col nuovo tipo scelto?
|
// A) Il provider attuale è ancora compatibile col nuovo tipo scelto?
|
||||||
if (newProviderId != null && newProviderId.isNotEmpty) {
|
if (targetProvider != null && !targetProvider.supportsOperation(newType)) {
|
||||||
final currentProvider = allProviders
|
// Non è più compatibile (es. da TIM fisso passo a Energy). Lo sbianchiamo!
|
||||||
.where((p) => p.id == newProviderId)
|
targetProvider = null;
|
||||||
.firstOrNull;
|
|
||||||
|
|
||||||
if (currentProvider == null ||
|
|
||||||
!currentProvider.supportsOperation(newType)) {
|
|
||||||
// Non è più compatibile (es. da TIM fisso passo a Energy). Lo sbianchiamo!
|
|
||||||
newProviderId = null;
|
|
||||||
newProviderName = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// B) Se non c'è un provider selezionato, proviamo ad auto-inserire quello di default del negozio
|
// B) Se non c'è un provider selezionato, proviamo ad auto-inserire quello di default del negozio
|
||||||
if ((newProviderId == null || newProviderId.isEmpty) &&
|
if (targetProvider == null && defaultProviderId != null) {
|
||||||
defaultProviderId != null) {
|
|
||||||
final defaultProvider = allProviders
|
final defaultProvider = allProviders
|
||||||
.where((p) => p.id == defaultProviderId)
|
.where((p) => p.id == defaultProviderId)
|
||||||
.firstOrNull;
|
.firstOrNull;
|
||||||
@@ -383,8 +363,7 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
// Controlliamo che il default del negozio supporti questa specifica operazione
|
// Controlliamo che il default del negozio supporti questa specifica operazione
|
||||||
if (defaultProvider != null &&
|
if (defaultProvider != null &&
|
||||||
defaultProvider.supportsOperation(newType)) {
|
defaultProvider.supportsOperation(newType)) {
|
||||||
newProviderId = defaultProvider.id;
|
targetProvider = defaultProvider;
|
||||||
newProviderName = defaultProvider.name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -395,13 +374,16 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
|||||||
state.copyWith(
|
state.copyWith(
|
||||||
operation: currentOp.copyWith(
|
operation: currentOp.copyWith(
|
||||||
type: newType,
|
type: newType,
|
||||||
subType:
|
subType: '', // Resettiamo il sottotipo per evitare incongruenze
|
||||||
'', // Resettiamo il sottotipo per evitare incongruenze (es. passo da Luce a DAZN)
|
|
||||||
expirationDate:
|
expirationDate:
|
||||||
defaultDate, // Impostiamo la scadenza di default se calcolata
|
defaultDate, // Impostiamo la scadenza di default se calcolata
|
||||||
providerId: newProviderId,
|
// 🥷 APPLICHIAMO IL TRUCCO NINJA DELLE FUNZIONI
|
||||||
providerDisplayName: newProviderName,
|
// Se targetProvider è null, le funzioni ritorneranno null sbiancando il DB!
|
||||||
|
providerId: () => targetProvider?.id,
|
||||||
|
provider: () => targetProvider,
|
||||||
|
|
||||||
|
// Nota: Per azzerare davvero questi due, ricordati in futuro di applicare
|
||||||
|
// il trucco delle funzioni anche a modelId e modelDisplayName nel modello!
|
||||||
modelId: null,
|
modelId: null,
|
||||||
modelDisplayName: null,
|
modelDisplayName: null,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -12,72 +12,103 @@ class OperationListCubit extends Cubit<OperationListState> {
|
|||||||
final OperationsRepository _repository = GetIt.I<OperationsRepository>();
|
final OperationsRepository _repository = GetIt.I<OperationsRepository>();
|
||||||
final SessionCubit _sessionCubit = GetIt.I<SessionCubit>();
|
final SessionCubit _sessionCubit = GetIt.I<SessionCubit>();
|
||||||
|
|
||||||
OperationListCubit() : super(const OperationListState()) {
|
OperationListCubit() : super(const OperationListState());
|
||||||
loadOperations(refresh: true);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> loadOperations({bool refresh = false}) async {
|
// 🥷 MOTORE 1: DESKTOP (Sostituisce la lista)
|
||||||
|
Future<void> loadSpecificPageDesktop(int page) async {
|
||||||
if (state.status == OperationListStatus.loading) return;
|
if (state.status == OperationListStatus.loading) return;
|
||||||
if (!refresh && state.hasReachedMax) return;
|
emit(state.copyWith(status: OperationListStatus.loading));
|
||||||
|
|
||||||
emit(
|
|
||||||
state.copyWith(
|
|
||||||
status: OperationListStatus.loading,
|
|
||||||
errorMessage: null,
|
|
||||||
operations: refresh ? [] : state.operations,
|
|
||||||
hasReachedMax: refresh ? false : state.hasReachedMax,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final currentOffset = refresh ? 0 : state.operations.length;
|
|
||||||
final companyId = _sessionCubit.state.company?.id;
|
final companyId = _sessionCubit.state.company?.id;
|
||||||
|
final paginatedData = await _repository.fetchPaginatedOperations(
|
||||||
if (companyId == null) {
|
companyId: companyId!,
|
||||||
throw Exception("Company ID non trovato nella sessione");
|
page: page,
|
||||||
}
|
itemsPerPage: state.itemsPerPage,
|
||||||
|
|
||||||
final newOperations = await _repository.fetchOperations(
|
|
||||||
companyId: companyId,
|
|
||||||
offset: currentOffset,
|
|
||||||
limit: 50,
|
|
||||||
searchTerm: state.query,
|
|
||||||
dateRange: state.dateRange,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final bool reachedMax = newOperations.length < 50;
|
|
||||||
|
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
status: OperationListStatus.success,
|
status: OperationListStatus.success,
|
||||||
operations: refresh
|
operations: paginatedData.operations, // 🎯 SOSTITUISCE I DATI
|
||||||
? newOperations
|
totalItems: paginatedData.totalCount,
|
||||||
: [...state.operations, ...newOperations],
|
currentPage: page,
|
||||||
hasReachedMax: reachedMax,
|
hasReachedMax: paginatedData.operations.length < state.itemsPerPage,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
status: OperationListStatus.failure,
|
status: OperationListStatus.failure,
|
||||||
errorMessage: "Errore nel caricamento operazioni: $e",
|
errorMessage: e.toString(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateFilters({String? query, DateTimeRange? range}) {
|
// 🥷 MOTORE 2: MOBILE (Accoda alla lista)
|
||||||
|
Future<void> loadNextPageMobile({bool refresh = false}) async {
|
||||||
|
if (state.status == OperationListStatus.loading) return;
|
||||||
|
if (state.hasReachedMax && !refresh) return;
|
||||||
|
|
||||||
|
// Se stiamo pullando verso il basso (refresh), ripartiamo da pagina 1
|
||||||
|
final targetPage = refresh ? 1 : state.currentPage + 1;
|
||||||
|
|
||||||
|
// Mostriamo il loading solo se è un refresh totale, altrimenti manteniamo lo stato success
|
||||||
|
// per non far sparire la UI mentre carica in fondo
|
||||||
|
if (refresh) emit(state.copyWith(status: OperationListStatus.loading));
|
||||||
|
|
||||||
|
try {
|
||||||
|
final companyId = _sessionCubit.state.company?.id;
|
||||||
|
final paginatedData = await _repository.fetchPaginatedOperations(
|
||||||
|
companyId: companyId!,
|
||||||
|
page: targetPage,
|
||||||
|
itemsPerPage: state.itemsPerPage,
|
||||||
|
);
|
||||||
|
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
status: OperationListStatus.success,
|
||||||
|
// 🎯 ACCODA I DATI SE NON È REFRESH, ALTRIMENTI SOSTITUISCE
|
||||||
|
operations:
|
||||||
|
refresh ? paginatedData.operations : List.of(state.operations)
|
||||||
|
..addAll(paginatedData.operations),
|
||||||
|
totalItems: paginatedData.totalCount,
|
||||||
|
currentPage: targetPage,
|
||||||
|
hasReachedMax: paginatedData.operations.length < state.itemsPerPage,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
emit(
|
||||||
|
state.copyWith(
|
||||||
|
status: OperationListStatus.failure,
|
||||||
|
errorMessage: e.toString(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateFilters({String? text, DateTimeRange? range}) {
|
||||||
emit(
|
emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
query: query ?? state.query,
|
// 🥷 FORZIAMO IL TIPO: Diciamo a Dart che il risultato del ternario è proprio una funzione
|
||||||
dateRange: range ?? state.dateRange,
|
searchTerm: text != null ? () => text : null,
|
||||||
|
dateRange: range != null ? () => range : null,
|
||||||
|
|
||||||
|
currentPage: 1, // Reset obbligatorio alla prima pagina
|
||||||
|
hasReachedMax: false,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
loadOperations(refresh: true);
|
|
||||||
|
// Ricarichiamo la pagina 1 con i nuovi filtri applicati
|
||||||
|
loadSpecificPageDesktop(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clearFilters() {
|
void clearFilters() {
|
||||||
emit(const OperationListState()); // Resetta tutto allo stato iniziale
|
// Invece di un const vuoto che potrebbe bruciarti l'impostazione itemsPerPage,
|
||||||
loadOperations(refresh: true);
|
// creiamo uno stato pulito ma manteniamo la preferenza di paginazione.
|
||||||
|
emit(OperationListState(itemsPerPage: state.itemsPerPage));
|
||||||
|
|
||||||
|
loadSpecificPageDesktop(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,35 +5,57 @@ enum OperationListStatus { initial, loading, success, failure }
|
|||||||
class OperationListState extends Equatable {
|
class OperationListState extends Equatable {
|
||||||
final OperationListStatus status;
|
final OperationListStatus status;
|
||||||
final List<OperationModel> operations;
|
final List<OperationModel> operations;
|
||||||
final bool hasReachedMax;
|
|
||||||
final String? errorMessage;
|
final String? errorMessage;
|
||||||
final String query;
|
|
||||||
|
// Paginazione Ibrida
|
||||||
|
final int currentPage;
|
||||||
|
final int itemsPerPage;
|
||||||
|
final int totalItems;
|
||||||
|
final bool hasReachedMax;
|
||||||
|
|
||||||
|
// 🥷 I FILTRI MANCANTI (Riparati!)
|
||||||
|
final String? searchTerm;
|
||||||
final DateTimeRange? dateRange;
|
final DateTimeRange? dateRange;
|
||||||
|
|
||||||
const OperationListState({
|
const OperationListState({
|
||||||
this.status = OperationListStatus.initial,
|
this.status = OperationListStatus.initial,
|
||||||
this.operations = const [],
|
this.operations = const [],
|
||||||
this.hasReachedMax = false,
|
|
||||||
this.errorMessage,
|
this.errorMessage,
|
||||||
this.query = '',
|
this.currentPage = 1,
|
||||||
|
this.itemsPerPage = 25,
|
||||||
|
this.totalItems = 0,
|
||||||
|
this.hasReachedMax = false,
|
||||||
|
this.searchTerm,
|
||||||
this.dateRange,
|
this.dateRange,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
int get totalPages => (totalItems / itemsPerPage).ceil();
|
||||||
|
|
||||||
|
// 🥷 COPYWITH AVANZATO: Gestisce lo sbiancamento dei filtri alla perfezione
|
||||||
OperationListState copyWith({
|
OperationListState copyWith({
|
||||||
OperationListStatus? status,
|
OperationListStatus? status,
|
||||||
List<OperationModel>? operations,
|
List<OperationModel>? operations,
|
||||||
bool? hasReachedMax,
|
|
||||||
String? errorMessage,
|
String? errorMessage,
|
||||||
String? query,
|
int? currentPage,
|
||||||
DateTimeRange? dateRange,
|
int? itemsPerPage,
|
||||||
|
int? totalItems,
|
||||||
|
bool? hasReachedMax,
|
||||||
|
String? Function()? searchTerm, // Callback per gestire il null esplicito
|
||||||
|
DateTimeRange? Function()?
|
||||||
|
dateRange, // Callback per gestire il null esplicito
|
||||||
}) {
|
}) {
|
||||||
return OperationListState(
|
return OperationListState(
|
||||||
status: status ?? this.status,
|
status: status ?? this.status,
|
||||||
operations: operations ?? this.operations,
|
operations: operations ?? this.operations,
|
||||||
|
errorMessage: errorMessage ?? this.errorMessage,
|
||||||
|
currentPage: currentPage ?? this.currentPage,
|
||||||
|
itemsPerPage: itemsPerPage ?? this.itemsPerPage,
|
||||||
|
totalItems: totalItems ?? this.totalItems,
|
||||||
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
|
hasReachedMax: hasReachedMax ?? this.hasReachedMax,
|
||||||
errorMessage: errorMessage,
|
|
||||||
query: query ?? this.query,
|
// Se passi la funzione la eseguiamo, altrimenti teniamo il valore corrente
|
||||||
dateRange: dateRange ?? this.dateRange,
|
searchTerm: searchTerm != null ? searchTerm() : this.searchTerm,
|
||||||
|
dateRange: dateRange != null ? dateRange() : this.dateRange,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,9 +63,12 @@ class OperationListState extends Equatable {
|
|||||||
List<Object?> get props => [
|
List<Object?> get props => [
|
||||||
status,
|
status,
|
||||||
operations,
|
operations,
|
||||||
hasReachedMax,
|
|
||||||
errorMessage,
|
errorMessage,
|
||||||
query,
|
currentPage,
|
||||||
|
itemsPerPage,
|
||||||
|
totalItems,
|
||||||
|
hasReachedMax,
|
||||||
|
searchTerm,
|
||||||
dateRange,
|
dateRange,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,82 @@ class OperationsRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 🥷 2. RECUPERO PAGINATO ASSOLUTO CON CONTEGGIO TOTALI
|
||||||
|
Future<PaginatedOperations> fetchPaginatedOperations({
|
||||||
|
required String companyId,
|
||||||
|
String? storeId,
|
||||||
|
String? staffId,
|
||||||
|
String? providerId,
|
||||||
|
required int page, // Usiamo 'page' (1, 2, 3...) invece di 'offset'
|
||||||
|
int itemsPerPage = 25, // Default a 25 elementi per pagina
|
||||||
|
String? searchTerm,
|
||||||
|
DateTimeRange? dateRange,
|
||||||
|
}) async {
|
||||||
|
try {
|
||||||
|
// Calcoliamo il range di partenza e fine per Supabase
|
||||||
|
// Es. Pagina 1, 25 items -> range(0, 24)
|
||||||
|
// Es. Pagina 2, 25 items -> range(25, 49)
|
||||||
|
final from = (page - 1) * itemsPerPage;
|
||||||
|
final to = from + itemsPerPage - 1;
|
||||||
|
|
||||||
|
var query = _supabase
|
||||||
|
.from(Tables.operations)
|
||||||
|
.select('''
|
||||||
|
*,
|
||||||
|
${Tables.customers}(*),
|
||||||
|
${Tables.stores}(name),
|
||||||
|
${Tables.providers}(name, color_hex),
|
||||||
|
${Tables.models}(name_with_brand),
|
||||||
|
${Tables.staffMembers}(name),
|
||||||
|
${Tables.attachments}(*)
|
||||||
|
''')
|
||||||
|
.eq('company_id', companyId);
|
||||||
|
|
||||||
|
// Filtro Range Date
|
||||||
|
if (dateRange != null) {
|
||||||
|
query = query
|
||||||
|
.gte('created_at', dateRange.start.toIso8601String())
|
||||||
|
.lte('created_at', dateRange.end.toIso8601String());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (storeId != null) {
|
||||||
|
query = query.or('store_id.eq.$storeId,store_id.is.null');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (staffId != null) {
|
||||||
|
query = query.or('staff_id.eq.$staffId,staff_id.is.null');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (providerId != null) {
|
||||||
|
query = query.or('provider_id.eq.$providerId,provider_id.is.null');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (searchTerm != null && searchTerm.isNotEmpty) {
|
||||||
|
query = query.or(
|
||||||
|
'reference.ilike.%$searchTerm%,note.ilike.%$searchTerm%,customer.name.ilike.%$searchTerm%',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final response = await query
|
||||||
|
.order('created_at', ascending: false)
|
||||||
|
.range(from, to)
|
||||||
|
.count(CountOption.exact);
|
||||||
|
// 3. Estrazione dei dati
|
||||||
|
final List<OperationModel> operations = (response.data as List)
|
||||||
|
.map((map) => OperationModel.fromMap(map))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
final int totalCount = response.count;
|
||||||
|
|
||||||
|
return PaginatedOperations(
|
||||||
|
operations: operations,
|
||||||
|
totalCount: totalCount,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
throw Exception('Errore nel recupero della pagina $page: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// --- RECUPERO PAGINATO CON FILTRI E JOIN ---
|
// --- RECUPERO PAGINATO CON FILTRI E JOIN ---
|
||||||
Future<List<OperationModel>> fetchOperations({
|
Future<List<OperationModel>> fetchOperations({
|
||||||
required String companyId,
|
required String companyId,
|
||||||
@@ -325,3 +401,10 @@ class OperationsRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PaginatedOperations {
|
||||||
|
final List<OperationModel> operations;
|
||||||
|
final int totalCount;
|
||||||
|
|
||||||
|
PaginatedOperations({required this.operations, required this.totalCount});
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:flux/core/enums_and_consts/consts.dart';
|
|||||||
import 'package:flux/core/utils/extensions.dart';
|
import 'package:flux/core/utils/extensions.dart';
|
||||||
import 'package:flux/features/attachments/models/attachment_model.dart';
|
import 'package:flux/features/attachments/models/attachment_model.dart';
|
||||||
import 'package:flux/features/customers/models/customer_model.dart';
|
import 'package:flux/features/customers/models/customer_model.dart';
|
||||||
|
import 'package:flux/features/master_data/providers/models/provider_model.dart';
|
||||||
|
|
||||||
enum OperationStatus {
|
enum OperationStatus {
|
||||||
success('success', 'OK'),
|
success('success', 'OK'),
|
||||||
@@ -30,7 +31,6 @@ class OperationModel extends Equatable {
|
|||||||
final String type;
|
final String type;
|
||||||
final String? subType;
|
final String? subType;
|
||||||
final String? providerId;
|
final String? providerId;
|
||||||
final String? providerDisplayName;
|
|
||||||
final String? modelId;
|
final String? modelId;
|
||||||
final String? modelDisplayName;
|
final String? modelDisplayName;
|
||||||
final String? description;
|
final String? description;
|
||||||
@@ -50,6 +50,7 @@ class OperationModel extends Equatable {
|
|||||||
final CustomerModel? customer;
|
final CustomerModel? customer;
|
||||||
final String reference;
|
final String reference;
|
||||||
final bool isBusiness;
|
final bool isBusiness;
|
||||||
|
final ProviderModel? provider;
|
||||||
|
|
||||||
// ALLEGATI (Aggiunto)
|
// ALLEGATI (Aggiunto)
|
||||||
final List<AttachmentModel> attachments;
|
final List<AttachmentModel> attachments;
|
||||||
@@ -60,7 +61,6 @@ class OperationModel extends Equatable {
|
|||||||
this.type = '',
|
this.type = '',
|
||||||
this.subType,
|
this.subType,
|
||||||
this.providerId,
|
this.providerId,
|
||||||
this.providerDisplayName,
|
|
||||||
this.modelId,
|
this.modelId,
|
||||||
this.modelDisplayName,
|
this.modelDisplayName,
|
||||||
this.description,
|
this.description,
|
||||||
@@ -81,6 +81,7 @@ class OperationModel extends Equatable {
|
|||||||
this.reference = '',
|
this.reference = '',
|
||||||
this.attachments = const [],
|
this.attachments = const [],
|
||||||
this.isBusiness = false,
|
this.isBusiness = false,
|
||||||
|
this.provider,
|
||||||
});
|
});
|
||||||
|
|
||||||
OperationModel copyWith({
|
OperationModel copyWith({
|
||||||
@@ -88,8 +89,9 @@ class OperationModel extends Equatable {
|
|||||||
DateTime? createdAt,
|
DateTime? createdAt,
|
||||||
String? type,
|
String? type,
|
||||||
String? subType,
|
String? subType,
|
||||||
String? providerId,
|
// 🥷 TRUCCO APPLICATO ANCHE QUI:
|
||||||
String? providerDisplayName,
|
String? Function()? providerId,
|
||||||
|
ProviderModel? Function()? provider,
|
||||||
String? modelId,
|
String? modelId,
|
||||||
String? modelDisplayName,
|
String? modelDisplayName,
|
||||||
String? description,
|
String? description,
|
||||||
@@ -115,8 +117,10 @@ class OperationModel extends Equatable {
|
|||||||
createdAt: createdAt ?? this.createdAt,
|
createdAt: createdAt ?? this.createdAt,
|
||||||
type: type ?? this.type,
|
type: type ?? this.type,
|
||||||
subType: subType ?? this.subType,
|
subType: subType ?? this.subType,
|
||||||
providerId: providerId ?? this.providerId,
|
// Se la funzione è passata, la eseguiamo (anche se ritorna null), altrimenti teniamo il vecchio
|
||||||
providerDisplayName: providerDisplayName ?? this.providerDisplayName,
|
providerId: providerId != null ? providerId() : this.providerId,
|
||||||
|
provider: provider != null ? provider() : this.provider,
|
||||||
|
|
||||||
modelId: modelId ?? this.modelId,
|
modelId: modelId ?? this.modelId,
|
||||||
modelDisplayName: modelDisplayName ?? this.modelDisplayName,
|
modelDisplayName: modelDisplayName ?? this.modelDisplayName,
|
||||||
description: description ?? this.description,
|
description: description ?? this.description,
|
||||||
@@ -146,7 +150,7 @@ class OperationModel extends Equatable {
|
|||||||
type,
|
type,
|
||||||
subType,
|
subType,
|
||||||
providerId,
|
providerId,
|
||||||
providerDisplayName,
|
provider,
|
||||||
modelId,
|
modelId,
|
||||||
modelDisplayName,
|
modelDisplayName,
|
||||||
description,
|
description,
|
||||||
@@ -185,8 +189,9 @@ class OperationModel extends Equatable {
|
|||||||
// I campi relazionali nullabili restano rigorosamente null!
|
// I campi relazionali nullabili restano rigorosamente null!
|
||||||
providerId: map['provider_id'] as String?,
|
providerId: map['provider_id'] as String?,
|
||||||
// MAGIA ANTI-CRASH: Usiamo ?['chiave'] per non far esplodere i join vuoti
|
// MAGIA ANTI-CRASH: Usiamo ?['chiave'] per non far esplodere i join vuoti
|
||||||
providerDisplayName: (map[Tables.providers]?['name'] as String?)
|
provider: (map[Tables.providers] != null)
|
||||||
?.myFormat(),
|
? ProviderModel.fromMap(map[Tables.providers] as Map<String, dynamic>)
|
||||||
|
: null,
|
||||||
|
|
||||||
modelId: map['model_id'] as String?,
|
modelId: map['model_id'] as String?,
|
||||||
modelDisplayName: (map[Tables.models]?['name_with_brand'] as String?)
|
modelDisplayName: (map[Tables.models]?['name_with_brand'] as String?)
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flux/core/routes/routes.dart';
|
import 'package:flux/core/routes/routes.dart';
|
||||||
|
import 'package:flux/core/widgets/staff_selector_modal.dart';
|
||||||
|
import 'package:flux/features/master_data/staff/models/staff_member_model.dart';
|
||||||
import 'package:flux/features/operations/blocs/operation_list_cubit.dart';
|
import 'package:flux/features/operations/blocs/operation_list_cubit.dart';
|
||||||
import 'package:flux/features/operations/models/operation_model.dart';
|
import 'package:flux/features/operations/models/operation_model.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@@ -14,20 +16,39 @@ class OperationListScreen extends StatefulWidget {
|
|||||||
|
|
||||||
class _OperationListScreenState extends State<OperationListScreen> {
|
class _OperationListScreenState extends State<OperationListScreen> {
|
||||||
final ScrollController _scrollController = ScrollController();
|
final ScrollController _scrollController = ScrollController();
|
||||||
|
final TextEditingController _searchController = TextEditingController();
|
||||||
|
|
||||||
// 🥷 1. LO STATO PER LE BULK ACTIONS
|
// Set per gestire le Bulk Actions (Selezione multipla)
|
||||||
final Set<String> _selectedOperationIds = {};
|
final Set<String> _selectedOperationIds = {};
|
||||||
bool get _isSelectionMode => _selectedOperationIds.isNotEmpty;
|
bool get _isSelectionMode => _selectedOperationIds.isNotEmpty;
|
||||||
|
|
||||||
|
// Flag per mostrare/nascondere la barra di ricerca integrata nell'AppBar
|
||||||
|
bool _showSearchBar = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_scrollController.addListener(_onScroll);
|
_scrollController.addListener(_onScroll);
|
||||||
|
|
||||||
|
// Primo caricamento: partiamo da pagina 1
|
||||||
|
// (Il Cubit deciderà se fare il boot iniziale o se c'era già roba in cache)
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
final isDesktop = MediaQuery.sizeOf(context).width >= 900;
|
||||||
|
if (isDesktop) {
|
||||||
|
context.read<OperationListCubit>().loadSpecificPageDesktop(1);
|
||||||
|
} else {
|
||||||
|
context.read<OperationListCubit>().loadNextPageMobile(refresh: true);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onScroll() {
|
void _onScroll() {
|
||||||
|
final isDesktop = MediaQuery.sizeOf(context).width >= 900;
|
||||||
|
// 🥷 COMPORTAMENTO IBRIDO: Lo scroll infinito si attiva SOLO su mobile
|
||||||
|
if (isDesktop) return;
|
||||||
|
|
||||||
if (_isBottom) {
|
if (_isBottom) {
|
||||||
context.read<OperationListCubit>().loadOperations();
|
context.read<OperationListCubit>().loadNextPageMobile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +62,7 @@ class _OperationListScreenState extends State<OperationListScreen> {
|
|||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
_scrollController.dispose();
|
_scrollController.dispose();
|
||||||
|
_searchController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +84,10 @@ class _OperationListScreenState extends State<OperationListScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final isDesktop = MediaQuery.sizeOf(context).width >= 900;
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
// 🥷 2. APPBAR DINAMICA (Standard o Modalità Selezione)
|
// --- APP BAR DINAMICA E INTEGRATA ---
|
||||||
appBar: _isSelectionMode
|
appBar: _isSelectionMode
|
||||||
? AppBar(
|
? AppBar(
|
||||||
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
backgroundColor: Theme.of(context).colorScheme.primaryContainer,
|
||||||
@@ -77,24 +101,53 @@ class _OperationListScreenState extends State<OperationListScreen> {
|
|||||||
icon: const Icon(Icons.edit_note),
|
icon: const Icon(Icons.edit_note),
|
||||||
tooltip: 'Cambia Stato Massivo',
|
tooltip: 'Cambia Stato Massivo',
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// TODO: Apri BottomSheet per cambiare stato a tutte le selezionate
|
// TODO: Integrare bottom sheet per azioni massive
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
: AppBar(
|
: AppBar(
|
||||||
title: const Text("Gestione Servizi"),
|
title: _showSearchBar
|
||||||
|
? TextField(
|
||||||
|
controller: _searchController,
|
||||||
|
autofocus: true,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Cerca per cliente, nota o riferimento...',
|
||||||
|
border: InputBorder.none,
|
||||||
|
),
|
||||||
|
style: const TextStyle(fontSize: 16),
|
||||||
|
onChanged: (text) {
|
||||||
|
context.read<OperationListCubit>().updateFilters(
|
||||||
|
text: text,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
: const Text("Gestione Servizi"),
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
IconButton(
|
||||||
icon: const Icon(Icons.filter_list),
|
icon: Icon(_showSearchBar ? Icons.close : Icons.search),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
// TODO: Apri drawer laterale o modal per i filtri avanzati
|
setState(() {
|
||||||
|
_showSearchBar = !_showSearchBar;
|
||||||
|
if (!_showSearchBar) {
|
||||||
|
_searchController.clear();
|
||||||
|
context.read<OperationListCubit>().clearFilters();
|
||||||
|
}
|
||||||
|
});
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
IconButton(icon: const Icon(Icons.search), onPressed: () {}),
|
if (!isDesktop) // Il pull-to-refresh c'è già su mobile, su desktop mettiamo un tasto manuale
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.filter_list),
|
||||||
|
onPressed: () {
|
||||||
|
// TODO: Bottone Filtri Avanzati (es. DateRange Picker)
|
||||||
|
},
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// --- CORPO RESPONSIVO ---
|
||||||
body: BlocBuilder<OperationListCubit, OperationListState>(
|
body: BlocBuilder<OperationListCubit, OperationListState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
if (state.status == OperationListStatus.loading &&
|
if (state.status == OperationListStatus.loading &&
|
||||||
@@ -103,83 +156,216 @@ class _OperationListScreenState extends State<OperationListScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (state.operations.isEmpty) {
|
if (state.operations.isEmpty) {
|
||||||
return const Center(child: Text("Nessuna pratica trovata."));
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Text("Nessuna pratica trovata."),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
ElevatedButton(
|
||||||
|
onPressed: () => isDesktop
|
||||||
|
? context
|
||||||
|
.read<OperationListCubit>()
|
||||||
|
.loadSpecificPageDesktop(1)
|
||||||
|
: context.read<OperationListCubit>().loadNextPageMobile(
|
||||||
|
refresh: true,
|
||||||
|
),
|
||||||
|
child: const Text("Ricarica"),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🥷 3. IL MOTORE RESPONSIVO
|
// 🥷 SCENARIO DESKTOP: Griglia + Barra di Paginazione Gmail-Style
|
||||||
return RefreshIndicator(
|
if (isDesktop) {
|
||||||
onRefresh: () => context.read<OperationListCubit>().loadOperations(
|
return Column(
|
||||||
refresh: true,
|
children: [
|
||||||
),
|
Expanded(
|
||||||
child: LayoutBuilder(
|
child: GridView.builder(
|
||||||
builder: (context, constraints) {
|
controller: _scrollController,
|
||||||
// Se lo schermo è largo (Desktop/Tablet), usiamo la griglia
|
padding: const EdgeInsets.all(16),
|
||||||
final isDesktop = constraints.maxWidth > 700;
|
gridDelegate: const SliverGridDelegateWithMaxCrossAxisExtent(
|
||||||
|
maxCrossAxisExtent:
|
||||||
return GridView.builder(
|
420, // Larghezza bilanciata per le card su desktop
|
||||||
controller: _scrollController,
|
mainAxisExtent:
|
||||||
padding: const EdgeInsets.all(12).copyWith(bottom: 80),
|
175, // Altezza controllata per evitare buchi bianchi
|
||||||
// Magia della griglia: si adatta!
|
crossAxisSpacing: 16,
|
||||||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
|
mainAxisSpacing: 16,
|
||||||
maxCrossAxisExtent:
|
),
|
||||||
450, // Larghezza massima della singola card
|
itemCount: state.operations.length,
|
||||||
mainAxisExtent:
|
itemBuilder: (context, index) {
|
||||||
180, // Altezza fissa della card (da aggiustare in base ai tuoi font)
|
final operation = state.operations[index];
|
||||||
crossAxisSpacing: 12,
|
return _buildResponsiveCard(operation);
|
||||||
mainAxisSpacing: 12,
|
},
|
||||||
),
|
),
|
||||||
itemCount: state.hasReachedMax
|
),
|
||||||
? state.operations.length
|
_buildDesktopPaginationFooter(
|
||||||
: state.operations.length + 1,
|
state,
|
||||||
itemBuilder: (context, index) {
|
), // La barra in fondo stile Gmail
|
||||||
if (index >= state.operations.length) {
|
],
|
||||||
return const Center(
|
);
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
}
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final operation = state.operations[index];
|
// 🥷 SCENARIO MOBILE: ListView con Infinite Scroll e Pull-to-Refresh
|
||||||
final isSelected = _selectedOperationIds.contains(
|
return RefreshIndicator(
|
||||||
operation.id,
|
onRefresh: () => context
|
||||||
);
|
.read<OperationListCubit>()
|
||||||
|
.loadNextPageMobile(refresh: true),
|
||||||
|
child: ListView.builder(
|
||||||
|
controller: _scrollController,
|
||||||
|
padding: const EdgeInsets.only(
|
||||||
|
bottom: 80,
|
||||||
|
left: 8,
|
||||||
|
right: 8,
|
||||||
|
top: 8,
|
||||||
|
),
|
||||||
|
itemCount: state.hasReachedMax
|
||||||
|
? state.operations.length
|
||||||
|
: state.operations.length + 1,
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
if (index >= state.operations.length) {
|
||||||
|
return const Center(
|
||||||
|
child: Padding(
|
||||||
|
padding: EdgeInsets.all(16.0),
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return _RichOperationCard(
|
final operation = state.operations[index];
|
||||||
operation: operation,
|
return Padding(
|
||||||
isSelected: isSelected,
|
padding: const EdgeInsets.symmetric(vertical: 4.0),
|
||||||
isSelectionMode: _isSelectionMode,
|
child: _buildResponsiveCard(operation),
|
||||||
onTap: () {
|
|
||||||
if (_isSelectionMode) {
|
|
||||||
_toggleSelection(operation.id!);
|
|
||||||
} else {
|
|
||||||
context.pushNamed(
|
|
||||||
Routes.operationForm,
|
|
||||||
extra: (createdBy: null, operation: operation),
|
|
||||||
pathParameters: {'id': operation.id!},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onLongPress: () => _toggleSelection(operation.id!),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
||||||
floatingActionButton: _isSelectionMode
|
floatingActionButton: _isSelectionMode
|
||||||
? null // Nascondi il FAB se stai selezionando
|
? null
|
||||||
: FloatingActionButton(
|
: FloatingActionButton(
|
||||||
onPressed: () {
|
onPressed: () async {
|
||||||
/* Tuo codice per nuova operazione */
|
StaffMemberModel? createdBy = await getStaffMember(context);
|
||||||
|
if (createdBy == null || !context.mounted) return;
|
||||||
|
context.pushNamed(
|
||||||
|
Routes.operationForm,
|
||||||
|
pathParameters: {'id': 'new'},
|
||||||
|
extra: (createdBy: createdBy, operation: null),
|
||||||
|
);
|
||||||
},
|
},
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- COSTRUZIONE DELLA COMPONENTISTICA DETTAGLIATA ---
|
||||||
|
|
||||||
|
Widget _buildResponsiveCard(OperationModel operation) {
|
||||||
|
final isSelected = _selectedOperationIds.contains(operation.id);
|
||||||
|
return _RichOperationCard(
|
||||||
|
operation: operation,
|
||||||
|
isSelected: isSelected,
|
||||||
|
isSelectionMode: _isSelectionMode,
|
||||||
|
onTap: () {
|
||||||
|
if (_isSelectionMode) {
|
||||||
|
_toggleSelection(operation.id!);
|
||||||
|
} else {
|
||||||
|
context.pushNamed(
|
||||||
|
Routes.operationForm,
|
||||||
|
extra: (createdBy: null, operation: operation),
|
||||||
|
pathParameters: {'id': operation.id!},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onLongPress: () => _toggleSelection(operation.id!),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 🥷 LA BARRA DI PAGINAZIONE DESKTOP (Stile Gmail / Typesense)
|
||||||
|
Widget _buildDesktopPaginationFooter(OperationListState state) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final cubit = context.read<OperationListCubit>();
|
||||||
|
|
||||||
|
// Calcolo intervallo visualizzato (es. 1-25 di 140)
|
||||||
|
final fromItem = ((state.currentPage - 1) * state.itemsPerPage) + 1;
|
||||||
|
final toItem =
|
||||||
|
DateUtils.isSameDay(DateTime.now(), DateTime.now()) // segnaposto logico
|
||||||
|
? (fromItem + state.operations.length - 1)
|
||||||
|
: fromItem;
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
height: 56,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.surface,
|
||||||
|
border: Border(top: BorderSide(color: theme.dividerColor, width: 0.5)),
|
||||||
|
),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
|
children: [
|
||||||
|
// Info totali a sinistra
|
||||||
|
Text(
|
||||||
|
"$fromItem-$toItem di ${state.totalItems} pratiche totali",
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: Colors.grey[700],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Controlli di navigazione a destra
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
// Prima Pagina
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.first_page),
|
||||||
|
onPressed: state.currentPage > 1
|
||||||
|
? () => cubit.loadSpecificPageDesktop(1)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
// Pagina Precedente
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.chevron_left),
|
||||||
|
onPressed: state.currentPage > 1
|
||||||
|
? () => cubit.loadSpecificPageDesktop(state.currentPage - 1)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
|
||||||
|
// Indicatore numerico centrale impacchettato
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
||||||
|
child: Text(
|
||||||
|
"Pagina ${state.currentPage} di ${state.totalPages}",
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Pagina Successiva
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.chevron_right),
|
||||||
|
onPressed: state.currentPage < state.totalPages
|
||||||
|
? () => cubit.loadSpecificPageDesktop(state.currentPage + 1)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
// Ultima Pagina
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.last_page),
|
||||||
|
onPressed: state.currentPage < state.totalPages
|
||||||
|
? () => cubit.loadSpecificPageDesktop(state.totalPages)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🥷 4. LA SUPER CARD ESTRATTA
|
// =========================================================================
|
||||||
|
// 🥷 3. LA CARD RICCA, REATTIVA E DEFINITIVA (Quella revisionata insieme)
|
||||||
|
// =========================================================================
|
||||||
class _RichOperationCard extends StatelessWidget {
|
class _RichOperationCard extends StatelessWidget {
|
||||||
final OperationModel operation;
|
final OperationModel operation;
|
||||||
final bool isSelected;
|
final bool isSelected;
|
||||||
@@ -195,7 +381,6 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
required this.onLongPress,
|
required this.onLongPress,
|
||||||
});
|
});
|
||||||
|
|
||||||
// 🥷 1. IL COLORE DELLO STATO: Centralizzato per usarlo ovunque
|
|
||||||
Color _getStatusColor(OperationStatus status) {
|
Color _getStatusColor(OperationStatus status) {
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case OperationStatus.success:
|
case OperationStatus.success:
|
||||||
@@ -206,11 +391,10 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
case OperationStatus.waitingForSupport:
|
case OperationStatus.waitingForSupport:
|
||||||
return Colors.blue;
|
return Colors.blue;
|
||||||
case OperationStatus.failure:
|
case OperationStatus.failure:
|
||||||
return Colors.grey.shade800; // O Colors.red se preferisci
|
return Colors.grey.shade800;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 🥷 2. IL COLORE DEL TIPO: Per farlo risaltare
|
|
||||||
Color _getTypeColor(String type) {
|
Color _getTypeColor(String type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'FIN':
|
case 'FIN':
|
||||||
@@ -239,6 +423,7 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
final typeColor = _getTypeColor(operation.type);
|
final typeColor = _getTypeColor(operation.type);
|
||||||
|
|
||||||
return Card(
|
return Card(
|
||||||
|
margin: EdgeInsets.zero, // Gestito dai margini dei padri (griglia/lista)
|
||||||
elevation: isSelected ? 4 : 1,
|
elevation: isSelected ? 4 : 1,
|
||||||
shape: RoundedRectangleBorder(
|
shape: RoundedRectangleBorder(
|
||||||
borderRadius: BorderRadius.circular(12),
|
borderRadius: BorderRadius.circular(12),
|
||||||
@@ -256,32 +441,35 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: isSelected
|
color: isSelected
|
||||||
? theme.colorScheme.primaryContainer.withValues(alpha: 0.2)
|
? theme.colorScheme.primaryContainer.withValues(alpha: 0.15)
|
||||||
: null,
|
: null,
|
||||||
// BANDA LATERALE LEGATA ALLO STATO (Stilosissima)
|
// 🥷 COERENZA 100%: Banda laterale legata allo status per eliminare i malintesi cromatici
|
||||||
border: Border(left: BorderSide(color: statusColor, width: 6)),
|
border: Border(left: BorderSide(color: statusColor, width: 6)),
|
||||||
),
|
),
|
||||||
padding: const EdgeInsets.all(12),
|
padding: const EdgeInsets.all(12),
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
// --- HEADER ---
|
// --- LINEA HEADER ---
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
if (isSelectionMode)
|
if (isSelectionMode)
|
||||||
SizedBox(
|
Padding(
|
||||||
height: 24,
|
padding: const EdgeInsets.only(right: 8.0),
|
||||||
width: 24,
|
child: SizedBox(
|
||||||
child: Checkbox(
|
height: 18,
|
||||||
value: isSelected,
|
width: 18,
|
||||||
onChanged: (_) => onTap(),
|
child: Checkbox(
|
||||||
|
value: isSelected,
|
||||||
|
onChanged: (_) => onTap(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Text(
|
child: Text(
|
||||||
operation.reference.isEmpty
|
(operation.reference.isEmpty)
|
||||||
? 'Nessuna Riferimento'
|
? 'Senza Riferimento'
|
||||||
: operation.reference,
|
: operation.reference,
|
||||||
style: theme.textTheme.labelSmall?.copyWith(
|
style: theme.textTheme.labelSmall?.copyWith(
|
||||||
color: Colors.grey[600],
|
color: Colors.grey[600],
|
||||||
@@ -291,7 +479,9 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
"${operation.createdAt?.day.toString().padLeft(2, '0')}/${operation.createdAt?.month.toString().padLeft(2, '0')}/${operation.createdAt?.year}",
|
operation.createdAt != null
|
||||||
|
? "${operation.createdAt!.day.toString().padLeft(2, '0')}/${operation.createdAt!.month.toString().padLeft(2, '0')}/${operation.createdAt!.year}"
|
||||||
|
: '',
|
||||||
style: theme.textTheme.labelSmall?.copyWith(
|
style: theme.textTheme.labelSmall?.copyWith(
|
||||||
color: Colors.grey[600],
|
color: Colors.grey[600],
|
||||||
),
|
),
|
||||||
@@ -300,7 +490,7 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
|
|
||||||
// --- CLIENTE E TIPO OPERAZIONE ---
|
// --- LINEA CENTRALE: CLIENTE + INSERTO OPERATIVO ---
|
||||||
Row(
|
Row(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
@@ -309,24 +499,25 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
operation.customer?.name ?? "Cliente sconosciuto",
|
operation.customer?.name ?? "Cliente sconosciuto",
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 16,
|
fontSize: 15,
|
||||||
),
|
),
|
||||||
maxLines: 2,
|
maxLines: 2,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
// IL TIPO DI OPERAZIONE CHE SPICCA
|
|
||||||
|
// 🥷 IL RE DEL SERVICE: Il tipo operazione svetta con box e contrasto ad hoc
|
||||||
Container(
|
Container(
|
||||||
padding: const EdgeInsets.symmetric(
|
padding: const EdgeInsets.symmetric(
|
||||||
horizontal: 10,
|
horizontal: 8,
|
||||||
vertical: 6,
|
vertical: 4,
|
||||||
),
|
),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: typeColor.withValues(alpha: 0.15),
|
color: typeColor.withValues(alpha: 0.12),
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(6),
|
||||||
border: Border.all(
|
border: Border.all(
|
||||||
color: typeColor.withValues(alpha: 0.3),
|
color: typeColor.withValues(alpha: 0.25),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
@@ -342,19 +533,20 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
operation.type,
|
operation.type,
|
||||||
operation.subType,
|
operation.subType,
|
||||||
),
|
),
|
||||||
size: 14,
|
size: 13,
|
||||||
color: typeColor,
|
color: typeColor,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
],
|
],
|
||||||
Text(
|
Text(
|
||||||
operation.subType?.isNotEmpty == true
|
(operation.subType != null &&
|
||||||
|
operation.subType!.isNotEmpty)
|
||||||
? operation.subType!
|
? operation.subType!
|
||||||
: operation.type,
|
: operation.type,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: typeColor,
|
color: typeColor,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
fontSize: 12,
|
fontSize: 11,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -362,14 +554,14 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 10),
|
||||||
|
|
||||||
// --- I TAG COMPATTI (Business/Privato, Provider, Device) ---
|
// --- LINEA DEI TAG TECNICI ---
|
||||||
Wrap(
|
Wrap(
|
||||||
spacing: 6,
|
spacing: 6,
|
||||||
runSpacing: 6,
|
runSpacing: 4,
|
||||||
children: [
|
children: [
|
||||||
// Espanso in "Business" e "Privato"
|
// Tag Target Espanso (Privato / Business)
|
||||||
_MiniChip(
|
_MiniChip(
|
||||||
label: operation.isBusiness ? 'Business' : 'Privato',
|
label: operation.isBusiness ? 'Business' : 'Privato',
|
||||||
icon: operation.isBusiness
|
icon: operation.isBusiness
|
||||||
@@ -378,17 +570,18 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
color: operation.isBusiness ? Colors.indigo : Colors.teal,
|
color: operation.isBusiness ? Colors.indigo : Colors.teal,
|
||||||
),
|
),
|
||||||
|
|
||||||
// Tag Provider con il suo colore personalizzato dal DB
|
// Tag Gestore (Agganciato dinamicamente al displayColor generato dall'esadecimale del DB!)
|
||||||
if (operation.providerId != null)
|
if (operation.providerId != null)
|
||||||
_MiniChip(
|
_MiniChip(
|
||||||
label: operation.providerDisplayName ?? 'Gestore',
|
label: operation.provider?.name ?? 'Gestore',
|
||||||
// Se hai popolato il campo colorHex, qui puoi usare: operation.provider?.displayColor ?? Colors.grey
|
color:
|
||||||
color: Colors.redAccent,
|
operation.provider?.displayColor ?? Colors.blueGrey,
|
||||||
),
|
),
|
||||||
|
|
||||||
|
// Specifiche addizionali del Finanziamento
|
||||||
if (operation.type == 'Fin' && operation.modelId != null)
|
if (operation.type == 'Fin' && operation.modelId != null)
|
||||||
_MiniChip(
|
_MiniChip(
|
||||||
label: operation.modelDisplayName ?? 'Modello',
|
label: operation.modelDisplayName ?? 'Prodotto',
|
||||||
icon: Icons.devices,
|
icon: Icons.devices,
|
||||||
color: Colors.deepPurple,
|
color: Colors.deepPurple,
|
||||||
),
|
),
|
||||||
@@ -397,7 +590,7 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
|
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
|
|
||||||
// --- FOOTER: Staff e Stato ---
|
// --- FOOTER CARD: AGENTE + CHIP STATO ---
|
||||||
Row(
|
Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||||
children: [
|
children: [
|
||||||
@@ -410,14 +603,31 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
Text(
|
Text(
|
||||||
operation.staffDisplayName ?? 'Staff',
|
operation.staffDisplayName ?? 'Assegnato',
|
||||||
style: theme.textTheme.labelSmall?.copyWith(
|
style: theme.textTheme.labelSmall?.copyWith(
|
||||||
color: Colors.grey[700],
|
color: Colors.grey[700],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
_buildOperationStatus(operation.status, statusColor),
|
Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 8,
|
||||||
|
vertical: 4,
|
||||||
|
),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: statusColor,
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
operation.status.displayName,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 10,
|
||||||
|
color: Colors.white,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -435,26 +645,9 @@ class _RichOperationCard extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildOperationStatus(OperationStatus status, Color statusColor) {
|
|
||||||
return Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: statusColor,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
),
|
|
||||||
child: Text(
|
|
||||||
status.displayName,
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 10,
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Micro Widget di supporto per i tag interni
|
||||||
class _MiniChip extends StatelessWidget {
|
class _MiniChip extends StatelessWidget {
|
||||||
final String label;
|
final String label;
|
||||||
final IconData? icon;
|
final IconData? icon;
|
||||||
@@ -465,23 +658,23 @@ class _MiniChip extends StatelessWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Container(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 4),
|
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 3),
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: color.withValues(alpha: 0.1),
|
color: color.withValues(alpha: 0.08),
|
||||||
border: Border.all(color: color.withValues(alpha: 0.3)),
|
border: Border.all(color: color.withValues(alpha: 0.25)),
|
||||||
borderRadius: BorderRadius.circular(6),
|
borderRadius: BorderRadius.circular(4),
|
||||||
),
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
if (icon != null) ...[
|
if (icon != null) ...[
|
||||||
Icon(icon, size: 12, color: color),
|
Icon(icon, size: 11, color: color),
|
||||||
const SizedBox(width: 4),
|
const SizedBox(width: 4),
|
||||||
],
|
],
|
||||||
Text(
|
Text(
|
||||||
label,
|
label,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 11,
|
fontSize: 10,
|
||||||
color: color,
|
color: color,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -102,10 +102,9 @@ class OperationDetailsSection extends StatelessWidget {
|
|||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
context.read<OperationFormCubit>().updateFields(
|
context
|
||||||
providerId: provider.id,
|
.read<OperationFormCubit>()
|
||||||
providerDisplayName: provider.name,
|
.updateProvider(provider);
|
||||||
);
|
|
||||||
Navigator.pop(modalContext);
|
Navigator.pop(modalContext);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@@ -134,9 +133,8 @@ class OperationDetailsSection extends StatelessWidget {
|
|||||||
ListTile(
|
ListTile(
|
||||||
title: const Text('Seleziona Gestore'),
|
title: const Text('Seleziona Gestore'),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
(currentOp?.providerDisplayName != null &&
|
(currentOp?.provider != null)
|
||||||
currentOp!.providerDisplayName!.isNotEmpty)
|
? currentOp!.provider!.name
|
||||||
? currentOp!.providerDisplayName!
|
|
||||||
: 'Nessun gestore selezionato',
|
: 'Nessun gestore selezionato',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color:
|
color:
|
||||||
|
|||||||
Reference in New Issue
Block a user