submission text control/model modifications

This commit is contained in:
madhekare 2021-02-16 13:46:54 -08:00 committed by CactusPuppy
parent baf488ad8a
commit b8f531783b
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
3 changed files with 19 additions and 2 deletions

View file

@ -175,7 +175,7 @@ module Admin
def event_params
params.require(:event).permit(
# 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
:track_id, :state, :language, :is_highlight, :max_attendees,
# Not used anymore?

View file

@ -170,7 +170,7 @@ class ProposalsController < ApplicationController
def event_params
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,
speaker_ids: [], volunteer_ids: []
)

View file

@ -73,6 +73,7 @@ class Event < ApplicationRecord
before_create :generate_guid
validate :abstract_limit
validate :submission_limit
validate :before_end_of_conference, on: :create
validates :title, presence: true
validates :abstract, presence: true
@ -217,6 +218,10 @@ class Event < ApplicationRecord
abstract.to_s.split.size
end
def submission_word_count
submission_text.to_s.split.size
end
def self.get_state_color(state)
COLORS[state.to_sym] || '#00FFFF' # azure
end
@ -353,6 +358,18 @@ class Event < ApplicationRecord
errors.add(:abstract, "cannot have more than #{max_words} words") if len > max_words
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
# venue.rb has same functionality which can be shared
# TODO: rename guid to UUID as guid is specifically Microsoft term