Skip to content
This repository was archived by the owner on Jan 19, 2019. It is now read-only.

Commit

Permalink
Add featured & featured_snippet attrs to event model. Default featured
Browse files Browse the repository at this point in the history
-> false, featured_snippet has limit of 200 chars. Update schema, etc.
  • Loading branch information
Colby Cox committed Feb 6, 2018
1 parent decee68 commit e735b9c
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 37 deletions.
73 changes: 37 additions & 36 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,27 @@ class Event < ApplicationRecord

belongs_to :org
validates :title, :location, presence: true
validates :featured_snippet, length: {maximum: 200}
validate :dates_present?
validate :valid_dates?
validate :category?

before_validation :set_category

scope :search_query, (lambda { |query|
scope :search_query, (lambda {|query|
return nil if query.blank?
# condition query, parse into individual keywords
terms = query.downcase.split(/\s+/)
# bracket with '%' to search anywhere in event name/org
terms = terms.map { |term| '%' + term + '%' }
terms = terms.map {|term| '%' + term + '%'}
# SQL query
where(
terms.map { 'LOWER(events.title) LIKE ?' }.join(' AND '),
*terms.map { |e| [e] }.flatten
terms.map {'LOWER(events.title) LIKE ?'}.join(' AND '),
*terms.map {|e| [e]}.flatten
)
})

scope :with_category, (lambda { |categories|
scope :with_category, (lambda {|categories|
where(display_category: [*categories])
})

Expand Down Expand Up @@ -57,36 +58,36 @@ def set_category
return if display_category
self.category = 'OTHER' if category.nil?
case category
when 'CLASS_EVENT'
self.display_category = 'Academic'
when 'ART_EVENT', 'ART_FILM', 'BOOK_EVENT', 'EVENT_ART', 'EVENT_LITERATURE', 'MOVIE_EVENT'
self.display_category = 'Arts'
when 'SPORTS_EVENT', 'FITNESS'
self.display_category = 'Athletic'
when 'NETWORKING'
self.display_category = 'Career and Professional'
when 'EVENT_CAUSE', 'CAUSES'
self.display_category = 'Causes'
when 'FUNDRAISER', 'VOLUNTEERING'
self.display_category = 'Charity and Community Service'
when 'CONFERENCE_EVENT', 'MEETUP', 'WORKSHOP'
self.display_category = 'Conferences, Meetings and Workshops'
when 'COMMUNITY'
self.display_category = 'Ethnic and Cultural'
when 'EVENT_FOOD', 'FOOD_DRINK', 'FOOD_TASTING', 'DINING_EVENT'
self.display_category = 'Food'
when 'HEALTH_WELLNESS'
self.display_category = 'Health and Wellness'
when 'LECTURE'
self.display_category = 'Lectures and Speakers'
when 'FESTIVAL_EVENT', 'MUSIC', 'MUSIC_EVENT', 'COMEDY_EVENT', 'DANCE_EVENT', 'THEATER_EVENT', 'THEATER_DANCE'
self.display_category = 'Music, Theater and Performances'
when 'RELIGION', 'RELIGIOUS_EVENT'
self.display_category = 'Religious and Spiritual'
when 'NIGHTLIFE', 'PARTIES_NIGHTLIFE'
self.display_category = 'Social'
else
self.display_category = 'Other'
when 'CLASS_EVENT'
self.display_category = 'Academic'
when 'ART_EVENT', 'ART_FILM', 'BOOK_EVENT', 'EVENT_ART', 'EVENT_LITERATURE', 'MOVIE_EVENT'
self.display_category = 'Arts'
when 'SPORTS_EVENT', 'FITNESS'
self.display_category = 'Athletic'
when 'NETWORKING'
self.display_category = 'Career and Professional'
when 'EVENT_CAUSE', 'CAUSES'
self.display_category = 'Causes'
when 'FUNDRAISER', 'VOLUNTEERING'
self.display_category = 'Charity and Community Service'
when 'CONFERENCE_EVENT', 'MEETUP', 'WORKSHOP'
self.display_category = 'Conferences, Meetings and Workshops'
when 'COMMUNITY'
self.display_category = 'Ethnic and Cultural'
when 'EVENT_FOOD', 'FOOD_DRINK', 'FOOD_TASTING', 'DINING_EVENT'
self.display_category = 'Food'
when 'HEALTH_WELLNESS'
self.display_category = 'Health and Wellness'
when 'LECTURE'
self.display_category = 'Lectures and Speakers'
when 'FESTIVAL_EVENT', 'MUSIC', 'MUSIC_EVENT', 'COMEDY_EVENT', 'DANCE_EVENT', 'THEATER_EVENT', 'THEATER_DANCE'
self.display_category = 'Music, Theater and Performances'
when 'RELIGION', 'RELIGIOUS_EVENT'
self.display_category = 'Religious and Spiritual'
when 'NIGHTLIFE', 'PARTIES_NIGHTLIFE'
self.display_category = 'Social'
else
self.display_category = 'Other'
end
end

Expand All @@ -103,7 +104,7 @@ def self.get_date_events(events)
display << [set[0], set[1].length]
end

display.sort_by! { |cat| cat[1] }.reverse!
display.sort_by! {|cat| cat[1]}.reverse!
end

def self.categories
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20180206000340_add_featured_to_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFeaturedToEvent < ActiveRecord::Migration[5.1]
def change
add_column :events, :featured, :boolean, :default => false
end
end
5 changes: 5 additions & 0 deletions db/migrate/20180206000719_add_featured_snippet_to_event.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddFeaturedSnippetToEvent < ActiveRecord::Migration[5.1]
def change
add_column :events, :featured_snippet, :string, :limit => 200
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170826164950) do
ActiveRecord::Schema.define(version: 20180206000719) do

create_table "events", force: :cascade do |t|
t.string "title", null: false
Expand All @@ -32,6 +32,8 @@
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "display_category"
t.boolean "featured", default: false
t.string "featured_snippet", limit: 200
t.index ["org_id"], name: "index_events_on_org_id"
end

Expand Down

0 comments on commit e735b9c

Please sign in to comment.