add submissions filtering by 'sent' and 'opened' statuses
This commit is contained in:
committed by
Pete Matsyburka
parent
8b6731a289
commit
96e4733f87
@@ -0,0 +1,6 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="<%= local_assigns[:class] %>" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" width="24" height="24" stroke-width="2">
|
||||
<path d="M3 9l9 6l9 -6l-9 -6l-9 6"></path>
|
||||
<path d="M21 9v10a2 2 0 0 1 -2 2h-14a2 2 0 0 1 -2 -2v-10"></path>
|
||||
<path d="M3 19l6 -6"></path>
|
||||
<path d="M15 13l6 6"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 401 B |
@@ -1,5 +1,5 @@
|
||||
<% query_params = params.permit(:q).merge(filter_params) %>
|
||||
<% if icon = { 'declined' => 'x_circle', 'expired' => 'clock_cancel', 'partially_completed' => 'clock_edit' }[params[:status]] %>
|
||||
<% if icon = { 'declined' => 'x_circle', 'expired' => 'clock_cancel', 'partially_completed' => 'clock_edit', 'sent' => 'send', 'opened' => 'mail_opened' }[params[:status]] %>
|
||||
<div class="flex h-10 px-2 py-1 text-lg items-center justify-between border text-center text-neutral font-semibold rounded-xl w-full md:w-34 border-neutral-700">
|
||||
<%= link_to submissions_filter_path('status', query_params.merge(path: url_for, with_remove: true)), data: { turbo_frame: 'modal' }, class: 'flex items-center space-x-1 w-full pr-1 md:max-w-[140px]' do %>
|
||||
<%= svg_icon(icon, class: 'w-5 h-5 shrink-0') %>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="flex flex-col md:flex-row gap-2 mt-5">
|
||||
<div class="form-control w-full">
|
||||
<div id="status" class="radio-select grid grid-cols-2 gap-2 px-1">
|
||||
<% ['', 'pending', 'completed', 'partially_completed', 'declined', 'expired'].each do |status| %>
|
||||
<% ['', 'pending', 'completed', 'partially_completed', 'sent', 'opened', 'declined', 'expired'].each do |status| %>
|
||||
<label class="radio-label cursor-pointer inline-flex items-center space-x-2">
|
||||
<%= radio_button_tag 'status', status, params[:status] == status || (status == '' && params[:status].blank?), class: 'base-radio' %>
|
||||
<span><%= t(status.presence || 'all') %></span>
|
||||
|
||||
+36
-21
@@ -37,30 +37,45 @@ module Submissions
|
||||
submissions.where(created_by_user_id: user&.id || -1)
|
||||
end
|
||||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def filter_by_status(submissions, filters)
|
||||
submissions = submissions.pending if filters[:status] == 'pending'
|
||||
submissions = submissions.completed if filters[:status] == 'completed'
|
||||
submissions = submissions.declined if filters[:status] == 'declined'
|
||||
submissions = submissions.expired if filters[:status] == 'expired'
|
||||
|
||||
if filters[:status] == 'partially_completed'
|
||||
submissions =
|
||||
submissions.joins(:submitters)
|
||||
.group(:id)
|
||||
.having(Arel::Nodes::NamedFunction.new(
|
||||
'COUNT', [Arel::Nodes::NamedFunction.new('NULLIF',
|
||||
[Submitter.arel_table[:completed_at].eq(nil),
|
||||
Arel::Nodes.build_quoted(false)])]
|
||||
).gt(0))
|
||||
.having(Arel::Nodes::NamedFunction.new(
|
||||
'COUNT', [Arel::Nodes::NamedFunction.new('NULLIF',
|
||||
[Submitter.arel_table[:completed_at].not_eq(nil),
|
||||
Arel::Nodes.build_quoted(false)])]
|
||||
).gt(0))
|
||||
case filters[:status]
|
||||
when 'pending'
|
||||
submissions.pending
|
||||
when 'completed'
|
||||
submissions.completed
|
||||
when 'declined'
|
||||
submissions.declined
|
||||
when 'expired'
|
||||
submissions.expired
|
||||
when 'sent'
|
||||
submissions.joins(:submitters)
|
||||
.where(submitters: { opened_at: nil, completed_at: nil, declined_at: nil })
|
||||
.where.not(submitters: { sent_at: nil })
|
||||
.group(:id)
|
||||
when 'opened'
|
||||
submissions.joins(:submitters)
|
||||
.where(submitters: { completed_at: nil, declined_at: nil })
|
||||
.where.not(submitters: { opened_at: nil })
|
||||
.group(:id)
|
||||
when 'partially_completed'
|
||||
submissions.joins(:submitters)
|
||||
.group(:id)
|
||||
.having(Arel::Nodes::NamedFunction.new(
|
||||
'COUNT', [Arel::Nodes::NamedFunction.new('NULLIF',
|
||||
[Submitter.arel_table[:completed_at].eq(nil),
|
||||
Arel::Nodes.build_quoted(false)])]
|
||||
).gt(0))
|
||||
.having(Arel::Nodes::NamedFunction.new(
|
||||
'COUNT', [Arel::Nodes::NamedFunction.new('NULLIF',
|
||||
[Submitter.arel_table[:completed_at].not_eq(nil),
|
||||
Arel::Nodes.build_quoted(false)])]
|
||||
).gt(0))
|
||||
else
|
||||
submissions
|
||||
end
|
||||
|
||||
submissions
|
||||
end
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
def filter_by_created_at(submissions, filters)
|
||||
submissions = submissions.where(created_at: filters[:created_at_from]..) if filters[:created_at_from].present?
|
||||
|
||||
Reference in New Issue
Block a user