Skip to content
Snippets Groups Projects
Commit fa2327bb authored by smayer's avatar smayer
Browse files

WIP: Bugfix for paginating datasets

parent ed3508e0
No related branches found
No related tags found
1 merge request!2Merging development into onb as preparation for Annolyzer release
......@@ -15,6 +15,7 @@ class DatasetController < ApplicationController
@dataset = Dataset.find(params[:id])
@current_page = params[:page] || 1
@per_page = params[:per_page] || 10
@nb_pages = params[:nb_pages] || (@dataset.nb_articles / @per_page).to_i + 1
session[:working_dataset] = @dataset.id
# puts "The session now has working_dataset " + String(session[:working_dataset])
end
......@@ -204,6 +205,7 @@ class DatasetController < ApplicationController
out[:pagination] = render_to_string(layout: false,
partial: "pagination",
locals: { nb_pages: res[:nb_pages].to_i, current_page: params[:page].to_i })
out[:nb_pages] = res[:nb_pages]
render json: out
end
......
......@@ -4,7 +4,7 @@ import {SearchAPI} from "../utils/search_api";
export default class extends Controller {
static targets = [ ]
static values = { id: Number, currentPage: Number, perPage: Number, sort: String, sortOrder: String, selectedDocuments: Array }
static values = { id: Number, currentPage: Number, nbPages: Number, perPage: Number, sort: String, sortOrder: String, selectedDocuments: Array }
connect() {
this.loadDocuments(this.idValue, this.currentPageValue, this.perPageValue, this.sortValue, this.sortOrderValue, "article")
......@@ -67,6 +67,7 @@ export default class extends Controller {
DatasetAPI.paginateDataset(datasetId, page, per_page, sort, sort_order, type, (data) => {
$("#documents-list").html(data.documents)
$("#results_navigation").html(data.pagination)
console.log(data.nb_pages)
})
}
......@@ -80,7 +81,7 @@ export default class extends Controller {
event.preventDefault()
if (this.currentPageValue > 1) {
this.currentPageValue--
this.loadDocuments(this.idValue, this.currentPageValue, this.perPageValue, this.sortValue, this.sortOrderValue, "all")
this.loadDocuments(this.idValue, this.currentPageValue, this.perPageValue, this.sortValue, this.sortOrderValue, $("#doctype_selection input:checked").data("doctype"))
}
}
......@@ -88,14 +89,14 @@ export default class extends Controller {
event.preventDefault()
if (this.currentPageValue < this.nbPagesValue) {
this.currentPageValue++
this.loadDocuments(this.idValue, this.currentPageValue, this.perPageValue, this.sortValue, this.sortOrderValue, "all")
this.loadDocuments(this.idValue, this.currentPageValue, this.perPageValue, this.sortValue, this.sortOrderValue, $("#doctype_selection input:checked").data("doctype"))
}
}
page_button(event) {
event.preventDefault()
this.currentPageValue = event.target.textContent
this.loadDocuments(this.idValue, this.currentPageValue, this.perPageValue, this.sortValue, this.sortOrderValue, "all")
this.loadDocuments(this.idValue, this.currentPageValue, this.perPageValue, this.sortValue, this.sortOrderValue, $("#doctype_selection input:checked").data("doctype"))
}
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import Sortable from 'sortablejs'
export default class extends Controller {
static targets = ['currentPage', 'articleOverlay', 'selectedArticlePanel', 'addArticleButton', 'addCompoundArticleButton', 'compoundArticlePanel']
static values = {currentPage: Number, nbpages: Number, pages: Array, articles: Array, selectedArticles: Array, issueId: String, compoundMode: Boolean}
static values = {currentPage: Number, nbPages: Number, pages: Array, articles: Array, selectedArticles: Array, issueId: String, compoundMode: Boolean}
isDragged = false
viewer = null
......
......@@ -3,8 +3,9 @@
<div class="row"
data-controller="dataset"
data-dataset-id-value="<%= @dataset.id %>"
data-dataset-current-page-value="1"
data-dataset-per-page-value="10"
data-dataset-current-page-value="<%= @current_page %>"
data-dataset-nb-pages-value="<%= @nb_pages %>"
data-dataset-per-page-value="<%= @per_page %>"
data-dataset-sort-value="default"
data-dataset-sort-order-value="asc"
data-dataset-selected-documents-value="">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment