Merge branch 'develop' into release/2.2

This commit is contained in:
Lorenz Hilpert
2023-02-22 16:38:42 +01:00
2 changed files with 32 additions and 13 deletions

View File

@@ -7,6 +7,7 @@ import { combineLatest } from 'rxjs';
import { filter, map, shareReplay, switchMap, tap } from 'rxjs/operators';
import { geoDistance } from '@utils/common';
import { BehaviorSubject } from 'rxjs';
import { ApplicationService } from '@core/application';
@Component({
selector: 'modal-availabilities',
@@ -20,7 +21,11 @@ export class ModalAvailabilitiesComponent {
stockFetching$ = new BehaviorSubject(true);
item = this.modalRef.data.item;
itemId = this.modalRef.data.itemId || this.modalRef.data.item.id;
userbranch$ = this.domainAvailabilityService.getDefaultBranch();
userbranch$ = combineLatest([
this.applicationService.getSelectedBranch$(this.applicationService.activatedProcessId),
this.domainAvailabilityService.getDefaultBranch(),
]).pipe(map(([selectedBranch, defaultBranch]) => selectedBranch || defaultBranch));
branches$ = this.domainAvailabilityService.getBranches();
filteredBranches$ = combineLatest([this.branches$, this.userbranch$, this.search$]).pipe(
@@ -66,7 +71,8 @@ export class ModalAvailabilitiesComponent {
constructor(
private modalRef: UiModalRef<BranchDTO, { item: ItemDTO; itemId: number }>,
private domainAvailabilityService: DomainAvailabilityService
private domainAvailabilityService: DomainAvailabilityService,
private applicationService: ApplicationService
) {}
filter(query: string) {

View File

@@ -3,7 +3,12 @@ import { DomainPrinterService } from '@domain/printer';
import { DomainProductListService } from '@domain/product-list';
import { PrintModalComponent, PrintModalData } from '@modal/printer';
import { ComponentStore, OnStoreInit, tapResponse } from '@ngrx/component-store';
import { ListResponseArgsOfProductListItemDTO, ProductListItemDTO, QuerySettingsDTO } from '@swagger/wws';
import {
BatchResponseArgsOfProductListItemDTOAndString,
ListResponseArgsOfProductListItemDTO,
ProductListItemDTO,
QuerySettingsDTO,
} from '@swagger/wws';
import { UiFilter } from '@ui/filter';
import { UiModalService } from '@ui/modal';
import { isNil } from 'lodash';
@@ -103,11 +108,9 @@ export class PriceUpdateComponentStore extends ComponentStore<PriceUpdateCompone
complete = this.effect(($) =>
$.pipe(
tap(() => this.beforeComplete()),
withLatestFrom(this.items$, this.selectedItemUids$),
switchMap(([_, items, selectedItemUids]) =>
this._productListService
.completeProductListItems(selectedItemUids)
.pipe(tapResponse((response) => this.onCompleteResponse({ selectedItemUids, items }), this.onCompleteError))
withLatestFrom(this.selectedItemUids$),
switchMap(([_, selectedItemUids]) =>
this._productListService.completeProductListItems(selectedItemUids).pipe(tapResponse(this.onCompleteResponse, this.onCompleteError))
)
)
);
@@ -137,15 +140,25 @@ export class PriceUpdateComponentStore extends ComponentStore<PriceUpdateCompone
beforeFetchingItems() {
this.setFetching(true);
this.setItems([]);
this.patchState({ selectedItemUids: [] });
}
onCompleteResponse = ({ selectedItemUids, items }: { selectedItemUids: string[]; items: ProductListItemDTO[] }) => {
let filteredItems: ProductListItemDTO[];
for (let uId of selectedItemUids) {
filteredItems = items.filter((item) => item.uId !== uId);
onCompleteResponse = (response: BatchResponseArgsOfProductListItemDTOAndString) => {
let items = this.items;
if (response.error) {
this._uiModal.error('Setzen der Produkte auf Erledigt enthält fehlerhafte Einträge.', new Error(response.message));
} else if (response.successful) {
items = items.filter((item) => !response.successful.some((s) => s.key === item.uId));
} else {
this._uiModal.error(
'Setzen der Produkte auf Erledigt enthält keine erfolgreichen Einträge.',
new Error('Keine erfolgreichen Einträge')
);
}
this.patchState({ selectedItemUids: [] });
this.setItems(filteredItems);
this.setItems(items);
this.setLoading(false);
};