Implemented new custom sort and separated the sorted view for each car
This commit is contained in:
@ -8,6 +8,7 @@ import 'package:hl_lieferservice/feature/delivery/overview/model/sorting_informa
|
||||
import 'package:hl_lieferservice/feature/delivery/repository/tour_repository.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/service/distance_service.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/overview/service/reorder_service.dart';
|
||||
import 'package:hl_lieferservice/feature/delivery/util.dart';
|
||||
import 'package:hl_lieferservice/model/tour.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_bloc.dart';
|
||||
import 'package:hl_lieferservice/widget/operations/bloc/operation_event.dart';
|
||||
@ -77,7 +78,7 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
event.deliveryId,
|
||||
event.articleId,
|
||||
event.amount,
|
||||
event.reason
|
||||
event.reason,
|
||||
);
|
||||
|
||||
opBloc.add(FinishOperation());
|
||||
@ -106,30 +107,18 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
) async {
|
||||
final currentState = state;
|
||||
if (currentState is TourLoaded) {
|
||||
int newPosition =
|
||||
event.newPosition == currentState.sortingInformation.sorting.length
|
||||
? event.newPosition - 1
|
||||
: event.newPosition;
|
||||
SortingInformation informationOld = currentState
|
||||
.sortingInformation
|
||||
.sorting
|
||||
.firstWhere((info) => info.position == event.oldPosition);
|
||||
Map<String, List<String>> container = {...currentState.sortingInformation};
|
||||
|
||||
SortingInformation information = currentState.sortingInformation.sorting
|
||||
.firstWhere((info) => info.position == newPosition);
|
||||
|
||||
information.position = event.oldPosition;
|
||||
informationOld.position = newPosition;
|
||||
|
||||
await ReorderService().saveSortingInformation(
|
||||
currentState.sortingInformation,
|
||||
List<String> reorderedList = reorderList(
|
||||
container[event.carId.toString()] ?? [],
|
||||
event.oldPosition,
|
||||
event.newPosition,
|
||||
);
|
||||
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
sortingInformation: currentState.sortingInformation.copyWith(),
|
||||
),
|
||||
);
|
||||
container[event.carId.toString()] = reorderedList;
|
||||
await ReorderService().saveSortingInformation(container);
|
||||
|
||||
emit(currentState.copyWith(sortingInformation: container));
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,9 +160,7 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
) async {
|
||||
try {
|
||||
ReorderService service = ReorderService();
|
||||
SortingInformationContainer container = SortingInformationContainer(
|
||||
sorting: [],
|
||||
);
|
||||
Map<String, List<String>> container = {};
|
||||
|
||||
// Create empty default value if it does not exist yet
|
||||
if (!service.orderInformationExist()) {
|
||||
@ -186,25 +173,14 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
|
||||
bool inconsistent = false;
|
||||
for (final delivery in event.tour.deliveries) {
|
||||
int info = container.sorting.indexWhere(
|
||||
(info) => info.deliveryId == delivery.id,
|
||||
int info = container[delivery.carId.toString()]!.indexWhere(
|
||||
(id) => id == delivery.id,
|
||||
);
|
||||
int max = container.sorting.fold(0, (acc, element) {
|
||||
if (element.position > acc) {
|
||||
return element.position;
|
||||
}
|
||||
return acc;
|
||||
});
|
||||
|
||||
// not found, so add it to the list
|
||||
if (info == -1) {
|
||||
inconsistent = true;
|
||||
container.sorting.add(
|
||||
SortingInformation(
|
||||
deliveryId: delivery.id,
|
||||
position: container.sorting.isEmpty ? 0 : max + 1,
|
||||
),
|
||||
);
|
||||
container[delivery.carId.toString()]!.add(delivery.id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,13 +209,9 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
),
|
||||
);
|
||||
|
||||
SortingInformationContainer container = SortingInformationContainer(
|
||||
sorting: [],
|
||||
);
|
||||
for (final (index, delivery) in event.tour.deliveries.indexed) {
|
||||
container.sorting.add(
|
||||
SortingInformation(deliveryId: delivery.id, position: index),
|
||||
);
|
||||
Map<String, List<String>> container = {};
|
||||
for (final delivery in event.tour.deliveries) {
|
||||
container[delivery.carId.toString()]!.add(delivery.id);
|
||||
}
|
||||
|
||||
emit(
|
||||
@ -365,7 +337,9 @@ class TourBloc extends Bloc<TourEvent, TourState> {
|
||||
);
|
||||
break;
|
||||
}
|
||||
} on TourNotFoundException {
|
||||
} catch (e, st) {
|
||||
debugPrint("FEHLER beim Scannen eines Artikels: $e");
|
||||
debugPrint("$st");
|
||||
opBloc.add(FailOperation(message: "Fehler beim Scannen des Artikels"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -35,8 +35,9 @@ class RequestSortingInformationEvent extends TourEvent {
|
||||
class ReorderDeliveryEvent extends TourEvent {
|
||||
int newPosition;
|
||||
int oldPosition;
|
||||
String carId;
|
||||
|
||||
ReorderDeliveryEvent({required this.newPosition, required this.oldPosition});
|
||||
ReorderDeliveryEvent({required this.newPosition, required this.oldPosition, required this.carId});
|
||||
}
|
||||
|
||||
class TourUpdated extends TourEvent {
|
||||
|
||||
@ -31,7 +31,7 @@ class TourLoaded extends TourState {
|
||||
Tour tour;
|
||||
Map<String, double>? distances;
|
||||
List<Payment> paymentOptions;
|
||||
SortingInformationContainer sortingInformation;
|
||||
Map<String, List<String>> sortingInformation;
|
||||
|
||||
TourLoaded({
|
||||
required this.tour,
|
||||
@ -44,7 +44,7 @@ class TourLoaded extends TourState {
|
||||
Tour? tour,
|
||||
Map<String, double>? distances,
|
||||
List<Payment>? paymentOptions,
|
||||
SortingInformationContainer? sortingInformation
|
||||
Map<String, List<String>>? sortingInformation
|
||||
}) {
|
||||
return TourLoaded(
|
||||
tour: tour ?? this.tour,
|
||||
|
||||
Reference in New Issue
Block a user