add templates and submissions search

pull/112/head
Alex Turchyn 2 years ago
parent 7f6c0af0e8
commit 53fa35fd01

@ -8,6 +8,7 @@ class DashboardController < ApplicationController
return render 'pages/landing' unless signed_in?
templates = current_account.templates.active.preload(:author).order(id: :desc)
templates = Templates.search(templates, params[:q])
@pagy, @templates = pagy(templates, items: 12)
end

@ -3,6 +3,7 @@
class TemplatesArchivedController < ApplicationController
def index
templates = current_account.templates.where.not(deleted_at: nil).preload(:author).order(id: :desc)
templates = Templates.search(templates, params[:q])
@pagy, @templates = pagy(templates, items: 12)
end

@ -4,7 +4,10 @@ class TemplatesArchivedSubmissionsController < ApplicationController
def show
@template = current_account.templates.find(params[:template_id])
@pagy, @submissions = pagy(@template.submissions.where.not(deleted_at: nil).preload(:submitters).order(id: :desc))
submissions = @template.submissions.where.not(deleted_at: nil)
submissions = Submissions.search(submissions, params[:q])
@pagy, @submissions = pagy(submissions.preload(:submitters).order(id: :desc))
rescue ActiveRecord::RecordNotFound
redirect_to root_path
end

@ -7,6 +7,7 @@ class TemplatesController < ApplicationController
@template = current_account.templates.find(params[:id])
submissions = @template.submissions
submissions = submissions.active if @template.deleted_at.blank?
submissions = Submissions.search(submissions, params[:q])
@pagy, @submissions = pagy(submissions.preload(:submitters).order(id: :desc))
rescue ActiveRecord::RecordNotFound

@ -1,8 +1,11 @@
<% if Docuseal.demo? %><%= render 'shared/demo_alert' %><% end %>
<% if @templates.any? %>
<% if @pagy.count > 0 || params[:q].present? %>
<div class="flex justify-between mb-4 items-center">
<h1 class="text-4xl font-bold"><span class="hidden md:inline">Document</span> Templates</h1>
<div class="flex space-x-2">
<% if params[:q].present? || @pagy.pages > 1 %>
<%= render 'shared/search_input' %>
<% end %>
<%= render 'templates/upload_button' %>
<%= link_to new_template_path, class: 'btn btn-primary text-base btn-md gap-2', data: { turbo_frame: :modal } do %>
<%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
@ -10,21 +13,29 @@
<% end %>
</div>
</div>
<div class="grid gap-4 md:grid-cols-3">
<%= render partial: 'templates/template', collection: @templates %>
</div>
<% view_archived_html = capture do %>
<% if current_account.templates.where.not(deleted_at: nil).exists? %>
<div>
<a href="<%= templates_archived_index_path %>" class="link text-sm">View Archived</a>
<% if @pagy.count > 0 %>
<div class="grid gap-4 md:grid-cols-3">
<%= render partial: 'templates/template', collection: @templates %>
</div>
<% view_archived_html = capture do %>
<% if current_account.templates.where.not(deleted_at: nil).exists? %>
<div>
<a href="<%= templates_archived_index_path %>" class="link text-sm">View Archived</a>
</div>
<% end %>
<% end %>
<% if @pagy.pages > 1 %>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'templates', left_additional_html: view_archived_html %>
<% else %>
<div class="mt-2">
<%= view_archived_html %>
</div>
<% end %>
<% end %>
<% if @pagy.pages > 1 %>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'templates', left_additional_html: view_archived_html %>
<% else %>
<div class="mt-2">
<%= view_archived_html %>
<% elsif params[:q].present? %>
<div class="text-center">
<div class="mt-16 text-3xl font-semibold">
Templates not Found
</div>
</div>
<% end %>
<% else %>

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" width="44" height="44" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
<path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
<path d="M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0"></path>
<path d="M21 21l-6 -6"></path>
</svg>

After

Width:  |  Height:  |  Size: 384 B

@ -0,0 +1,11 @@
<form action="<%= request.path %>" method="get" class="items-center hidden md:flex">
<input id="search" name="q" value="<%= params[:q] %>" class="input input-ghost text-lg pr-10 -mr-12">
<button type="submit" title="Search" class="btn btn-ghost btn-circle" onclick="window.search.value || document.activeElement === window.search ? null : [event.preventDefault(), window.search.focus()]">
<span class="enabled">
<%= svg_icon('search', class: 'w-6 h-6 stroke-2') %>
</span>
<span class="disabled">
<%= svg_icon('loader', class: 'w-5 h-5 animate-spin') %>
</span>
</button>
</form>

