-
-
Notifications
You must be signed in to change notification settings - Fork 457
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/add-feature-flags-via-flipper
- Loading branch information
Showing
27 changed files
with
378 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
app/assets/stylesheets/shared/tomselect_additional_styles.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.ts-dropdown [data-selectable] .highlight { | ||
display: inline-block; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,77 @@ | ||
require "csv" | ||
|
||
class CaseContactsExportCsvService | ||
attr_reader :case_contacts, :filtered_columns | ||
attr_reader :case_contacts_scope, :filtered_columns | ||
|
||
def initialize(case_contacts, filtered_columns = nil) | ||
@filtered_columns = filtered_columns || CaseContactsExportCsvService.DATA_COLUMNS.keys | ||
|
||
@case_contacts = case_contacts.preload({creator: :supervisor}, :contact_types, :casa_case) | ||
def initialize(case_contacts_scope, filtered_columns) | ||
@filtered_columns = filtered_columns | ||
@case_contacts_scope = case_contacts_scope | ||
end | ||
|
||
def perform | ||
CSV.generate(headers: true) do |csv| | ||
csv << filtered_columns.map(&:to_s).map(&:titleize) | ||
case_contacts = case_contacts_scope.preload({creator: :supervisor}, :contact_types, :casa_case, :contact_topic_answers) | ||
|
||
CSV.generate do |csv| | ||
csv << fixed_column_headers + court_topics.values | ||
|
||
if case_contacts.present? | ||
case_contacts.decorate.each do |case_contact| | ||
csv << CaseContactsExportCsvService.DATA_COLUMNS(case_contact).slice(*filtered_columns).values | ||
csv << fixed_column_values(case_contact) + court_topic_answers(case_contact) | ||
end | ||
end | ||
end | ||
end | ||
|
||
def self.DATA_COLUMNS(case_contact = nil) | ||
def fixed_column_values(case_contact) | ||
# Note: these header labels are for stakeholders and do not match the | ||
# Rails DB names in all cases, e.g. added_to_system_at header is case_contact.created_at | ||
{ | ||
internal_contact_number: case_contact&.id, | ||
duration_minutes: case_contact&.report_duration_minutes, | ||
contact_types: case_contact&.report_contact_types, | ||
contact_made: case_contact&.report_contact_made, | ||
contact_medium: case_contact&.medium_type, | ||
occurred_at: I18n.l(case_contact&.occurred_at, format: :full, default: nil), | ||
added_to_system_at: case_contact&.created_at, | ||
miles_driven: case_contact&.miles_driven, | ||
wants_driving_reimbursement: case_contact&.want_driving_reimbursement, | ||
casa_case_number: case_contact&.casa_case&.case_number, | ||
creator_email: case_contact&.creator&.email, | ||
creator_name: case_contact&.creator&.display_name, | ||
supervisor_name: case_contact&.creator&.supervisor&.display_name, | ||
case_contact_notes: case_contact&.notes | ||
mappings = { | ||
internal_contact_number: case_contact.id, | ||
duration_minutes: case_contact.report_duration_minutes, | ||
contact_types: case_contact.report_contact_types, | ||
contact_made: case_contact.report_contact_made, | ||
contact_medium: case_contact.medium_type, | ||
occurred_at: I18n.l(case_contact.occurred_at, format: :full, default: nil), | ||
added_to_system_at: case_contact.created_at, | ||
miles_driven: case_contact.miles_driven, | ||
wants_driving_reimbursement: case_contact.want_driving_reimbursement, | ||
casa_case_number: case_contact.casa_case&.case_number, | ||
creator_email: case_contact.creator&.email, | ||
creator_name: case_contact.creator&.display_name, | ||
supervisor_name: case_contact.creator&.supervisor&.display_name, | ||
case_contact_notes: case_contact.notes | ||
} | ||
|
||
mappings.slice(*filtered_columns).values | ||
end | ||
|
||
def fixed_column_headers | ||
filtered_columns.excluding(:court_topics).map(&:to_s).map(&:titleize) | ||
end | ||
|
||
def court_topic_answers(case_contact) | ||
return [] if court_topics_filtered? | ||
|
||
# index_by so we don't loop through answers multiple times | ||
answers_by_topic_id = case_contact.contact_topic_answers.index_by(&:contact_topic_id) | ||
|
||
# we have to map values for all topics so we 'skip' unanswered ones (with a blank cell) | ||
court_topics.keys.map { |topic_id| answers_by_topic_id[topic_id]&.value } | ||
end | ||
|
||
def court_topics | ||
return {} if court_topics_filtered? | ||
|
||
@court_topics ||= ContactTopic | ||
.with_answers_in(case_contacts_scope) | ||
.order(:id) | ||
.select(:id, :question) | ||
.distinct | ||
.to_h { |topic| [topic.id, topic.question] } | ||
end | ||
|
||
def court_topics_filtered? | ||
return @court_topics_filtered if defined? @court_topics_filtered | ||
@court_topics_filtered = filtered_columns.exclude?(:court_topics) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.