diff --git a/Gemfile b/Gemfile index c857d165..07606352 100644 --- a/Gemfile +++ b/Gemfile @@ -14,3 +14,5 @@ gem 'selenium-webdriver' gem 'sqlite3' gem 'webdrivers', require: false gem 'yard' + +gem 'geared_pagination', '~> 1.1' diff --git a/Gemfile.lock b/Gemfile.lock index ca1cc0c2..e85034fc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,7 +6,6 @@ PATH activejob (>= 6.0) activerecord (>= 6.0) job-iteration (~> 1.1) - pagy (~> 3.9) railties (>= 6.0) GEM @@ -89,6 +88,9 @@ GEM concurrent-ruby (1.1.8) crass (1.0.6) erubi (1.10.0) + geared_pagination (1.1.0) + activesupport (>= 5.0) + addressable (>= 2.5.0) globalid (0.4.2) activesupport (>= 4.2.0) i18n (1.8.9) @@ -112,7 +114,6 @@ GEM nokogiri (1.11.1) mini_portile2 (~> 2.5.0) racc (~> 1.4) - pagy (3.11.0) parallel (1.20.1) parser (2.7.2.0) ast (~> 2.4.1) @@ -206,6 +207,7 @@ PLATFORMS DEPENDENCIES capybara + geared_pagination (~> 1.1) maintenance_tasks! mocha pry-byebug diff --git a/app/controllers/maintenance_tasks/application_controller.rb b/app/controllers/maintenance_tasks/application_controller.rb index e15c030c..56b9e02a 100644 --- a/app/controllers/maintenance_tasks/application_controller.rb +++ b/app/controllers/maintenance_tasks/application_controller.rb @@ -5,8 +5,6 @@ module MaintenanceTasks # # Can be extended to add different authentication and authorization code. class ApplicationController < ActionController::Base - include Pagy::Backend - BULMA_CDN = 'https://cdn.jsdelivr.net' content_security_policy do |policy| diff --git a/app/controllers/maintenance_tasks/tasks_controller.rb b/app/controllers/maintenance_tasks/tasks_controller.rb index 7a05c86c..ba55c39b 100644 --- a/app/controllers/maintenance_tasks/tasks_controller.rb +++ b/app/controllers/maintenance_tasks/tasks_controller.rb @@ -20,7 +20,9 @@ def index def show @task = TaskData.find(params.fetch(:id)) set_refresh if @task.last_run&.active? - @pagy, @previous_runs = pagy(@task.previous_runs) + set_page_and_extract_portion_from(@task.previous_runs, + ordered_by: { created_at: :desc }) + set_paginated_headers end # Runs a given Task and redirects to the Task page. diff --git a/app/helpers/maintenance_tasks/application_helper.rb b/app/helpers/maintenance_tasks/application_helper.rb index 2a610dda..4f8755ea 100644 --- a/app/helpers/maintenance_tasks/application_helper.rb +++ b/app/helpers/maintenance_tasks/application_helper.rb @@ -4,15 +4,19 @@ module MaintenanceTasks # # @api private module ApplicationHelper - include Pagy::Frontend - - # Renders pagination for the page, if there is more than one page present. - # - # @param pagy [Pagy] the pagy instance containing pagination details, - # including the number of pages the results are spread across. - # @return [String] the HTML to render for pagination. - def pagination(pagy) - raw(pagy_bulma_nav(pagy)) if pagy.pages > 1 + # Renders pagination-related text showing the current page, total pages, + # and total number of records, if there is more than one page present. + # @param page [GearedPagination::Page] the page instance containing + # pagination details. + # @param record_type [String] the type of the recordset. + # @return [String] the HTML to render with the helpful pagination text. + def pagination_text(page, record_type) + page_count = page.recordset.page_count + if page_count > 1 + record_count = page.recordset.records_count + tag.span("Showing page #{page.number} of #{page_count} " \ + "(#{record_count} total #{record_type.pluralize(record_count)})") + end end # Renders a time element with the given datetime, worded as relative to the diff --git a/app/models/maintenance_tasks/task_data.rb b/app/models/maintenance_tasks/task_data.rb index 4d0bb3a7..b7ed7ff1 100644 --- a/app/models/maintenance_tasks/task_data.rb +++ b/app/models/maintenance_tasks/task_data.rb @@ -83,7 +83,7 @@ def code # @return [nil] if there are no Runs associated with the Task. def last_run return @last_run if defined?(@last_run) - @last_run = runs.first + @last_run = runs.last end # Returns the set of Run records associated with the Task previous to the @@ -135,7 +135,7 @@ def csv_task? private def runs - Run.where(task_name: name).with_attached_csv.order(created_at: :desc) + Run.where(task_name: name).with_attached_csv end end end diff --git a/app/views/maintenance_tasks/tasks/show.html.erb b/app/views/maintenance_tasks/tasks/show.html.erb index 3c6494ca..ed06231c 100644 --- a/app/views/maintenance_tasks/tasks/show.html.erb +++ b/app/views/maintenance_tasks/tasks/show.html.erb @@ -41,12 +41,11 @@
<%= highlight_code(code) %>
<% end %>
-<% if @previous_runs.present? %>
+<% if @task.previous_runs.any? %>