Skip to content

Commit

Permalink
Merge branch 'dev' into 322_variable_application_fields_details
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterCarl committed Jan 18, 2017
2 parents b82664a + 70e97a7 commit 62d4097
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 95 deletions.
3 changes: 2 additions & 1 deletion app/controllers/application_letters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def set_application
# Only allow a trusted parameter "white list" through.
# Don't allow user_id as you shouldn't be able to set the user from outside of create/update.
def application_params
params.require(:application_letter).permit(:grade, :experience, :motivation, :coding_skills, :emergency_number, :vegeterian, :vegan, :allergic, :allergies, :user_id, :event_id)
params.require(:application_letter).permit(:grade, :experience, :motivation, :coding_skills, :emergency_number,
:vegetarian, :vegan, :allergic, :allergies, :user_id, :event_id)
end

# Only allow to update the status
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/requests_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create
@request = Request.new(request_params)

if @request.save
redirect_to @request, notice: 'Request was successfully created.'
redirect_to root_path, notice: I18n.t('requests.notice.was_created')
else
render :new
end
Expand All @@ -34,7 +34,7 @@ def create
# PATCH/PUT /requests/1
def update
if @request.update(request_params)
redirect_to @request, notice: 'Request was successfully updated.'
redirect_to @request, notice: I18n.t('requests.notice.was_updated')
else
render :edit
end
Expand All @@ -43,7 +43,7 @@ def update
# DELETE /requests/1
def destroy
@request.destroy
redirect_to requests_url, notice: 'Request was successfully destroyed.'
redirect_to requests_url, notice:I18n.t('requests.notice.was_deleted')
end

def accept
Expand Down
8 changes: 4 additions & 4 deletions app/models/application_letter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ApplicationLetter < ActiveRecord::Base
validates :user, :event, :experience, :motivation, :coding_skills, :emergency_number, presence: true
validates :grade, presence: true, numericality: { only_integer: true }
validates_inclusion_of :grade, :in => VALID_GRADES
validates :vegeterian, :vegan, :allergic, inclusion: { in: [true, false] }
validates :vegeterian, :vegan, :allergic, exclusion: { in: [nil] }
validates :vegetarian, :vegan, :allergic, inclusion: { in: [true, false] }
validates :vegetarian, :vegan, :allergic, exclusion: { in: [nil] }
validate :deadline_cannot_be_in_the_past, :if => Proc.new { |letter| !(letter.status_changed?) }
validate :status_cannot_be_changed, :if => Proc.new { |letter| letter.status_changed?}

Expand Down Expand Up @@ -93,13 +93,13 @@ def applicant_age_when_event_starts
user.profile.age_at_time(event.start_date)
end

# Returns an array of eating habits (including allergies, vegan and vegeterian)
# Returns an array of eating habits (including allergies, vegan and vegetarian)
#
# @param none
# @return [Array <String>] array of eating habits, empty if none
def eating_habits
habits = Array.new
habits.push(ApplicationLetter.human_attribute_name(:vegeterian)) if vegeterian
habits.push(ApplicationLetter.human_attribute_name(:vegetarian)) if vegetarian
habits.push(ApplicationLetter.human_attribute_name(:vegan)) if vegan
habits.push(ApplicationLetter.human_attribute_name(:allergic)) if allergic
habits
Expand Down
6 changes: 3 additions & 3 deletions app/views/application_letters/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<%= f.check_box :vegeterian%>
<%= f.label :vegeterian, :class => 'control-label' %>
<%=f.error_span(:vegeterian) %>
<%= f.check_box :vegetarian%>
<%= f.label :vegetarian, :class => 'control-label' %>
<%=f.error_span(:vegetarian) %>
</div>
</div>
<div class="form-group">
Expand Down
92 changes: 48 additions & 44 deletions app/views/requests/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,60 +1,64 @@
<%= form_for @request, :html => { :class => "form-horizontal request" } do |f| %>
<%= render partial: "shared/error_message", locals: {entity: @request} %>

<div class="form-group">
<div class="btn-group col-lg-10 col-lg-offset-2" data-toggle="buttons">
<% Request.form_of_addresses.keys.each do |key| %>
<label class="btn btn-default <%= 'active' if @request.form_of_address == key %>">
<%= f.radio_button :form_of_address, key %>
<%= I18n.t :"requests.form_of_addresses.#{key}" %>
</label>
<% end %>
<%=f.error_span(:form_of_address) %>
</div>
</div>
<%= form_for @request, :html => {:class => "form-horizontal request"} do |f| %>
<%= render partial: "shared/error_message", locals: {entity: @request} %>

