Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement categories #44

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
4b40ef2
Implement event categories
danielres Aug 16, 2013
646c75b
Add validation spec for refinery-calendar event category
danielres Aug 16, 2013
ded4fab
Add spec coverage for associations between events and categories
danielres Aug 17, 2013
9ce95b4
Implement many-to-many relationship between events and their categories
danielres Aug 17, 2013
03af4c4
Add request spec for categories admin, with english I18n that was mis…
danielres Aug 17, 2013
9da1af1
Add a link list of all categories to category show page
danielres Aug 20, 2013
f11dff0
Extract categories_list into own partial
danielres Aug 21, 2013
5030034
Display only upcoming events under a given category
danielres Aug 21, 2013
67f888b
Order upcoming events under a category by field 'starts_at'
danielres Aug 21, 2013
c2a3b06
Add menu of categories to event side content
danielres Aug 21, 2013
082b847
Improve display of an event's categories
danielres Aug 21, 2013
2cc8d28
Extract event show markup into _event partial
danielres Aug 21, 2013
902b5ae
Improve rendering of event
danielres Aug 21, 2013
6074828
Improve events index page: separate events into lists 'featured', 'up…
danielres Aug 22, 2013
0d386df
Fix html error
danielres Aug 22, 2013
25ad642
Add venue address on event page
danielres Aug 28, 2013
6293cdb
Add/fix some translations in EN and FR
danielres Aug 28, 2013
b94c811
Move event excerpt under title on detailed event display
danielres Aug 28, 2013
b6b8b78
Add scope 'current' for events
danielres Sep 29, 2013
2bc16ea
Implement scope 'current' for events in view and controller
danielres Sep 29, 2013
f9844a1
Update en and fr locales
danielres Sep 29, 2013
bb45cf9
Add refinerycms-i18n to Gemfile
danielres Jan 7, 2014
7f5bf9a
Add migration for calendar translations
danielres Jan 7, 2014
c45e8aa
Add translation support to Event model
danielres Jan 7, 2014
fff12f6
Add locale picker to view 'admin/events/_form'
danielres Jan 7, 2014
8438bc7
Add migration for calendar categories translations
danielres Jan 25, 2014
e926e57
Add translations support to Refinery::Calendar::Category model
danielres Jan 25, 2014
a094063
Add locale picker to view 'admin/categories/_form'
danielres Jan 25, 2014
687857d
Fix migration 'down' block
danielres Jan 25, 2014
c97bbbe
Keep column 'name' in original table upon translation table creation
danielres Jan 25, 2014
e351ba2
Implement attaching an image to an event
danielres Jan 25, 2014
56dd83d
Dsiplay event image if present
danielres Jan 25, 2014
a2dd71f
Reduce size of small event image
danielres Jan 25, 2014
afe7da0
Reduce value of width constraint for event image in full view
danielres Feb 12, 2014
9ba0a66
Move event image below event excerpt
danielres Feb 12, 2014
4846ac6
Fix english date format for events
danielres Feb 17, 2014
32118ec
Fix short english date format for events
danielres Feb 17, 2014
3a66e24
Bump dependecy to refinerycms-core from '~> 2.0.3' to '~> 2.1.0'
danielres Feb 23, 2014
0db314e
Remove checks for Refinery.i18n_enabled?
danielres Feb 23, 2014
6c5cfb5
Update CategoriesController to provide list of current + upcoming events
danielres Jan 11, 2016
a84f659
Fix category page not listing current events
danielres Jan 11, 2016
455a31f
Revert: Bump dependecy to refinerycms-core from '~> 2.0.3' to '~> 2.…
danielres Jan 11, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source "http://rubygems.org"

gemspec

gem 'refinerycms', '~> 2.0.0'
gem 'refinerycms-i18n', '~> 2.0.2'

# Refinery/rails should pull in the proper versions of these
group :assets do
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/refinery/calendar/admin/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Refinery
module Calendar
module Admin
class CategoriesController < ::Refinery::AdminController

