Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions app/controllers/inner_performance/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

module InnerPerformance
class EventsController < ApplicationController
include Pagy::Backend
RESULTS_PER_PAGE = 50

def index
@q = InnerPerformance::Event.all.ransack(params[:q])
@current_page = params[:page].presence&.to_i

if current_page.nil? || current_page < 1
@current_page = 1
end

@q = InnerPerformance::Event
.all
.limit(RESULTS_PER_PAGE)
.offset(RESULTS_PER_PAGE * (@current_page - 1))
.ransack(params[:q])

@q.sorts = "created_at desc" if @q.sorts.empty?
@pagy, @events = pagy(@q.result)

@events = @q.result
end

def show
Expand Down
2 changes: 0 additions & 2 deletions app/helpers/inner_performance/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

module InnerPerformance
module ApplicationHelper
include Pagy::Frontend

# Based on https://stackoverflow.com/a/45428183/552936 and
# https://datadome.co/learning-center/how-to-reduce-server-response-time/
def row_class_from_duration(duration)
Expand Down
10 changes: 9 additions & 1 deletion app/views/inner_performance/events/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@
</tbody>
</table>

<%== pagy_nav(@pagy) if @pagy.pages > 1 %>
<div style="text-align: center;">
<% if @current_page > 1 %>
<%= link_to "Prev Page", params.to_unsafe_h(page: @current_page - 1), style: "margin-right: 20px;" %>
<% end %>

<% if @events.size == InnerPerformance::EventsController::RESULTS_PER_PAGE %>
<%= link_to "Next Page", params.to_unsafe_h(page: @current_page + 1) %>
<% end %>
</div>
1 change: 0 additions & 1 deletion inner_performance.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ Gem::Specification.new do |spec|
end

spec.add_dependency("activejob", ">= 7.1.5")
spec.add_dependency("pagy", ">= 9.3.1")
spec.add_dependency("rails", ">= 7.1.5")
spec.add_dependency("ransack", ">= 4.2.1")

Expand Down
1 change: 0 additions & 1 deletion lib/inner_performance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
require_relative "inner_performance/current_request"

require "ransack"
require "pagy"

module InnerPerformance
class << self
Expand Down