Merged PR 179: merge into integration

Related work items: #661, #724, #742
This commit is contained in:
Lorenz Hilpert
2020-06-18 17:49:31 +00:00
committed by Sebastian Neumair
5 changed files with 87 additions and 144 deletions

View File

@@ -223,4 +223,15 @@ export class RemissionSelectors {
return remission.activeView;
}
@Selector([RemissionState])
static getRemissionSupplierId(remissionState: RemissionStateModel) {
const remission = remissionState.remission;
const supplier =
remission.remissionProcess &&
remission.remissionProcess.filter &&
remission.remissionProcess.filter.target;
return supplier && supplier.id;
}
}

View File

@@ -1,35 +1,9 @@
import {
Component,
OnInit,
Input,
OnDestroy,
ViewChild,
Output,
EventEmitter,
ElementRef,
ChangeDetectorRef,
} from '@angular/core';
import { Component, OnInit, Input, OnDestroy, ViewChild, Output, EventEmitter, ElementRef, ChangeDetectorRef } from '@angular/core';
import { RemissionListDataSource } from './remission-list.datasource';
import {
RemissionService,
RemissionProcess,
RemissionProduct,
RemissionFilter,
} from '@isa/remission';
import { RemissionService, RemissionProcess, RemissionProduct, RemissionFilter } from '@isa/remission';
import { RemissionHelperService } from '../../services/remission-helper.service';
import { Subject, of, Subscription, Observable } from 'rxjs';
import {
takeUntil,
filter,
take,
catchError,
share,
debounceTime,
first,
map,
switchMap,
tap,
} from 'rxjs/operators';
import { takeUntil, filter, take, catchError, share, debounceTime, first, map, switchMap, tap } from 'rxjs/operators';
import { isNullOrUndefined } from 'util';
import { CdkVirtualScrollViewport } from '@angular/cdk/scrolling';
import { Select, Store } from '@ngxs/store';
@@ -55,9 +29,7 @@ export class RemissionListComponent implements OnInit, OnDestroy {
@Output() fullListLoaded = new EventEmitter();
@Output() scroll = new EventEmitter<void>();
@Output() updateShippingDocument = new EventEmitter<void>();
@Select(RemissionSelectors.getRemissionProcess) remissionProcess$: Observable<
RemissionProcess
>;
@Select(RemissionSelectors.getRemissionProcess) remissionProcess$: Observable<RemissionProcess>;
@Select(RemissionSelectors.getRemissionActiveFilters)
selectedFilters$: Observable<{ [key: string]: [] }>;
@@ -109,9 +81,7 @@ export class RemissionListComponent implements OnInit, OnDestroy {
}
subscribeToResetCurrentPage() {
this.selectedFilters$
.pipe(takeUntil(this.destroy$))
.subscribe(() => this.resetPagesFetched());
this.selectedFilters$.pipe(takeUntil(this.destroy$)).subscribe(() => this.resetPagesFetched());
}
private resetPagesFetched() {
@@ -121,11 +91,9 @@ export class RemissionListComponent implements OnInit, OnDestroy {
}
subscribeToRefetchAllProducts() {
this.remissionHelper.refetchProducts$
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.refetchLoadedProducts(10);
});
this.remissionHelper.refetchProducts$.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.refetchLoadedProducts(10);
});
}
subscribeToFetchLastProducts() {
@@ -134,10 +102,7 @@ export class RemissionListComponent implements OnInit, OnDestroy {
const takeParam = this.pageSize;
const skipParam = Math.max(0, this.totalHits - takeParam);
if (
this.products.length >
this.pageSize + (this.totalHits % this.pageSize)
) {
if (this.products.length > this.pageSize + (this.totalHits % this.pageSize)) {
this.products = this.cleanResidualProducts(this.products);
}
@@ -150,16 +115,11 @@ export class RemissionListComponent implements OnInit, OnDestroy {
}
private filterUniqueProducts(products: RemissionProduct[]) {
return products.filter(
(product, i, allProducts) =>
allProducts.findIndex((t) => t.id === product.id) === i
);
return products.filter((product, i, allProducts) => allProducts.findIndex((t) => t.id === product.id) === i);
}
subscribeToRefetchProducts() {
this.refetchProducts$
.pipe(debounceTime(10), takeUntil(this.destroy$))
.subscribe((_) => this.fetchNewProducts());
this.refetchProducts$.pipe(debounceTime(10), takeUntil(this.destroy$)).subscribe((_) => this.fetchNewProducts());
}
onScrollDown() {
@@ -244,73 +204,53 @@ export class RemissionListComponent implements OnInit, OnDestroy {
map((process) => process.id),
tap((_) => this.store.dispatch(new SetRemissionIsLoading(true))),
switchMap((remissionProcessId) =>
this.remissionService
.getRemissionProducts({ remissionProcessId })
.pipe(
filter((data) => !isNullOrUndefined(data)),
debounceTime(250),
catchError((_) => {
this.store.dispatch(new SetRemissionIsLoading(false));
return [
{
hits: 0,
completed: true,
},
];
})
)
this.remissionService.getRemissionProducts({ remissionProcessId }).pipe(
filter((data) => !isNullOrUndefined(data)),
debounceTime(250),
catchError((_) => {
this.store.dispatch(new SetRemissionIsLoading(false));
return [
{
hits: 0,
completed: true,
},
];
})
)
),
takeUntil(this.destroy$)
)
.subscribe(
(result: {
skip?: number;
take?: number;
hits?: number;
items: RemissionProduct[];
completed: boolean;
}) => {
this.totalHits = result.hits;
.subscribe((result: { skip?: number; take?: number; hits?: number; items: RemissionProduct[]; completed: boolean }) => {
this.totalHits = result.hits;
this.updateFullListLoaded({
totalHits: this.totalHits,
numberOfProductsFetched: this.products.length,
});
this.updateFullListLoaded({
totalHits: this.totalHits,
numberOfProductsFetched: this.products.length,
});
this.isLoading = false;
if ((this.page === 0 || result.skip === 0) && !this.isFullLoad) {
this.products = [];
}
this.remissionHelper.setRemissionListHits(result.hits || -1);
if (result.items && result.items.length > 0) {
if (!this.isItRefetch && !this.isFullLoad) {
this.products = this.filterUniqueProducts([
...this.products,
...result.items,
]);
} else if (this.isItRefetch && !this.isFullLoad) {
this.products.splice(
result.skip,
result.items.length,
...result.items
);
this.isItRefetch = false;
} else if (this.isFullLoad) {
this.products = this.filterUniqueProducts([
...this.products,
...result.items,
]);
this.isFullLoad = false;
this.isFullListLoaded = true;
this.cdr.detectChanges();
this.fullListLoaded.emit();
}
}
this.store.dispatch(new SetRemissionIsLoading(false));
this.cdr.detectChanges();
this.isLoading = false;
if ((this.page === 0 || result.skip === 0) && !this.isFullLoad) {
this.products = [];
}
);
this.remissionHelper.setRemissionListHits(result.hits || -1);
if (result.items && result.items.length > 0) {
if (!this.isItRefetch && !this.isFullLoad) {
this.products = this.filterUniqueProducts([...this.products, ...result.items]);
} else if (this.isItRefetch && !this.isFullLoad) {
this.products.splice(result.skip, result.items.length, ...result.items);
this.isItRefetch = false;
} else if (this.isFullLoad) {
this.products = this.filterUniqueProducts([...this.products, ...result.items]);
this.isFullLoad = false;
this.isFullListLoaded = true;
this.cdr.detectChanges();
this.fullListLoaded.emit();
}
}
this.store.dispatch(new SetRemissionIsLoading(false));
this.cdr.detectChanges();
});
}
public loadFullList() {
@@ -346,20 +286,11 @@ export class RemissionListComponent implements OnInit, OnDestroy {
this.isFullListLoaded = false;
}
private updateFullListLoaded(params: {
totalHits: number;
numberOfProductsFetched: number;
}) {
if (this.page === 0) {
return;
}
private updateFullListLoaded(params: { totalHits: number; numberOfProductsFetched: number }) {
this.page = Math.floor(params.numberOfProductsFetched / this.pageSize);
const allProductsFetched = params.numberOfProductsFetched >= this.totalHits;
allProductsFetched
? (this.isFullListLoaded = true)
: (this.isFullListLoaded = false);
allProductsFetched ? (this.isFullListLoaded = true) : (this.isFullListLoaded = false);
}
deleteProduct(product: RemissionProduct) {
@@ -376,9 +307,7 @@ export class RemissionListComponent implements OnInit, OnDestroy {
)
.subscribe((result) => {
if (result.result) {
this.products = this.products.filter(
(existingProduct) => existingProduct.id !== product.id
);
this.products = this.products.filter((existingProduct) => existingProduct.id !== product.id);
this.hits = this.products.length;
}
});

View File

@@ -55,6 +55,8 @@ export class RemissionListFilterComponent implements OnInit, OnDestroy {
remissionSource$: Observable<RemissionResourceType>;
@Select(RemissionSelectors.getRemissionFilters)
remissionFilter$: Observable<RemissionSelectedFilters>;
@Select(RemissionSelectors.getRemissionSupplierId)
remissionSupplierId$: Observable<number>;
@Select(RemissionSelectors.getRemissionActiveFilters)
activeFilters$: Observable<{
[filterId: string]: string[];
@@ -144,8 +146,9 @@ export class RemissionListFilterComponent implements OnInit, OnDestroy {
map(([pendingFilters]) =>
this.filterService.mapToRemissionFilter(pendingFilters || [])
),
switchMap((selectedFilters) =>
this.remissionService.getCapacities(selectedFilters)
withLatestFrom(this.remissionSupplierId$),
switchMap(([selectedFilters, supplierId]) =>
this.remissionService.getCapacities({ selectedFilters, supplierId })
)
);
}

24
package-lock.json generated
View File

@@ -3261,33 +3261,33 @@
}
},
"@isa/catsearch-api": {
"version": "0.0.55",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/catsearch-api/-/catsearch-api-0.0.55.tgz",
"integrity": "sha1-J29nBWk+aT0zUShXFMfLX+uThZs=",
"version": "0.0.56",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/catsearch-api/-/catsearch-api-0.0.56.tgz",
"integrity": "sha1-VQWugpfYeSER3UnIsYOQVtnd5FA=",
"requires": {
"tslib": "^1.9.0"
}
},
"@isa/print-api": {
"version": "0.0.55",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/print-api/-/print-api-0.0.55.tgz",
"integrity": "sha1-DFH2J4gmqEHHmtpr2NsXmOkVgNY=",
"version": "0.0.56",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/print-api/-/print-api-0.0.56.tgz",
"integrity": "sha1-8cSMtEczwDnSe/C8piozLDmVYMA=",
"requires": {
"tslib": "^1.9.0"
}
},
"@isa/remi-api": {
"version": "0.0.55",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/remi-api/-/remi-api-0.0.55.tgz",
"integrity": "sha1-+s05XrFx0Z9pSVnZMtZsjeOkVjE=",
"version": "0.0.56",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/remi-api/-/remi-api-0.0.56.tgz",
"integrity": "sha1-bQBbsKL7D+j+nrB26qIOaobBjmc=",
"requires": {
"tslib": "^1.9.0"
}
},
"@isa/remission": {
"version": "0.3.23",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/remission/-/remission-0.3.23.tgz",
"integrity": "sha1-hqHKegGcgIFEu4N/pa1BEDriJOc=",
"version": "0.3.26",
"resolved": "https://pkgs.dev.azure.com/hugendubel/_packaging/hugendubel@Local/npm/registry/@isa/remission/-/remission-0.3.26.tgz",
"integrity": "sha1-SJdKN1Nj8sj8W4EOrsuVvt+l/xo=",
"requires": {
"tslib": "^1.9.0"
}

View File

@@ -54,10 +54,10 @@
"@cmf/core": "^0.1.33",
"@cmf/inventory-api": "^0.1.33",
"@cmf/trade-api": "^0.1.33",
"@isa/catsearch-api": "^0.0.55",
"@isa/print-api": "0.0.55",
"@isa/remi-api": "^0.0.55",
"@isa/remission": "^0.3.23",
"@isa/catsearch-api": "^0.0.56",
"@isa/print-api": "0.0.56",
"@isa/remi-api": "^0.0.56",
"@isa/remission": "^0.3.26",
"@ng-idle/core": "^8.0.0-beta.4",
"@ng-idle/keepalive": "^8.0.0-beta.4",
"@ngxs/store": "^3.6.2",