Merged PR 1210: #3081 #3051 Remember Filter Settings on continuing Remission and Remission start

#3081 #3051 Remember Filter Settings on continuing Remission and Remission start
This commit is contained in:
Nino Righi
2022-04-28 14:24:24 +00:00
committed by Andreas Schickinger
parent b7d7c88fc6
commit 0c5aedfee8
7 changed files with 39 additions and 36 deletions

View File

@@ -81,7 +81,7 @@ export class CreateRemissionComponent implements OnInit {
async navigateToList(returnId: number) {
await this._router.navigate(['/filiale', 'remission', returnId, 'list'], {
queryParams: { supplier: this.supplierId, source: this.source },
queryParams: { ...this._activatedRoute.snapshot.queryParams, supplier: this.supplierId, source: this.source },
});
}

View File

@@ -45,7 +45,7 @@ export class FinishRemissionComponent implements OnInit, OnDestroy {
const returnDto = await this._remissionService.getReturn(returnId).toPromise();
this.clearProcessData();
await this._router.navigate(['/filiale', 'remission', 'create', returnDto.returnGroup], {
queryParams: { supplier: returnDto.supplier.id },
queryParams: { ...this._activatedRoute.snapshot.queryParams },
});
} catch (err) {
this._modal.open({

View File

@@ -122,7 +122,25 @@ export class FinishShippingDocumentComponent implements OnInit, OnDestroy {
}
async navigateToFinishRemission() {
await this._router.navigate(['../../', 'finish-remission'], { relativeTo: this._activatedRoute });
await this._router.navigate(['../../', 'finish-remission'], {
relativeTo: this._activatedRoute,
queryParams: { ...this.cleanupQueryParams(this._activatedRoute.snapshot.queryParams) },
});
}
cleanupQueryParams(params: Record<string, string> = {}) {
const clean = { ...params };
delete clean['scroll_position'];
for (const key in clean) {
if (Object.prototype.hasOwnProperty.call(clean, key)) {
if (clean[key] == undefined) {
delete clean[key];
}
}
}
return clean;
}
addBreadcrumbIfNotExists() {

View File

@@ -159,7 +159,7 @@ export class RemissionListComponentStore extends ComponentStore<RemissionState>
combineLatest([this._sourceOrSupplierChange$, this._filterChange$])
.pipe(debounceTime(500), takeUntil(this._onDestroy$))
.subscribe(([change, filter]) => {
const data = this.getCachedData({ processId: String(this.processId) });
const data = this.getCachedData();
if (change || data.items?.length === 0 || filter) {
this.clearItems();
this.search({ newSearch: true });
@@ -347,41 +347,25 @@ export class RemissionListComponentStore extends ComponentStore<RemissionState>
requiredCapacities,
}));
cacheCurrentData(params: Record<string, string> = {}) {
const qparams = this.cleanupQueryParams({ ...params, processId: String(this.processId) });
this._cache.set(qparams, {
items: this.items,
hits: this.hits,
});
cacheCurrentData() {
this._cache.set(
{ processId: String(this.processId) },
{
items: this.items,
hits: this.hits,
}
);
}
getCachedData(params: Record<string, string> = {}) {
const qparams = this.cleanupQueryParams({ ...params, processId: String(this.processId) });
getCachedData() {
return (
this._cache.get<{
items: RemissionListItem[];
hits: number;
}>(qparams) || { items: [], hits: 0 }
}>({ processId: String(this.processId) }) || { items: [], hits: 0 }
);
}
cleanupQueryParams(params: Record<string, string> = {}) {
const clean = { ...params };
delete clean['scroll_position'];
for (const key in clean) {
if (Object.prototype.hasOwnProperty.call(clean, key)) {
if (clean[key] == undefined) {
delete clean[key];
}
}
}
return clean;
}
clearItems() {
this.setFetching(true);
this.setSearchResult({ result: [], hits: 0 });

View File

@@ -81,7 +81,7 @@
<a
*ngIf="showStartRemissionAction$ | async"
routerLink="../create"
[queryParams]="{ supplier: selectedSupplierId$ | async, source: selectedSource$ | async }"
[queryParams]="queryParams$ | async"
routerLinkParam
class="bg-brand text-white font-bold text-lg px-6 py-3 rounded-full"
>

View File

@@ -72,11 +72,11 @@ export class RemissionListComponent implements OnInit, OnDestroy {
get queryParams$() {
return this._activatedRoute.queryParams.pipe(
withLatestFrom(this._remissionListStore.filter$),
map(([params, filter]) => {
withLatestFrom(this._remissionListStore.filter$, this.selectedSupplierId$, this.selectedSource$),
map(([params, filter, supplier, source]) => {
let queryParams = params;
if (filter) {
queryParams = { ...filter.getQueryParams(), ...params };
queryParams = { ...filter.getQueryParams(), ...params, supplier, source };
}
return queryParams;
})
@@ -123,7 +123,7 @@ export class RemissionListComponent implements OnInit, OnDestroy {
this._remissionListStore.setSelectedSource(source);
}
const data = this._remissionListStore.getCachedData({ processId: String(this.processId) });
const data = this._remissionListStore.getCachedData();
if (data.items?.length !== 0) {
this._remissionListStore.setItems(data.items);
this._remissionListStore.setHits(data.hits);
@@ -172,7 +172,7 @@ export class RemissionListComponent implements OnInit, OnDestroy {
this._onDestroy$.complete();
if (!!this._remissionStore.return) {
this._remissionListStore.cacheCurrentData({ processId: String(this.processId) });
this._remissionListStore.cacheCurrentData();
const params = await this._activatedRoute.queryParams.pipe(first()).toPromise();
await this.updateBreadcrumb(params);
}

View File

@@ -36,6 +36,7 @@
</a>
<button
[routerLink]="['..', 'finish-shipping-document', firstReceiptId$ | async]"
[queryParams]="queryParams$ | async"
[disabled]="finishShippingDocumentDisabled$ | async"
class="bg-brand text-white font-bold text-lg px-6 py-3 rounded-full shadow-cta whitespace-nowrap"
>