Skip to content

Commit

Permalink
An admin can add custom fields for proposals to an event
Browse files Browse the repository at this point in the history
  • Loading branch information
Kel4545 committed Jun 5, 2015
1 parent 91d2e1c commit ceda1ce
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def require_proposal
end

def event_params
params.require(:event).permit(:name, :contact_email, :slug, :url, :valid_proposal_tags, :valid_review_tags, :state, :guidelines, :closes_at, :speaker_notification_emails, :accept, :reject, :waitlist, :opens_at, :start_date, :end_date)
params.require(:event).permit(:name, :contact_email, :slug, :url, :valid_proposal_tags, :valid_review_tags, :custom_fields_string, :state, :guidelines, :closes_at, :speaker_notification_emails, :accept, :reject, :waitlist, :opens_at, :start_date, :end_date)
end

def set_event
Expand Down
23 changes: 18 additions & 5 deletions app/controllers/organizer/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,24 @@ def show
rating_counts = @event.ratings.group(:person_id).count

render locals: {
event: @event.decorate,
rating_counts: rating_counts,
participants: participants
}
event: @event.decorate,
rating_counts: rating_counts,
participants: participants
}
end

def edit_custom_fields
@event = Event.find(params[:id])
end

def update_custom_fields
if @event.update_attributes(event_params)
flash[:info] = 'Your event was saved.'
redirect_to organizer_event_path(@event)
else
flash[:danger] = flash[:danger] = 'There was a problem saving your event; please review the form for issues and try again.'
render :edit_custom_fields
end
end

def update
Expand All @@ -27,5 +41,4 @@ def update
render :edit
end
end

end
29 changes: 15 additions & 14 deletions app/controllers/organizer/proposals_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Organizer::ProposalsController < Organizer::ApplicationController
before_filter :require_proposal, except: [ :index, :new, :create ]
before_filter :require_proposal, except: [:index, :new, :create, :edit_all]

decorates_assigned :proposal, with: Organizer::ProposalDecorator

Expand All @@ -21,13 +21,13 @@ def update_state
def index
proposals = @event.proposals.includes(:review_taggings, :proposal_taggings, :ratings, {speakers: :person}).load

session[:prev_page] = { name: 'Proposals', path: organizer_event_proposals_path }
session[:prev_page] = {name: 'Proposals', path: organizer_event_proposals_path}

taggings_count = Tagging.count_by_tag(@event)

proposals = Organizer::ProposalsDecorator.decorate(proposals)
respond_to do |format|
format.html { render locals: { event: @event, proposals: proposals, taggings_count: taggings_count} }
format.html { render locals: {event: @event, proposals: proposals, taggings_count: taggings_count} }
format.csv { render text: proposals.to_csv }
end
end
Expand All @@ -44,15 +44,16 @@ def show
end

render locals: {
speakers: @proposal.speakers.decorate,
other_proposals: Organizer::ProposalsDecorator.decorate(other_proposals),
rating: current_user.rating_for(@proposal)
}
speakers: @proposal.speakers.decorate,
other_proposals: Organizer::ProposalsDecorator.decorate(other_proposals),
rating: current_user.rating_for(@proposal)
}
end

def edit
end


def update
if @proposal.update_without_touching_updated_by_speaker_at(proposal_params)
flash[:info] = 'Proposal Updated'
Expand Down Expand Up @@ -91,19 +92,19 @@ def create

def proposal_params
# add updating_person to params so Proposal does not update last_change attribute when updating_person is organizer_for_event?
params.require(:proposal).permit(:title, {review_tags: []}, :abstract, :details, :pitch, :slides_url, :video_url,
params.require(:proposal).permit(:title, {review_tags: []}, :abstract, :details, :pitch, :slides_url, :video_url, :custom_fields,
comments_attributes: [:body, :proposal_id, :person_id],
speakers_attributes: [:bio, :person_id, :id, person_attributes:[:id, :name, :email]])
speakers_attributes: [:bio, :person_id, :id, person_attributes: [:id, :name, :email]])
end

def send_state_mail(state)
case state
when Proposal::State::ACCEPTED
Organizer::ProposalMailer.accept_email(@event, @proposal).deliver
when Proposal::State::REJECTED
Organizer::ProposalMailer.reject_email(@event, @proposal).deliver
when Proposal::State::WAITLISTED
Organizer::ProposalMailer.waitlist_email(@event, @proposal).deliver
Organizer::ProposalMailer.accept_email(@event, @proposal).deliver
when Proposal::State::REJECTED
Organizer::ProposalMailer.reject_email(@event, @proposal).deliver
when Proposal::State::WAITLISTED
Organizer::ProposalMailer.waitlist_email(@event, @proposal).deliver
end
end
end
34 changes: 27 additions & 7 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,20 @@ class Event < ActiveRecord::Base
store_accessor :speaker_notification_emails, :waitlist

