Merge pull request #41 in ~VLE2FE/definma-ui from b/sample-page to master

* commit '8912330d29f0aa1341acd3357dd899872b0f3335':
  Reset current page when applying filter.
  Samples get now loaded according to page.
This commit is contained in:
Hartenstein Ruben (PEA4-Fe) 2020-12-07 08:01:36 +01:00
commit dabf9fcf22

View File

@ -126,10 +126,6 @@ export class SamplesComponent implements OnInit {
this.loadTemplateKeys('material', 'type', onLoad); this.loadTemplateKeys('material', 'type', onLoad);
this.loadTemplateKeys('condition', 'notes.comment', onLoad); this.loadTemplateKeys('condition', 'notes.comment', onLoad);
this.loadTemplateKeys('measurement', 'status', onLoad); this.loadTemplateKeys('measurement', 'status', onLoad);
if("currentPage" in localStorage){
this.page = Number(localStorage.getItem("currentPage"));
}
} }
loadTemplateKeys(collection, insertBefore, f) { loadTemplateKeys(collection, insertBefore, f) {
@ -183,6 +179,9 @@ export class SamplesComponent implements OnInit {
} }
this.updateActiveKeys(); this.updateActiveKeys();
} }
if(options.firstPage){
this.storage.set('currentPage', 1);
}
this.loadSamplesQueue.push(options); this.loadSamplesQueue.push(options);
if (this.loadSamplesQueue.length <= 1) { // nothing queued up if (this.loadSamplesQueue.length <= 1) { // nothing queued up
this.sampleLoader(this.loadSamplesQueue[0]); 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: { sampleUrl(options: {
@ -303,11 +305,11 @@ export class SamplesComponent implements OnInit {
} }
loadPage(delta) { 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; return;
} }
this.page += delta; this.page += delta;
localStorage.setItem("currentPage", this.page.toString()); this.storage.set('currentPage', this.page);
this.loadSamples({toPage: delta}); this.loadSamples({toPage: delta});
} }