diff --git a/app/controllers/dataset_controller.rb b/app/controllers/dataset_controller.rb index e3d41a120097fdbf67390fe80a1305d2ea28fdf7..2478c32a563f2ee0569fe43d85661aefa40cc5d5 100644 --- a/app/controllers/dataset_controller.rb +++ b/app/controllers/dataset_controller.rb @@ -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 diff --git a/app/javascript/packs/controllers/dataset_controller.js b/app/javascript/packs/controllers/dataset_controller.js index e9aa9f5304ec81c9275032b818fac7ce57ef6ccb..914b258bd82838f285922420c64242b6c0d4102b 100644 --- a/app/javascript/packs/controllers/dataset_controller.js +++ b/app/javascript/packs/controllers/dataset_controller.js @@ -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 diff --git a/app/javascript/packs/controllers/viewer_controller.js b/app/javascript/packs/controllers/viewer_controller.js index 62a64dff52bc8785918b3c7f3a749651e3f0222e..42888d45c33c5a4260139210ddef5da8e7afceca 100644 --- a/app/javascript/packs/controllers/viewer_controller.js +++ b/app/javascript/packs/controllers/viewer_controller.js @@ -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 diff --git a/app/views/dataset/show.html.erb b/app/views/dataset/show.html.erb index 442dc6b51658e747cce16031cf30dca5511ebf5f..23bbb1d2a9f28595c261c91bb43720d7c156f082 100644 --- a/app/views/dataset/show.html.erb +++ b/app/views/dataset/show.html.erb @@ -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="">