Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
open-source
aoz-003
Commits
fac9051e
Commit
fac9051e
authored
Jul 26, 2017
by
Kaspar Vollenweider
👻
Committed by
Kaspar
Jul 26, 2017
Browse files
change collections methods to constants - faster and slimer, better readability
parent
e2aecf6d
Changes
28
Hide whitespace changes
Inline
Side-by-side
app/controllers/concerns/contact_attributes.rb
View file @
fac9051e
...
...
@@ -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:
c
ontact
_p
oint
_attrs
,
contact_phones_attributes:
c
ontact
_p
oint
_attrs
contact_emails_attributes:
C
ontact
P
oint
::
FORM_ATTRS
,
contact_phones_attributes:
C
ontact
P
oint
::
FORM_ATTRS
]
}
end
def
contact_point_attrs
[
:id
,
:body
,
:label
,
:_destroy
,
:type
,
:contacts_id
]
end
end
end
app/models/assignment.rb
View file @
fac9051e
...
...
@@ -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
app/models/client.rb
View file @
fac9051e
...
...
@@ -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
}
"
...
...
app/models/contact_email.rb
View file @
fac9051e
...
...
@@ -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
app/models/contact_phone.rb
View file @
fac9051e
class
ContactPhone
<
ContactPoint
LABELS
=
[
:fax
,
:work
,
:home
,
:miscellaneous
].
freeze
def
self
.
label_collection
[
:fax
,
:work
,
:home
,
:miscellaneous
]
end
...
...
app/models/contact_point.rb
View file @
fac9051e
...
...
@@ -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
app/models/language_skill.rb
View file @
fac9051e
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?
...
...
app/models/relative.rb
View file @
fac9051e
...
...
@@ -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
app/models/volunteer.rb
View file @
fac9051e
...
...
@@ -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
}
"
...
...
app/policies/department_policy.rb
View file @
fac9051e
...
...
@@ -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:
c
ontact
_p
oint
_attrs
,
contact_phones_attributes:
c
ontact
_p
oint
_attrs
contact_emails_attributes:
C
ontact
P
oint
::
FORM_ATTRS
,
contact_phones_attributes:
C
ontact
P
oint
::
FORM_ATTRS
]
]
end
...
...
app/views/assignments/_age_request_select.html.slim
View file @
fac9051e
...
...
@@ -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
})
app/views/assignments/_duration_select.html.slim
View file @
fac9051e
...
...
@@ -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
})
app/views/assignments/_form.html.slim
View file @
fac9051e
...
...
@@ -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
...
...
app/views/assignments/_gender_request_select.html.slim
View file @
fac9051e
...
...
@@ -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
})
app/views/assignments/_seeking_client.html.slim
View file @
fac9051e
...
...
@@ -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
...
...
app/views/assignments/find_client.html.slim
View file @
fac9051e
...
...
@@ -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
...
...
app/views/clients/_form.html.slim
View file @
fac9051e
...
...
@@ -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
...
...
app/views/contacts/_email_fields.slim
View file @
fac9051e
...
...
@@ -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'
app/views/contacts/_phone_fields.slim
View file @
fac9051e
...
...
@@ -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'
app/views/language_skills/_fields.html.slim
View file @
fac9051e
...
...
@@ -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'
Prev
1
2
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment