Skip to content

Commit

Permalink
Merge e48881b into d118dc9
Browse files Browse the repository at this point in the history
  • Loading branch information
feliciaan committed Jan 14, 2017
2 parents d118dc9 + e48881b commit 888ca05
Show file tree
Hide file tree
Showing 21 changed files with 72 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ def check_in
end

def event_params
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description, :bank_number, :registration_close_date, :registration_open_date, :show_ticket_count, :signature, :registration_cancelable)
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description, :registration_cancelable, :phone_number_state, :bank_number, :registration_close_date, :registration_open_date, :show_ticket_count, :signature)
end

def event_create_params
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description)
params.require(:event).permit(:name, :club_id, :location, :website, :contact_email, :start_date, :end_date, :description, :registration_cancelable, :phone_number_state)
end
end
2 changes: 1 addition & 1 deletion app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def basic
authorize! :register, requested_access_level

# Make the registration
@registration = @event.registrations.new params.require(:registration).permit(:email, :name, :student_number, :comment)
@registration = @event.registrations.new params.require(:registration).permit(:email, :name, :student_number, :comment, :phone_number)
@registration.access_levels << requested_access_level
@registration.price = requested_access_level.price
@registration.paid = 0
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def form_email_field(f, tag)
render partial: "form_email_field", locals: {f: f, tag: tag}
end

def form_telephone_field(f, tag)
render partial: "form_telephone_field", locals: {f: f, tag: tag}
end

def form_date_field(f, tag, id, value)
render partial: "form_date_field", locals: {f: f, tag: tag, id: id, value: value}
end
Expand All @@ -46,6 +50,10 @@ def form_number_field(f, tag)
render partial: "form_number_field", locals: {f: f, tag: tag}
end

def form_radio_field(f, tag, selected_state, states)
render partial: "form_radio_field", locals: {f: f, tag: tag, selected_state: selected_state, states: states}
end

def form_collection_select(f, *args)
# This line enable passing optional arguments such as include_blank to the
# partial. If nothing is passed, an empty options hash is appended.
Expand Down
2 changes: 1 addition & 1 deletion app/models/access_level.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# price :integer
# has_comment :boolean
# hidden :boolean
# permit :string default('everyone')
# permit :string default("everyone")
#

class AccessLevel < ActiveRecord::Base
Expand Down
11 changes: 9 additions & 2 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
# registration_open :boolean default(TRUE)
# signature :text
# registration_cancelable :boolean
# phone_number_state :string default("optional")
#

class Event < ActiveRecord::Base
Expand All @@ -40,13 +41,15 @@ class Event < ActiveRecord::Base

has_many :periods, dependent: :destroy


validates :description, presence: true
validates :end_date, presence: true
validates :location, presence: true
validates :contact_email, presence: true
validates :name, presence: true
validates :club, presence: true
validates :start_date, presence: true
validates :phone_number_state, presence: true

validates :contact_email, email: true
validates_with IBANValidator
Expand All @@ -62,6 +65,10 @@ class Event < ActiveRecord::Base

before_save :prettify_bank_number

def self.phone_number_states
[:optional, :required, :disabled]
end

def prettify_bank_number
self.bank_number = IBANTools::IBAN.new(self.bank_number).prettify if bank_number_changed?
end
Expand All @@ -72,9 +79,9 @@ def generate_xls
xls = Spreadsheet::Workbook.new
sheet = xls.create_worksheet

sheet.update_row 0, "Naam", "Email", "Studentnummer", "Ticket", "Comment", "Te betalen"
sheet.update_row 0, 'Naam', 'Email', 'Studentnummer', 'Telefoonnummer', 'Ticket', 'Comment', 'Te betalen'
registrations.each.with_index do |reg, i|
sheet.update_row i + 1, reg.name, reg.email, reg.student_number, reg.access_levels.first.name, reg.comment, reg.to_pay
sheet.update_row i + 1, reg.name, reg.email, reg.student_number, reg.phone_number, reg.access_levels.first.name, reg.comment, reg.to_pay
end
data = Tempfile.new(["export", ".xls"])

Expand Down
6 changes: 6 additions & 0 deletions app/models/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# comment :text
# barcode_data :string
# payment_code :string
# phone_number :string
#

class Registration < ActiveRecord::Base
Expand All @@ -35,6 +36,7 @@ class Registration < ActiveRecord::Base
validates :paid, presence: true, numericality: { only_integer: true }
validates :price, presence: true, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
validates :payment_code, presence: true, uniqueness: true
validates :phone_number, presence: true, if: 'phone_number_required?'

has_paper_trail only: [:paid, :payment_code, :checked_in_at]

Expand Down Expand Up @@ -126,4 +128,8 @@ def to_cents(value)
if value.is_a? String then value.sub!(',', '.') end
(value.to_f * 100).to_int
end

def phone_number_required?
return event && event.phone_number_state.to_s=='required'
end
end
7 changes: 7 additions & 0 deletions app/views/application/_form_radio_field.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="form-group btn-group" data-toggle="buttons">
<p><strong><%= tag.to_s.humanize %>:</strong></p>

