diff --git a/src/app/samples/samples.component.ts b/src/app/samples/samples.component.ts index 6f38f19..9ec3226 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) { @@ -168,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 @@ -183,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]); @@ -210,6 +209,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 +305,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}); }