Merge branch 'develop' into feature/splitscreen-pickup-shelf-design

This commit is contained in:
Nino
2023-09-20 17:32:39 +02:00
8 changed files with 79 additions and 26 deletions

View File

@@ -8,7 +8,7 @@ import { Cached } from './cached';
export class CacheService {
constructor() {}
set(token: Object, data: any, options?: CacheOptions) {
set<T>(token: Object, data: T, options?: CacheOptions) {
const persist = options?.persist;
const ttl = options?.ttl;
const cached: Cached = {
@@ -29,13 +29,15 @@ export class CacheService {
return cached;
}
get<T = any>(token: Object, from: 'session' | 'persist' = 'session'): T {
get<T = any>(token: Object, from?: 'session' | 'persist'): T {
let cached: Cached;
if (from === 'session') {
cached = this.deserialize(sessionStorage.getItem(this.getKey(token)));
} else if (from === 'persist') {
cached = this.deserialize(localStorage.getItem(this.getKey(token)));
} else {
cached = this.deserialize(sessionStorage.getItem(this.getKey(token))) || this.deserialize(localStorage.getItem(this.getKey(token)));
}
if (!cached) {

View File

@@ -1,4 +1,4 @@
import { Component, ChangeDetectionStrategy, OnInit, OnDestroy, ElementRef, ViewChild } from '@angular/core';
import { Component, ChangeDetectionStrategy, OnInit, OnDestroy, ElementRef, ViewChild, inject } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ApplicationService } from '@core/application';
import { DomainPrinterService } from '@domain/printer';
@@ -20,7 +20,7 @@ import { DateAdapter } from '@ui/common';
import { DatePipe } from '@angular/common';
import { PurchaseOptionsModalService } from '@shared/modals/purchase-options-modal';
import { EnvironmentService } from '@core/environment';
import { CheckoutNavigationService, ProductCatalogNavigationService } from '@shared/services';
import { CheckoutNavigationService, ProductCatalogNavigationService, CustomerSearchNavigation } from '@shared/services';
import { DomainCheckoutService } from '@domain/checkout';
import { Store } from '@ngrx/store';
@@ -33,6 +33,8 @@ import { Store } from '@ngrx/store';
animations: [slideYAnimation],
})
export class ArticleDetailsComponent implements OnInit, OnDestroy {
private _customerSearchNavigation = inject(CustomerSearchNavigation);
private readonly subscriptions = new Subscription();
showRecommendations: boolean;
@@ -411,6 +413,7 @@ export class ArticleDetailsComponent implements OnInit, OnDestroy {
}
async navigateToCustomerSearch() {
const nav = this._customerSearchNavigation.defaultRoute({ processId: this.applicationService.activatedProcessId });
try {
const response = await this.customerFeatures$
.pipe(
@@ -420,11 +423,11 @@ export class ArticleDetailsComponent implements OnInit, OnDestroy {
})
)
.toPromise();
this._router.navigate(['/kunde', this.applicationService.activatedProcessId, 'customer', 'search'], {
this._router.navigate(nav.path, {
queryParams: { filter_customertype: response.filter.customertype },
});
} catch (error) {
this._router.navigate(['/kunde', this.applicationService.activatedProcessId, 'customer', 'search']);
this._router.navigate(nav.path);
}
}

View File

@@ -8,6 +8,7 @@ import {
QueryList,
AfterViewInit,
TrackByFunction,
inject,
} from '@angular/core';
import { Router } from '@angular/router';
import { ApplicationService } from '@core/application';
@@ -29,6 +30,7 @@ import { EnvironmentService } from '@core/environment';
import { CheckoutReviewStore } from './checkout-review.store';
import { ToasterService } from '@shared/shell';
import { ShoppingCartItemComponent } from './shopping-cart-item/shopping-cart-item.component';
import { CustomerSearchNavigation } from '@shared/services';
@Component({
selector: 'page-checkout-review',
@@ -37,6 +39,7 @@ import { ShoppingCartItemComponent } from './shopping-cart-item/shopping-cart-it
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit {
private _customerSearchNavigation = inject(CustomerSearchNavigation);
checkingOla$ = new BehaviorSubject<boolean>(false);
payer$ = this._store.payer$;
@@ -467,6 +470,8 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
}
async navigateToCustomerSearch(processId: number) {
const nav = this._customerSearchNavigation.defaultRoute({ processId });
try {
const response = await this.customerFeatures$
.pipe(
@@ -477,11 +482,11 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
)
.toPromise();
this.router.navigate(['/kunde', this.applicationService.activatedProcessId, 'customer', 'search'], {
this.router.navigate(nav.path, {
queryParams: { filter_customertype: response.filter.customertype },
});
} catch (error) {
this.router.navigate(['/kunde', this.applicationService.activatedProcessId, 'customer', 'search']);
this.router.navigate(nav.path);
}
}
@@ -501,7 +506,8 @@ export class CheckoutReviewComponent implements OnInit, OnDestroy, AfterViewInit
return;
}
const customerId = customer.source;
this.router.navigate(['/kunde', this.applicationService.activatedProcessId, 'customer', `${customerId}`]);
const nav = this._customerSearchNavigation.detailsRoute({ processId, customerId });
this.router.navigate(nav.path);
}
async order() {

View File

@@ -39,9 +39,7 @@ export class CustomerFilterMainViewComponent {
private _location: Location,
private _router: Router,
private _customerSearchNavigation: CustomerSearchNavigation
) {
console.log(this.isOnMainRoute);
}
) {}
search(filter: Filter) {
this._store.setFilter(filter);

View File

@@ -5,9 +5,10 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
import { Breadcrumb, BreadcrumbService } from '@core/breadcrumb';
import { switchMap, take, tap, withLatestFrom } from 'rxjs/operators';
import { NavigationRoute } from '@shared/services';
import { DBHOrderItemListItemDTO, OrderItemProcessingStatusValue } from '@swagger/oms';
import { DBHOrderItemListItemDTO } from '@swagger/oms';
import { isEmpty } from 'lodash';
import { Observable, combineLatest, concat } from 'rxjs';
import { Observable, combineLatest } from 'rxjs';
import { CacheService } from '@core/cache';
/**
* Enthält die gemeinsame Logik für die Suche und verbindet die Komponenten mit dem Store.
@@ -31,6 +32,10 @@ export abstract class PickupShelfBaseComponent implements OnInit {
this.regsiterProcessIdHandler();
this.registerQueryParamsHandler();
this.registerViewHandler();
if (this.getView() === 'list') {
this.listStore.fetchList();
}
}
regsiterFetchListResponseHandler() {
@@ -92,6 +97,10 @@ export abstract class PickupShelfBaseComponent implements OnInit {
.subscribe();
}
getView(): string {
return this.activatedRoute.snapshot.data.view;
}
/**
* Sucht die Breadcrumb anhand des Tags.
* @param tag Der gesuchte Tag

View File

@@ -7,7 +7,7 @@ import { PickupShelfIOService, PickupShelfOutService } from '@domain/pickup-shel
import { PickupShelfBaseComponent } from '../pickup-shelf-base.component';
import { NavigationRoute, PickUpShelfOutNavigationService } from '@shared/services';
import { AsyncPipe } from '@angular/common';
import { DBHOrderItemListItemDTO, OrderItemProcessingStatusValue } from '@swagger/oms';
import { DBHOrderItemListItemDTO } from '@swagger/oms';
import { Observable, combineLatest, of } from 'rxjs';
import { filter, map } from 'rxjs/operators';

View File

@@ -22,6 +22,5 @@ function findDataInActivatedRouteSnapshot(snapshot: ActivatedRouteSnapshot, data
export const viewResolver: ResolveFn<string> = (route: ActivatedRouteSnapshot) => {
const result = findDataInActivatedRouteSnapshot(route, 'view', 2);
console.log('viewResolver', result);
return result;
};

View File

@@ -1,17 +1,26 @@
import { ComponentStore, tapResponse, OnStoreInit } from '@ngrx/component-store';
import { PickupShelfState } from './pickup-shelf.state';
import { PickupShelfIOService } from '@domain/pickup-shelf';
import { delayWhen, filter, switchMap, takeUntil, tap, withLatestFrom } from 'rxjs/operators';
import { ListResponseArgsOfDBHOrderItemListItemDTO, ResponseArgsOfQuerySettingsDTO } from '@swagger/oms';
import { delay, delayWhen, filter, map, switchMap, takeUntil, tap, withLatestFrom } from 'rxjs/operators';
import {
DBHOrderItemListItemDTO,
ListResponseArgsOfDBHOrderItemListItemDTO,
QueryTokenDTO,
ResponseArgsOfQuerySettingsDTO,
} from '@swagger/oms';
import { DestroyRef, Injectable, inject } from '@angular/core';
import { ToasterService } from '@shared/shell';
import { UiModalService } from '@ui/modal';
import * as Selectors from './pickup-shelf.selectors';
import { Subject } from 'rxjs';
import { CacheService } from '@core/cache';
import { Filter } from '@shared/components/filter';
@Injectable()
export class PickupShelfStore extends ComponentStore<PickupShelfState> implements OnStoreInit {
private _cacheService = inject(CacheService);
private _destronyRef = inject(DestroyRef);
private _cancelListRequests = new Subject<void>();
@@ -70,6 +79,8 @@ export class PickupShelfStore extends ComponentStore<PickupShelfState> implement
this.cancelListRequests();
this._fetchListResponse.complete();
});
this.select((s) => s).subscribe(console.log.bind(console, 'PickupShelfStore'));
}
setProcessId(processId: number) {
@@ -87,6 +98,7 @@ export class PickupShelfStore extends ComponentStore<PickupShelfState> implement
cancelListRequests() {
this._cancelListRequests.next();
this.patchState({ fetchingList: false });
}
ngrxOnStoreInit = () => {
@@ -116,24 +128,48 @@ export class PickupShelfStore extends ComponentStore<PickupShelfState> implement
fetchList = this.effect((trigger$) =>
trigger$.pipe(
this.delayWhenFilterIsNotReady,
tap(this.beforeFetchList),
withLatestFrom(this.filter$),
switchMap(([_, filter]) =>
withLatestFrom(this.filter$, this.processId$),
map(([_, filter, processId]) => this.beforeFetchList(filter, processId)),
switchMap(({ filter, processId, list }) =>
this._pickupShelfIOService
.search(filter.getQueryToken())
.pipe(takeUntil(this._cancelListRequests), tapResponse(this.fetchListDone, this.fetchListError))
.search({
...filter.getQueryToken(),
take: Math.max(list.length, 25),
})
.pipe(
takeUntil(this._cancelListRequests),
tapResponse(
(res) => this.fetchListDone({ processId, queryToken: filter.getQueryToken() })(res),
(err) => this.fetchListError(err)
)
)
)
)
);
private beforeFetchList = () => {
private beforeFetchList = (filter: Filter, processId: number) => {
this.cancelListRequests();
this.patchState({ fetchingList: true, list: [], listHits: 0 });
const queryToken = filter.getQueryToken();
const cachedListResponse = this._cacheService.get<ListResponseArgsOfDBHOrderItemListItemDTO>({ processId, queryToken });
let list: DBHOrderItemListItemDTO[] = [];
if (!!cachedListResponse) {
this.patchState({ fetchingList: false, list: cachedListResponse.result, listHits: cachedListResponse.hits });
list = cachedListResponse.result;
} else {
this.patchState({ fetchingList: true, list: [], listHits: 0 });
}
return { filter, processId, list };
};
private fetchListDone = (resp: ListResponseArgsOfDBHOrderItemListItemDTO) => {
private fetchListDone = ({ processId, queryToken }: { processId: number; queryToken: QueryTokenDTO }) => (
resp: ListResponseArgsOfDBHOrderItemListItemDTO
) => {
this.patchState({ fetchingList: false, list: resp.result, listHits: resp.hits });
this._fetchListResponse.next(resp);
this._cacheService.set<ListResponseArgsOfDBHOrderItemListItemDTO>({ processId, queryToken }, resp, { persist: true });
};
private fetchListError = (err: any) => {