@ -3,6 +3,9 @@
<div class="flex justify-between mb-6 md:items-end flex-col md:flex-row">
<p class="text-3xl font-bold">Submissions</p>
<div class="flex space-x-2 mt-3 md:mt-0">
<% if params[:q].present? || @pagy.pages > 1 %>
<%= render 'shared/search_input' %>
<% end %>
<%= link_to new_template_submissions_export_path(@template), class: 'order-3 md:order-1 btn btn-ghost text-base', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
<span>Export</span>
@ -12,7 +15,7 @@
<%= render 'shared/clipboard_copy', text: start_form_url(slug: @template.slug), class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy Share Link', copied_title: 'Copied to Clipboard', copy_title_md: 'Copy', copied_title_md: 'Copied' %>
</span>
<% end %>
<% if !@pagy.count.zero? && !@template.deleted_at? %>
<% if (!@pagy.count.zero? || params[:q].present?) && !@template.deleted_at? %>
<%= link_to new_template_submission_path(@template), class: 'order-1 btn btn-primary text-base', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('plus', class: 'w-6 h-6 stroke-2') %>
<span>Add <span class="hidden md:inline">Recipients</span></span>
@ -44,7 +47,7 @@
<div class="card-body text-center py-16">
<div class="max-w-lg mx-auto">
<p class="text-3xl font-bold text-base-content mb-4">There are no Submissions</p>
<% if @template.deleted_at.blank? %>
<% if @template.deleted_at.blank? && params[:q].blank? %>
<p class="text-gray-600">Send an invitation to fill and complete the form</p>
<div class="space-x-2">
<%= link_to new_template_submission_path(@template), class: 'base-button mt-6', data: { turbo_frame: 'modal' } do %>

@ -6,8 +6,19 @@
</div>
<div class="flex justify-between mb-4 items-center">
<h1 class="text-4xl font-bold"><span class="hidden md:inline">Document</span> Templates <span class="badge badge-outline badge-lg align-middle">Archived</span></h1>
<% if params[:q].present? || @pagy.pages > 1 %>
<%= render 'shared/search_input' %>
<% end %>
</div>
<div class="grid gap-4 md:grid-cols-3">
<%= render partial: 'templates/template', collection: @templates %>
</div>
<% if @pagy.count > 0 %>
<div class="grid gap-4 md:grid-cols-3">
<%= render partial: 'templates/template', collection: @templates %>
</div>
<% elsif params[:q].present? %>
<div class="text-center">
<div class="mt-16 text-3xl font-semibold">
Templates not Found
</div>
</div>
<% end %>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'templates' %>

@ -8,13 +8,24 @@
<div class="flex justify-between mb-6 md:items-end flex-col md:flex-row">
<p class="text-3xl font-bold">Submissions <span class="badge badge-outline badge-lg align-middle">Archived</span></p>
<div class="flex space-x-2 mt-3 md:mt-0">
<% if params[:q].present? || @pagy.pages > 1 %>
<%= render 'shared/search_input' %>
<% end %>
<%= link_to new_template_submissions_export_path(@template), class: 'order-3 md:order-1 btn btn-ghost text-base', data: { turbo_frame: 'modal' } do %>
<%= svg_icon('download', class: 'w-6 h-6 stroke-2') %>
<span>Export</span>
<% end %>
</div>
</div>
<div class="space-y-4">
<%= render partial: 'templates/submission', collection: @submissions %>
</div>
<% if @pagy.count > 0 %>
<div class="space-y-4">
<%= render partial: 'templates/submission', collection: @submissions %>
</div>
<% elsif params[:q].present? %>
<div class="text-center">
<div class="mt-16 text-3xl font-semibold">
Submissions not Found
</div>
</div>
<% end %>
<%= render 'shared/pagination', pagy: @pagy, items_name: 'submissions' %>

@ -5,6 +5,20 @@ module Submissions
module_function
def search(submissions, keyword)
return submissions if keyword.blank?
term = "%#{keyword.downcase}%"
arel_table = Submitter.arel_table
arel = arel_table[:email].lower.matches(term)
.or(arel_table[:phone].matches(term))
.or(arel_table[:name].lower.matches(term))
submissions.joins(:submitters).where(arel).distinct
end
def update_template_fields!(submission)
submission.template_fields = submission.template.fields
submission.template_schema = submission.template.schema

@ -17,4 +17,10 @@ module Templates
hash
end
def search(templates, keyword)
return templates if keyword.blank?
templates.where(Template.arel_table[:name].lower.matches("%#{keyword.downcase}%"))
end
end

Loading…
Cancel
Save