Skip to content

Commit

Permalink
Add notifications for redemption of teacher vouchers
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterfarrell9 committed Aug 17, 2024
1 parent 102bcc2 commit 09f47c2
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 63 deletions.
2 changes: 2 additions & 0 deletions app/controllers/vouchers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ def success_message(voucher)
I18n.t("controllers.become_tutor_success")
elsif voucher.editor?
I18n.t("controllers.become_editor_success")
elsif voucher.teacher?
I18n.t("controllers.become_teacher_success")
end
end

Expand Down
6 changes: 6 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,10 @@ def get_class_for_any_path(paths)
def get_class_for_any_path_startswith(paths)
paths.any? { |path| request.path.starts_with?(path) } ? ACTIVE_CSS_CLASS : ""
end

def truncate_result(result, length = 40)
result.first(length).tap do |truncated|
return truncated.length < length ? truncated : "#{truncated}..."
end
end
end
59 changes: 0 additions & 59 deletions app/helpers/notifications_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,63 +89,4 @@ def items_card_size(small, comments_below)

"70vh"
end

# create text for lecture announcement in notification card header
def redemption_notification_card_header(redemption)
link_to(redemption.lecture.title_for_viewers,
edit_lecture_path(redemption.lecture, anchor: "people"),
class: "text-dark")
end

def redemption_notification_item_header(redemption)
t("notifications.redemption_in_lecture",
lecture: redemption.lecture.title_for_viewers)
end

def redemption_notification_details(redemption)
if redemption.tutor?
tutor_notification_details(redemption)
else
editor_notification_details(redemption)
end
end

def redemption_notification_item_details(redemption)
result = if redemption.tutor?
tutor_notification_item_details(redemption)
elsif redemption.editor?
editor_notification_item_details(redemption)
end

truncate_result(result)
end

private

def tutor_notification_item_details(redemption)
tutorials = redemption.claimed_tutorials.map(&:title).join(", ")
"#{t("basics.tutor")} #{redemption.user.tutorial_name}: #{tutorials}"
end

def editor_notification_item_details(redemption)
"#{t("basics.editor")} #{redemption.user.tutorial_name}"
end

def tutor_notification_details(redemption)
details = I18n.t("notifications.became_tutor",
user: redemption.user.info)
tutorial_titles = redemption.claimed_tutorials.map(&:title).join(", ")
details << I18n.t("notifications.tutorial_details",
tutorials: tutorial_titles)
end

def editor_notification_details(redemption)
I18n.t("notifications.became_editor", user: redemption.user.info)
end

def truncate_result(result)
result.first(40).tap do |truncated|
return truncated.length < 40 ? truncated : "#{truncated}..."
end
end
end
66 changes: 66 additions & 0 deletions app/helpers/redemptions_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Redemptions Helper
module RedemptionsHelper
def redemption_notification_card_header(redemption)
link_to(redemption.lecture.title_for_viewers,
edit_lecture_path(redemption.lecture, anchor: "people"),
class: "text-dark")
end

def redemption_notification_item_header(redemption)
t("notifications.redemption_in_lecture",
lecture: redemption.lecture.title_for_viewers)
end

def redemption_notification_details(redemption)
if redemption.tutor?
tutor_notification_details(redemption)
elsif redemption.editor?
editor_notification_details(redemption)
elsif redemption.teacher?
teacher_notification_details(redemption)
end
end

def redemption_notification_item_details(redemption)
result = if redemption.tutor?
tutor_notification_item_details(redemption)
elsif redemption.editor?
editor_notification_item_details(redemption)
elsif redemption.teacher?
teacher_notification_item_details(redemption)
end

truncate_result(result)
end

private

def tutor_notification_item_details(redemption)
tutorials = redemption.claimed_tutorials.map(&:title).join(", ")
"#{t("basics.tutor")} #{redemption.user.tutorial_name}: #{tutorials}"
end

def editor_notification_item_details(redemption)
"#{t("basics.editor")} #{redemption.user.tutorial_name}"
end

def teacher_notification_item_details(redemption)
"#{t("basics.teacher")} #{redemption.user.tutorial_name}"
end

