From 42b9eb979a8f0ba36ec8fd253a144e4d5ac12d04 Mon Sep 17 00:00:00 2001 From: "Ruben Hartenstein (PEA4-Fe)" Date: Fri, 4 Dec 2020 11:37:25 +0100 Subject: [PATCH 1/2] Samples get now loaded according to page. --- src/app/samples/samples.component.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/app/samples/samples.component.ts b/src/app/samples/samples.component.ts index 6f38f19..5eb4b0e 100644 --- a/src/app/samples/samples.component.ts +++ b/src/app/samples/samples.component.ts @@ -105,7 +105,7 @@ export class SamplesComponent implements OnInit { const onLoad = () => { if ((--this.loading) <= 0) { this.loadSamples(); - } + } }; this.calcFieldSelectKeys(); @@ -126,10 +126,6 @@ export class SamplesComponent implements OnInit { this.loadTemplateKeys('material', 'type', onLoad); this.loadTemplateKeys('condition', 'notes.comment', onLoad); this.loadTemplateKeys('measurement', 'status', onLoad); - - if("currentPage" in localStorage){ - this.page = Number(localStorage.getItem("currentPage")); - } } loadTemplateKeys(collection, insertBefore, f) { @@ -210,6 +206,9 @@ export class SamplesComponent implements OnInit { } } }); + if(this.storage.get('currentPage') !== this.page){ + this.loadPage(Number(this.storage.get('currentPage')) - this.page); + } } sampleUrl(options: { @@ -303,11 +302,11 @@ export class SamplesComponent implements OnInit { } loadPage(delta) { - if (!/[0-9]+/.test(delta) || this.page + delta < 1 || this.page + delta > this.pages) { // invalid delta + if (!/[0-9]+/.test(delta) || this.page + delta < 1) { // invalid delta return; - } - this.page += delta; - localStorage.setItem("currentPage", this.page.toString()); + } + this.page += delta; + this.storage.set('currentPage', this.page); this.loadSamples({toPage: delta}); } From 8912330d29f0aa1341acd3357dd899872b0f3335 Mon Sep 17 00:00:00 2001 From: "Ruben Hartenstein (PEA4-Fe)" Date: Fri, 4 Dec 2020 13:55:04 +0100 Subject: [PATCH 2/2] Reset current page when applying filter. --- src/app/samples/samples.component.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app/samples/samples.component.ts b/src/app/samples/samples.component.ts index 5eb4b0e..9ec3226 100644 --- a/src/app/samples/samples.component.ts +++ b/src/app/samples/samples.component.ts @@ -164,7 +164,7 @@ export class SamplesComponent implements OnInit { f(); }); } - + // set toPage to null to reload first page, queues calls loadSamples(options: LoadSamplesOptions = {}, event = null) { if (event) { // adjust active keys @@ -179,6 +179,9 @@ export class SamplesComponent implements OnInit { } this.updateActiveKeys(); } + if(options.firstPage){ + this.storage.set('currentPage', 1); + } this.loadSamplesQueue.push(options); if (this.loadSamplesQueue.length <= 1) { // nothing queued up this.sampleLoader(this.loadSamplesQueue[0]);