@@ -31,6 +31,10 @@ class OperationFilesBloc
|
||||
on<DeleteOperationFilesEvent>(_onDeleteOperationFiles);
|
||||
on<ToggleOperationFileSelectionEvent>(_onToggleOperationFileSelection);
|
||||
on<LinkFilesToCustomerEvent>(_onLinkFilesToCustomer);
|
||||
on<RenameOperationFileEvent>(_onRenameOperationFile);
|
||||
on<DeleteSpecificOperationFileEvent>(_onDeleteSpecificOperationFiles);
|
||||
on<SelectAllOperationFilesEvent>(_onSelectAllOperationFiles);
|
||||
on<ClearOperationFileSelectionEvent>(_onClearOperationFileSelection);
|
||||
|
||||
// Se il BLoC nasce con un ID, accendiamo subito lo stream!
|
||||
if (operationId != null) {
|
||||
@@ -266,6 +270,22 @@ class OperationFilesBloc
|
||||
emit(state.copyWith(selectedFiles: selectedFiles));
|
||||
}
|
||||
|
||||
void _onSelectAllOperationFiles(
|
||||
SelectAllOperationFilesEvent event,
|
||||
Emitter<OperationFilesState> emit,
|
||||
) {
|
||||
// Prendiamo TUTTI i file (locali e remoti) e li buttiamo nei selezionati
|
||||
emit(state.copyWith(selectedFiles: state.allFiles));
|
||||
}
|
||||
|
||||
void _onClearOperationFileSelection(
|
||||
ClearOperationFileSelectionEvent event,
|
||||
Emitter<OperationFilesState> emit,
|
||||
) {
|
||||
// Svuotiamo brutalmente la lista
|
||||
emit(state.copyWith(selectedFiles: []));
|
||||
}
|
||||
|
||||
FutureOr<void> _onLinkFilesToCustomer(
|
||||
LinkFilesToCustomerEvent event,
|
||||
Emitter<OperationFilesState> emit,
|
||||
@@ -323,4 +343,47 @@ class OperationFilesBloc
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onRenameOperationFile(
|
||||
RenameOperationFileEvent event,
|
||||
Emitter<OperationFilesState> emit,
|
||||
) async {
|
||||
// BIVIO 1: File Locale (Bozza)
|
||||
if (event.file.localBytes != null) {
|
||||
final updatedLocalFiles = state.localFiles.map((f) {
|
||||
if (f == event.file) {
|
||||
return f.copyWith(name: event.newName);
|
||||
}
|
||||
return f;
|
||||
}).toList();
|
||||
emit(state.copyWith(localFiles: updatedLocalFiles));
|
||||
return;
|
||||
}
|
||||
|
||||
// BIVIO 2: File Remoto (Salvato su DB)
|
||||
emit(state.copyWith(status: OperationFilesStatus.loading));
|
||||
try {
|
||||
await _repository.renameAttachment(event.file.id!, event.newName);
|
||||
emit(state.copyWith(status: OperationFilesStatus.success));
|
||||
} catch (e) {
|
||||
emit(
|
||||
state.copyWith(
|
||||
status: OperationFilesStatus.failure,
|
||||
error: "Errore rinomina: $e",
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
FutureOr<void> _onDeleteSpecificOperationFiles(
|
||||
DeleteSpecificOperationFileEvent event,
|
||||
Emitter<OperationFilesState> emit,
|
||||
) {
|
||||
if (event.file.localBytes != null) {
|
||||
final updatedLocalFiles = state.localFiles
|
||||
.where((f) => f != event.file)
|
||||
.toList();
|
||||
emit(state.copyWith(localFiles: updatedLocalFiles));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,3 +56,26 @@ class ToggleOperationFileSelectionEvent extends OperationFilesEvent {
|
||||
final AttachmentModel file;
|
||||
const ToggleOperationFileSelectionEvent(this.file);
|
||||
}
|
||||
|
||||
class RenameOperationFileEvent extends OperationFilesEvent {
|
||||
final AttachmentModel file;
|
||||
final String newName;
|
||||
|
||||
const RenameOperationFileEvent(this.file, this.newName);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [file, newName];
|
||||
}
|
||||
|
||||
class DeleteSpecificOperationFileEvent extends OperationFilesEvent {
|
||||
final AttachmentModel file;
|
||||
|
||||
const DeleteSpecificOperationFileEvent(this.file);
|
||||
|
||||
@override
|
||||
List<Object?> get props => [file];
|
||||
}
|
||||
|
||||
class SelectAllOperationFilesEvent extends OperationFilesEvent {}
|
||||
|
||||
class ClearOperationFileSelectionEvent extends OperationFilesEvent {}
|
||||
|
||||
@@ -217,6 +217,7 @@ class OperationsCubit extends Cubit<OperationsState> {
|
||||
String? providerId,
|
||||
String? providerDisplayName,
|
||||
String? subtype,
|
||||
String? description,
|
||||
DateTime? expirationDate,
|
||||
int? quantity,
|
||||
String? modelId,
|
||||
@@ -227,6 +228,7 @@ class OperationsCubit extends Cubit<OperationsState> {
|
||||
bool clearProvider = false,
|
||||
bool clearType = false,
|
||||
bool clearSubtype = false,
|
||||
bool clearDescription = false,
|
||||
bool clearExpiration = false,
|
||||
bool clearQuantity = false,
|
||||
bool clearModel = false,
|
||||
@@ -258,6 +260,9 @@ class OperationsCubit extends Cubit<OperationsState> {
|
||||
: (providerDisplayName ?? current.providerDisplayName),
|
||||
quantity: newQuantity,
|
||||
type: clearType ? null : (type ?? current.type),
|
||||
description: clearDescription
|
||||
? null
|
||||
: (description ?? current.description),
|
||||
subtype: clearSubtype ? null : (subtype ?? current.subtype),
|
||||
expirationDate: clearExpiration
|
||||
? null
|
||||
|
||||
Reference in New Issue
Block a user