Add booth limit

This commit is contained in:
nasia 2017-07-28 21:46:48 +03:00 committed by nasia-sam
parent 703813248d
commit e73218b5ca
10 changed files with 66 additions and 18 deletions

View file

@ -11,6 +11,8 @@ linters:
# Offense count: 945 # Offense count: 945
LineLength: LineLength:
exclude: exclude:
- "app/views/admin/booths/_change_state_dropdown.html.haml"
- "app/views/admin/booths/_form.html.haml"
- "app/views/admin/booths/index.html.haml" - "app/views/admin/booths/index.html.haml"
- "app/views/admin/booths/show.html.haml" - "app/views/admin/booths/show.html.haml"
- "app/views/admin/campaigns/_form.html.haml" - "app/views/admin/campaigns/_form.html.haml"

View file

@ -47,18 +47,21 @@ module Admin
end end
def accept def accept
@booth.accept!
if @booth.save if can? :accept, @booth
if @conference.email_settings.send_on_booths_acceptance @booth.accept!
Mailbot.conference_booths_acceptance_mail(@booth).deliver
if @booth.save
if @conference.email_settings.send_on_booths_acceptance
Mailbot.conference_booths_acceptance_mail(@booth).deliver
end
redirect_to admin_conference_booths_path(conference_id: @conference.short_title),
notice: 'Booth successfully accepted!'
else
redirect_to admin_conference_booths_path(conference_id: @conference.short_title)
flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}."
end end
redirect_to admin_conference_booths_path(conference_id: @conference.short_title), end
notice: 'Booth successfully accepted!'
else
redirect_to admin_conference_booths_path(conference_id: @conference.short_title)
flash[:error] = "Booth could not be accepted. #{@booth.errors.full_messages.to_sentence}."
end
end end
def to_accept def to_accept

View file

@ -211,7 +211,7 @@ module Admin
:vpositions_attributes, :use_volunteers, :color, :vpositions_attributes, :use_volunteers, :color,
:sponsorship_levels_attributes, :sponsors_attributes, :sponsorship_levels_attributes, :sponsors_attributes,
:targets, :targets_attributes, :targets, :targets_attributes,
:campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout) :campaigns, :campaigns_attributes, :registration_limit, :organization_id, :ticket_layout, :booth_limit)
end end
end end
end end

View file

@ -25,6 +25,7 @@ class Booth < ActiveRecord::Base
:submitter_relationship, :submitter_relationship,
presence: true presence: true
scope :accepted, -> { where(state: 'accepted') }
scope :confirmed, -> { where(state: 'confirmed') } scope :confirmed, -> { where(state: 'confirmed') }
mount_uploader :picture, PictureUploader, mount_on: :logo_link mount_uploader :picture, PictureUploader, mount_on: :logo_link

View file

@ -738,6 +738,15 @@ class Conference < ActiveRecord::Base
(start_hour..(end_hour - 1)).cover?(current_hour) ? current_hour - start_hour : 0 (start_hour..(end_hour - 1)).cover?(current_hour) ? current_hour - start_hour : 0
end end
##
#
# ====Returns
# * +True+ -> if accepted booths are equal to the booth limit
# * +False+ -> Accepted booths have not reached the booth limit
def maximum_accepted_booths?
booth_limit > 0 && booths.accepted.count + booths.confirmed.count >= booth_limit
end
## ##
# Return the current conference object to be used in RevisionCount # Return the current conference object to be used in RevisionCount
# #

View file

