diff --git a/app/controllers/templates_dashboard_controller.rb b/app/controllers/templates_dashboard_controller.rb index af47d179..51922c48 100644 --- a/app/controllers/templates_dashboard_controller.rb +++ b/app/controllers/templates_dashboard_controller.rb @@ -36,6 +36,8 @@ class TemplatesDashboardController < ApplicationController end @pagy, @templates = pagy_auto(@templates, limit:) + + load_related_submissions if params[:q].present? && @templates.blank? end end @@ -100,4 +102,19 @@ class TemplatesDashboardController < ApplicationController template_folders.order(id: :desc) end end + + def load_related_submissions + @related_submissions = Submission.accessible_by(current_ability) + .left_joins(:template) + .where(archived_at: nil) + .where(templates: { archived_at: nil }) + .preload(:template_accesses, :created_by_user, + template: :author, + submitters: :start_form_submission_events) + + @related_submissions = Submissions.search(current_user, @related_submissions, params[:q]) + .order(id: :desc) + + @related_submissions_pagy, @related_submissions = pagy_auto(@related_submissions, limit: 5) + end end diff --git a/app/views/shared/_pagination.html.erb b/app/views/shared/_pagination.html.erb index 7676eb5f..b50c7ac1 100644 --- a/app/views/shared/_pagination.html.erb +++ b/app/views/shared/_pagination.html.erb @@ -1,27 +1,29 @@ -<% link = pagy_anchor(@pagy) %> -<% if @pagy.pages > 1 %> +<% link = pagy_anchor(pagy) %> +<% if pagy.pages > 1 %>
<%= local_assigns[:right_additional_html] %>
- <% if @pagy.prev %> - <%== link.call(@pagy.prev, '«', classes: 'join-item btn min-h-full h-10') %> + <% if pagy.prev %> + <%== link.call(pagy.prev, '«', classes: 'join-item btn min-h-full h-10') %> <% else %> « <% end %> - <%= t('page_number', number: @pagy.page) %> + <%= t('page_number', number: pagy.page) %> - <% if @pagy.next %> - <%== link.call(@pagy.next, '»', classes: 'join-item btn min-h-full h-10') %> + <% if local_assigns[:next_page_path].present? %> + <%= link_to '»', local_assigns[:next_page_path], class: 'join-item btn min-h-full h-10' %> + <% elsif pagy.next %> + <%== link.call(pagy.next, '»', classes: 'join-item btn min-h-full h-10') %> <% else %> » <% end %> diff --git a/app/views/templates_dashboard/index.html.erb b/app/views/templates_dashboard/index.html.erb index f1a4c3de..d4bbd8b0 100644 --- a/app/views/templates_dashboard/index.html.erb +++ b/app/views/templates_dashboard/index.html.erb @@ -98,5 +98,14 @@ <%= t('templates_not_found') %>
+ <% if @related_submissions.present? %> +

+ <%= t('submissions') %> +

+
+ <%= render partial: 'templates/submission', collection: @related_submissions, locals: { with_template: true } %> +
+ <%= render 'shared/pagination', pagy: @related_submissions_pagy, items_name: 'submissions', next_page_path: submissions_path(q: params[:q]) %> + <% end %> <% end %> <%= render 'shared/review_form' %> diff --git a/spec/system/dashboard_spec.rb b/spec/system/dashboard_spec.rb index 81d16458..beca9606 100644 --- a/spec/system/dashboard_spec.rb +++ b/spec/system/dashboard_spec.rb @@ -49,5 +49,18 @@ RSpec.describe 'Dashboard Page' do expect(page).to have_current_path(edit_template_path(Template.last), ignore_query: true) end end + + it 'searches be submitter email' do + submission = create(:submission, :with_submitters, template: templates[0]) + submitter = submission.submitters.first + + SearchEntries.reindex_all + + visit root_path(q: submitter.email) + + expect(page).to have_content('Templates not Found') + expect(page).to have_content('Submissions') + expect(page).to have_content(submitter.name) + end end end