Skip to content

Commit

Permalink
Merge branch 'dev' into 148__ConsGerman_Errors_MeineBewerbungen
Browse files Browse the repository at this point in the history
  • Loading branch information
radscheit committed Jan 5, 2017
2 parents 88f95d1 + 04bd244 commit f9d3a88
Show file tree
Hide file tree
Showing 32 changed files with 142 additions and 71 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_letters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create
@application_letter.user_id = current_user.id

if @application_letter.save
redirect_to @application_letter, notice: 'Application was successfully created.'
redirect_to @application_letter, notice: I18n.t('application_letters.successful_creation')
else
render :new
end
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def create

if @profile.save
if flash[:event_id]
redirect_to new_application_letter_path(:event_id => flash[:event_id])
redirect_to new_application_letter_path(:event_id => flash[:event_id]), notice: I18n.t('profiles.successful_creation')
else
redirect_to @profile
redirect_to @profile, notice: I18n.t('profiles.successful_creation')
end
else
render :new
Expand All @@ -41,7 +41,7 @@ def create
# PATCH/PUT /profiles/1
def update
if @profile.update(profile_params)
redirect_to @profile, notice: 'Profile was successfully updated.'
redirect_to @profile, notice: I18n.t('profiles.successful_update')
else
render :edit
end
Expand All @@ -50,7 +50,7 @@ def update
# DELETE /profiles/1
def destroy
@profile.destroy
redirect_to profiles_url, notice: 'Profile was successfully destroyed.'
redirect_to profiles_url, notice: I18n.t('profiles.successful_deletion')
end

private
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/applicants_overview_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ def sort_caret(label, attr)
#{label} <span class=\"caret\"></span>
</a>".html_safe
end

def sort_application_letters
@application_letters.sort_by! {|l| l.user.profile.send(params[:sort]) } if params[:sort] && params[:sort] != 'applicant_age_when_event_starts'
@application_letters.sort_by! {|l| l.send(params[:sort]) } if params[:sort] && params[:sort] == 'applicant_age_when_event_starts'
@application_letters.reverse! if params[:order] == 'descending'
end
end
8 changes: 8 additions & 0 deletions app/models/application_letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,12 @@ def status_cannot_be_changed
errors.add(:event, "Die Bewerbungen wurden bereits bearbeitet, eine Statusänderung ist nicht mehr erlaubt.")
end
end

# Returns the age of the user based on the date the event starts
#
# @param none
# @return [Int] for age as number of years
def applicant_age_when_event_starts
user.profile.age_at_time(event.start_date)
end
end
13 changes: 10 additions & 3 deletions app/models/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ def adult?()
# @param none
# @return [Int] for age as number of years
def age
now = Time.now.utc.to_date
current_time_is_before_birthday = now.month > birth_date.month || (now.month == birth_date.month && now.day >= birth_date.day)
return now.year - birth_date.year - (current_time_is_before_birthday ? 0 : 1)
return age_at_time(Time.now)
end

# Returns the age of the user based on the given date
#
# @param none
# @return [Int] for age as number of years
def age_at_time (given_date)
given_date_is_before_birth_date = given_date.month > birth_date.month || (given_date.month == birth_date.month && given_date.day >= birth_date.day)
return given_date.year - birth_date.year - (given_date_is_before_birth_date ? 0 : 1)
end

# Returns the Full Name of the user
Expand Down
6 changes: 2 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,8 @@ def requires_agreement_letter_for_event?(given_event)
# @return [Boolean]
def older_than_required_age_at_start_date_of_event?(given_event, age)
return false unless self.profile
event_start = given_event.start_date
event_start_is_before_birthday = event_start.month > self.profile.birth_date.month || (event_start.month == self.profile.birth_date.month && event_start.day >= self.profile.birth_date.day)
age_at_event_start = event_start.year - self.profile.birth_date.year - (event_start_is_before_birthday ? 0 : 1)
return age_at_event_start >= age
age_at_event_start = self.profile.age_at_time(given_event.start_date)
return age_at_event_start >= age
end

