Skip to content

Commit

Permalink
Merge pull request #2311 from samvera/i1020-ga4-follow-up
Browse files Browse the repository at this point in the history
🧹 [i1020] - ga4 follow up
  • Loading branch information
ShanaLMoore authored Sep 4, 2024
2 parents f09b786 + 98a3d55 commit 83a5893
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ GIT

GIT
remote: https://github.com/samvera/hyrax.git
revision: 69f0b81ff7bdbe5dff9620306ee542668ac86425
revision: e1160bbbb1b917640515f8db1f3ad3dcdc376c47
branch: main
specs:
hyrax (5.0.1)
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/hyku.scss
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ div#collapse-citations {
}

@media (min-width: 576px) {
.citations-button .download-pdf-button {
.citations-button .file_download {
max-width: 300px;
}
}
Expand Down Expand Up @@ -552,7 +552,7 @@ span.constraint-value p, .facet-values p {
}
}

#download-pdf-button {
#file_download {
margin: 10px 0 10px 0;
}

Expand Down
2 changes: 2 additions & 0 deletions app/jobs/depositor_email_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def perform
statistics = user.statistics_for
next if statistics.nil?

next if statistics[:new_work_views].zero? && statistics[:new_file_downloads].zero?

HykuMailer.depositor_email(user, statistics, current_account).deliver_now
end
DepositorEmailNotificationJob.set(wait_until: (Time.zone.now + 1.month).beginning_of_month).perform_later
Expand Down
4 changes: 2 additions & 2 deletions app/mailers/hyku_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def summary_email(user, messages, account)
@messages = messages || []
@account = account
@url = notifications_url_for(@account)
@application_name = account.sites.application_name
@application_name = account.sites.application_name || account.name.humanize

mail(to: @user.email,
subject: "You have #{@messages.count} new message(s) on #{@application_name}",
Expand All @@ -25,7 +25,7 @@ def depositor_email(user, statistics, account)
@statistics = statistics
@account = account
@url = dashboard_url_for(@account)
@application_name = account.sites.application_name
@application_name = account.sites.application_name || account.name.humanize

mail(to: @user.email,
subject: "Monthly Downloads Summary for #{@application_name}",
Expand Down
60 changes: 30 additions & 30 deletions app/views/hyku_mailer/depositor_email.html.erb
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
.email-container { max-width: 600px; margin: auto; padding: 20px; border: 1px solid #ccc; }
.footer { font-size: 12px; color: #666; margin-top: 20px; }
.highlight { color: #0056b3; }
.button {
display: inline-block;
padding: 10px 20px;
margin: 10px 0;
background-color: #0056b3;
color: white;
text-decoration: none;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="email-container">
<p>Dear Author,</p>
<p>You had <%= pluralize(@statistics[:new_file_downloads], 'download') %> in <%= Date.today.prev_month.strftime("%B %Y") %> across your <%= pluralize(@statistics[:new_work_views], 'work') %> in <%= @application_name %>. Your current readership:</p>
<ul>
<li><%= pluralize(@statistics[:total_file_downloads], 'Total File Download') %></li>
<li><%= pluralize(@statistics[:total_work_views], 'Total Work View') %></li>
</ul>
<a href="<%= @url %>" class="button">VISIT MY DASHBOARD</a>
<div class="footer">
<p>These monthly reports are provided to you on behalf of <%= @application_name %>. For questions, comments, or to add more content and increase your readership and visibility as an author, please contact your repository administrator.</p>
<head>
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; }
.email-container { max-width: 600px; margin: auto; padding: 20px; border: 1px solid #ccc; }
.footer { font-size: 12px; color: #666; margin-top: 20px; }
.highlight { color: #0056b3; }
.button {
display: inline-block;
padding: 10px 20px;
margin: 10px 0;
background-color: #0056b3;
color: white;
text-decoration: none;
border-radius: 5px;
}
</style>
</head>
<body>
<div class="email-container">
<p>Dear Author,</p>
<p>You had <%= "#{@statistics[:new_file_downloads]} new files downloaded" %> in <%= Date.today.prev_month.strftime("%B %Y") %> and <%= "#{@statistics[:new_work_views]} new works viewed" %> in <%= @application_name %>. Your current readership:</p>
<ul>
<li><%= pluralize(@statistics[:total_file_downloads], 'Total File Download') %></li>
<li><%= pluralize(@statistics[:total_work_views], 'Total Work View') %></li>
</ul>
<a href="<%= @url %>" class="button">VISIT MY DASHBOARD</a>
<div class="footer">
<p>These monthly reports are provided to you on behalf of <%= @application_name %>. For questions, comments, or to add more content and increase your readership and visibility as an author, please contact your repository administrator.</p>
</div>
</div>
</div>
</body>
</body>
</html>
4 changes: 2 additions & 2 deletions app/views/hyrax/base/_download_pdf.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<div class="download-pdf-controls">
<% if @presenter.representative_presenter.present? && presenter.file_set_presenters.any?(&:pdf?) %>
<%= button_tag type: 'button',
id: "download-pdf-button",
id: "file_download",
data: { label: @presenter.representative_presenter.id,
path: hyrax.download_path(presenter.representative_presenter) },
class: "btn btn-success btn-block download-pdf-button center-block",
class: "btn btn-success btn-block file_download center-block",
onclick: "window.open(this.dataset.path, '_blank');" do %>
Download PDF
<% end %>
Expand Down
15 changes: 15 additions & 0 deletions spec/jobs/depositor_email_notification_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@
end
end

context 'when the user has zero new counts in statistics' do
let(:statistics) { { new_file_downloads: 0, new_work_views: 0, total_file_downloads: 6, total_file_views: 7, total_work_views: 16 } }

before do
allow(User).to receive(:all).and_return([user])
allow(user).to receive(:statistics_for).and_return(statistics)
end

it 'does not send emails to users' do
switch!(account)
described_class.perform_now
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end

context 'when the user has no new statistics' do
let(:statistics) { nil }

Expand Down

0 comments on commit 83a5893

Please sign in to comment.