diff --git a/app/controllers/conference_administration_controller.rb b/app/controllers/conference_administration_controller.rb index 69caa62..2cd37d4 100644 --- a/app/controllers/conference_administration_controller.rb +++ b/app/controllers/conference_administration_controller.rb @@ -106,6 +106,8 @@ class ConferenceAdministrationController < ApplicationController end def administrate_providers + @conditions = Conference.default_provider_conditions.deep_merge( + @this_conference.provider_conditions || {}) end def administrate_payment_message @@ -1195,6 +1197,23 @@ class ConferenceAdministrationController < ApplicationController return false end + def admin_update_providers + case params[:button] + when 'save_distance' + @this_conference.provider_conditions ||= Conference.default_provider_conditions + @this_conference.provider_conditions['distance'] = { + 'number' => params[:distance_number], + 'unit' => params[:distance_unit] + } + @this_conference.save + set_success_message :distance_saved + return false + end + + do_404 + return false + end + def get_empty(hash, keys) keys = [keys] unless keys.is_a?(Array) keys.each do | key | diff --git a/app/controllers/conferences_controller.rb b/app/controllers/conferences_controller.rb index 01b02af..803c77e 100644 --- a/app/controllers/conferences_controller.rb +++ b/app/controllers/conferences_controller.rb @@ -58,7 +58,7 @@ class ConferencesController < ApplicationController steps = nil return do_404 unless registration_steps.present? - + @register_template = :administration if params[:admin_step].present? @errors = {} @@ -330,7 +330,7 @@ class ConferencesController < ApplicationController steps -= [:questions] unless status == :open steps -= [:payment] unless status == :open && conference.paypal_email_address.present? && conference.paypal_username.present? && conference.paypal_password.present? && conference.paypal_signature.present? if @registration.present? - if @registration.city_id == conference.city_id + if view_context.potential_provider(@registration) steps -= [:questions] # if this is a housing provider that is not attending the conference, remove these steps diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e26f76d..1fbd759 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -2191,6 +2191,24 @@ module ApplicationHelper } end + def potential_provider(registration) + return false unless registration.present? && registration.city.present? && registration.conference.present? + conditions = registration.conference.provider_conditions || + Conference.default_provider_conditions + return city_distance_less_than(registration.conference.city, registration.city, + (conditions['distance']['number'] || '0').to_i, + conditions['distance']['unit']) + end + + def city_distance_less_than(city1, city2, max_distance, unit) + return false if city1.nil? || city2.nil? + return true if city1.id == city2.id + return false if max_distance < 1 + return Geocoder::Calculations.distance_between( + [city1.latitude, city1.longitude], [city2.latitude, city2.longitude], + units: unit.to_sym) < max_distance + end + private def _original_content(value, lang) content_tag(:div, ( diff --git a/app/helpers/registration_helper.rb b/app/helpers/registration_helper.rb index 6b680f2..0d39dae 100644 --- a/app/helpers/registration_helper.rb +++ b/app/helpers/registration_helper.rb @@ -8,7 +8,7 @@ module RegistrationHelper completed_steps = registration.steps_completed || [] registration_complete = registration_complete?(registration) - if registration.city_id == registration.conference.city_id + if potential_provider(registration) steps -= [:questions] else steps -= [:hosting] diff --git a/app/models/conference.rb b/app/models/conference.rb index 8481bb1..5bb10bc 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -153,4 +153,8 @@ class Conference < ActiveRecord::Base Conference.conference_types[(type || :annual).to_sym][:title].gsub('%{city}', city).gsub('%{year}', year.to_s) end + def self.default_provider_conditions + { 'distance' => { 'number' => 0, 'unit' => 'mi' }} + end + end diff --git a/app/views/conference_administration/_providers.html.haml b/app/views/conference_administration/_providers.html.haml index 6bad602..35e14fd 100644 --- a/app/views/conference_administration/_providers.html.haml +++ b/app/views/conference_administration/_providers.html.haml @@ -1,2 +1,10 @@ -= columns(medium: 12) do - TO COME \ No newline at end of file += admin_update_form do + = columns(medium: 12) do + %h3=_'articles.admin.housing.headings.provider_distance', :t + %p=_'articles.admin.housing.descriptions.provider_distance', :p, vars: { city: @this_conference.city_name } + = columns(medium: 12, class: 'flex-column') do + = numberfield :distance_number, @conditions['distance']['number'], step: 1, min: 0, stretch: true, label: false + = selectfield :distance_unit, @conditions['distance']['unit'], [:km, :mi], label: false, inline: true + = columns(medium: 12) do + .actions.right + = button_tag :save, value: :save_distance diff --git a/config/locales/en.yml b/config/locales/en.yml index 439cee9..6cb5fbb 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -243,6 +243,7 @@ en: org_member_removed: User removed from organization administrator_added: Administrator added to conference administrator_removed: Administrator removed from conference + distance_saved: Provider options updated helpers: select: prompt: Please select @@ -999,8 +1000,10 @@ en: arrival_departure: In City providers: Housing Providers housing: Arrange Housing + provider_distance: Distance from host city descriptions: providers: Although most housing providers shuold be encouraged to supply their own details through the registration process, you can add and edit housing provider details manually here. + provider_distance: Any registrant who enters their location in the same city as the conference will get a housing provider form during registration instead of a guest form. If you want to consider surrounding cities as well, enter the distance from %{city} that you wish to be included as providers. Cities are measured from center to center. housing: Pair each housing provider with a list of guests. locations: heading: Locations diff --git a/db/schema.rb b/db/schema.rb index ddeb1cd..76c49c2 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170110061048) do +ActiveRecord::Schema.define(version: 20170111013903) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -180,6 +180,7 @@ ActiveRecord::Schema.define(version: 20170110061048) do t.integer "city_id" t.boolean "is_public" t.boolean "is_featured" + t.json "provider_conditions" end create_table "delayed_jobs", force: :cascade do |t|