add pagy, improve checks#index
This commit is contained in:
parent
c44c9ccaba
commit
6d3a269231
11 changed files with 274 additions and 10 deletions
1
Gemfile
1
Gemfile
|
|
@ -51,6 +51,7 @@ gem 'bootstrap_form'
|
|||
gem 'caxlsx'
|
||||
gem 'caxlsx_rails'
|
||||
gem 'image_processing', '~> 1.2'
|
||||
gem 'pagy', '~> 9.0'
|
||||
gem 'prawn-rails'
|
||||
gem 'sablon'
|
||||
|
||||
|
|
|
|||
|
|
@ -178,6 +178,7 @@ GEM
|
|||
racc (~> 1.4)
|
||||
nokogiri (1.16.6-x86_64-linux)
|
||||
racc (~> 1.4)
|
||||
pagy (9.0.2)
|
||||
parallel (1.25.1)
|
||||
parser (3.3.4.0)
|
||||
ast (~> 2.4.1)
|
||||
|
|
@ -350,6 +351,7 @@ DEPENDENCIES
|
|||
image_processing (~> 1.2)
|
||||
jbuilder
|
||||
jsbundling-rails
|
||||
pagy (~> 9.0)
|
||||
prawn-rails
|
||||
puma (>= 5.0)
|
||||
rails (~> 7.1.3, >= 7.1.3.4)
|
||||
|
|
|
|||
|
|
@ -54,3 +54,7 @@
|
|||
border: 0;
|
||||
border-left: 4px solid var(--bs-warning);
|
||||
}
|
||||
|
||||
.navbar-brand {
|
||||
color: $pink;
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationController < ActionController::Base
|
||||
include Pagy::Backend
|
||||
|
||||
before_action :initialize_navbar
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ class ChecksController < ApplicationController
|
|||
|
||||
# GET /checks or /checks.json
|
||||
def index
|
||||
@checks = Check.all
|
||||
@pagy, @checks = pagy(Check.search(filter_params[:s]))
|
||||
end
|
||||
|
||||
# GET /checks/1 or /checks/1.json
|
||||
|
|
@ -66,6 +66,10 @@ class ChecksController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def filter_params
|
||||
@filter_params ||= params.permit(filter: %i[s level])[:filter] || {}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ApplicationHelper
|
||||
include Pagy::Frontend
|
||||
|
||||
delegate :filter_params, to: :controller
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,4 +4,8 @@ class Check < ApplicationRecord
|
|||
enum :level, %i[A AA AAA]
|
||||
|
||||
has_rich_text :success_criterion_html
|
||||
|
||||
scope :search, lambda { |term|
|
||||
joins("INNER JOIN action_text_rich_texts ON action_text_rich_texts.record_id = checks.id AND record_type = 'Check'").where('checks.name LIKE :term OR action_text_rich_texts.body LIKE :term', term: "%#{term}%")
|
||||
}
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,17 @@
|
|||
<div id="<%= dom_id checklist_entry %>" class="row hover-row py-1 p-1">
|
||||
<div class="col">
|
||||
<%= button_to tag.i(class: "bi bi-arrow-down"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position + 1 }} %>
|
||||
<%= button_to tag.i(class: "bi bi-arrow-up"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 pe-3 float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position - 1 }} %>
|
||||
<%= button_to tag.i(class: "bi bi-trash"), checklist_entry_path(checklist_entry), method: :delete, class: "btn btn-link p-0 ps-3 float-end" %>
|
||||
<%= link_to tag.i(class: "bi bi-pencil"), edit_checklist_entry_path(checklist_entry), class: "float-end" %>
|
||||
<% is_first = checklist_entry == checklist_entry.checklist.checklist_entries.first %>
|
||||
<% is_last = checklist_entry == checklist_entry.checklist.checklist_entries.last %>
|
||||
|
||||
<div id="<%= dom_id checklist_entry %>" class="hover-row py-1">
|
||||
<div class="d-flex">
|
||||
<div style="width: 56px">
|
||||
<%= button_to tag.i(class: "bi bi-arrow-down"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 #{"pe-3" if is_last } float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position + 1 }} unless is_last %>
|
||||
<%= button_to tag.i(class: "bi bi-arrow-up"), checklist_entry_path(checklist_entry), method: :patch, class: "btn btn-link p-0 pe-3 float-start", data: { turbo_frame: "checklist_entries" }, params: { checklist_entry: { position: checklist_entry.position - 1 }} unless is_first %>
|
||||
</div>
|
||||
<div class="d-inline-flex flex-grow-1">
|
||||
<%# checklist_entry.position %>
|
||||
<%= link_to(checklist_entry.check.name, checklist_entry.check, data: { turbo_frame: "_top" }) %>
|
||||
<%= link_to(checklist_entry.check.name, checklist_entry.check, data: { turbo_frame: "_top" }, class: "flex-grow-1") %>
|
||||
<%= button_to tag.i(class: "bi bi-trash"), checklist_entry_path(checklist_entry), method: :delete, class: "btn btn-link" %>
|
||||
<%= link_to tag.i(class: "bi bi-pencil"), edit_checklist_entry_path(checklist_entry), class: "btn btn-link" %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,18 @@
|
|||
<h1><%= t("scaffold.pagetitle_index", model: Check.model_name.human(count: 2)) %></h1>
|
||||
<%= bootstrap_form_with(url: checks_path(page: params[:page]), method: :get, scope: :filter) do |form| %>
|
||||
<%= form.hidden_field :page, value: params[:page] if params[:page] %>
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<%= form.text_field(:s, placeholder: "suchen...", hide_label: true, value: filter_params[:s]) %>
|
||||
</div>
|
||||
<div class="col">
|
||||
<%= form.submit name: "", value: "Suchen" %>
|
||||
<%= link_to "Filter löschen", checks_path, class: "btn btn-outline-secondary" if filter_params[:s] %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%== pagy_info(@pagy) %>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
|
|
@ -20,6 +33,8 @@
|
|||
</tbody>
|
||||
</table>
|
||||
|
||||
<%== pagy_bootstrap_nav(@pagy) %>
|
||||
|
||||
<div class="action-row">
|
||||
<%= link_to t("scaffold.link_new", model: Check.model_name.human), new_check_path %>
|
||||
</div>
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
<nav class="navbar navbar-expand-lg bg-body-tertiary">
|
||||
<div class="container">
|
||||
<a class="navbar-brand" href="<%= root_path %>">A11yist</a>
|
||||
<a class="navbar-brand" href="<%= root_path %>">
|
||||
<%= tag.i(class: "bi bi-universal-access") %>
|
||||
</a>
|
||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
|
|
|||
220
config/initializers/pagy.rb
Normal file
220
config/initializers/pagy.rb
Normal file
|
|
@ -0,0 +1,220 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Pagy initializer file (9.0.2)
|
||||
# Customize only what you really need and notice that the core Pagy works also without any of the following lines.
|
||||
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
||||
|
||||
|
||||
# Pagy Variables
|
||||
# See https://ddnexus.github.io/pagy/docs/api/pagy#variables
|
||||
# You can set any pagy variable as a Pagy::DEFAULT. They can also be overridden per instance by just passing them to
|
||||
# Pagy.new|Pagy::Countless.new|Pagy::Calendar::*.new or any of the #pagy* controller methods
|
||||
# Here are the few that make more sense as DEFAULTs:
|
||||
# Pagy::DEFAULT[:limit] = 20 # default
|
||||
# Pagy::DEFAULT[:size] = 7 # default
|
||||
# Pagy::DEFAULT[:ends] = true # default
|
||||
# Pagy::DEFAULT[:page_param] = :page # default
|
||||
# Pagy::DEFAULT[:count_args] = [] # example for non AR ORMs
|
||||
# Pagy::DEFAULT[:max_pages] = 3000 # example
|
||||
|
||||
|
||||
# Extras
|
||||
# See https://ddnexus.github.io/pagy/categories/extra
|
||||
|
||||
|
||||
# Legacy Compatibility Extras
|
||||
|
||||
# Size extra: Enable the Array type for the `:size` variable (e.g. `size: [1,4,4,1]`)
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/size
|
||||
# require 'pagy/extras/size' # must be required before the other extras
|
||||
|
||||
|
||||
# Backend Extras
|
||||
|
||||
# Arel extra: For better performance utilizing grouped ActiveRecord collections:
|
||||
# See: https://ddnexus.github.io/pagy/docs/extras/arel
|
||||
# require 'pagy/extras/arel'
|
||||
|
||||
# Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/array
|
||||
# require 'pagy/extras/array'
|
||||
|
||||
# Calendar extra: Add pagination filtering by calendar time unit (year, quarter, month, week, day)
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/calendar
|
||||
# require 'pagy/extras/calendar'
|
||||
# Default for each calendar unit class in IRB:
|
||||
# >> Pagy::Calendar::Year::DEFAULT
|
||||
# >> Pagy::Calendar::Quarter::DEFAULT
|
||||
# >> Pagy::Calendar::Month::DEFAULT
|
||||
# >> Pagy::Calendar::Week::DEFAULT
|
||||
# >> Pagy::Calendar::Day::DEFAULT
|
||||
#
|
||||
# Uncomment the following lines, if you need calendar localization without using the I18n extra
|
||||
# module LocalizePagyCalendar
|
||||
# def localize(time, opts)
|
||||
# ::I18n.l(time, **opts)
|
||||
# end
|
||||
# end
|
||||
# Pagy::Calendar.prepend LocalizePagyCalendar
|
||||
|
||||
# Countless extra: Paginate without any count, saving one query per rendering
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/countless
|
||||
# require 'pagy/extras/countless'
|
||||
# Pagy::DEFAULT[:countless_minimal] = false # default (eager loading)
|
||||
|
||||
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/elasticsearch_rails
|
||||
# Default :pagy_search method: change only if you use also
|
||||
# the searchkick or meilisearch extra that defines the same
|
||||
# Pagy::DEFAULT[:elasticsearch_rails_pagy_search] = :pagy_search
|
||||
# Default original :search method called internally to do the actual search
|
||||
# Pagy::DEFAULT[:elasticsearch_rails_search] = :search
|
||||
# require 'pagy/extras/elasticsearch_rails'
|
||||
|
||||
# Headers extra: http response headers (and other helpers) useful for API pagination
|
||||
# See http://ddnexus.github.io/pagy/extras/headers
|
||||
# require 'pagy/extras/headers'
|
||||
# Pagy::DEFAULT[:headers] = { page: 'Current-Page',
|
||||
# limit: 'Page-Items',
|
||||
# count: 'Total-Count',
|
||||
# pages: 'Total-Pages' } # default
|
||||
|
||||
# Keyset extra: Paginate with the Pagy keyset pagination technique
|
||||
# See http://ddnexus.github.io/pagy/extras/keyset
|
||||
# require 'pagy/extras/keyset'
|
||||
|
||||
# Meilisearch extra: Paginate `Meilisearch` result objects
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/meilisearch
|
||||
# Default :pagy_search method: change only if you use also
|
||||
# the elasticsearch_rails or searchkick extra that define the same method
|
||||
# Pagy::DEFAULT[:meilisearch_pagy_search] = :pagy_search
|
||||
# Default original :search method called internally to do the actual search
|
||||
# Pagy::DEFAULT[:meilisearch_search] = :ms_search
|
||||
# require 'pagy/extras/meilisearch'
|
||||
|
||||
# Metadata extra: Provides the pagination metadata to Javascript frameworks like Vue.js, react.js, etc.
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/metadata
|
||||
# you must require the JS Tools internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
|
||||
# require 'pagy/extras/js_tools'
|
||||
# require 'pagy/extras/metadata'
|
||||
# For performance reasons, you should explicitly set ONLY the metadata you use in the frontend
|
||||
# Pagy::DEFAULT[:metadata] = %i[scaffold_url page prev next last] # example
|
||||
|
||||
# Searchkick extra: Paginate `Searchkick::Results` objects
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/searchkick
|
||||
# Default :pagy_search method: change only if you use also
|
||||
# the elasticsearch_rails or meilisearch extra that defines the same
|
||||
# DEFAULT[:searchkick_pagy_search] = :pagy_search
|
||||
# Default original :search method called internally to do the actual search
|
||||
# Pagy::DEFAULT[:searchkick_search] = :search
|
||||
# require 'pagy/extras/searchkick'
|
||||
# uncomment if you are going to use Searchkick.pagy_search
|
||||
# Searchkick.extend Pagy::Searchkick
|
||||
|
||||
|
||||
# Frontend Extras
|
||||
|
||||
# Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/bootstrap
|
||||
require 'pagy/extras/bootstrap'
|
||||
|
||||
# Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/bulma
|
||||
# require 'pagy/extras/bulma'
|
||||
|
||||
# Pagy extra: Add the pagy styled versions of the javascript-powered navs
|
||||
# and a few other components to the Pagy::Frontend module.
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/pagy
|
||||
# require 'pagy/extras/pagy'
|
||||
|
||||
# Multi size var used by the *_nav_js helpers
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/pagy#steps
|
||||
# Pagy::DEFAULT[:steps] = { 0 => 5, 540 => 7, 720 => 9 } # example
|
||||
|
||||
|
||||
# Feature Extras
|
||||
|
||||
# Gearbox extra: Automatically change the limit per page depending on the page number
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/gearbox
|
||||
# require 'pagy/extras/gearbox'
|
||||
# set to false only if you want to make :gearbox_extra an opt-in variable
|
||||
# Pagy::DEFAULT[:gearbox_extra] = false # default true
|
||||
# Pagy::DEFAULT[:gearbox_limit] = [15, 30, 60, 100] # default
|
||||
|
||||
# Limit extra: Allow the client to request a custom limit per page with an optional selector UI
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/limit
|
||||
# require 'pagy/extras/limit'
|
||||
# set to false only if you want to make :limit_extra an opt-in variable
|
||||
# Pagy::DEFAULT[:limit_extra] = false # default true
|
||||
# Pagy::DEFAULT[:limit_param] = :limit # default
|
||||
# Pagy::DEFAULT[:limit_max] = 100 # default
|
||||
|
||||
# Overflow extra: Allow for easy handling of overflowing pages
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/overflow
|
||||
# require 'pagy/extras/overflow'
|
||||
# Pagy::DEFAULT[:overflow] = :empty_page # default (other options: :last_page and :exception)
|
||||
|
||||
# Trim extra: Remove the page=1 param from links
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/trim
|
||||
# require 'pagy/extras/trim'
|
||||
# set to false only if you want to make :trim_extra an opt-in variable
|
||||
# Pagy::DEFAULT[:trim_extra] = false # default true
|
||||
|
||||
# Standalone extra: Use pagy in non Rack environment/gem
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/standalone
|
||||
# require 'pagy/extras/standalone'
|
||||
# Pagy::DEFAULT[:url] = 'http://www.example.com/subdir' # optional default
|
||||
|
||||
# Jsonapi extra: Implements JSON:API specifications
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/jsonapi
|
||||
# require 'pagy/extras/jsonapi' # must be required after the other extras
|
||||
# set to false only if you want to make :jsonapi an opt-in variable
|
||||
# Pagy::DEFAULT[:jsonapi] = false # default true
|
||||
|
||||
# Rails
|
||||
# Enable the .js file required by the helpers that use javascript
|
||||
# (pagy*_nav_js, pagy*_combo_nav_js, and pagy_limit_selector_js)
|
||||
# See https://ddnexus.github.io/pagy/docs/api/javascript
|
||||
|
||||
# With the asset pipeline
|
||||
# Sprockets need to look into the pagy javascripts dir, so add it to the assets paths
|
||||
# Rails.application.config.assets.paths << Pagy.root.join('javascripts')
|
||||
|
||||
# I18n
|
||||
|
||||
# Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem
|
||||
# See https://ddnexus.github.io/pagy/docs/api/i18n
|
||||
# Notice: No need to configure anything in this section if your app uses only "en"
|
||||
# or if you use the i18n extra below
|
||||
#
|
||||
# Examples:
|
||||
# load the "de" built-in locale:
|
||||
# Pagy::I18n.load(locale: 'de')
|
||||
#
|
||||
# load the "de" locale defined in the custom file at :filepath:
|
||||
# Pagy::I18n.load(locale: 'de', filepath: 'path/to/pagy-de.yml')
|
||||
#
|
||||
# load the "de", "en" and "es" built-in locales:
|
||||
# (the first passed :locale will be used also as the default_locale)
|
||||
# Pagy::I18n.load({ locale: 'de' },
|
||||
# { locale: 'en' },
|
||||
# { locale: 'es' })
|
||||
#
|
||||
# load the "en" built-in locale, a custom "es" locale,
|
||||
# and a totally custom locale complete with a custom :pluralize proc:
|
||||
# (the first passed :locale will be used also as the default_locale)
|
||||
# Pagy::I18n.load({ locale: 'en' },
|
||||
# { locale: 'es', filepath: 'path/to/pagy-es.yml' },
|
||||
# { locale: 'xyz', # not built-in
|
||||
# filepath: 'path/to/pagy-xyz.yml',
|
||||
# pluralize: lambda{ |count| ... } )
|
||||
|
||||
|
||||
# I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory
|
||||
# than the default pagy internal i18n (see above)
|
||||
# See https://ddnexus.github.io/pagy/docs/extras/i18n
|
||||
# require 'pagy/extras/i18n'
|
||||
|
||||
|
||||
# When you are done setting your own default freeze it, so it will not get changed accidentally
|
||||
Pagy::DEFAULT.freeze
|
||||
Loading…
Add table
Add a link
Reference in a new issue