add pagy, improve checks#index
This commit is contained in:
parent
c44c9ccaba
commit
6d3a269231
11 changed files with 274 additions and 10 deletions
|
|
@ -53,4 +53,8 @@
|
|||
|
||||
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" }) %>
|
||||
</div>
|
||||
<%= 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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue