Skip to content

Commit

Permalink
Projects: add pagination
Browse files Browse the repository at this point in the history
References #352
  • Loading branch information
ybakos committed Apr 5, 2024
1 parent ffd19cb commit e2e0dfe
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class ProjectsController < ApplicationController
include Pagy::Backend

before_action :authenticate_user!, except: [:index, :map, :show]
before_action :set_project, only: [:edit, :update, :destroy]
before_action :require_author_or_admin, only: [:edit, :update, :destroy]
Expand All @@ -7,10 +9,14 @@ def index
@projects = Project.search(params[:query], params[:organization_id]).includes(affiliations: :organization).distinct.order(:name)
@organizations = Organization.all.order(:name)
respond_to do |format|
format.html
format.html do
@pagy, @projects = pagy(@projects, params: {query: params[:query], organization_id: params[:organization_id]})
end
format.csv { send_data @projects.reorder(:id).to_csv, filename: 'projects.csv' }
format.json
end
rescue Pagy::OverflowError
redirect_to projects_url
end

def map
Expand Down
7 changes: 7 additions & 0 deletions app/views/projects/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
%h5.text-secondary.text-center.mt-4.mb-4= pluralize(@projects.count, 'Project')
.projects
= render @projects
.row.mb-5
.col
- if @pagy.prev
= link_to '&lsaquo; Previous page'.html_safe, @pagy.params.merge(page: @pagy.prev), class: 'btn btn-sm btn-outline-secondary', 'aria-label': 'previous'
.col.text-right
- if @pagy.next
= link_to 'Next page &rsaquo;'.html_safe, @pagy.params.merge(page: @pagy.next), class: 'btn btn-sm btn-outline-secondary', 'aria-label': 'next'
:javascript
$('.select2').select2({
placeholder: "Select organization...",
Expand Down

0 comments on commit e2e0dfe

Please sign in to comment.