<% states.each do |state, _| %>
<label class="btn btn-primary<%= ' active ' if state.to_s == selected_state %>"> <%= f.radio_button(tag, state) %><%= state.to_s.capitalize %></label>
<% end %>
</div>
5 changes: 5 additions & 0 deletions app/views/application/_form_telephone_field.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div class="form-group">
<%= f.label tag %>:<br/>
<%= f.telephone_field tag, class: 'form-control' %>
<small>Your telephone number will be kept confidential,...</small>
</div>
2 changes: 2 additions & 0 deletions app/views/events/_general_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<%= form_date_field f, :start_date, "start", datepicker_time(f.object.start_date) %>
<%= form_date_field f, :end_date, "end", datepicker_time(f.object.end_date) %>
<%= form_check_box f, :registration_cancelable %>
<%= form_radio_field f, :phone_number_state, @event.phone_number_state, Event.phone_number_states %>
<%= form_fancy_text_area f, :description %>
<%= f.button :submit, class: 'btn btn-primary' %>
Expand Down
4 changes: 3 additions & 1 deletion app/views/registrations/_basic.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
<%= form_text_field f, :name %>
<%= form_email_field f, :email %>
<%= f.hidden_field :student_number %>
<% unless @registration.event.phone_number_state == 'disabled' %>
<%= form_telephone_field f, :phone_number %>
<% end %>
<%= form_collection_select f, :access_levels, @event.access_levels.find_all { |al| can? :register, al }, :id, :name_with_price %>
<%= form_text_area f, :comment %>
<%= javascript_tag do %>
Expand Down
3 changes: 3 additions & 0 deletions app/views/registrations/_info_content.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
</p>
<% end %>

<h4>Telephonenumber</h4>
<%= @registration.phone_number %>


<h4>Changes</h4>
<table class="table table-responsive table-striped">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPhoneNumberToRegistrations < ActiveRecord::Migration
def change
add_column :registrations, :phone_number, :string
end
end
5 changes: 5 additions & 0 deletions db/migrate/20170111204432_add_phone_number_enum_to_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPhoneNumberEnumToEvent < ActiveRecord::Migration
def change
add_column :events, :phone_number_state, :string, default: 'optional'
end
end
4 changes: 3 additions & 1 deletion 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: 20170110175339) do
ActiveRecord::Schema.define(version: 20170111204432) do

create_table "access_levels", force: :cascade do |t|
t.string "name"
Expand Down Expand Up @@ -105,6 +105,7 @@
t.boolean "registration_open", default: true
t.text "signature"
t.boolean "registration_cancelable"
t.string "phone_number_state", default: "optional"
end

create_table "included_zones", force: :cascade do |t|
Expand Down Expand Up @@ -177,6 +178,7 @@
t.text "comment"
t.string "barcode_data"
t.string "payment_code"
t.string "phone_number"
end

add_index "registrations", ["event_id"], name: "index_registrations_on_event_id"
Expand Down
Binary file modified public/favicon.ico
Binary file not shown.
2 changes: 1 addition & 1 deletion test/fixtures/access_levels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# price :integer
# has_comment :boolean
# hidden :boolean
# permit :string default('everyone')
# permit :string default("everyone")
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/events.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# club_id :integer
# registration_open :boolean default(TRUE)
# signature :text
# registration_cancelable :boolean
# phone_number_state :string default("optional")
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
Expand All @@ -39,6 +41,7 @@ codenight:
website: zeus.ugent.be
description: THEYRE TAKING THE HOBBITS TO ISENGARD
club: zeus
phone_number_state: 'optional'

galabal:
id: 2
Expand All @@ -51,6 +54,7 @@ galabal:
description: Super awesome galabal
club: fk
bank_number: BE62 5100 0754 7061
phone_number_state: 'optional'

twaalfurenloop:
id: 3
Expand All @@ -62,6 +66,7 @@ twaalfurenloop:
website: 12urenloop.be
description: rondjes lopeuh!
club: fk
phone_number_state: 'optional'

sko:
id: 4
Expand All @@ -73,3 +78,4 @@ sko:
website: studentkickoff.be
description: Los gaan op Samson&Gert!
club: fk
phone_number_state: 'optional'
1 change: 1 addition & 0 deletions test/fixtures/registrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# comment :text
# barcode_data :string
# payment_code :string
# phone_number :string
#

# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtures.html
Expand Down
2 changes: 1 addition & 1 deletion test/models/access_level_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# updated_at :datetime
# capacity :integer
# price :integer
# public :boolean default(TRUE)
# has_comment :boolean
# hidden :boolean
# permit :string default("everyone")
#

require 'test_helper'
Expand Down
2 changes: 2 additions & 0 deletions test/models/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# club_id :integer
# registration_open :boolean default(TRUE)
# signature :text
# registration_cancelable :boolean
# phone_number_state :string default("optional")
#

require 'test_helper'
Expand Down
1 change: 1 addition & 0 deletions test/models/registration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# comment :text
# barcode_data :string
# payment_code :string
# phone_number :string
#

require 'test_helper'
Expand Down

0 comments on commit 888ca05

Please sign in to comment.