diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index aa0bd5d5..7118ee77 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,6 +2,7 @@ class ApplicationController < ActionController::Base include ActiveStorage::SetCurrent + include Pagy::Backend before_action :maybe_redirect_to_setup, unless: :signed_in? before_action :authenticate_user!, unless: :devise_controller? diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 4ecbef8b..04bdda1e 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -6,6 +6,6 @@ class DashboardController < ApplicationController def index return render 'pages/landing' unless signed_in? - @templates = current_account.templates.active + @pagy, @templates = pagy(current_account.templates.active, items: 12) end end diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 45dc072f..6722b1e2 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -4,7 +4,7 @@ class SubmissionsController < ApplicationController before_action :load_template, only: %i[index new create] def index - @submissions = @template.submissions.active + @pagy, @submissions = pagy(@template.submissions.active) end def show diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 601f2594..c5ad45bd 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,7 +4,7 @@ class UsersController < ApplicationController before_action :load_user, only: %i[edit update destroy] def index - @users = current_account.users.active.order(id: :desc) + @pagy, @users = pagy(current_account.users.active.order(id: :desc)) end def new diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb index 59e3ce78..c8f45b40 100644 --- a/app/views/dashboard/index.html.erb +++ b/app/views/dashboard/index.html.erb @@ -25,6 +25,7 @@ <% end %> + <%= render 'shared/pagination', pagy: @pagy %> <% else %>
diff --git a/app/views/shared/_field_error.html.erb b/app/views/shared/_field_error.html.erb index 1305c8c6..42c7c344 100644 --- a/app/views/shared/_field_error.html.erb +++ b/app/views/shared/_field_error.html.erb @@ -1,4 +1,4 @@ <% 'input-error' %> - + <%= message %> diff --git a/app/views/shared/_pagination.html.erb b/app/views/shared/_pagination.html.erb new file mode 100644 index 00000000..d0e65d4d --- /dev/null +++ b/app/views/shared/_pagination.html.erb @@ -0,0 +1,20 @@ +<% link = pagy_link_proc(@pagy) %> +<% if @pagy.pages > 1 %> +
+
+ <% if @pagy.prev %> + <%== link.call(@pagy.prev, "«", 'class="join-item btn btn-sm"') %> + <% else %> + « + <% end %> + + Page <%= @pagy.page %> + + <% if @pagy.next %> + <%== link.call(@pagy.next, "»", 'class="join-item btn btn-sm"') %> + <% else %> + » + <% end %> +
+
+<% end %> diff --git a/app/views/submissions/index.html.erb b/app/views/submissions/index.html.erb index cc009d06..fd9446b3 100644 --- a/app/views/submissions/index.html.erb +++ b/app/views/submissions/index.html.erb @@ -62,39 +62,41 @@ <% submission.submitters.each do |submitter| %> <%= submitter.email %> -
- <% end %> - - - <% submission.submitters.each do |submitter| %> -
- - <%= submitter.status %> - -
- <% end %> - - - <% submission.submitters.each do |submitter| %> - <% share_link_input_id = "share-link-input_#{submitter.id}" %> -
- - - <%= svg_icon('clipboard', class: 'w-3 h-3 swap-on text-white') %> - <%= svg_icon('clipboard_copy', class: 'w-3 h-3 swap-off text-white') %> - -
-
- <% end %> - - - <%= link_to 'View', submission_path(submission), title: 'View', class: 'btn btn-outline btn-xs' %> - <%= button_to 'Remove', submission_path(submission), class: 'btn btn-outline btn-error btn-xs', title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' } %> - - - <% end %> - - +
+ <% end %> + + + <% submission.submitters.each do |submitter| %> +
+ + <%= submitter.status %> + +
+ <% end %> + + + <% submission.submitters.each do |submitter| %> + <% share_link_input_id = "share-link-input_#{submitter.id}" %> +
+ + + <%= svg_icon('clipboard', class: 'w-3 h-3 swap-on text-white') %> + <%= svg_icon('clipboard_copy', class: 'w-3 h-3 swap-off text-white') %> + +
+
+ <% end %> + + + <%= link_to 'View', submission_path(submission), title: 'View', class: 'btn btn-outline btn-xs' %> + <%= button_to 'Remove', submission_path(submission), class: 'btn btn-outline btn-error btn-xs', title: 'Delete', method: :delete, data: { turbo_confirm: 'Are you sure?' } %> + + + <% end %> + + +
+ <%= render 'shared/pagination', pagy: @pagy %> <% else %> <%= render 'shared/no_data_banner' %> <% end %> diff --git a/app/views/users/index.html.erb b/app/views/users/index.html.erb index ef24ffcb..c1307039 100644 --- a/app/views/users/index.html.erb +++ b/app/views/users/index.html.erb @@ -58,5 +58,6 @@
+ <%= render 'shared/pagination', pagy: @pagy %> diff --git a/config/initializers/pagy.rb b/config/initializers/pagy.rb new file mode 100644 index 00000000..463fa58a --- /dev/null +++ b/config/initializers/pagy.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +Pagy::DEFAULT[:items] = 10 +Pagy::DEFAULT.freeze + +ActiveSupport.on_load(:action_view) do + include Pagy::Frontend +end