Skip to content

Commit

Permalink
States: paginate projects
Browse files Browse the repository at this point in the history
References #370
  • Loading branch information
ybakos committed Apr 29, 2024
1 parent 20cf12a commit cb72a54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/states_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'hash'

class StatesController < ApplicationController
include Pagy::Backend

def index
@states = State.with_projects.without_geom.order('projects_count DESC, name')
Expand All @@ -18,6 +19,7 @@ def show
@chart_project_count = @projects.group_by_day(:implementation_date, format: "%d %b %Y").count.accumulate!
@chart_structure_count = @projects.group_by_day(:implementation_date).sum(:number_of_structures).accumulate!
@chart_total_length = @projects.group_by_day(:implementation_date).sum(:length).accumulate!.transform_values! { |v| v / 1000.0 }
@pagy, @projects = pagy(@projects)
end
end
rescue ActiveRecord::RecordNotFound
Expand Down
7 changes: 7 additions & 0 deletions app/views/states/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@
.container.mt-5
%h2 State Projects
= render @projects
.row.mb-5
.col.text-right
- if @pagy.prev
= link_to '&lsaquo; Previous page'.html_safe, @pagy.params.merge(page: @pagy.prev), class: 'btn btn-outline-primary', 'aria-label': 'previous'
.col
- if @pagy.next
= link_to 'Next page &rsaquo;'.html_safe, @pagy.params.merge(page: @pagy.next), class: 'btn btn-outline-primary', 'aria-label': 'next'
:javascript
var ctx = document.getElementById('myChart').getContext('2d');

Expand Down

0 comments on commit cb72a54

Please sign in to comment.