has_one :profile
Expand Down
2 changes: 1 addition & 1 deletion app/views/application_letters/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
application_letter_path(application),
:method => :delete,
:data => {:confirm => t('.confirm', :default => t("application_letters.confirm_deletion", :default => 'Are you sure?'))},
:data => {:confirm => t('.confirm', :default => t("helpers.links.confirm", :default => t("application_letters.confirmApplicationDelete")))},
:class => 'btn btn-xs btn-danger' %>
<% end %>
</td>
Expand Down
4 changes: 2 additions & 2 deletions app/views/application_letters/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<dl class="dl-horizontal" id="applicant_details">
<dt><strong><%= Profile.human_attribute_name(:gender) %>:</strong></dt>
<dd><%= @application_letter.user.profile.gender %></dd>
<dt><strong><%= Profile.human_attribute_name(:age) %>:</strong></dt>
<dd><%= @application_letter.user.profile.age %></dd>
<dt><strong><%= t('.age_when_event_starts') %>:</strong></dt>
<dd><%= @application_letter.user.profile.age_at_time(@application_letter.event.start_date) %></dd>
<dt><strong><%= Profile.human_attribute_name(:address) %>:</strong></dt>
<dd><%= @application_letter.user.profile.address %></dd>
<dt><strong><%= User.human_attribute_name(:accepted_application_count) %>:</strong></dt>
Expand Down
12 changes: 4 additions & 8 deletions app/views/devise/registrations/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@
<%= f.email_field :email, autofocus: true, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :name %>
<%= f.text_field :name, autofocus: true, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password %> <i>(<%= t('.leave_blank_if_you_don_t_want_to_change_it', :default => "leave blank if you don't want to change it") %>)</i>
<%= f.label :password %> <i>(<%= t('devise.messages.leave_blank_if_you_don_t_want_to_change_it', :default => "leave blank if you don't want to change it") %>)</i>
<%= f.password_field :password, :autocomplete => "off", class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :password_confirmation %>
<%= f.label :password_confirmation %> <i>(<%= t('devise.messages.leave_blank_if_you_don_t_want_to_change_it', :default => "leave blank if you don't want to change it") %>)</i>
<%= f.password_field :password_confirmation, class: "form-control" %>
</div>
<div class="form-group">
<%= f.label :current_password %> <i>(<%= t('.we_need_your_current_password_to_confirm_your_changes', :default => 'we need your current password to confirm your changes') %>)</i>
<%= f.label :current_password %> <i>(<%= t('devise.messages.we_need_your_current_password_to_confirm_your_changes', :default => 'we need your current password to confirm your changes') %>)</i>
<%= f.password_field :current_password, class: "form-control" %>
</div>
<div class="form-group">
Expand All @@ -36,4 +32,4 @@

<p><%= t('.unhappy', :default => 'Unhappy') %>? <%= link_to t('.cancel_my_account', :default => "Cancel my account"), registration_path(resource_name), :data => { :confirm => t('.are_you_sure', :default => "Are you sure?") }, :method => :delete %>.</p>