<h3><%=t 'requests.new.workshop_information' %></h3>

<% [:first_name, :last_name, :phone_number, :street, :zip_code_city, :email ].each do |attribute_name| %>
<div class="form-group">
<%= f.label attribute_name, :class => 'control-label col-lg-2 required'%>
<%= f.label :topic_of_workshop, :class => 'control-label col-lg-2 required' %>
<div class="col-lg-10">
<%= f.text_field attribute_name, :class => 'form-control' %>
<%=f.error_span(attribute_name) %>
<%= f.text_field :topic_of_workshop, :class => 'form-control', :placeholder => I18n.t('requests.hints.please_enter_two_topics') %>
<%= f.error_span(:topic_of_workshop) %>
</div>
</div>
<% end %>

<div class="form-group">
<%= f.label :topic_of_workshop, :class => 'control-label col-lg-2 required' %>
<div class="col-lg-10">
<%= f.text_field :topic_of_workshop, :class => 'form-control', :placeholder => I18n.t('requests.hints.please_enter_two_topics')%>
<%=f.error_span(:topic_of_workshop) %>
</div>
</div>
<% [:time_period, :number_of_participants, :knowledge_level].each do |attribute_name| %>
<div class="form-group">
<%= f.label attribute_name, :class => 'control-label col-lg-2 ' %>
<div class="col-lg-10">
<%= f.text_field attribute_name, :class => 'form-control' %>
<%= f.error_span(attribute_name) %>
</div>
</div>
<% end %>

<% [:time_period, :number_of_participants, :knowledge_level ].each do |attribute_name| %>
<div class="form-group">
<%= f.label attribute_name, :class => 'control-label col-lg-2 '%>
<%= f.label :annotations, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= f.text_field attribute_name, :class => 'form-control' %>
<%=f.error_span(attribute_name) %>
<%= f.text_area :annotations, :class => 'form-control' %>
<%= f.error_span(:annotations) %>
</div>
</div>
<% end %>

<div class="form-group">
<%= f.label :annotations, :class => 'control-label col-lg-2' %>
<div class="col-lg-10">
<%= f.text_area :annotations, :class => 'form-control' %>
<%= f.error_span(:annotations) %>
<h3><%=t 'requests.new.personal_information' %></h3>

<div class="form-group">
<div class="btn-group col-lg-10 col-lg-offset-2" data-toggle="buttons">
<% Request.form_of_addresses.keys.each do |key| %>
<label class="btn btn-default <%= 'active' if @request.form_of_address == key %>">
<%= f.radio_button :form_of_address, key %>
<%= I18n.t :"requests.form_of_addresses.#{key}" %>
</label>
<% end %>
<%= f.error_span(:form_of_address) %>
</div>
</div>
</div>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
requests_path, :class => 'btn btn-default' %>
<% [:first_name, :last_name, :phone_number, :street, :zip_code_city, :email].each do |attribute_name| %>
<div class="form-group">
<%= f.label attribute_name, :class => 'control-label col-lg-2 required' %>
<div class="col-lg-10">
<%= f.text_field attribute_name, :class => 'form-control' %>
<%= f.error_span(attribute_name) %>
</div>
</div>
<% end %>

<div class="form-group">
<div class="col-lg-offset-2 col-lg-10">
<%= f.submit nil, :class => 'btn btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
requests_path, :class => 'btn btn-default' %>
</div>
</div>
</div>
<% end %>
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 => model_class.model_name.human(count: 2).titleize %></h1>
<h1><%=t 'requests.new.title', :default => model_class.model_name.human(count: 1).titleize %></h1>
</div>
<%= render :partial => 'form' %>
2 changes: 1 addition & 1 deletion config/locales/de.application_letters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ de:
motivation: "Motivationsschreiben"
coding_skills: "Mit welchen Programmiersprachen hast du bereits Erfahrungen gesammelt?"
emergency_number: "Telefonnummer für Notfälle"
vegeterian: "Vegetarisch"
vegetarian: "Vegetarisch"
vegan: "Vegan"
allergic: "Allergien vorhanden"
allergies: "Falls Allergien vorhanden, welche?"
Expand Down
7 changes: 7 additions & 0 deletions config/locales/de.requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

