mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 1339: #3265 Warenausgabe Scrolling und SilentReload Bugfix
#3265 Warenausgabe Scrolling und SilentReload Bugfix Related work items: #3265
This commit is contained in:
committed by
Nino Righi
parent
cc5c3167b1
commit
1f62040560
@@ -6,7 +6,7 @@ import { ComponentStore, tapResponse } from '@ngrx/component-store';
|
||||
import { ListResponseArgsOfOrderItemListItemDTO, OrderItemListItemDTO, QuerySettingsDTO } from '@swagger/oms';
|
||||
import { UiFilter } from '@ui/filter';
|
||||
import { isResponseArgs } from '@utils/object';
|
||||
import { NEVER, Observable, Subject } from 'rxjs';
|
||||
import { Observable, Subject } from 'rxjs';
|
||||
import { switchMap, filter, tap, first, map } from 'rxjs/operators';
|
||||
|
||||
export interface GoodsOutSearchState {
|
||||
@@ -15,6 +15,7 @@ export interface GoodsOutSearchState {
|
||||
filter?: UiFilter;
|
||||
message?: string;
|
||||
fetching: boolean;
|
||||
silentFetching: boolean;
|
||||
hits: number;
|
||||
results: OrderItemListItemDTO[];
|
||||
}
|
||||
@@ -51,6 +52,10 @@ export class GoodsOutSearchStore extends ComponentStore<GoodsOutSearchState> {
|
||||
|
||||
readonly fetching$ = this.select((s) => s.fetching);
|
||||
|
||||
get silentFetching() {
|
||||
return this.get((s) => s.silentFetching);
|
||||
}
|
||||
|
||||
get queryParams() {
|
||||
return this.get((s) => s.queryParams);
|
||||
}
|
||||
@@ -72,6 +77,7 @@ export class GoodsOutSearchStore extends ComponentStore<GoodsOutSearchState> {
|
||||
constructor(private _domainGoodsInService: DomainGoodsService, private _cache: CacheService) {
|
||||
super({
|
||||
fetching: false,
|
||||
silentFetching: false,
|
||||
hits: 0,
|
||||
results: [],
|
||||
});
|
||||
@@ -152,7 +158,10 @@ export class GoodsOutSearchStore extends ComponentStore<GoodsOutSearchState> {
|
||||
tap(([options, _, filter]: [{ clear?: boolean; siletReload?: boolean }, OrderItemListItemDTO[], UiFilter]) => {
|
||||
if (!options?.siletReload) {
|
||||
this.patchState({ fetching: true });
|
||||
} else {
|
||||
this.patchState({ silentFetching: true });
|
||||
}
|
||||
|
||||
if (options?.clear) {
|
||||
this._searchResultClearedSubject.next();
|
||||
this._cache.delete(filter?.getQueryToken());
|
||||
@@ -201,6 +210,7 @@ export class GoodsOutSearchStore extends ComponentStore<GoodsOutSearchState> {
|
||||
hits: res.hits,
|
||||
results: _results,
|
||||
fetching: false,
|
||||
silentFetching: false,
|
||||
});
|
||||
|
||||
this._cache.set(filter?.getQueryToken(), {
|
||||
@@ -223,7 +233,7 @@ export class GoodsOutSearchStore extends ComponentStore<GoodsOutSearchState> {
|
||||
cached,
|
||||
});
|
||||
}
|
||||
this.patchState({ fetching: false });
|
||||
this.patchState({ fetching: false, silentFetching: false });
|
||||
console.error('GoodsInSearchStore.search()', err);
|
||||
}
|
||||
)
|
||||
|
||||
@@ -93,14 +93,16 @@ export class GoodsOutSearchResultsComponent extends ComponentStore<GoodsOutSearc
|
||||
}
|
||||
|
||||
saveScrollPosition(processId: number, scrollPosition: number) {
|
||||
if (scrollPosition > 0) {
|
||||
localStorage.setItem(`SCROLL_POSITION_${processId}`, JSON.stringify(scrollPosition));
|
||||
}
|
||||
localStorage.setItem(`SCROLL_POSITION_${processId}`, JSON.stringify(scrollPosition));
|
||||
}
|
||||
|
||||
getScrollPosition(processId: number): number | undefined {
|
||||
const scroll_position = localStorage.getItem(`SCROLL_POSITION_${processId}`);
|
||||
return scroll_position ? JSON.parse(scroll_position) : undefined;
|
||||
try {
|
||||
const scroll_position = localStorage.getItem(`SCROLL_POSITION_${processId}`);
|
||||
return scroll_position ? JSON.parse(scroll_position) : undefined;
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
removeScrollPosition(processId: number) {
|
||||
@@ -229,19 +231,21 @@ export class GoodsOutSearchResultsComponent extends ComponentStore<GoodsOutSearc
|
||||
this._searchResultSubscription.add(
|
||||
this._goodsOutSearchStore.searchResultFromCache$.pipe(takeUntil(this._onDestroy$)).subscribe(async (result) => {
|
||||
if (result?.hits > 0) {
|
||||
const scrollPos = this.getScrollPosition(processId);
|
||||
if (scrollPos > 0) {
|
||||
this.scrollTo = scrollPos;
|
||||
this.scrollContainer?.scrollTo(scrollPos);
|
||||
this.removeScrollPosition(processId);
|
||||
}
|
||||
const scrollPos = this.getScrollPosition(processId) || 0;
|
||||
this.scrollTo = scrollPos;
|
||||
this.scrollContainer?.scrollTo(scrollPos);
|
||||
this.removeScrollPosition(processId);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
async loadMore() {
|
||||
if (this._goodsOutSearchStore.hits > this._goodsOutSearchStore.results.length && !this._goodsOutSearchStore.fetching) {
|
||||
if (
|
||||
this._goodsOutSearchStore.hits > this._goodsOutSearchStore.results.length &&
|
||||
!this._goodsOutSearchStore.fetching &&
|
||||
!this._goodsOutSearchStore.silentFetching
|
||||
) {
|
||||
this.saveScrollPosition(this.previousProcessId, this.scrollContainer?.scrollPos);
|
||||
this._goodsOutSearchStore.search({});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user