From e73218b5ca009ee7a159d55b99f09db320ec6951 Mon Sep 17 00:00:00 2001 From: nasia Date: Fri, 28 Jul 2017 21:46:48 +0300 Subject: [PATCH] Add booth limit --- .haml-lint_todo.yml | 2 ++ app/controllers/admin/booths_controller.rb | 23 +++++++++++-------- .../admin/conferences_controller.rb | 2 +- app/models/booth.rb | 1 + app/models/conference.rb | 9 ++++++++ .../booths/_change_state_dropdown.html.haml | 16 +++++++------ app/views/admin/booths/index.html.haml | 22 ++++++++++++++++++ app/views/admin/conferences/edit.html.haml | 3 +++ ...28182033_add_booth_limit_to_conferences.rb | 5 ++++ db/schema.rb | 1 + 10 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 db/migrate/20170728182033_add_booth_limit_to_conferences.rb diff --git a/.haml-lint_todo.yml b/.haml-lint_todo.yml index a456dcd2..2e4c2995 100644 --- a/.haml-lint_todo.yml +++ b/.haml-lint_todo.yml @@ -11,6 +11,8 @@ linters: # Offense count: 945 LineLength: 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/show.html.haml" - "app/views/admin/campaigns/_form.html.haml" diff --git a/app/controllers/admin/booths_controller.rb b/app/controllers/admin/booths_controller.rb index a200e42e..26bacc8f 100644 --- a/app/controllers/admin/booths_controller.rb +++ b/app/controllers/admin/booths_controller.rb @@ -47,18 +47,21 @@ module Admin end def accept - @booth.accept! - if @booth.save - if @conference.email_settings.send_on_booths_acceptance - Mailbot.conference_booths_acceptance_mail(@booth).deliver + if can? :accept, @booth + @booth.accept! + + 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 - 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 end def to_accept diff --git a/app/controllers/admin/conferences_controller.rb b/app/controllers/admin/conferences_controller.rb index 6716a253..3905012c 100644 --- a/app/controllers/admin/conferences_controller.rb +++ b/app/controllers/admin/conferences_controller.rb @@ -211,7 +211,7 @@ module Admin :vpositions_attributes, :use_volunteers, :color, :sponsorship_levels_attributes, :sponsors_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 diff --git a/app/models/booth.rb b/app/models/booth.rb index d7cc3eb2..4e42d839 100644 --- a/app/models/booth.rb +++ b/app/models/booth.rb @@ -25,6 +25,7 @@ class Booth < ActiveRecord::Base :submitter_relationship, presence: true + scope :accepted, -> { where(state: 'accepted') } scope :confirmed, -> { where(state: 'confirmed') } mount_uploader :picture, PictureUploader, mount_on: :logo_link diff --git a/app/models/conference.rb b/app/models/conference.rb index b528d755..729db645 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -738,6 +738,15 @@ class Conference < ActiveRecord::Base (start_hour..(end_hour - 1)).cover?(current_hour) ? current_hour - start_hour : 0 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 # diff --git a/app/views/admin/booths/_change_state_dropdown.html.haml b/app/views/admin/booths/_change_state_dropdown.html.haml index 8178a790..85f8b971 100644 --- a/app/views/admin/booths/_change_state_dropdown.html.haml +++ b/app/views/admin/booths/_change_state_dropdown.html.haml @@ -1,11 +1,13 @@ - if booth.transition_possible? :accept - - if @conference.email_settings.send_on_booths_acceptance - - link = 'Accept with email' - - else - - link = 'Accept booth' - %li= link_to link, - accept_admin_conference_booth_path(@conference.short_title, booth), - method: :patch ,id: "accept_booth_#{booth.id}" + - if can? :accept, @booth + - if @conference.email_settings.send_on_booths_acceptance + - link = 'Accept with email' + - else + - link = 'Accept booth' + %li= link_to link, + 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 @conference.email_settings.send_on_booths_rejection diff --git a/app/views/admin/booths/index.html.haml b/app/views/admin/booths/index.html.haml index 27f505ad..a7ee53cd 100644 --- a/app/views/admin/booths/index.html.haml +++ b/app/views/admin/booths/index.html.haml @@ -9,8 +9,30 @@ = link_to 'Add Booth', new_admin_conference_booth_path(@conference.short_title), class: 'button btn btn-primary' %p.text-muted All the booth requests + + .row .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 %table.table.table-striped.table-bordered.table-hover.datatable %thead diff --git a/app/views/admin/conferences/edit.html.haml b/app/views/admin/conferences/edit.html.haml index 2d5df126..26ae198f 100644 --- a/app/views/admin/conferences/edit.html.haml +++ b/app/views/admin/conferences/edit.html.haml @@ -26,4 +26,7 @@ = f.input :end_hour, input_html: {size: 2, type: 'number', min: 1, max: 24} = 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.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'} diff --git a/db/migrate/20170728182033_add_booth_limit_to_conferences.rb b/db/migrate/20170728182033_add_booth_limit_to_conferences.rb new file mode 100644 index 00000000..60643784 --- /dev/null +++ b/db/migrate/20170728182033_add_booth_limit_to_conferences.rb @@ -0,0 +1,5 @@ +class AddBoothLimitToConferences < ActiveRecord::Migration + def change + add_column :conferences, :booth_limit, :integer, default: 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 6c40c572..83499b33 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -127,6 +127,7 @@ ActiveRecord::Schema.define(version: 20170807092805) do t.integer "end_hour", default: 20 t.integer "organization_id" t.integer "ticket_layout", default: 0 + t.integer "booth_limit", default: 0 end add_index "conferences", ["organization_id"], name: "index_conferences_on_organization_id"