mirror of
https://github.com/rickbarrette/redmine_qbo_vehicles.git
synced 2026-11-18 02:40:37 -05:00
Vehicles paged by Redmine instead of will_paginate
The vehicle search, a customer's vehicles and the customer page's vehicle list use Redmine's paginator (will_paginate came from redmine_qbo's Gemfile, which no longer has it). The customer page's list keeps its own page parameter, without per-page links, and lists vehicles by year, make and model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
53991ed087
commit
d842b9b724
4 files changed
+22
-9
No files matched your search
@@ -27,13 +27,13 @@ class VehiclesController < ApplicationController
|
|||||||
@customer = Customer.find_by(id: params[:customer_id])
|
@customer = Customer.find_by(id: params[:customer_id])
|
||||||
return render_404 unless @customer
|
return render_404 unless @customer
|
||||||
|
|
||||||
@vehicles = @customer.vehicles.order(:year, :make, :model).paginate(page: params[:page])
|
paginate_vehicles(@customer.vehicles.order(:year, :make, :model, :id))
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:search].present?
|
if params[:search].present?
|
||||||
@vehicles = Vehicle.search_all(params[:search]).paginate(page: params[:page])
|
paginate_vehicles(Vehicle.search_all(params[:search]).order(:id))
|
||||||
redirect_to @vehicles.first if @vehicles.total_entries == 1
|
redirect_to @vehicles.first if @vehicle_count == 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -115,4 +115,11 @@ class VehiclesController < ApplicationController
|
|||||||
render_404
|
render_404
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Redmine's paging: @vehicle_count, @vehicle_pages and this page's @vehicles
|
||||||
|
def paginate_vehicles(scope)
|
||||||
|
@vehicle_count = scope.count
|
||||||
|
@vehicle_pages = Paginator.new @vehicle_count, per_page_option, params['page']
|
||||||
|
@vehicles = scope.limit(@vehicle_pages.per_page).offset(@vehicle_pages.offset).to_a
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
<% if User.current.allowed_to?(:view_vehicles, nil, global: true) %>
|
<% if User.current.allowed_to?(:view_vehicles, nil, global: true) %>
|
||||||
<h4><%=t(:field_vehicles)%>:</h4>
|
<h4><%=t(:field_vehicles)%>:</h4>
|
||||||
<%# Own page parameter so this list doesn't page together with the other lists on the customer page %>
|
<%# Own page parameter so this list doesn't page together with the other lists on the customer page %>
|
||||||
<%= render partial: 'vehicles/list', locals: { vehicles: customer.vehicles.paginate(page: params[:vehicles_page]), show_customer: false, show_checkbox: true, page_param: :vehicles_page } %>
|
<% vehicle_scope = customer.vehicles.order(:year, :make, :model, :id) %>
|
||||||
|
<% vehicle_count = vehicle_scope.count %>
|
||||||
|
<% vehicle_pages = Redmine::Pagination::Paginator.new(vehicle_count, Setting.per_page_options_array.first || 25, params[:vehicles_page], :vehicles_page) %>
|
||||||
|
<%= render partial: 'vehicles/list', locals: { vehicles: vehicle_scope.limit(vehicle_pages.per_page).offset(vehicle_pages.offset).to_a,
|
||||||
|
pages: vehicle_pages, count: vehicle_count, per_page_links: false,
|
||||||
|
show_customer: false, show_checkbox: true } %>
|
||||||
<div style="float: right;">
|
<div style="float: right;">
|
||||||
<% if User.current.allowed_to?(:add_vehicles, nil, global: true) %>
|
<% if User.current.allowed_to?(:add_vehicles, nil, global: true) %>
|
||||||
<%= button_to t(:button_new_vehicle), new_customer_vehicle_path(customer), method: :get %>
|
<%= button_to t(:button_new_vehicle), new_customer_vehicle_path(customer), method: :get %>
|
||||||
|
|||||||
@@ -40,11 +40,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<div class="actions">
|
<%# pages: a Redmine::Pagination::Paginator for the list (count: how many in all); per_page_links: false to leave out "Per page" %>
|
||||||
<%= will_paginate vehicles, param_name: (local_assigns[:page_param] || :page) %>
|
<% if local_assigns[:pages] %>
|
||||||
</div>
|
<span class="pagination"><%= pagination_links_full pages, count, per_page_links: local_assigns[:per_page_links] %></span>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%=t(:label_matching)%> <%= vehicles.respond_to?(:total_entries) ? vehicles.total_entries : vehicles.size %> <%=t(:field_vehicles) %>
|
<%=t(:label_matching)%> <%= local_assigns[:count] || vehicles.size %> <%=t(:field_vehicles) %>
|
||||||
|
|
||||||
<% else %>
|
<% else %>
|
||||||
<p><%=t(:label_no_vehicles)%> <%= params[:search] %>.</p>
|
<p><%=t(:label_no_vehicles)%> <%= params[:search] %>.</p>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<h2><%=t(:label_customer_vehicles)%> <span style="float:right"> <%= render partial: 'vehicles/search' %> </span> </h2>
|
<h2><%=t(:label_customer_vehicles)%> <span style="float:right"> <%= render partial: 'vehicles/search' %> </span> </h2>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
<%= render partial: 'vehicles/list', locals: {vehicles: @vehicles, show_customer: true, show_checkbox: false} %>
|
<%= render partial: 'vehicles/list', locals: {vehicles: @vehicles, pages: @vehicle_pages, count: @vehicle_count, show_customer: true, show_checkbox: false} %>
|
||||||
Reference in new issue
Block a user