crudify :'refinery/calendar/category',
:title_attribute => 'name',
:xhr_paging => true,
:sortable => false,
:order => 'created_at DESC'
end
end
end
end
4 changes: 4 additions & 0 deletions app/controllers/refinery/calendar/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Refinery
module Calendar
module Admin
class EventsController < ::Refinery::AdminController
before_filter :find_categories, :except => [:index, :destroy]
before_filter :find_venues, :except => [:index, :destroy]

crudify :'refinery/calendar/event',
Expand All @@ -13,6 +14,9 @@ class EventsController < ::Refinery::AdminController
def find_venues
@venues = Venue.order('name')
end
def find_categories
@categories = Category.order('name')
end
end
end
end
Expand Down
45 changes: 45 additions & 0 deletions app/controllers/refinery/calendar/categories_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
module Refinery
module Calendar
class CategoriesController < ::ApplicationController
before_filter :find_categories

def show
@category = Category.find(params[:id])
@upcoming_events = @category.events.upcoming.order('refinery_calendar_events.starts_at')
@current_events = @category.events.current.order('refinery_calendar_events.starts_at')
@events = (@current_events + @upcoming_events).uniq
end
# before_filter :find_page, :except => :archive

# def index
# @events = Event.upcoming.order('refinery_calendar_events.starts_at DESC')

# # you can use meta fields from your model instead (e.g. browser_title)
# # by swapping @page for @event in the line below:
# present(@page)
# end

# def show
# @event = Event.find(params[:id])

# # you can use meta fields from your model instead (e.g. browser_title)
# # by swapping @page for @event in the line below:
# present(@page)
# end

# def archive
# @events = Event.archive.order('refinery_calendar_events.starts_at DESC')
# render :template => 'refinery/calendar/events/index'
# end

# protected
# def find_page
# @page = ::Refinery::Page.where(:link_url => "/calendar/events").first
# end
protected
def find_categories
@categories ||= Refinery::Calendar::Category.order('refinery_calendar_categories.name')
end
end
end
end
13 changes: 10 additions & 3 deletions app/controllers/refinery/calendar/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ module Refinery
module Calendar
class EventsController < ::ApplicationController
before_filter :find_page, :except => :archive
before_filter :find_categories

def index
@events = Event.upcoming.order('refinery_calendar_events.starts_at DESC')
@events = Event.upcoming.order('refinery_calendar_events.starts_at DESC')
@featured_events = Event.upcoming.featured.order('refinery_calendar_events.starts_at')
@upcoming_events = Event.upcoming.order('refinery_calendar_events.starts_at')
@current_events = Event.current.order('refinery_calendar_events.starts_at')
@past_events = Event.archive.order('refinery_calendar_events.starts_at DESC')

# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @event in the line below:
Expand All @@ -13,10 +18,9 @@ def index

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

# you can use meta fields from your model instead (e.g. browser_title)
# by swapping @page for @event in the line below:
present(@page)
present(@event)
end

def archive
Expand All @@ -28,6 +32,9 @@ def archive
def find_page
@page = ::Refinery::Page.where(:link_url => "/calendar/events").first
end
def find_categories
@categories ||= Refinery::Calendar::Category.order( 'refinery_calendar_categories.name')
end

end
end
Expand Down
17 changes: 17 additions & 0 deletions app/models/refinery/calendar/category.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Refinery
module Calendar
class Category < Refinery::Core::BaseModel
has_and_belongs_to_many :events
validates :name, presence: true, uniqueness: true
attr_accessible :name, :position

translates :name
class Translation
attr_accessible :locale
end
acts_as_indexed :fields => [:name]


end
end
end
22 changes: 20 additions & 2 deletions app/models/refinery/calendar/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,27 @@ module Calendar
class Event < Refinery::Core::BaseModel
extend FriendlyId


translates :title, :excerpt, :description
class Translation
attr_accessible :locale
end
acts_as_indexed :fields => [:title, :excerpt, :description]


attr_accessible :image_id
belongs_to :image, :class_name => '::Refinery::Image'

friendly_id :title, :use => :slugged

