Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor submission tags for reporting performance #1248

Merged
merged 8 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/controllers/admin/site_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def index

def a11; end

def a11_v2_collections
end

def heartbeat
render json: {
status: :success,
Expand All @@ -40,7 +43,7 @@ def heartbeat
def invite
# /views/admin/site/invite.html.erb
end

def invite_post
invitee = invite_params[:refer_user]

Expand Down
29 changes: 15 additions & 14 deletions app/controllers/admin/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
module Admin
class SubmissionsController < AdminController
before_action :ensure_admin, only: %i[
feed
feed
export_feed
]
before_action :set_form, except: %i[
feed
feed
export_feed
]
before_action :set_submission, except: %i[
feed
export_feed
search
a11_chart
a11_analysis
responses_per_day
responses_by_status
performance_gov
feed
export_feed
search
a11_chart
a11_analysis
responses_per_day
responses_by_status
performance_gov
submissions_table
]

Expand Down Expand Up @@ -65,6 +65,7 @@ def unflag
def add_tag
@submission.tag_list.add(admin_submission_params[:tag_list].split(','))
@submission.save!
@submission.form.update_submission_tags!(@submission.tag_list)
end

def remove_tag
Expand Down Expand Up @@ -98,12 +99,12 @@ def performance_gov

def submissions_table
@show_archived = true if params[:archived]
@all_submissions = @form.submissions
@all_submissions = @all_submissions.tagged_with(params[:tag]) if params[:tag]
all_submissions = @form.submissions
all_submissions = all_submissions.tagged_with(params[:tag]) if params[:tag]
if params[:archived]
@submissions = @all_submissions.order('submissions.created_at DESC').page params[:page]
@submissions = all_submissions.order('submissions.created_at DESC').page params[:page]
else
@submissions = @all_submissions.non_archived.order('submissions.created_at DESC').page params[:page]
@submissions = all_submissions.non_archived.order('submissions.created_at DESC').page params[:page]
end
end

Expand Down
50 changes: 35 additions & 15 deletions app/models/form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,23 @@ def short_uuid
uuid[0..7]
end

# used to initially set tags (or reset them, if necessary)
def set_submission_tags!
submission_tags = submissions.collect(&:tags).uniq.sort_by { |i| i.name }
self.update!(submission_tags: submission_tags)
end

# called when a tag is added to a submission
def update_submission_tags!(tag_list)
submission_tags = (self.submission_tags + tag_list).uniq.sort
self.update!(submission_tags: submission_tags)
end

# lazily called from a view when a tag is used to search, but returns 0 results
def remove_submission_tag!(tag)
self.update!(submission_tags: submission_tags - [tag])
end

aasm do
state :in_development, initial: true
state :live # manual
Expand Down Expand Up @@ -260,28 +277,31 @@ def to_a11_v2_csv(start_date: nil, end_date: nil)

attributes = fields_for_export

answer_02_options = self.questions.where(answer_field: "answer_02").first.question_options.collect(&:value)
answer_03_options = self.questions.where(answer_field: "answer_03").first.question_options.collect(&:value)

CSV.generate(headers: true) do |csv|
csv << header_attributes

non_flagged_submissions.each do |submission|
csv << [
submission.id,
submission.answer_01,
submission.answer_02 && submission.answer_02.split(",").include?("effectiveness") ? 1 : 0,
submission.answer_02 && submission.answer_02.split(",").include?("ease") ? 1 : 0,
submission.answer_02 && submission.answer_02.split(",").include?("efficiency") ? 1 : 0,
submission.answer_02 && submission.answer_02.split(",").include?("transparency") ? 1 : 0,
submission.answer_02 && submission.answer_02.split(",").include?("humanity") ? 1 : 0,
submission.answer_02 && submission.answer_02.split(",").include?("employee") ? 1 : 0,
submission.answer_02 && submission.answer_02.split(",").include?("other") ? 1 : 0,

submission.answer_03 && submission.answer_03.split(",").include?("effectiveness") ? 1 : 0,
submission.answer_03 && submission.answer_03.split(",").include?("ease") ? 1 : 0,
submission.answer_03 && submission.answer_03.split(",").include?("efficiency") ? 1 : 0,
submission.answer_03 && submission.answer_03.split(",").include?("transparency") ? 1 : 0,
submission.answer_03 && submission.answer_03.split(",").include?("humanity") ? 1 : 0,
submission.answer_03 && submission.answer_03.split(",").include?("employee") ? 1 : 0,
submission.answer_03 && submission.answer_03.split(",").include?("other") ? 1 : 0,
submission.answer_02 && submission.answer_02.split(",").include?("effectiveness") ? 1 :(answer_02_options.include?("effectiveness") ? 0 : 'null'),
submission.answer_02 && submission.answer_02.split(",").include?("ease") ? 1 : (answer_02_options.include?("ease") ? 0 : 'null'),
submission.answer_02 && submission.answer_02.split(",").include?("efficiency") ? 1 : (answer_02_options.include?("efficiency") ? 0 : 'null'),
submission.answer_02 && submission.answer_02.split(",").include?("transparency") ? 1 : (answer_02_options.include?("transparency") ? 0 : 'null'),
submission.answer_02 && submission.answer_02.split(",").include?("humanity") ? 1 : (answer_02_options.include?("humanity") ? 0 : 'null'),
submission.answer_02 && submission.answer_02.split(",").include?("employee") ? 1 : (answer_02_options.include?("employee") ? 0 : 'null'),
submission.answer_02 && submission.answer_02.split(",").include?("other") ? 1 : (answer_02_options.include?("other") ? 0 : 'null'),

submission.answer_03 && submission.answer_03.split(",").include?("effectiveness") ? 1 : (answer_03_options.include?("effectiveness") ? 0 : 'null'),
submission.answer_03 && submission.answer_03.split(",").include?("ease") ? 1 : (answer_03_options.include?("ease") ? 0 : 'null'),
submission.answer_03 && submission.answer_03.split(",").include?("efficiency") ? 1 : (answer_03_options.include?("efficiency") ? 0 : 'null'),
submission.answer_03 && submission.answer_03.split(",").include?("transparency") ? 1 : (answer_03_options.include?("transparency") ? 0 : 'null'),
submission.answer_03 && submission.answer_03.split(",").include?("humanity") ? 1 : (answer_03_options.include?("humanity") ? 0 : 'null'),
submission.answer_03 && submission.answer_03.split(",").include?("employee") ? 1 : (answer_03_options.include?("employee") ? 0 : 'null'),
submission.answer_03 && submission.answer_03.split(",").include?("other") ? 1 : (answer_03_options.include?("other") ? 0 : 'null'),

submission.answer_04
]
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/question_options/update.js.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<% if @question_option.question.question_type == "radio_buttons" %>
<% @form_component_path = "components/forms/edit/question_types/radio_button_option" %>
<% elsif @question_option.question.question_type == "icon_checkboxes" %>
<% @form_component_path = "components/forms/question_types/icon_radio_button_option" %>
<% @form_component_path = "components/forms/edit/question_types/checkbox_option" %>
<% elsif @question_option.question.question_type == "thumbs_up_down_buttons" %>
<% @form_component_path = 'components/forms/question_types/thumbs_up_down_buttons' %>
<% elsif @question_option.question.question_type == "dropdown" %>
Expand Down
82 changes: 82 additions & 0 deletions app/views/admin/site/a11_v2_collections.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

<form>
<label class="usa-label" for="input-type-text">Department name</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">HISP name</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Service name</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Service type</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Digital service or Contact center?</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">URL?</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Fiscal Year</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Quarter</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Transaction point - at what point in a journey?</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Channel of survey</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Survey Title</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Text of the trust question</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text">Likert of Thumb question?</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text"># of interactions</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-text"># of people offered the survey</label>
<input class="usa-input" id="input-type-text" name="input-type-text" />

<label class="usa-label" for="input-type-textarea">Reflection Text</label>
<textarea
class="usa-textarea"
id="input-type-textarea"
name="input-type-textarea"></textarea>

<br>
<br>
<br>

<h3>
Step 2 - File upload
</h3>

<div class="field">
<%#= form.label :logo, class: "usa-label" %>
<div class="usa-alert usa-alert--info">
<div class="usa-alert__body">
<p class="usa-alert__text">
Upload a .csv with your detailed survey responses,
in the specified format.
</p>
</div>
</div>
<p>
<%= file_field_tag :logo, class: "usa-2button" %>
</p>
</div>
</form>




<br>
<br>
15 changes: 10 additions & 5 deletions app/views/admin/submissions/_submissions.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% @tags = @form.submissions.collect(&:tags).flatten.sort_by { |i| i.name } %>
<% @tags = form.submission_tags %>

<button id="button-toggle-table-display-options" type="button" class="font-sans-2xs">
<i class="fa fa-cog"></i>
Expand All @@ -8,17 +8,19 @@
<%= render 'admin/forms/ui_form', form: form %>
</div>

<% if @tags.first %>
<% if @tags.any? %>
<div class="well">
<div class="field">
<p>
Filter by tag
</p>
<div class="tag-list">
<% @tags.uniq.each do | tag | %>
<a href="#" class="search-tag-link" data-name="<%= tag.name %>">
<% @tags.uniq.each do |tag| %>
<a href="javascript:void(0)"
class="search-tag-link"
data-name="<%= tag %>">
<span class="usa-tag">
<%= tag.name %>
<%= tag %>
</span>
</a>
<% end %>
Expand All @@ -29,6 +31,9 @@
<h2>
<%= page_entries_info submissions, entry_name: 'Responses' %>
<% if params[:tag] %>
<% if params[:tag] && submissions.size == 0 %>
<% form.remove_submission_tag!(params[:tag])%>
<% end %>
<span class="font-sans-3xs">tagged with <span class="code"><%= params[:tag] %></span></span>
<% end %>
</h2>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/submissions/_submissions_table.html.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<%= render template: "admin/submissions/index", locals: { form: @form, submissions: @submissions } %>
<%= render template: "admin/submissions/index", locals: { form: form, submissions: submissions } %>
2 changes: 1 addition & 1 deletion app/views/admin/submissions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<br>
<%= link_to "Export All Responses to CSV", export_submissions_admin_form_url(form, start_date: "2019-10-01", format: "json"), class: "usa-button export-btn" %>
<br>
<% if @form.kind == "a11_v2" %>
<% if form.kind == "a11_v2" %>
<p>
<%= link_to "Export A11-v2 Responses to CSV", export_a11_v2_submissions_admin_form_url(form, start_date: "2019-10-01", format: "json"), class: "usa-button export-btn" %>
</p>
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/submissions/submissions_table.js.erb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
$(".submissions-table-widget").html("<%= escape_javascript render(partial: 'admin/submissions/submissions_table', locals: { form: @form }) %>");
$(".submissions-table-widget").html("<%= escape_javascript render(partial: 'admin/submissions/submissions_table', locals: { form: @form, submissions: @submissions }) %>");
5 changes: 4 additions & 1 deletion app/views/components/widget/_modal.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div id="fba-modal-dialog" class="fba-modal-dialog" role="dialog" aria-modal="true">
<div id="fba-modal-dialog"
class="fba-modal-dialog"
role="dialog"
aria-modal="<%= ['modal', 'custom-button-modal'].include?(form.delivery_method) ? 'true' : 'false' %>">
<%= render "components/widget/no_modal", form: form do %>
<%= render partial: 'components/forms/footer', locals: { form: form } %>
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@
end
end

get '/a11_v2_collections', to: 'site#a11_v2_collections'

resources :omb_cx_reporting_collections
resources :cscrm_data_collections do
member do
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231003181018_add_form_submission_tags.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFormSubmissionTags < ActiveRecord::Migration[7.0]
def change
add_column :forms, :submission_tags, :string, array: true, default: [], comment: "cache the form's submissions tags for reporting"
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_09_27_214053) do
ActiveRecord::Schema[7.0].define(version: 2023_10_03_181018) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -331,6 +331,7 @@
t.string "whitelist_url_7"
t.string "whitelist_url_8"
t.string "whitelist_url_9"
t.string "submission_tags", default: [], comment: "cache the form's submissions tags for reporting", array: true
t.index ["legacy_touchpoint_id"], name: "index_forms_on_legacy_touchpoint_id"
t.index ["legacy_touchpoint_uuid"], name: "index_forms_on_legacy_touchpoint_uuid"
t.index ["organization_id"], name: "index_forms_on_organization_id"
Expand Down
Loading