has_many :participants, dependent: :destroy
has_many :proposals, dependent: :destroy
has_many :speakers, through: :proposals
has_many :rooms, dependent: :destroy
has_many :tracks, dependent: :destroy
has_many :sessions, dependent: :destroy
has_many :proposals, dependent: :destroy
has_many :speakers, through: :proposals
has_many :rooms, dependent: :destroy
has_many :tracks, dependent: :destroy
has_many :sessions, dependent: :destroy
has_many :taggings, through: :proposals
has_many :ratings, through: :proposals
has_many :participant_invitations


serialize :proposal_tags, Array
serialize :review_tags, Array
serialize :custom_fields, Array


scope :recent, -> { order('name ASC') }
scope :live, -> { where("state = 'open' and (closes_at is null or closes_at > ?)", Time.current).order('closes_at ASC') }
Expand All @@ -41,6 +44,22 @@ def valid_review_tags=(tags_string)
self.review_tags = Tagging.tags_string_to_array(tags_string)
end

def custom_fields_string=(custom_fields_string)
self.custom_fields = self.custom_fields_string_to_array(custom_fields_string)
end

def custom_fields_string_to_array(string)
(string || '').split(',').map(&:strip).reject(&:blank?).uniq
end

def custom_fields_string
custom_fields.join(',')
end

def fields
self.proposals.column_names.join(', ')
end

def generate_slug
self.slug = name.parameterize if slug.blank?
end
Expand All @@ -54,7 +73,7 @@ def open?
end

def closed?
! open?
!open?
end

def past_open?
Expand Down Expand Up @@ -87,7 +106,7 @@ def unarchive
end

def current?
! archived?
!archived?
end

def cfp_opens
Expand Down Expand Up @@ -125,6 +144,7 @@ def conference_date(conference_day)
# created_at :datetime
# updated_at :datetime
# archived :boolean default(FALSE)
# custom_fields :text
#
# Indexes
#
Expand Down
6 changes: 5 additions & 1 deletion app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Proposal < ActiveRecord::Base
serialize :proposal_data, Hash

attr_accessor :tags, :review_tags, :updating_person
attr_accessor :video_url, :slide_url
attr_accessor :video_url, :slide_url, :custom_fields

accepts_nested_attributes_for :public_comments, reject_if: Proc.new { |comment_attributes| comment_attributes[:body].blank? }
accepts_nested_attributes_for :speakers
Expand Down Expand Up @@ -87,6 +87,10 @@ def slides_url=(slides_url)
proposal_data[:slides_url] = slides_url
end

def custom_fields=(custom_fields)
proposal_data[:custom_fields] = custom_fields
end

def update_state(new_state)
state_string = new_state.to_s
state_string.gsub!("_", " ") if state_string.include?('_')
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/proposal_serializer.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class ProposalSerializer < ActiveModel::Serializer
attributes :title, :abstract, :review_tags, :id, :track, :video_url, :slides_url
attributes :title, :abstract, :review_tags, :id, :track, :video_url, :slides_url, :custom_fields
has_many :speakers

def review_tags
Expand Down
6 changes: 6 additions & 0 deletions app/views/organizer/events/edit_custom_fields.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%h2 Custom Fields
.form-group
= form_for @event, :url => update_custom_fields_organizer_event_path, :method => :put do |f|
= f.text_field :custom_fields_string
%p.help-block This is a comma separated list of custom fields allowed for use on proposals.
%button.pull-right.btn.btn-success{:type => "submit"} Save
3 changes: 2 additions & 1 deletion app/views/organizer/events/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
%p= link_to "Edit Tags", edit_organizer_event_path(:form => "tags_form"), class: "btn btn-primary"

%h4 Fields
%p= link_to "Add Custom Field", "#", class: "btn btn-primary"
%dd=event.fields
%p= link_to "Add Custom Field", edit_custom_fields_organizer_event_path(event), class: "btn btn-primary"


.col-sm-4
Expand Down
6 changes: 6 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@

namespace 'organizer' do
resources :events, only: [:edit, :show, :update] do
member do
get :edit_custom_fields
put :update_custom_fields
end
resources :participant_invitations, except: [ :new, :edit, :update, :show ]


controller :program do
get 'program' => 'program#show'
end
Expand All @@ -77,6 +82,7 @@
post :update_state
end


controller :speakers do
get :speaker_emails, action: :emails
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20150604225912_add_custom_fields_to_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCustomFieldsToEvent < ActiveRecord::Migration
def change
add_column :events, :custom_fields, :text
end
end
3 changes: 2 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: 20150512191412) do
ActiveRecord::Schema.define(version: 20150604225912) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -48,6 +48,7 @@
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "archived", default: false
t.text "custom_fields"
end

add_index "events", ["slug"], name: "index_events_on_slug", using: :btree
Expand Down

0 comments on commit ceda1ce

Please sign in to comment.