belongs_to :venue
has_and_belongs_to_many :categories


validates :title, :presence => true, :uniqueness => true

attr_accessible :title, :from, :to, :registration_link,
:venue_id, :excerpt, :description,
:venue_id, :category_ids, :excerpt, :description,
:featured, :position

alias_attribute :from, :starts_at
Expand All @@ -33,6 +46,11 @@ class Event < Refinery::Core::BaseModel
}

class << self
def current
where('refinery_calendar_events.starts_at < ?', Time.now)
.where('refinery_calendar_events.ends_at >= ?', Time.now)
end

def upcoming
where('refinery_calendar_events.starts_at >= ?', Time.now)
end
Expand All @@ -42,7 +60,7 @@ def featured
end

def archive
where('refinery_calendar_events.starts_at < ?', Time.now)
where('refinery_calendar_events.ends_at < ?', Time.now)
end

end
Expand Down
26 changes: 26 additions & 0 deletions app/views/refinery/calendar/admin/categories/_actions.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<ul>
<% if ::Refinery::Calendar::Admin::CategoriesController.searchable? %>
<li>
<%= render '/refinery/admin/search', :url => refinery.calendar_admin_categories_path %>
</li>
<% end %>
<li>
<%= link_to t('.create_new'), refinery.new_calendar_admin_category_path,
:class => "add_icon" %>
</li>
<%= render 'refinery/calendar/admin/shared/links' %>
<% if !searching? && ::Refinery::Calendar::Admin::CategoriesController.sortable? && ::Refinery::Calendar::Category.any? %>
<li>
<%= link_to t('.reorder', :what => "Categories"),
refinery.calendar_admin_category_path,
:id => "reorder_action",
:class => "reorder_icon" %>

<%= link_to t('.reorder_done', :what => "Categories"),
refinery.calendar_admin_categories_path,
:id => "reorder_action_done",
:style => "display: none;",
:class => "reorder_icon" %>
</li>
<% end %>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<%= will_paginate @categories if Refinery::Calendar::Admin::CategoriesController.pageable? %>
<%= render 'sortable_list' %>
15 changes: 15 additions & 0 deletions app/views/refinery/calendar/admin/categories/_category.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(category) -%>">
<span class='title'>
<%= category.name %>

</span>
<span class='actions'>
<%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_calendar_admin_category_path(category),
:title => t('.edit') %>
<%= link_to refinery_icon_tag("delete.png"), refinery.calendar_admin_category_path(category),
:class => "cancel confirm-delete",
:title => t('.delete'),
:confirm => t('message', :scope => 'refinery.admin.delete', :title => category.name),
:method => :delete %>
</span>
</li>
21 changes: 21 additions & 0 deletions app/views/refinery/calendar/admin/categories/_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<%= form_for [refinery, :calendar_admin, @category] do |f| -%>
<%= render '/refinery/admin/error_messages',
:object => @category,
:include_object_name => true %>

<%= render "locale_picker",
:current_locale => Thread.current[:globalize_locale] %>


<div class='field'>
<%= f.label :name -%>
<%= f.text_field :name, :class => 'larger widest' -%>

</div>


