-
-
Notifications
You must be signed in to change notification settings - Fork 485
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
Issue 3028 convert csv to excel #5209
Closed
xeniabarreto
wants to merge
15
commits into
rubyforgood:main
from
xeniabarreto:issue-3028-convert-csv-to-excel
Closed
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ec3e610
feat add Excel data to existing CSV files.
xeniabarreto c5a318c
Merge branch 'main' into issue-3028-convert-csv-to-excel
xeniabarreto 367637e
fix sheet.add_row
xeniabarreto fcd9eaf
add modal to export csv/excel
xeniabarreto 6c28b5d
feat formatted automatic line break column in "Case Contact Notes"
xeniabarreto 7334fd4
chore: rubocop
xeniabarreto f37d9a1
chore: lint
xeniabarreto 4f58744
fix: update test message to match the latest changes for Excel file g…
xeniabarreto 9110d41
chore: remove blank spaces
xeniabarreto 9cf1ab4
chore: added file name for skipping test
xeniabarreto 819b320
chore: Fixed formatting issues in the case contact reports controller
xeniabarreto e7a1f0c
fix close button Filter Columns modal
xeniabarreto 8c0207a
fix: refactor data columns
xeniabarreto 510c33d
3028 Convert CSV to Excel //
ff0b6c3
3028 Convert CSV to Excel //
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix: refactor data columns
- Loading branch information
commit 8c0207ad37de38d563c55d45c157981efe05a334
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module CaseContactsExportDataColumns | ||
def self.data_columns(case_contact = nil) | ||
|
||
data = { | ||
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&.strftime('%Y-%m-%d %H:%M:%S %Z'), | ||
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 | ||
} | ||
|
||
data | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,17 @@ | |
|
||
# CaseContactsExportExcelService handles the conversion of case contact data to Excel format. | ||
# It provides methods for exporting case contact information to Excel files. | ||
require 'case_contacts_export_data_columns' | ||
|
||
class CaseContactsExportExcelService | ||
attr_reader :case_contacts, :filtered_columns | ||
include CaseContactsExportDataColumns | ||
|
||
FONT_SIZE = 11 | ||
LINE_PADDING = 10 | ||
|
||
def initialize(case_contacts, filtered_columns = nil) | ||
@filtered_columns = filtered_columns || CaseContactsExportExcelService.DATA_COLUMNS.keys | ||
@filtered_columns = filtered_columns || CaseContactsExportDataColumns.data_columns.keys | ||
|
||
@case_contacts = case_contacts.preload({ creator: :supervisor }, :contact_types, :casa_case) | ||
end | ||
|
@@ -39,11 +42,13 @@ def perform | |
def configure_case_contact_notes_width(sheet) | ||
case_contact_notes_index = filtered_columns.index(:case_contact_notes) | ||
|
||
sheet.column_info[case_contact_notes_index].width = 140 | ||
if case_contact_notes_index | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a good catch from the previous code. It was throwing a nil --> Integer error when the notes weren't a selected column. |
||
sheet.column_info[case_contact_notes_index].width = 140 | ||
end | ||
end | ||
|
||
def format_row(sheet, case_contact, wrap_style) | ||
row_data = CaseContactsExportExcelService.DATA_COLUMNS(case_contact).slice(*filtered_columns).values | ||
row_data = CaseContactsExportDataColumns.data_columns(case_contact).slice(*filtered_columns).values | ||
row_data << '' | ||
sheet.add_row(row_data, style: wrap_style) | ||
end | ||
|
@@ -63,25 +68,5 @@ def string_width(string, row, font_size) | |
font_scale = font_size / row.worksheet.workbook.font_scale_divisor | ||
(string.to_s.size + 3) * font_scale | ||
end | ||
|
||
def self.DATA_COLUMNS(case_contact = nil) | ||
# 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.strftime('%Y-%m-%d %H:%M:%S %Z'), | ||
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 | ||
} | ||
end | ||
|
||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked how you extracted the same code here so both CSV and Excel services could use it.
But what I don't like (and predates your code) is how this is used for two totally different things:
This is why all the safe operators (&) because in the view it's sending in nil for the case contact. I think a better pattern is to have a list of the columns and use them in the decorator.