de:
requests:
new:
title: "Neue Anfrage stellen"
workshop_information: "Informationen über den gewünschten Workshop"
personal_information: "Persönliche Daten"
form_of_addresses:
mr: "Herr"
mrs: "Frau"
Expand All @@ -12,7 +16,10 @@ de:
hints:
please_enter_two_topics: "Bitte 2 Wünsche angeben"
notice:
was_created: "Ihre Anfrage wurde erfolgreich abgesendet"
was_updated: "Die Anfrage wurde aktualisiert"
was_accepted: "Die Anfrage wurde angenommen"
was_deleted: "Die Anfrage wurde gelöscht"
activerecord:
models:
request:
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20170118161954_rename_vegeterian_to_vegetarian.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameVegeterianToVegetarian < ActiveRecord::Migration
def change
rename_column :application_letters, :vegeterian, :vegetarian
end
end
12 changes: 6 additions & 6 deletions db/sample_data/application_letters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def application_letter_applicant_gongakrobatik(user, event)
experience: "Über einen Facebookpost ihrer Seite bin ich auf das Angebot aufmerksam geworden",
coding_skills: "HTML",
emergency_number: "01234567891",
vegeterian: false,
vegetarian: false,
vegan: false,
allergic: false,
allergies: "",
Expand All @@ -21,7 +21,7 @@ def application_letter_applicant_gongakrobatik_rejected(user, event)
experience: "Über einen Facebookpost ihrer Seite bin ich auf das Angebot aufmerksam geworden",
coding_skills: "HTML",
emergency_number: "01234567891",
vegeterian: false,
vegetarian: false,
vegan: false,
allergic: false,
allergies: "",
Expand All @@ -38,7 +38,7 @@ def application_letter_applicant_gongakrobatik_accepted(user, event)
experience: "Über einen Zeitungsartikel",
coding_skills: "For, While und If-Schleifen in Java",
emergency_number: "01234567891",
vegeterian: false,
vegetarian: false,
vegan: false,
allergic: true,
allergies: "Tomaten",
Expand All @@ -55,7 +55,7 @@ def application_letter_applicant_programmierkurs_1(user, event)
experience: "Über einen Zeitungsartikel",
coding_skills: "For, While und If-Schleifen in Java",
emergency_number: "01234567891",
vegeterian: false,
vegetarian: false,
vegan: false,
allergic: true,
allergies: "Tomaten",
Expand All @@ -71,7 +71,7 @@ def application_letter_applicant_programmierkurs_2(user, event)
experience: "Suche im Internet",
coding_skills: "keine",
emergency_number: "01234567891",
vegeterian: true,
vegetarian: true,
vegan: false,
allergic: false,
allergies: "",
Expand All @@ -88,7 +88,7 @@ def application_letter_applicant_programmierkurs_3(user, event)
experience: "Suche im Internetz",
coding_skills: "absolut keine",
emergency_number: "01234567819",
vegeterian: true,
vegetarian: true,
vegan: false,
allergic: false,
allergies: "",
Expand Down
4 changes: 2 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170118132170) do
ActiveRecord::Schema.define(version: 20170118161954) do

create_table "agreement_letters", force: :cascade do |t|
t.integer "user_id", null: false
Expand All @@ -35,7 +35,7 @@
t.string "experience"
t.string "coding_skills"
t.string "emergency_number"
t.boolean "vegeterian"
t.boolean "vegetarian"
t.boolean "vegan"
t.boolean "allergic"
t.string "allergies"
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/application_letters_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
motivation: "None",
coding_skills: "None",
emergency_number: "01234567891",
vegeterian: true,
vegetarian: true,
vegan: true,
allergic: true,
allergys: "Many"
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@

it "redirects to the created request" do
post :create, request: valid_attributes, session: valid_session
expect(response).to redirect_to(Request.last)
expect(response).to redirect_to(root_path)
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/factories/application_letters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
motivation "None"
coding_skills "None"
emergency_number "01234567891"
vegeterian false
vegetarian false
vegan false
allergic true
allergies "Many"
Expand All @@ -31,7 +31,7 @@
experience "A lot"
motivation "Ich bin sehr motiviert, glaubt mir."
emergency_number "110"
vegeterian true
vegetarian true
end

factory :application_letter_long, parent: :application_letter do
Expand Down
Loading

0 comments on commit 62d4097

Please sign in to comment.