Skip to content

Commit

Permalink
Extract qualifications info to event/kind decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
amaierhofer committed Mar 28, 2024
1 parent 174cbfd commit 228e6e5
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 47 deletions.
53 changes: 53 additions & 0 deletions app/decorators/event/kind_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# encoding: utf-8

# Copyright (c) 2012-2013, Jungwacht Blauring Schweiz. This file is part of
# hitobito and licensed under the Affero General Public License version 3
# or later. See the COPYING file at the top-level directory or at
# https://github.com/hitobito/hitobito.

class Event::KindDecorator < ApplicationDecorator
decorates 'event/kind'

def issued_qualifications_info_for_leaders(quali_date)
qualis = qualification_kinds('qualification', 'leader').list.to_a
prolongs = qualification_kinds('prolongation', 'leader').list.to_a
variables = { until: h.f(quali_date),
model: quali_model_name(qualis),
issued: qualis.join(', '),
prolonged: prolongs.join(', '),
count: prolongs.size }

translate_issued_qualifications_info(qualis, prolongs, variables)
end

def issued_qualifications_info_for_participants(quali_date)
qualis = qualification_kinds('qualification', 'participant').list.to_a
prolongs = qualification_kinds('prolongation', 'participant').list.to_a
variables = { until: h.f(quali_date),
model: quali_model_name(qualis),
issued: qualis.join(', '),
prolonged: prolongs.join(', '),
count: prolongs.size }

translate_issued_qualifications_info(qualis, prolongs, variables)
end

private

def translate_issued_qualifications_info(qualis, prolongs, variables)
variables = variables.merge(scope: :event_decorator)
if qualis.present? && prolongs.present?
I18n.t(:issue_and_prolong, **variables)
elsif qualis.present?
I18n.t(:issue_only, **variables)
elsif prolongs.present?
I18n.t(:prolong_only, **variables)
else
''
end
end

def quali_model_name(list)
Qualification.model_name.human(count: list.size)
end
end
56 changes: 9 additions & 47 deletions app/decorators/event_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
class EventDecorator < ApplicationDecorator
decorates :event
decorates_association :contact
decorates_association :kind

class_attribute :icons
self.icons = {
Expand Down Expand Up @@ -76,35 +77,19 @@ def external_application_link(group)
end
end

def new_role
p = participations.new
role = p.roles.new
role.participation = p
role
end

def issued_qualifications_info_for_leaders
qualis = kind.qualification_kinds('qualification', 'leader').list.to_a
prolongs = kind.qualification_kinds('prolongation', 'leader').list.to_a
variables = { until: quali_date,
model: quali_model_name(qualis),
issued: qualis.join(', '),
prolonged: prolongs.join(', '),
count: prolongs.size }

translate_issued_qualifications_info(qualis, prolongs, variables)
kind.issued_qualifications_info_for_leaders(qualification_date)
end

def issued_qualifications_info_for_participants
qualis = kind.qualification_kinds('qualification', 'participant').list.to_a
prolongs = kind.qualification_kinds('prolongation', 'participant').list.to_a
variables = { until: quali_date,
model: quali_model_name(qualis),
issued: qualis.join(', '),
prolonged: prolongs.join(', '),
count: prolongs.size }
kind.issued_qualifications_info_for_participants(qualification_date)
end

translate_issued_qualifications_info(qualis, prolongs, variables)
def new_role
p = participations.new
role = p.roles.new
role.participation = p
role
end

def as_typeahead
Expand All @@ -130,27 +115,4 @@ def any_conditions_present?
(object.used_attributes.include?(:application_conditions) &&
application_conditions.present?)
end

private

def translate_issued_qualifications_info(qualis, prolongs, variables)
if qualis.present? && prolongs.present?
translate(:issue_and_prolong, variables)
elsif qualis.present?
translate(:issue_only, variables)
elsif prolongs.present?
translate(:prolong_only, variables)
else
''
end
end

def quali_model_name(list)
Qualification.model_name.human(count: list.size)
end

def quali_date
h.f(qualification_date)
end

end

0 comments on commit 228e6e5

Please sign in to comment.