Set Filter after adding product to ensure correct re-navigation

+ ISA Package Update 0.3.19
This commit is contained in:
Sebastian
2020-06-03 17:06:11 +02:00
parent ab6e94df4f
commit d3d6bfb250
5 changed files with 141 additions and 63 deletions

View File

@@ -142,11 +142,11 @@ export class AddProductToRemissionDialogComponent implements OnInit, OnDestroy {
take(1),
delay(2000)
)
.subscribe(([response]) => {
.subscribe((product: RemissionProduct) => {
this.reasonError = false;
this.remissionHelper.addRemissionListItem(response);
this.remissionHelper.addRemissionListItem(product);
this.modalService.close(this.id);
this.add.emit();
this.add.emit(product);
});
}
}

View File

@@ -10,11 +10,33 @@ import {
ElementRef,
AfterViewInit,
} from '@angular/core';
import { Observable, of, Subject, BehaviorSubject, combineLatest, merge } from 'rxjs';
import { RemissionProduct, RemissionService, RemissionProcess } from '@isa/remission';
import {
Observable,
of,
Subject,
BehaviorSubject,
combineLatest,
merge,
} from 'rxjs';
import {
RemissionProduct,
RemissionService,
RemissionProcess,
} from '@isa/remission';
import { Store, Select } from '@ngxs/store';
import { RemissionSelectors } from 'apps/sales/src/app/core/store/selectors/remission.selectors';
import { map, switchMap, filter, catchError, takeUntil, take, distinctUntilChanged, debounceTime, tap, skip } from 'rxjs/operators';
import {
map,
switchMap,
filter,
catchError,
takeUntil,
take,
distinctUntilChanged,
debounceTime,
tap,
skip,
} from 'rxjs/operators';
import { RemissionListComponent } from '../../../components/remission-list';
import { RemissionResourceType } from '../../../models/remission-resource-type.model';
import { isNullOrUndefined } from 'util';
@@ -29,20 +51,28 @@ import { RemissionHelperService } from '../../../services';
styleUrls: ['./product-list.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class RemissionProductListComponent implements OnInit, OnDestroy, AfterViewInit {
export class RemissionProductListComponent
implements OnInit, OnDestroy, AfterViewInit {
@ViewChild('toTopToBottomActions', { static: false })
toTopToBottomActions: RemissionToTopToBottomActionsComponent;
@ViewChild('remissionList', { static: false }) remissionList: RemissionListComponent;
@ViewChild('remissionList', { static: false })
remissionList: RemissionListComponent;
@ViewChildren('remissionListHitsRef') remissionHitsRef: QueryList<ElementRef>;
@Input() remissionListContainer: HTMLElement;
@Input() shippingDocumentContainer: HTMLElement;
@Input() containerScrolled$: Observable<Event> = new Subject<Event>().asObservable();
@Input() containerScrolled$: Observable<Event> = new Subject<
Event
>().asObservable();
@Input() shippingDocumentRef: QueryList<ElementRef>;
@Select(RemissionSelectors.getIsLoading) isLoading$: Observable<boolean>;
@Select(RemissionSelectors.getRemissionProcess) remissionProcess$: Observable<RemissionProcess>;
@Select(RemissionSelectors.getRemissionSource) source$: Observable<RemissionResourceType>;
@Select(RemissionSelectors.getRemissionProcess) remissionProcess$: Observable<
RemissionProcess
>;
@Select(RemissionSelectors.getRemissionSource) source$: Observable<
RemissionResourceType
>;
@Select(RemissionSelectors.getRemissionProcessStatuses)
remissionProcessStatuses$: Observable<RemissionProcessStatuses>;
@Select(RemissionSelectors.getRemissiontarget)
@@ -87,7 +117,10 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
// Feature Flag: Indicates whether to load entire remission list on navigate to bottom
loadAllProductsOnNavigateToBottom = false;
constructor(private store: Store, private remissionService: RemissionService) { }
constructor(
private store: Store,
private remissionService: RemissionService
) {}
ngOnInit() {
this.initProducts();
@@ -107,7 +140,10 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
initProducts() {
this.remissionProductsData$ = this.remissionProcess$.pipe(
filter((process) => !isNullOrUndefined(process) && !isNullOrUndefined(process.id)),
filter(
(process) =>
!isNullOrUndefined(process) && !isNullOrUndefined(process.id)
),
take(1),
map((process) => process.id),
switchMap((remissionProcessId) =>
@@ -115,7 +151,10 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
filter((data) => !isNullOrUndefined(data)),
map((data) => {
if (!data.hits) {
data.hits = (this.latestRemissionProductsData$.value && this.latestRemissionProductsData$.value.hits) || 0;
data.hits =
(this.latestRemissionProductsData$.value &&
this.latestRemissionProductsData$.value.hits) ||
0;
}
return data;
@@ -155,7 +194,10 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
map((process) => process.id),
take(1)
)
.subscribe((remissionProcessId) => this.store.dispatch(new UpdateShippingDocuent(remissionProcessId)));
.subscribe((remissionProcessId) => {
this.store.dispatch(new UpdateShippingDocuent(remissionProcessId));
setTimeout(() => this.navigateToBottom(), 5000);
});
}
navigateToTop() {
@@ -196,7 +238,8 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
const { clientHeight, scrollHeight, scrollTop } = target;
if (this.refetchProductsOnScroll()) {
const shippingContainerHeight = this.shippingDocumentContainer.clientHeight;
const shippingContainerHeight = this.shippingDocumentContainer
.clientHeight;
if (
this.shouldRefreshProducts({
clientHeight,
@@ -234,7 +277,8 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
const pixelsScrolledUpToTriggerRefresh = 150;
return (
scrollTop + clientHeight - scrollHeight < pixelsScrolledUpToTriggerRefresh - shippingContainerHeight &&
scrollTop + clientHeight - scrollHeight <
pixelsScrolledUpToTriggerRefresh - shippingContainerHeight &&
!!this.viewShippingDocumentFromJumpToBottom
);
}
@@ -245,7 +289,10 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
this.refetchRemissionProductsOnScrollUp$.next();
}
private setScrollToTopBotomVisibility(topValue: boolean, bottomValue: boolean) {
private setScrollToTopBotomVisibility(
topValue: boolean,
bottomValue: boolean
) {
this.showJumpToTop$.next(topValue);
this.showJumpToBottom$.next(bottomValue);
}
@@ -256,21 +303,25 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
}
private setUpIntersectionObservers() {
this.remissionHitsRef.changes.pipe(this.returnFirstElement).subscribe((element) => {
this.subscribeToIntersectionSub({
element,
sub: this.isNumberOfHitsVisible$,
type: 'top',
this.remissionHitsRef.changes
.pipe(this.returnFirstElement)
.subscribe((element) => {
this.subscribeToIntersectionSub({
element,
sub: this.isNumberOfHitsVisible$,
type: 'top',
});
});
});
this.shippingDocumentRef.changes.pipe(this.returnFirstElement).subscribe((element) => {
this.subscribeToIntersectionSub({
element,
sub: this.isShippingDocumentVisible$,
type: 'bottom',
this.shippingDocumentRef.changes
.pipe(this.returnFirstElement)
.subscribe((element) => {
this.subscribeToIntersectionSub({
element,
sub: this.isShippingDocumentVisible$,
type: 'bottom',
});
});
});
}
private returnFirstElement(el: Observable<any>): Observable<any> {
@@ -280,7 +331,11 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
);
}
private subscribeToIntersectionSub(params: { element: Element; sub: BehaviorSubject<boolean>; type: 'top' | 'bottom'; }) {
private subscribeToIntersectionSub(params: {
element: Element;
sub: BehaviorSubject<boolean>;
type: 'top' | 'bottom';
}) {
const { element, sub, type } = params;
const unsubscribe = this.intersectionObserverSubs.get(type);
@@ -288,7 +343,10 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
unsubscribe();
}
this.intersectionObserverSubs.set(type, this.initIntersectionObserver(element, type));
this.intersectionObserverSubs.set(
type,
this.initIntersectionObserver(element, type)
);
this.intersectionObserver$
.pipe(
@@ -307,11 +365,13 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
}
private initIntersectionObserver(element: Element, type: 'top' | 'bottom') {
const intersectionObserver = new IntersectionObserver((entries, observer) => {
entries.forEach((entry) => {
this.intersectionObserver$.next({ entry, observer, type });
});
});
const intersectionObserver = new IntersectionObserver(
(entries, observer) => {
entries.forEach((entry) => {
this.intersectionObserver$.next({ entry, observer, type });
});
}
);
intersectionObserver.observe(element);
@@ -346,22 +406,31 @@ export class RemissionProductListComponent implements OnInit, OnDestroy, AfterVi
this.isLoading$
)
.pipe(
map(([isNumberOfHitsVisible, isShippingDocumentVisible, hits, isLoading]) => {
if (!hits || hits === -1 || !!isLoading) {
map(
([
isNumberOfHitsVisible,
isShippingDocumentVisible,
hits,
isLoading,
]) => {
if (!hits || hits === -1 || !!isLoading) {
return {
showTop: false,
showBottom: false,
};
}
return {
showTop: false,
showBottom: false,
showTop: !isShippingDocumentVisible,
showBottom: !isNumberOfHitsVisible,
};
}
return {
showTop: !isShippingDocumentVisible,
showBottom: !isNumberOfHitsVisible,
};
}),
),
takeUntil(this.destroy$),
debounceTime(350)
)
.subscribe(({ showTop, showBottom }) => this.setScrollToTopBotomVisibility(showTop, showBottom));
.subscribe(({ showTop, showBottom }) =>
this.setScrollToTopBotomVisibility(showTop, showBottom)
);
}
}

View File

@@ -62,6 +62,7 @@ import { RemissionToTopToBottomActionsComponent } from '../../components/remissi
import { RemissionScanProductInvalidBarcodeComponent } from '../../components/remission-scan-product-invalid-barcode/remission-scan-product-invalid-barcode.component';
import { NativeContainerService } from 'shared/lib/remission-container-scanner/native-container.service';
import { remissionProcess } from '../../mocks';
import { SupplierDTO } from '@cmf/inventory-api';
@Component({
selector: 'app-remission-list-create',
@@ -363,7 +364,7 @@ export class RemissionListCreateComponent implements OnInit, OnDestroy {
this.store.dispatch(new SetBranchProcessCurrentPath(path));
}
addProductToRemissionList() {
addProductToRemissionList(product: RemissionProduct) {
this.searchedRemissionProduct = undefined;
this.resetFilters = true;
@@ -371,25 +372,33 @@ export class RemissionListCreateComponent implements OnInit, OnDestroy {
.pipe(
take(1),
map((process) => process.id),
withLatestFrom(this.currentRemissionSource$),
withLatestFrom(this.currentRemissionTarget$),
catchError((error) => {
this.store.dispatch(new SetRemissionIsLoading(false));
return [error];
})
)
.subscribe(
([remissionProcessId, source]) =>
source === 'ueberlauf' &&
this.store.dispatch(
new RequestUpdateRemissionFilter(remissionProcessId, {
source: 'zentral',
})
)
);
.subscribe(([remissionProcessId, target]) => {
let newTarget = target;
if (this.isValidSupplierDTO(product.target)) {
newTarget = product.target;
}
this.store.dispatch(
new RequestUpdateRemissionFilter(remissionProcessId, {
source: 'zentral',
target: newTarget,
})
);
});
this.navigateRemissionCreateList();
}
private isValidSupplierDTO(supplier: Partial<SupplierDTO>): boolean {
return !!supplier.id && !!supplier.name && !!supplier.supplierNumber;
}
closeAddProductToRemissionDialog() {
this.searchedRemissionProduct = undefined;
this.navigateRemissionCreateList();

6
package-lock.json generated
View File

@@ -3285,9 +3285,9 @@
}
},
"@isa/remission": {
"version": "0.3.18",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/remission/-/remission-0.3.18.tgz",
"integrity": "sha1-1pdpm5RfaG4j/QlnklCGIThXmiI=",
"version": "0.3.19",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/remission/-/remission-0.3.19.tgz",
"integrity": "sha1-HmxtA1rbbrbnMsghCLdEx22Y+Fs=",
"requires": {
"tslib": "^1.9.0"
}

View File

@@ -56,7 +56,7 @@
"@isa/catsearch-api": "^0.0.55",
"@isa/print-api": "0.0.55",
"@isa/remi-api": "^0.0.55",
"@isa/remission": "^0.3.18",
"@isa/remission": "^0.3.19",
"@ng-idle/core": "^8.0.0-beta.4",
"@ng-idle/keepalive": "^8.0.0-beta.4",
"@ngxs/store": "^3.6.2",