Commit fac9051e authored by Kaspar Vollenweider's avatar Kaspar Vollenweider 👻 Committed by Kaspar
Browse files

change collections methods to constants - faster and slimer, better readability

parent e2aecf6d
......@@ -9,14 +9,10 @@ module ContactAttributes
:id, :first_name, :last_name, :_destroy, :contactable_id,
:contactable_type, :street, :extended, :city, :postal_code,
:primary_email, :primary_phone, :title,
contact_emails_attributes: contact_point_attrs,
contact_phones_attributes: contact_point_attrs
contact_emails_attributes: ContactPoint::FORM_ATTRS,
contact_phones_attributes: ContactPoint::FORM_ATTRS
]
}
end
def contact_point_attrs
[:id, :body, :label, :_destroy, :type, :contacts_id]
end
end
end
......@@ -5,7 +5,5 @@ class Assignment < ApplicationRecord
validates :client_id, uniqueness: { scope: :volunteer_id, message: I18n.t('assignment_exists') }
def self.state_collection
[:suggested, :active]
end
STATES = [:suggested, :active].freeze
end
......@@ -27,17 +27,13 @@ class Client < ApplicationRecord
validates :state, inclusion: { in: STATES }
def self.gender_request_collection
[:no_matter, :same]
end
def self.age_request_collection
[:age_no_matter, :age_young, :age_middle, :age_old]
end
scope :need_accompanying, lambda {
includes(:assignment).where(assignments: { client_id: nil }).order(created_at: :asc)
}
def self.need_accompanying
Client.includes(:assignment).where(assignments: { client_id: nil }).order(created_at: :asc)
end
GENDER_REQUESTS = [:no_matter, :same].freeze
AGE_REQUESTS = [:age_no_matter, :age_young, :age_middle, :age_old].freeze
PERMITS = [:N, :F, :'B-FL', :B, :C].freeze
def to_s
"#{contact.first_name} #{contact.last_name}"
......
......@@ -4,7 +4,5 @@ class ContactEmail < ContactPoint
message: 'Not an email address.'
}
def self.label_collection
[:work, :home, :miscellaneous]
end
LABELS = [:work, :home, :miscellaneous].freeze
end
class ContactPhone < ContactPoint
LABELS = [:fax, :work, :home, :miscellaneous].freeze
def self.label_collection
[:fax, :work, :home, :miscellaneous]
end
......
......@@ -2,4 +2,6 @@ class ContactPoint < ApplicationRecord
belongs_to :contact, optional: true
validates :body, presence: true
FORM_ATTRS = [:id, :body, :label, :_destroy, :type, :contacts_id].freeze
end
class LanguageSkill < ApplicationRecord
belongs_to :languageable, polymorphic: true, optional: true
def self.language_level_collection
[:native_speaker, :fluent, :good, :basic]
end
LANGUAGE_LEVELS = [:native_speaker, :fluent, :good, :basic].freeze
def language_name
return '' if language.blank?
......
......@@ -12,7 +12,7 @@ class Relative < ApplicationRecord
"#{first_name} #{last_name}"
end
def self.relation_collection
[:wife, :husband, :mother, :father, :daughter, :son, :sister, :brother, :aunt, :uncle]
end
RELATIONS = [
:wife, :husband, :mother, :father, :daughter, :son, :sister, :brother, :aunt, :uncle
].freeze
end
......@@ -64,22 +64,6 @@ class Volunteer < ApplicationRecord
state == REJECTED
end
def self.duration_collection
[:short, :long]
end
def self.region_collection
[:city, :region, :canton]
end
def self.single_accompaniment
[:man, :woman, :family, :kid]
end
def self.group_accompaniment
[:sport, :creative, :music, :culture, :training, :german_course]
end
def self.human_boolean(boolean)
boolean ? I18n.t('simple_form.yes') : I18n.t('simple_form.no')
end
......@@ -88,17 +72,13 @@ class Volunteer < ApplicationRecord
STATES.map(&:to_sym)
end
def self.state_collection_for_reviewed
STATES_FOR_REVIEWED.map(&:to_sym)
end
def self.rejection_collection
[:us, :her, :other]
end
def self.target_group
[:adults, :teenagers, :children]
end
DURATIONS = [:short, :long].freeze
REGIONS = [:city, :region, :canton].freeze
SINGLE_ACCOMPANIMENTS = [:man, :woman, :family, :kid].freeze
GROUP_ACCOMPANIMENTS = [:sport, :creative, :music, :culture, :training, :german_course].freeze
REJECTIONS = [:us, :her, :other].freeze
TARGET_GROUPS = [:adults, :teenagers, :children].freeze
GENDERS = [:female, :male].freeze
def to_s
"#{contact.first_name} #{contact.last_name}"
......
......@@ -68,17 +68,13 @@ class DepartmentPolicy < ApplicationPolicy
@user.superadmin? || @department.user.include?(@user)
end
def contact_point_attrs
[:id, :body, :label, :_destroy, :type, :contacts_id]
end
def department_attributes
[
contact_attributes: [
:id, :last_name, :_destroy, :contactable_id, :contactable_type, :street,
:extended, :city, :postal_code,
contact_emails_attributes: contact_point_attrs,
contact_phones_attributes: contact_point_attrs
contact_emails_attributes: ContactPoint::FORM_ATTRS,
contact_phones_attributes: ContactPoint::FORM_ATTRS
]
]
end
......
......@@ -7,5 +7,5 @@
ul.dropdown-menu
li
= link_to t('all'), request_params_filter({age_request_cont: ''})
- Client.age_request_collection.each do |s|
- Client::AGE_REQUESTS.each do |s|
li= link_to t(s.to_s, scope: [:simple_form, :options, :client, :age_request]), request_params_filter({age_request_cont: s})
......@@ -7,5 +7,5 @@
ul.dropdown-menu
li
= link_to t('all'), params.permit!.to_h.deep_merge(q: {duration_cont: ''})
- Volunteer.duration_collection.each do |s|
- Volunteer::DURATIONS.each do |s|
li= link_to t(s.to_s, scope: [:simple_form, :options, :volunteer, :duration]), params.permit!.to_h.deep_merge(q: {duration_cont: s})
......@@ -11,7 +11,7 @@
.row
.col-xs-12
= f.input :state, collection: Assignment.state_collection, default: :suggested
= f.input :state, collection: Assignment::STATES, default: :suggested
.row
.col-xs-12
......
......@@ -7,5 +7,5 @@
ul.dropdown-menu
li
= link_to t('all'), request_params_filter({gender_request_cont: ''})
- Client.gender_request_collection.each do |s|
- Client::GENDER_REQUESTS.each do |s|
li= link_to t(s.to_s, scope: [:simple_form, :options, :client, :gender_request]), request_params_filter({gender_request_cont: s})
......@@ -12,12 +12,12 @@ tr
td= Volunteer.human_boolean(seeking_client.experience)
td= t("duration.#{seeking_client.duration}") if seeking_client.duration.present?
td
- Volunteer.single_accompaniment.each do |single|
- Volunteer::SINGLE_ACCOMPANIMENTS.each do |single|
- if seeking_client[single]
= t("activerecord.attributes.volunteer.#{single}")
br
td
- Volunteer.group_accompaniment.each do |group|
- Volunteer::GROUP_ACCOMPANIMENTS.each do |group|
- if seeking_client[group]
= t("activerecord.attributes.volunteer.#{group}")
br
......
......@@ -9,11 +9,11 @@ h3= t_attr(:single_accompaniment)
table.table.table-striped
thead
tr
- Volunteer.single_accompaniment.each do |single|
- Volunteer::SINGLE_ACCOMPANIMENTS.each do |single|
th.text-center= t_attr(single)
tbody
tr
- Volunteer.single_accompaniment.each do |single|
- Volunteer::SINGLE_ACCOMPANIMENTS.each do |single|
td.text-center
- if @volunteer.read_attribute(single)
i.glyphicon.glyphicon-ok.text-success
......
......@@ -19,7 +19,7 @@
= f.input :nationality, as: :country
.col-xs-12.col-md-6
= f.input :permit,
collection: permit_collection,
collection: Client::PERMITS,
as: :radio_buttons,
wrapper: :vertical_radio_and_checkboxes
......@@ -32,8 +32,8 @@
h3= t('personal_background')
= f.input :goals
h3= t('volunteer_request')
= f.input :gender_request, collection: Client.gender_request_collection, default: :no_matter
= f.input :age_request, collection: Client.age_request_collection, default: :age_no_matter
= f.input :gender_request, collection: Client::GENDER_REQUESTS, default: :no_matter
= f.input :age_request, collection: Client::AGE_REQUESTS, default: :age_no_matter
= f.input :other_request
= f.input :education
= f.input :actual_activities
......
......@@ -4,7 +4,7 @@
= f.input :body, as: :email
.col-xs-12.col-md-4
= f.input :label, collection: ContactEmail.label_collection, include_blank: true
= f.input :label, collection: ContactEmail::LABELS, include_blank: true
.col-xs-12.col-md-12
= link_to_remove_association t_title(:destroy, ContactEmail), f, class: 'btn btn-xs btn-danger'
......@@ -4,7 +4,7 @@
= f.input :body, as: :tel
.col-xs-12.col-md-4
= f.input :label, collection: ContactPhone.label_collection, include_blank: true
= f.input :label, collection: ContactPhone::LABELS, include_blank: true
.col-xs-12.col-md-12
= link_to_remove_association t_title(:destroy, ContactPhone), f, class: 'btn btn-xs btn-danger'
......@@ -3,7 +3,7 @@
.col-xs-12.col-md-6
= f.input :language, collection: languages
.col-xs-12.col-md-6
= f.input :level, collection: LanguageSkill.language_level_collection
= f.input :level, collection: LanguageSkill::LANGUAGE_LEVELS
.row
.col-xs-12.col-md-12
= link_to_remove_association t('remove_language'), f, class: 'btn btn-danger'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment