a
This commit is contained in:
1 parent
c6a1b203ce
commit
c6e3594850
5 files changed
+131
-50
No files matched your search
@@ -0,0 +1,4 @@
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flux/features/operations/models/operation_detail_model.dart';
|
||||
|
||||
part 'operation_details_form_state.dart';
|
||||
@@ -0,0 +1,30 @@
|
||||
part of 'operation_details_form_cubit.dart';
|
||||
|
||||
enum OperationDetailsFormStatus { ready, updated, failure }
|
||||
|
||||
class OperationDetailsFormState extends Equatable {
|
||||
final OperationDetailModel operationDetail;
|
||||
final String? errorMessage;
|
||||
final OperationDetailsFormStatus status;
|
||||
|
||||
const OperationDetailsFormState({
|
||||
required this.operationDetail,
|
||||
this.errorMessage,
|
||||
this.status = OperationDetailsFormStatus.ready,
|
||||
});
|
||||
|
||||
OperationDetailsFormState copyWith({
|
||||
OperationDetailModel? operationDetail,
|
||||
String? errorMessage,
|
||||
OperationDetailsFormStatus? status,
|
||||
}) {
|
||||
return OperationDetailsFormState(
|
||||
operationDetail: operationDetail ?? this.operationDetail,
|
||||
errorMessage: errorMessage ?? this.errorMessage,
|
||||
status: status ?? this.status,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [operationDetail, errorMessage, status];
|
||||
}
|
||||
@@ -7,4 +7,91 @@ part 'operation_details_list_state.dart';
|
||||
class OperationDetailsListCubit extends Cubit<OperationDetailsListState> {
|
||||
OperationDetailsListCubit({required List<OperationDetailModel> details})
|
||||
: super(OperationDetailsListState(details: details));
|
||||
|
||||
void addOperationDetail(OperationDetailModel operationDetail) {
|
||||
emit(state.copyWith(status: OperationDetailsListStatus.ready));
|
||||
final updatedDetails = List<OperationDetailModel>.from(state.details);
|
||||
updatedDetails.add(operationDetail);
|
||||
emit(
|
||||
OperationDetailsListState(
|
||||
details: updatedDetails,
|
||||
status: OperationDetailsListStatus.updated,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void deleteOperationDetail(int index) {
|
||||
emit(state.copyWith(status: OperationDetailsListStatus.ready));
|
||||
final updatedDetails = List<OperationDetailModel>.from(state.details);
|
||||
updatedDetails.removeAt(index);
|
||||
emit(
|
||||
OperationDetailsListState(
|
||||
details: updatedDetails,
|
||||
status: OperationDetailsListStatus.updated,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void toggleOperationDetailsSelection(int index) {
|
||||
final updatedSelectedIds = List<int>.from(state.selectedIds);
|
||||
if (updatedSelectedIds.contains(index)) {
|
||||
updatedSelectedIds.remove(index);
|
||||
} else {
|
||||
updatedSelectedIds.add(index);
|
||||
}
|
||||
emit(
|
||||
OperationDetailsListState(
|
||||
details: state.details,
|
||||
selectedIds: updatedSelectedIds,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void selectAllOperationDetails() {
|
||||
final updatedSelectedIds = List<int>.from(state.selectedIds);
|
||||
for (int i = 0; i < state.details.length; i++) {
|
||||
if (!updatedSelectedIds.contains(i)) {
|
||||
updatedSelectedIds.add(i);
|
||||
}
|
||||
}
|
||||
emit(
|
||||
OperationDetailsListState(
|
||||
details: state.details,
|
||||
selectedIds: updatedSelectedIds,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void clearOperationDetailsSelection() {
|
||||
emit(OperationDetailsListState(details: state.details, selectedIds: []));
|
||||
}
|
||||
|
||||
void deleteSelectedOperationDetails() {
|
||||
emit(state.copyWith(status: OperationDetailsListStatus.ready));
|
||||
final updatedDetails = List<OperationDetailModel>.from(state.details);
|
||||
final updatedSelectedIds = List<int>.from(state.selectedIds);
|
||||
for (int i = updatedSelectedIds.length - 1; i >= 0; i--) {
|
||||
final index = updatedSelectedIds[i];
|
||||
updatedDetails.removeAt(index);
|
||||
}
|
||||
emit(
|
||||
OperationDetailsListState(
|
||||
details: updatedDetails,
|
||||
selectedIds: [],
|
||||
status: OperationDetailsListStatus.updated,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void updateOperationDetail(int index, OperationDetailModel operationDetail) {
|
||||
emit(state.copyWith(status: OperationDetailsListStatus.ready));
|
||||
final updatedDetails = List<OperationDetailModel>.from(state.details);
|
||||
updatedDetails[index] = operationDetail;
|
||||
emit(
|
||||
OperationDetailsListState(
|
||||
details: updatedDetails,
|
||||
status: OperationDetailsListStatus.updated,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +1,34 @@
|
||||
part of 'operation_details_list_cubit.dart';
|
||||
|
||||
enum OperationDetailsListStatus {
|
||||
initial,
|
||||
loading,
|
||||
ready,
|
||||
saving,
|
||||
success,
|
||||
failure,
|
||||
}
|
||||
enum OperationDetailsListStatus { ready, updated, failure }
|
||||
|
||||
class OperationDetailsListState extends Equatable {
|
||||
final OperationDetailsListStatus status;
|
||||
final List<OperationDetailModel> details;
|
||||
final String? errorMessage;
|
||||
final List<int> selectedIds;
|
||||
final OperationDetailsListStatus status;
|
||||
|
||||
const OperationDetailsListState({
|
||||
this.status = OperationDetailsListStatus.initial,
|
||||
this.details = const [],
|
||||
this.errorMessage,
|
||||
this.selectedIds = const [],
|
||||
this.status = OperationDetailsListStatus.ready,
|
||||
});
|
||||
|
||||
OperationDetailsListState copyWith({
|
||||
OperationDetailsListStatus? status,
|
||||
List<OperationDetailModel>? details,
|
||||
String? errorMessage,
|
||||
List<int>? selectedIds,
|
||||
OperationDetailsListStatus? status,
|
||||
}) {
|
||||
return OperationDetailsListState(
|
||||
status: status ?? this.status,
|
||||
details: details ?? this.details,
|
||||
errorMessage: errorMessage,
|
||||
selectedIds: selectedIds ?? this.selectedIds,
|
||||
status: status ?? this.status,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
List<Object?> get props => [status, details, errorMessage];
|
||||
List<Object?> get props => [details, errorMessage, selectedIds, status];
|
||||
}
|
||||
@@ -126,55 +126,18 @@ class OperationFormCubit extends Cubit<OperationFormState> {
|
||||
}
|
||||
|
||||
// --- GESTIONE DEI CAMPI IN TEMPO REALE ---
|
||||
|
||||
void updateDetails
|
||||
|
||||
void updateFields({
|
||||
String? reference,
|
||||
String? note,
|
||||
String? type,
|
||||
String? subType,
|
||||
String? description,
|
||||
DateTime? expirationDate,
|
||||
int? quantity,
|
||||
String? modelId,
|
||||
String? modelDisplayName,
|
||||
String? staffId,
|
||||
String? staffDisplayName,
|
||||
OperationStatus? status,
|
||||
bool? isBusiness,
|
||||
|
||||
bool clearProvider = false,
|
||||
bool clearType = false,
|
||||
bool clearSubType = false,
|
||||
bool clearDescription = false,
|
||||
bool clearExpiration = false,
|
||||
bool clearQuantity = false,
|
||||
bool clearModel = false,
|
||||
}) {
|
||||
final current = state.operation;
|
||||
|
||||
int? newQuantity;
|
||||
if (clearQuantity) newQuantity = 1;
|
||||
if (quantity != null && quantity <= 0) newQuantity = 0;
|
||||
if (quantity != null && quantity > 0) newQuantity = quantity;
|
||||
|
||||
final updated = current.copyWith(
|
||||
reference: reference ?? current.reference,
|
||||
note: note ?? current.note,
|
||||
quantity: newQuantity ?? current.quantity,
|
||||
type: clearType ? null : (type ?? current.type),
|
||||
description: clearDescription
|
||||
? null
|
||||
: (description ?? current.description),
|
||||
subType: clearSubType ? null : (subType ?? current.subType),
|
||||
expirationDate: clearExpiration
|
||||
? null
|
||||
: (expirationDate ?? current.expirationDate),
|
||||
modelId: clearModel ? null : (modelId ?? current.modelId),
|
||||
modelDisplayName: clearModel
|
||||
? null
|
||||
: (modelDisplayName ?? current.modelDisplayName),
|
||||
staffId: staffId ?? current.staffId,
|
||||
staffDisplayName: staffDisplayName ?? current.staffDisplayName,
|
||||
status: status ?? current.status,
|
||||
|
||||
Reference in new issue
Block a user