def tutor_notification_details(redemption)
details = I18n.t("notifications.became_tutor",
user: redemption.user.info)
tutorial_titles = redemption.claimed_tutorials.map(&:title).join(", ")
details << I18n.t("notifications.tutorial_details",
tutorials: tutorial_titles)
end

def editor_notification_details(redemption)
I18n.t("notifications.became_editor", user: redemption.user.info)
end

def teacher_notification_details(redemption)
I18n.t("notifications.became_teacher", user: redemption.user.info)
end
end
2 changes: 1 addition & 1 deletion app/models/lecture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ def update_teacher_status!(user)
return if teacher == user

previous_teacher = teacher
self.teacher = user
update(teacher: user)
editors << previous_teacher
# touch to invalidate the cache
touch
Expand Down
1 change: 1 addition & 0 deletions app/models/redemption.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Redemption < ApplicationRecord
delegate :sort, to: :voucher
delegate :tutor?, to: :voucher
delegate :editor?, to: :voucher
delegate :teacher?, to: :voucher

def create_notifications!
lecture.editors_and_teacher.each do |editor|
Expand Down
4 changes: 3 additions & 1 deletion app/views/vouchers/_redeem_teacher_voucher.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<%= t('profile.become_teacher', lecture: voucher.lecture.title) %>
<p>
<%= t('profile.become_teacher', lecture: voucher.lecture.title) %>
</p>

<% if current_user == voucher.lecture.teacher %>
<%= t('profile.already_teacher') %>
Expand Down
13 changes: 11 additions & 2 deletions config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,15 @@ de:
section_needed: Bitte erstelle zuerst einen Abschnitt
voucher_for_tutor: >
Gutscheine für TutorInnen können von NutzerInnen eingelöst werden, um
TutorIn für diese Veranstaltung zu werden.
TutorInnenstatus für diese Veranstaltung zu erhalten und ggf. direkt
Tutorien zu übernehmen.
voucher_for_editor: >
Gutscheine für EditorInnen können von NutzerInnen eingelöst werden, um
EditorIn für diese Veranstaltung zu werden.
EditorInnenstatus für diese Veranstaltung zu ehalten.
voucher_for_teacher: >
Gutscheine für DozentInnen können von NutzerInnen eingelöst werden, um
DozentInnenstatus für diese Veranstaltung zu erhalten. Die bisherige
DozentIn wird dann EditorIn.
show_media: 'Medien einblenden'
workflow: 'Workflow'
content_mode: 'Inhaltsermittlung'
Expand Down Expand Up @@ -2271,6 +2276,9 @@ de:
became_editor: >
%{user} hat einen EditorInnen-Gutschein eingelöst und ist jetzt EditorIn in der
Veranstaltung.
became_teacher: >
%{user} hat einen DozentInnen-Gutschein eingelöst und ist jetzt DozentIn
der Veranstaltung.
tutorial_details: >
Neu übernommene Tutorien: %{tutorials}.
redemption: 'Gutschein eingelöst:'
Expand Down Expand Up @@ -3755,6 +3763,7 @@ de:
voucher_invalid: 'Der Gutschein ist ungültig.'
become_tutor_success: 'Dein Tutorenstatus wurde geupdatet.'
become_editor_success: 'Dein Editorenstatus wurde geupdatet.'
become_teacher_success: 'Dein DozentInnenstatus wurde geupdatet.'
tutorials:
destruction_failed: >
Das Tutorium konnte nicht gelöscht werden. Das kann z.B. daran liegen,
Expand Down
5 changes: 5 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2141,6 +2141,9 @@ en:
became_editor: >
%{user} has redeemed an editor voucher and has therefore become editor
in the event series.
became_teacher: >
%{user} has redeemed a teacher voucher and has therefore become teacher
in the event series.
tutorial_details: >
Tutorials taken over: %{tutorials}.
redemption: 'Voucher redeemed:'
Expand Down Expand Up @@ -3564,6 +3567,8 @@ en:
Your tutor status has been updated.
become_editor_success: >
Your editor status has been updated.
become_teacher_success: >
Your teacher status has been updated.
tutorials:
destruction_failed: >
The tutorial could not be deleted. That may be because there are already
Expand Down

0 comments on commit 09f47c2

Please sign in to comment.