<%= link_to t('.back', :default => 'Back'), :back %>
<%= link_to t('.back', :default => t('navigational.back')), :back %>
12 changes: 5 additions & 7 deletions app/views/events/_applicants_overview.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<th>
<%= sort_caret(Profile.human_attribute_name(:gender), :gender) %>
</th>
<th>
<%= sort_caret(Profile.human_attribute_name(:age), :age) %>
<th style="max-width: 100px">
<%= sort_caret(( t('.age_when_event_starts')), :applicant_age_when_event_starts ) %>
</th>
<th>
<%= t '.participations' %> <br>
Expand All @@ -33,14 +33,12 @@
</tr>
</thead>
<tbody>
<%
@application_letters.sort_by! {|l| l.user.profile.send(params[:sort]) } if params[:sort]
@application_letters.reverse! if params[:order] == 'descending'
@application_letters.select {|l| l.user.profile }.each do | application_letter | %>
<% sort_application_letters
@application_letters.select {|l| l.user.profile }.each do | application_letter |%>
<tr>
<td><%= application_letter.user.profile.name %></td>
<td><%= application_letter.user.profile.gender %></td>
<td><%= application_letter.user.profile.age %></td>
<td><%= application_letter.user.profile.age_at_time(@event.start_date) %> </td>
<td><%= application_letter.user.accepted_applications_count(@event) %> / <%= application_letter.user.rejected_applications_count(@event) %></td>
<td>
<%= render :partial => 'application_letters/application_selective', locals: {application_letter: application_letter} %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/profiles/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= form_for @profile, :html => { :class => "form-horizontal profile" } do |f| %>
<%= render partial: "shared/error_message", locals: {entity: @profile} %>
<%= render partial: "shared/error_message_detailed", locals: {entity: @profile} %>
<%# Create an input field for each of the mandatory attributes%>
<% [:first_name, :last_name, :gender, :birth_date, :school, :street_name, :zip_code, :city, :state, :country].each do |attr_name| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/requests/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%- model_class = Request -%>
<div class="page-header">
<h1><%=t '.title', :default => [:'helpers.titles.edit', 'Edit %{model}'], :model => model_class.model_name.human.titleize %></h1>
<h1><%=t '.title', :default => model_class.model_name.human(count: 2).titleize %></h1>
</div>
<%= render :partial => 'form' %>
4 changes: 2 additions & 2 deletions app/views/requests/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%- model_class = Request -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human.pluralize.titleize %></h1>
<h1><%=t '.title', :default => model_class.model_name.human(count: 2).titleize %></h1>
</div>
<table class="table table-striped">
<thead>
Expand Down Expand Up @@ -28,7 +28,7 @@
<%= link_to t('.destroy', :default => t("helpers.links.destroy")),
request_path(request),
:method => :delete,
:data => { :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')) },
:data => { :confirm => t('dialogues.confirm_delete') },
:class => 'btn btn-xs btn-danger' %>
<% end %>
</td>
Expand Down
2 changes: 1 addition & 1 deletion app/views/requests/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%- model_class = Request -%>
<div class="page-header">
<h1><%=t '.title', :default => [:'helpers.titles.new', 'New %{model}'], :model => model_class.model_name.human.titleize %></h1>
<h1><%=t '.title', :default => model_class.model_name.human(count: 2).titleize %></h1>
</div>
<%= render :partial => 'form' %>
2 changes: 1 addition & 1 deletion app/views/requests/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%- model_class = Request -%>
<div class="page-header">
<h1><%=t '.title', :default => model_class.model_name.human.titleize %></h1>
<h1><%=t '.title', :default => model_class.model_name.human(count: 2).titleize %></h1>
</div>

<dl class="dl-horizontal">
Expand Down
3 changes: 2 additions & 1 deletion app/views/shared/_error_message_detailed.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@
</ul>
</div>
</div>
<% end %>
<% end %>

1 change: 1 addition & 0 deletions config/locales/de.application_letters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ de:
confirmApplicationDelete: "Bist du dir sicher, dass du diese Bewerbung löschen möchtest? Dieser Schritt kann nicht widerrufen werden."
show:
application_title: "Bewerbung für %{title}"
age_when_event_starts: "Alter bei Beginn"
new_note: "Neue Anmerkung:"
form:
warning: "Die Deadline ist schon vorbei. Du kannst deine Bewerbung nicht mehr ändern."
Expand Down
3 changes: 3 additions & 0 deletions config/locales/de.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,6 @@ de:
long: "%A, %d. %B %Y, %H:%M Uhr"
short: "%d. %B, %H:%M Uhr"
pm: nachmittags



7 changes: 5 additions & 2 deletions config/locales/de.devise.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

de:
devise:
messages:
leave_blank_if_you_don_t_want_to_change_it: "Leer lassen, falls du dein Passwort jetzt nicht verändern möchtest."
we_need_your_current_password_to_confirm_your_changes: "Bitte ausfüllen, falls du Änderungen speichern möchtest."
confirmations:
confirmed: "Vielen Dank für Deine Registrierung. Bitte melde dich jetzt an."
confirmed_and_signed_in: "Vielen Dank für Deine Registrierung. Du bist jetzt angemeldet."
Expand Down Expand Up @@ -56,5 +59,5 @@ de:
not_found: "nicht gefunden"
not_locked: "ist nicht gesperrt"
not_saved:
one: "Konnte %{resource} nicht speichern: ein Fehler."
other: "Konnte %{resource} nicht speichern: %{count} Fehler."
one: "%{resource} konnte nicht gespeichert werden: ein Fehler. Bitte korrigiere deine Eingabe, um fortzufahren."
other: "%{resource} konnte nicht gespeichert werden: %{count} Fehler. Bitte korrigiere deine Eingaben, um fortzufahren."
1 change: 1 addition & 0 deletions config/locales/de.events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ de:
filter: "Filtern"
status: "Status"
details: "Details"
age_when_event_starts: "Alter bei Beginn"
free_places:
one: '%{count} Platz frei'
other: '%{count} Plätze frei'
Expand Down
16 changes: 16 additions & 0 deletions config/locales/de.requests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# German translation for the requests

de:
activerecord:
models:
request:
one: "Anfrage"
other: "Anfragen"
attributes:
request:
topics: "Themen"
user_id: "Benutzer"
id: "Nummer"
created_at: "Erstellt am"
dialogues:
confirm_delete: "Bist du sicher, dass du diese Anfrage löschen möchtest? Diese Aktion kann nicht widerrufen werden."
9 changes: 9 additions & 0 deletions config/locales/de.users.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,16 @@

de:
activerecord:
models:
user:
one: "Benutzer"
other: "Benutzer"
attributes:
user:
accepted_application_count: "Angenommene Bewerbungen"
rejected_application_count: "Abgelehnte Bewerbungen"
role: Rolle
current_password: Aktives Passwort
password: Passwort
password_confirmation: Passwort-Wiederholung
email: E-Mail-Adresse
7 changes: 6 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ de:
requests: "Anfragen"
profile: "Mein Profil"
create_profile: "Mein Profil anlegen"
settings: "Profilinfo"
settings: "Einstellungen"
login: "Einloggen"
logout: "Ausloggen"
users:
Expand All @@ -43,3 +43,8 @@ de:
sign_in: "Einloggen"
remember_me: "Eingeloggt bleiben"
midnight: "Mitternacht"
navigational:
back: Zurück
forward: Weiter
top: oben
bottom: unten
6 changes: 3 additions & 3 deletions lib/pdf_generation/applications_pdf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def overview_table_data
data = [["", "", "", t("events.applicants_overview.participations"), ""]]
data += [[Profile.human_attribute_name(:name),
Profile.human_attribute_name(:gender),
Profile.human_attribute_name(:age),
t('application_letters.show.age_when_event_starts'),
t("events.applicants_overview.accepted_rejected"),
ApplicationLetter.human_attribute_name(:status)]]
data += @event.application_letters.map do |a|
[a.user.profile.name,
a.user.profile.gender,
a.user.profile.age,
a.applicant_age_when_event_starts,
"#{a.user.accepted_applications_count(@event)} / #{a.user.rejected_applications_count(@event)}",
t("application_status.#{a.status}")]
end
Expand Down Expand Up @@ -114,7 +114,7 @@ def create_application_page_content(application_letter)

def applicants_detail_data(application_letter)
[[Profile.human_attribute_name(:gender)+":", application_letter.user.profile.gender],
[Profile.human_attribute_name(:age)+":", application_letter.user.profile.age],
[t('application_letters.show.age_when_event_starts')+":", application_letter.applicant_age_when_event_starts],
[Profile.human_attribute_name(:address)+":", application_letter.user.profile.address],
[User.human_attribute_name(:accepted_application_count)+":", application_letter.user.accepted_applications_count(@event)],
[User.human_attribute_name(:rejected_application_count)+":", application_letter.user.rejected_applications_count(@event)],
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@
@event.application_letters.each do |a|
expect(text).to include(
a.user.profile.name,
a.user.profile.age.to_s,
a.user.profile.age_at_time(@event.start_date).to_s,
a.user.profile.gender,
a.user.accepted_applications_count(@event).to_s,
a.user.rejected_applications_count(@event).to_s,
Expand Down
11 changes: 10 additions & 1 deletion spec/features/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
expect(table).to have_text(application_letter.user.profile.name)
end

['name', 'gender', 'age'].each do |attribute|
['name', 'gender'].each do |attribute|
link_name = I18n.t("activerecord.attributes.profile.#{attribute}")
click_link link_name
sorted_by_attribute = @event.application_letters.to_a.sort_by { |letter| letter.user.profile.send(attribute) }
Expand All @@ -173,6 +173,15 @@
click_link link_name # again
expect(page).to contain_ordered(names.reverse)
end

link_name = I18n.t('events.applicants_overview.age_when_event_starts')
click_link link_name
sorted_by_attribute = @event.application_letters.to_a.sort_by { |letter| letter.send(attribute) }
names = sorted_by_attribute.map {|l| l.user.profile.name }
expect(page).to contain_ordered(names)

click_link link_name # again
expect(page).to contain_ordered(names.reverse)
end

scenario "logged in as Organizer I can filter displayed application letters by their status", js: true do
Expand Down
2 changes: 1 addition & 1 deletion spec/features/profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def mock_writing_to_filesystem

find('input[name=commit]').click

expect(page).to have_text('Profile was successfully updated.')
expect(page).to have_text(I18n.t('profiles.successful_update'))
end

scenario "user fills in an invalid birth date" do
Expand Down
Loading

0 comments on commit f9d3a88

Please sign in to comment.