Skip to content

Commit

Permalink
addressing text rendering issues in email
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcam-src committed Aug 12, 2024
1 parent bf71af9 commit 9f6deb9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/services/tasks/dimensions_reporting_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def generate_report
def extract_publication_info
publication_info = {successfully_ingested: [], failed_to_ingest: []}
@ingested_publications[:ingested].map do |publication|
publication_item = { title: publication['title'], id: publication['id'], linkout: publication['linkout'] || 'None', url: "#{ENV['HYRAX_HOST']}/concern/articles/#{publication['article_id']}?locale=en", pdf_attached: publication['pdf_attached'] ? 'Yes' : 'No' }
publication_item = { title: publication['title'], id: publication['id'], linkout: publication['linkout'], url: "#{ENV['HYRAX_HOST']}/concern/articles/#{publication['article_id']}?locale=en", pdf_attached: publication['pdf_attached'] ? 'Yes' : 'No' }
publication_info[:successfully_ingested] << publication_item
end
@ingested_publications[:failed].map do |publication|
publication_info[:failed_to_ingest] << { title: publication['title'], id: publication['id'], linkout: publication['linkout'] || 'None', error: "#{publication['error'][0]} - #{publication['error'][1]}" }
publication_info[:failed_to_ingest] << { title: publication['title'], id: publication['id'], linkout: publication['linkout'], error: "#{publication['error'][0]} - #{publication['error'][1]}" }
end
publication_info
end
Expand Down
18 changes: 16 additions & 2 deletions app/views/dimensions_report_mailer/dimensions_report_email.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,14 @@
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;"><%= publication[:id] %></td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;"><a href="<%= publication[:url] %>"><%= publication[:url] %></a></td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;"><%= publication[:pdf_attached] %></td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;"><a href="<%= publication[:linkout].gsub('"', '\"') %>">Link</a></td>
<!-- Render PDF Link Text Conditionally -->
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;">
<% if publication[:linkout].blank? %>
N/A
<% else %>
<a href="<%= publication[:linkout].gsub('"', '\"') %>">Link</a>
<% end %>
</td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;">N/A</td>
</tr>
<% end %>
Expand All @@ -54,7 +61,14 @@
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;"><%= publication[:id] %></td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;">N/A</td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;">N/A</td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;"><%= publication[:linkout] %></td>
<!-- Render PDF Link Text Conditionally -->
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;">
<% if publication[:linkout].blank? %>
N/A
<% else %>
<a href="<%= publication[:linkout].gsub('"', '\"') %>">Link</a>
<% end %>
</td>
<td style="border: 2px solid #dddddd; text-align: left; padding: 10px;"><%= publication[:error] %></td>
</tr>
<% end %>
Expand Down
13 changes: 13 additions & 0 deletions spec/mailers/previews/dimensions_report_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ def dimensions_report_email
pub.merge('error' => ['Test error', 'Test error message'])
end

# Test conditional rendering of linkout for even publications in both failed and ingested arrays
ingested_publications[:failed].each_with_index do |pub, index|
if index.even?
pub['linkout'] = nil
end
end

ingested_publications[:ingested].each_with_index do |pub, index|
if index.even?
pub['linkout'] = nil
end
end

dimensions_reporting_service = Tasks::DimensionsReportingService.new(ingested_publications, FIXED_DIMENSIONS_TOTAL_COUNT, { start_date: TEST_START_DATE, end_date: TEST_END_DATE }, FALSE)
report = dimensions_reporting_service.generate_report
DimensionsReportMailer.dimensions_report_email(report)
Expand Down

0 comments on commit 9f6deb9

Please sign in to comment.