<%= render '/refinery/admin/form_actions', :f => f,
:continue_editing => false,
:delete_title => t('delete', :scope => 'refinery.categories.admin.categories.category'),
:delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @category.name) %>
<% end -%>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<input type='hidden' name='switch_locale' id='switch_locale' value='<%= local_assigns[:current_locale] %>' />
<% if (locales ||= Refinery::I18n.frontend_locales).present? and locales.many? %>
<ul id='switch_locale_picker' class='clearfix'>
<% locales.each do |locale| %>
<li<%= " class='selected'" if locale.to_s == local_assigns[:current_locale].to_s %>>
<%= link_to refinery_icon_tag("flags/#{locale}.png", :size => "32x22"),
refinery.url_for(:switch_locale => locale) %>
</li>
<% end %>
</ul>
<% end %>
18 changes: 18 additions & 0 deletions app/views/refinery/calendar/admin/categories/_records.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<% if searching? %>
<h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
<% end %>
<div class='pagination_container'>
<% if @categories.any? %>
<%= render 'categories' %>
<% else %>
<p>
<% unless searching? %>
<strong>
<%= t('.no_items_yet') %>
</strong>
<% else %>
<%= t('no_results', :scope => 'refinery.admin.search') %>
<% end %>
</p>
<% end %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul id='sortable_list'>
<%= render :partial => 'category', :collection => @categories %>
</ul>
<%= render '/refinery/admin/sortable_list',
:continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true %>
1 change: 1 addition & 0 deletions app/views/refinery/calendar/admin/categories/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form' %>
8 changes: 8 additions & 0 deletions app/views/refinery/calendar/admin/categories/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<section id='records'>
<h2>Calendar: Categories</h2>
<%= render 'records' %>
</section>
<aside id='actions'>
<%= render 'actions' %>
</aside>
<%= render '/refinery/admin/make_sortable', :tree => false if !searching? and ::Refinery::Calendar::Admin::CategoriesController.sortable? and ::Refinery::Calendar::Category.count > 1 %>
1 change: 1 addition & 0 deletions app/views/refinery/calendar/admin/categories/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= render 'form' %>
35 changes: 34 additions & 1 deletion app/views/refinery/calendar/admin/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@
:object => @event,
:include_object_name => true %>

<%= render "locale_picker",
:current_locale => Thread.current[:globalize_locale] %>


<div class="field">
<%= f.label :image %>
<%= render :partial => "/refinery/admin/image_picker", :locals => {
:f => f,
:field => :image_id,
:image => f.object.image,
:toggle_image_display => false
}
%>
</div>

<div class='field'>
<%= f.label :title -%>
Expand Down Expand Up @@ -36,6 +50,25 @@
<%= f.collection_select :venue_id, @venues, :id, :name, { :include_blank => 'None' }, :class => 'chzn-select', :'data-placeholder' => 'Search Venues', :style => 'width: 300px;' %>
</div>

<% if @categories.any? -%>
<div class='field'>
<label for='event[category_ids][]'>Categories</label>
<ul class="check_box_list">
<% @categories.each do |category| -%>
<li>
<%= check_box_tag 'event[category_ids][]', category.id,
@event.categories.include?(category),
:id => (id="event_category_ids_#{category.id}") %>
<%= label_tag 'event[category_ids][]', category.name,
:class => 'stripped',
:for => id %>
</li>
<% end -%>
</ul>
</div>
<% end -%>


<div class='field'>
<%= f.label :excerpt -%>
<%= f.text_area :excerpt, :size => '65x5' -%>
Expand Down Expand Up @@ -76,7 +109,7 @@
$(document).ready(function(){
page_options.init(false, '', '');

$('#event_venue_id').chosen({
$('#event_venue_id,#event_category_id').chosen({
no_results_text: "No results matched",
allow_single_deselect: true
});
Expand Down
11 changes: 11 additions & 0 deletions app/views/refinery/calendar/admin/events/_locale_picker.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<input type='hidden' name='switch_locale' id='switch_locale' value='<%= local_assigns[:current_locale] %>' />
<% if (locales ||= Refinery::I18n.frontend_locales).present? and locales.many? %>
<ul id='switch_locale_picker' class='clearfix'>
<% locales.each do |locale| %>
<li<%= " class='selected'" if locale.to_s == local_assigns[:current_locale].to_s %>>
<%= link_to refinery_icon_tag("flags/#{locale}.png", :size => "32x22"),
refinery.url_for(:switch_locale => locale) %>
</li>
<% end %>
</ul>
<% end %>
4 changes: 4 additions & 0 deletions app/views/refinery/calendar/admin/shared/_links.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@
<%= link_to t('.manage_venues'), refinery.calendar_admin_venues_path,
:class => "manage_icon" %>
</li>
<li>
<%= link_to t('.manage_categories'), refinery.calendar_admin_categories_path,
:class => "manage_icon" %>
</li>
Loading