Intalled pagy and applyed to admin/users index

This commit is contained in:
2024-09-16 18:16:42 +02:00
parent 11d944b64c
commit e6cbeb9596
10 changed files with 283 additions and 27 deletions

View File

@@ -82,3 +82,5 @@ gem "authentication-zero", "~> 3.0"
gem "pwned" gem "pwned"
gem "action_policy", "~> 0.7.1" gem "action_policy", "~> 0.7.1"
gem "pagy", "~> 9.0"

View File

@@ -186,6 +186,7 @@ GEM
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux) nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
pagy (9.0.9)
parallel (1.26.3) parallel (1.26.3)
parser (3.3.5.0) parser (3.3.5.0)
ast (~> 2.4.1) ast (~> 2.4.1)
@@ -371,6 +372,7 @@ DEPENDENCIES
jbuilder jbuilder
kredis kredis
letter_opener letter_opener
pagy (~> 9.0)
pdf-reader (~> 2.12) pdf-reader (~> 2.12)
puma (>= 5.0) puma (>= 5.0)
pwned pwned

View File

@@ -1,7 +1,10 @@
@import "pagy.tailwind.css";
@tailwind base; @tailwind base;
@tailwind components; @tailwind components;
@tailwind utilities; @tailwind utilities;
@layer components { @layer components {
.btn { .btn {
@apply px-4 py-2 font-semibold text-white transition-colors duration-100 bg-opacity-100 shadow bg-hsrm-gray-light hover:bg-opacity-75 ; @apply px-4 py-2 font-semibold text-white transition-colors duration-100 bg-opacity-100 shadow bg-hsrm-gray-light hover:bg-opacity-75 ;

View File

@@ -0,0 +1,21 @@
.pagy {
@apply flex pt-2 space-x-1 font-semibold text-gray-500;
a:not(.gap) {
@apply block px-3 py-1 bg-gray-200 shadow-lg;
&:hover {
@apply bg-gray-300;
}
&:not([href]) { /* disabled links */
@apply text-gray-300 bg-gray-100 cursor-default;
}
&.current {
@apply text-white bg-hsrm-red;
}
}
label {
@apply inline-block whitespace-nowrap bg-gray-200 px-3 py-0.5;
input {
@apply bg-gray-100 border-none rounded-md;
}
}
}

View File

@@ -4,6 +4,7 @@ class Admin::UsersController < ApplicationController
def index def index
@users = User.all.order(:lastname, :firstname) @users = User.all.order(:lastname, :firstname)
@pagy, @records = pagy(@users, limit: 20)
end end
def edit def edit

View File

@@ -1,4 +1,6 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
include Pagy::Backend
before_action :set_current_request_details before_action :set_current_request_details
before_action :authenticate_user! before_action :authenticate_user!

View File

@@ -1,4 +1,6 @@
module ApplicationHelper module ApplicationHelper
include Pagy::Frontend
def icon(name, options = {}) def icon(name, options = {})
options[:title] ||= name.underscore.humanize options[:title] ||= name.underscore.humanize
options[:aria] = true options[:aria] = true

View File

@@ -1,7 +1,7 @@
<%= turbo_frame_tag dom_id(user) do %> <%= turbo_frame_tag dom_id(user) do %>
<tr id="<%= dom_id user %>" class="bg-role-<%= user.role %>-light odd:bg-opacity-25 even:bg-opacity-15 text-hsrm-gray whitespace-nowrap hover:bg-opacity-30""> <tr id="<%= dom_id user %>" class="bg-role-<%= user.role %>-light odd:bg-opacity-25 even:bg-opacity-15 text-hsrm-gray whitespace-nowrap hover:bg-opacity-30"">
<td class="p-2 py-3 text-center"> <td class="p-2 py-3 text-center">
<%= link_to admin_user_path(user) do %> <%= link_to admin_user_path(user), target: "_top" do %>
<span class="badge badge-xl text-role-<%= user.role %> bg-role-<%= user.role %>-light rounded-lg shadow"> <span class="badge badge-xl text-role-<%= user.role %> bg-role-<%= user.role %>-light rounded-lg shadow">
<%= user.id %> <%= user.id %>
</span> </span>
@@ -19,15 +19,15 @@
<%= user.role %> <%= user.role %>
</span> </span>
</td> </td>
<td class="p-2 py-3 flex space-x-2 justify-center"> <td class="flex justify-center p-2 py-3 space-x-2">
<%= link_to do %> <%= link_to do %>
<span class="badge block w-28 bg-gray-300 hover:bg-role-user-light hover:texft-black">User</span> <span class="block bg-gray-300 badge w-28 hover:bg-role-user-light hover:texft-black">User</span>
<% end unless user.user? %> <% end unless user.user? %>
<%= link_to do %> <%= link_to do %>
<span class="badge block w-28 bg-gray-300 hover:bg-role-operator-light hover:texft-black">Operator</span> <span class="block bg-gray-300 badge w-28 hover:bg-role-operator-light hover:texft-black">Operator</span>
<% end unless user.operator? %> <% end unless user.operator? %>
<%= link_to do %> <%= link_to do %>
<span class="badge block w-28 bg-gray-300 hover:bg-role-admin-light hover:texft-black">Admin</span> <span class="block bg-gray-300 badge w-28 hover:bg-role-admin-light hover:texft-black">Admin</span>
<% end unless user.admin? %> <% end unless user.admin? %>
</td> </td>
</tr> </tr>

View File

@@ -1,23 +1,26 @@
<div class="w-full"> <%= turbo_frame_tag "admin_user" do %>
<% content_for :title, "Current Print Jobs" %> <div class="w-full">
<div class="flex items-center justify-between py-4"> <% content_for :title, "Current Print Jobs" %>
<h1 class="text-4xl font-bold text-hsrm-gray">Benutzerliste</h1> <div class="flex items-center justify-between py-4">
<%= link_to "Filter", "#", class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors hover:bg-hsrm-red-light text-white block font-medium" %> <h1 class="text-4xl font-bold text-hsrm-gray">Benutzerliste</h1>
<%= link_to "Filter", "#", class: "px-3 py-2 bg-hsrm-red drop-shadow-lg transition-colors hover:bg-hsrm-red-light text-white block font-medium" %>
</div>
<div class="min-w-full overflow-auto shadow-lg">
<table class="w-full py-8 table-auto">
<thead class="font-semibold tracking-wide bg-gray-200 border-b-2 border-gray-300 text text-hsrm-gray">
<tr>
<th class="w-1 p-2 py-3 text-center">ID</th>
<th class="w-1 p-2 py-3 text-left">Name</th>
<th class="p-2 py-3 text-left">E-Mail-Adresse</th>
<th class="w-1 p-2 py-3 text-center">Rolle</th>
<th class="w-1 p-2 py-3 text-center">Rolle ändern zu</th>
</tr>
</thead>
<tbody id='jobs' class="divide-y divivde-gray-300">
<%= render partial: "user_tr", collection: @records, as: :user %>
</tbody>
</table>
</div>
<%== pagy_nav(@pagy) %>
</div> </div>
<div class="min-w-full overflow-auto shadow-lg"> <% end %>
<table class="w-full py-8 table-auto">
<thead class="font-semibold tracking-wide bg-gray-200 border-b-2 border-gray-300 text text-hsrm-gray">
<tr>
<th class="w-1 p-2 py-3 text-center">ID</th>
<th class="w-1 p-2 py-3 text-left">Name</th>
<th class="p-2 py-3 text-left">E-Mail-Adresse</th>
<th class="w-1 p-2 py-3 text-center">Rolle</th>
<th class="w-1 p-2 py-3 text-center">Rolle ändern zu</th>
</tr>
</thead>
<tbody id='jobs' class="divide-y divivde-gray-300">
<%= render partial: "user_tr", collection: @users, as: :user %>
</tbody>
</table>
</div>
</div>

220
config/initializers/pagy.rb Normal file
View File

@@ -0,0 +1,220 @@
# frozen_string_literal: true
# Pagy initializer file (9.0.9)
# 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 https://ddnexus.github.io/pagy/docs/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 https://ddnexus.github.io/pagy/docs/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
# Pagy::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