fix(study-list): Use offset and limit in the dicomweb queries used to search studies with next/prev pagination in study list (#290)
This commit is contained in:
1 parent
6ad7586d25
commit
99041bebde
6 files changed
+97
-66
No files matched your search
@@ -1,8 +1,6 @@
|
||||
import { Template } from 'meteor/templating';
|
||||
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
|
||||
import 'twbs-pagination';
|
||||
|
||||
const visiblePages = 10;
|
||||
import { $ } from 'meteor/jquery';
|
||||
|
||||
Template.paginationArea.onCreated(function() {
|
||||
const instance = Template.instance();
|
||||
@@ -19,60 +17,66 @@ Template.paginationArea.onCreated(function() {
|
||||
|
||||
Template.paginationArea.onRendered(() => {
|
||||
const instance = Template.instance();
|
||||
instance.$paginationControl = instance.$('.pagination-control');
|
||||
|
||||
// Track changes on recordCount and rowsPerPage
|
||||
instance.autorun(() => {
|
||||
const recordCount = instance.data.recordCount.get();
|
||||
const rowsPerPage = instance.data.rowsPerPage.get();
|
||||
const currentPage = instance.data.currentPage.get();
|
||||
|
||||
// Destroy plugin if exists
|
||||
if (instance.$paginationControl.data().twbsPagination) {
|
||||
instance.$paginationControl.twbsPagination('destroy');
|
||||
}
|
||||
Meteor.defer(() => {
|
||||
const prevButton = instance.$('.prev')[0];
|
||||
const nextButton = instance.$('.next')[0];
|
||||
if (!prevButton || !nextButton) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (recordCount && rowsPerPage) {
|
||||
const totalPages = Math.ceil(recordCount / rowsPerPage);
|
||||
// Enable if there are potentially more records, otherwise disable it
|
||||
if (recordCount >= rowsPerPage) {
|
||||
nextButton.classList.remove('disabled');
|
||||
} else {
|
||||
nextButton.classList.add('disabled');
|
||||
}
|
||||
|
||||
// Initialize plugin
|
||||
instance.$paginationControl.twbsPagination({
|
||||
totalPages,
|
||||
visiblePages,
|
||||
onPageClick: (event, page) => {
|
||||
// Update currentPage
|
||||
// Decrease page by 1 to set currentPage
|
||||
// Since reactive table current page index starts by 0
|
||||
instance.data.currentPage.set(page - 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
// Enable the previous button if it is not the first page, otherwise disable it
|
||||
if (currentPage > 0) {
|
||||
prevButton.classList.remove('disabled');
|
||||
} else {
|
||||
prevButton.classList.add('disabled');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Template.paginationArea.onDestroyed(() => {
|
||||
const instance = Template.instance();
|
||||
if (instance.$paginationControl.data().twbsPagination) {
|
||||
instance.$paginationControl.twbsPagination('destroy');
|
||||
}
|
||||
});
|
||||
|
||||
Template.paginationArea.helpers({
|
||||
recordCount() {
|
||||
paginationButtonsEnabled() {
|
||||
const instance = Template.instance();
|
||||
return instance.data.recordCount.get();
|
||||
},
|
||||
|
||||
isRowsPerPageSelected(rowsPerPage) {
|
||||
const instance = Template.instance();
|
||||
return rowsPerPage === instance.data.rowsPerPage.get();
|
||||
const recordCount = instance.data.recordCount.get();
|
||||
const rowsPerPage = instance.data.rowsPerPage.get();
|
||||
const currentPage = instance.data.currentPage.get();
|
||||
|
||||
// Show pagination if it is not first page or there are potentially more records
|
||||
return currentPage > 0 || recordCount >= rowsPerPage;
|
||||
}
|
||||
});
|
||||
|
||||
Template.paginationArea.events({
|
||||
'click .prev > a'(event, instance) {
|
||||
const currentPage = instance.data.currentPage.get();
|
||||
instance.data.currentPage.set(currentPage - 1);
|
||||
},
|
||||
|
||||
'click .next > a'(event, instance) {
|
||||
const currentPage = instance.data.currentPage.get();
|
||||
instance.data.currentPage.set(currentPage + 1);
|
||||
},
|
||||
|
||||
'change [data-key=rowsPerPage]'(event, instance) {
|
||||
const rowsPerPage = $(event.currentTarget).data('component').value();
|
||||
|
||||
// Update rowsPerPage
|
||||
instance.data.rowsPerPage.set(parseInt(rowsPerPage, 10));
|
||||
instance.data.currentPage.set(0);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user