@ -1,11 +1,13 @@
- if booth.transition_possible? :accept - if booth.transition_possible? :accept
- if @conference.email_settings.send_on_booths_acceptance - if can? :accept, @booth
- link = 'Accept with email' - if @conference.email_settings.send_on_booths_acceptance
- else - link = 'Accept with email'
- link = 'Accept booth' - else
%li= link_to link, - link = 'Accept booth'
accept_admin_conference_booth_path(@conference.short_title, booth), %li= link_to link,
method: :patch ,id: "accept_booth_#{booth.id}" accept_admin_conference_booth_path(@conference.short_title, booth),
method: :patch ,id: "accept_booth_#{booth.id}",
data: (@conference.booth_limit > 0 ? { confirm: 'You are able to accept '+ pluralize(@conference.booth_limit - @conference.booths.accepted.count, 'more booth') + " (booth limit set to #{@conference.booth_limit}). Are you sure you want to accept this one?" } : nil )
- if booth.transition_possible? :reject - if booth.transition_possible? :reject
- if @conference.email_settings.send_on_booths_rejection - if @conference.email_settings.send_on_booths_rejection

View file

@ -9,8 +9,30 @@
= link_to 'Add Booth', new_admin_conference_booth_path(@conference.short_title), class: 'button btn btn-primary' = link_to 'Add Booth', new_admin_conference_booth_path(@conference.short_title), class: 'button btn btn-primary'
%p.text-muted %p.text-muted
All the booth requests All the booth requests
.row .row
.col-md-12 .col-md-12
%h4
- if @conference.booth_limit == 0
%p
Set the
= link_to 'Booth limit', edit_admin_conference_path(@conference.short_title)
to make sure you are not accepting more booths than you can accommodate.
- elsif !@conference.maximum_accepted_booths?
%p
You cannot accept more than
%b
= pluralize(@conference.booth_limit, 'booth')
(
= pluralize(@conference.booths.accepted.count + @conference.booths.confirmed.count, 'accepted booth')
so far)
- else
%p
You have reached the maximum number of accepted booths.
(
= link_to "#{@conference.booth_limit} booths", edit_admin_conference_path(@conference.short_title)
)
.margin-booth-table .margin-booth-table
%table.table.table-striped.table-bordered.table-hover.datatable %table.table.table-striped.table-bordered.table-hover.datatable
%thead %thead

View file

@ -26,4 +26,7 @@
= f.input :end_hour, input_html: {size: 2, type: 'number', min: 1, max: 24} = f.input :end_hour, input_html: {size: 2, type: 'number', min: 1, max: 24}
= f.inputs name: 'Registrations' do = f.inputs name: 'Registrations' do
= f.input :registration_limit, as: :number, in: 0..9999, hint: 'Limit the number of registrations to the conference (0 no limit). Please note that the registration limit doesn\'t apply to speakers of confirmed events (they will still be able to register even if it has been reached). You currently have ' + pluralize(@conference.registrations.count, 'registration') = f.input :registration_limit, as: :number, in: 0..9999, hint: 'Limit the number of registrations to the conference (0 no limit). Please note that the registration limit doesn\'t apply to speakers of confirmed events (they will still be able to register even if it has been reached). You currently have ' + pluralize(@conference.registrations.count, 'registration')
= f.inputs name: 'Booths' do
= f.input :booth_limit, as: :number, in: 0..9999,
hint: 'Booth limit is the maximum number of booths that you can accept for this conference. By setting this number (0 no limit) you can be sure that you are not going to accept more booths than the conference can accommodate. You currently have ' + pluralize(@conference.booths.accepted.count, 'accepted booth') +'.'
= f.action :submit, as: :button, button_html: {class: 'btn btn-primary'} = f.action :submit, as: :button, button_html: {class: 'btn btn-primary'}

View file

@ -0,0 +1,5 @@
class AddBoothLimitToConferences < ActiveRecord::Migration
def change
add_column :conferences, :booth_limit, :integer, default: 0
end
end

View file

@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170807092805) do
t.integer "end_hour", default: 20 t.integer "end_hour", default: 20
t.integer "organization_id" t.integer "organization_id"
t.integer "ticket_layout", default: 0 t.integer "ticket_layout", default: 0
t.integer "booth_limit", default: 0
end end
add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id" add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id"