submission text control/model modifications
This commit is contained in:
parent
baf488ad8a
commit
b8f531783b
3 changed files with 19 additions and 2 deletions
|
|
@ -175,7 +175,7 @@ module Admin
|
||||||
def event_params
|
def event_params
|
||||||
params.require(:event).permit(
|
params.require(:event).permit(
|
||||||
# Set also in proposals controller
|
# Set also in proposals controller
|
||||||
:title, :subtitle, :event_type_id, :abstract, :description, :require_registration, :difficulty_level_id,
|
:title, :subtitle, :event_type_id, :abstract, :submission_text, :description, :require_registration, :difficulty_level_id,
|
||||||
# Set only in admin/events controller
|
# Set only in admin/events controller
|
||||||
:track_id, :state, :language, :is_highlight, :max_attendees,
|
:track_id, :state, :language, :is_highlight, :max_attendees,
|
||||||
# Not used anymore?
|
# Not used anymore?
|
||||||
|
|
|
||||||
|
|
@ -170,7 +170,7 @@ class ProposalsController < ApplicationController
|
||||||
|
|
||||||
def event_params
|
def event_params
|
||||||
params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id,
|
params.require(:event).permit(:event_type_id, :track_id, :difficulty_level_id,
|
||||||
:title, :subtitle, :abstract, :description,
|
:title, :subtitle, :abstract, :submission_text, :description,
|
||||||
:require_registration, :max_attendees, :language,
|
:require_registration, :max_attendees, :language,
|
||||||
speaker_ids: [], volunteer_ids: []
|
speaker_ids: [], volunteer_ids: []
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ class Event < ApplicationRecord
|
||||||
before_create :generate_guid
|
before_create :generate_guid
|
||||||
|
|
||||||
validate :abstract_limit
|
validate :abstract_limit
|
||||||
|
validate :submission_limit
|
||||||
validate :before_end_of_conference, on: :create
|
validate :before_end_of_conference, on: :create
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :abstract, presence: true
|
validates :abstract, presence: true
|
||||||
|
|
@ -217,6 +218,10 @@ class Event < ApplicationRecord
|
||||||
abstract.to_s.split.size
|
abstract.to_s.split.size
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def submission_word_count
|
||||||
|
submission_text.to_s.split.size
|
||||||
|
end
|
||||||
|
|
||||||
def self.get_state_color(state)
|
def self.get_state_color(state)
|
||||||
COLORS[state.to_sym] || '#00FFFF' # azure
|
COLORS[state.to_sym] || '#00FFFF' # azure
|
||||||
end
|
end
|
||||||
|
|
@ -353,6 +358,18 @@ class Event < ApplicationRecord
|
||||||
errors.add(:abstract, "cannot have more than #{max_words} words") if len > max_words
|
errors.add(:abstract, "cannot have more than #{max_words} words") if len > max_words
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def submission_limit
|
||||||
|
# If we don't have an event type, there is no need to count anything
|
||||||
|
return unless event_type && submission_text
|
||||||
|
|
||||||
|
len = submission_text.split.size
|
||||||
|
max_words = event_type.maximum_abstract_length
|
||||||
|
min_words = event_type.minimum_abstract_length
|
||||||
|
|
||||||
|
errors.add(:submission_text, "cannot have less than #{min_words} words") if len < min_words
|
||||||
|
errors.add(:submission_text, "cannot have more than #{max_words} words") if len > max_words
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: create a module to be mixed into model to perform same operation
|
# TODO: create a module to be mixed into model to perform same operation
|
||||||
# venue.rb has same functionality which can be shared
|
# venue.rb has same functionality which can be shared
|
||||||
# TODO: rename guid to UUID as guid is specifically Microsoft term
|
# TODO: rename guid to UUID as guid is specifically Microsoft term
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue