From 43a5b25562c90ee74d201847d986233e6fc9d70e Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Thu, 5 Jun 2008 18:18:35 +0000 Subject: [PATCH] ActionItem26: several things to integrate events --- app/controllers/public/search_controller.rb | 3 ++- app/helpers/assets_helper.rb | 1 + app/models/category_finder.rb | 2 +- app/models/environment.rb | 2 ++ app/models/event.rb | 4 +--- app/views/cms/_event.rhtml | 9 +++++++-- db/migrate/037_add_dates_to_articles.rb | 22 ++++++++++++++++++++++ public/designs/icons/default/calendar.gif | 1 + public/designs/icons/default/style.css | 1 + public/images/icons-mime/event.png | 1 + test/functional/search_controller_test.rb | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/event_test.rb | 5 +++++ 12 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 db/migrate/037_add_dates_to_articles.rb create mode 120000 public/designs/icons/default/calendar.gif create mode 120000 public/images/icons-mime/event.png diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index bc019a5..0ef0f90 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -54,7 +54,8 @@ class SearchController < ApplicationController [ :enterprises, N_('Enterprises') ], [ :people, N_('People') ], [ :communities, N_('Communities') ], - [ :products, N_('Products') ] + [ :products, N_('Products') ], + [ :events, N_('Events') ] ] # TODO don't hardcode like this >:-( diff --git a/app/helpers/assets_helper.rb b/app/helpers/assets_helper.rb index 2257cb2..a1e84a0 100644 --- a/app/helpers/assets_helper.rb +++ b/app/helpers/assets_helper.rb @@ -10,6 +10,7 @@ module AssetsHelper [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ], [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], [ options.merge(:asset => 'comments'), "icon-menu-comments", _('Comments') ], + [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], ].map do |target,css_class,name| content_tag('li', diff --git a/app/models/category_finder.rb b/app/models/category_finder.rb index d1db15b..2a50555 100644 --- a/app/models/category_finder.rb +++ b/app/models/category_finder.rb @@ -50,7 +50,7 @@ class CategoryFinder {:select => 'distinct comments.*', :joins => 'inner join articles_categories on articles_categories.article_id = comments.article_id', :conditions => ['articles_categories.category_id in (?)', category_ids]}.merge!(options) when 'Product' {:select => 'distinct products.*', :joins => 'inner join categories_profiles on products.enterprise_id = categories_profiles.profile_id', :conditions => ['categories_profiles.category_id in (?)', category_ids]}.merge!(options) - when 'Article', 'Person', 'Community', 'Enterprise' + when 'Article', 'Person', 'Community', 'Enterprise', 'Event' {:include => 'categories', :conditions => ['categories.id IN (?)', category_ids]}.merge!(options) else raise "unreconized class #{klass.name}" diff --git a/app/models/environment.rb b/app/models/environment.rb index 42e67d1..a1b5e39 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -218,6 +218,8 @@ class Environment < ActiveRecord::Base self.articles.recent(limit) end + has_many :events, :through => :profiles, :source => :articles, :class_name => 'Event' + # FIXME is this the better/faster way to do this? has_many :comments, :through => :articles diff --git a/app/models/event.rb b/app/models/event.rb index 864f627..eb9ab3b 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -4,9 +4,7 @@ class Event < Article settings_items :description, :type => :string settings_items :link, :type => :string - - settings_items :start_date, :type => :date - settings_items :end_date, :type => :date + settings_items :address, :type => :string validates_presence_of :title, :start_date diff --git a/app/views/cms/_event.rhtml b/app/views/cms/_event.rhtml index 414f138..4d7d693 100644 --- a/app/views/cms/_event.rhtml +++ b/app/views/cms/_event.rhtml @@ -5,8 +5,13 @@ <%= f.text_field('name', :size => '64') %> -<%= labelled_form_field(_('Description:'), text_area(:article, :description, :cols => 64)) %> - <%= labelled_form_field(_('Start date'), calendar_date_select(:article, :start_date)) %> <%= labelled_form_field(_('End date'), calendar_date_select(:article, :end_date)) %> + +<%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> + +<%= labelled_form_field(_('Address:'), text_field(:article, :address)) %> + +<%= labelled_form_field(_('Information about the event:'), text_area(:article, :description, :cols => 64)) %> + diff --git a/db/migrate/037_add_dates_to_articles.rb b/db/migrate/037_add_dates_to_articles.rb new file mode 100644 index 0000000..f143ccc --- /dev/null +++ b/db/migrate/037_add_dates_to_articles.rb @@ -0,0 +1,22 @@ +class AddDatesToArticles < ActiveRecord::Migration + + def self.each_table + [ :articles, :article_versions ].each do |table| + yield(table) + end + end + + def self.up + each_table do |table| + add_column table, :start_date, :type => :date + add_column table, :end_date, :type => :date + end + end + + def self.down + each_table do |table| + remove_column table, :start_date + remove_column table, :end_date + end + end +end diff --git a/public/designs/icons/default/calendar.gif b/public/designs/icons/default/calendar.gif new file mode 120000 index 0000000..f1a3483 --- /dev/null +++ b/public/designs/icons/default/calendar.gif @@ -0,0 +1 @@ +../../../images/calendar_date_select/calendar.gif \ No newline at end of file diff --git a/public/designs/icons/default/style.css b/public/designs/icons/default/style.css index 5e5e5a4..b000d66 100644 --- a/public/designs/icons/default/style.css +++ b/public/designs/icons/default/style.css @@ -37,6 +37,7 @@ .icon-menu-logout { background-image: url(exit-HC.gif) } .icon-menu-search { background-image: url(search-HC.gif) } .icon-menu-ed-design { background-image: url(edit-design-HC.gif) } +.icon-menu-events { background-image: url(calendar.gif) } .icon-todo { background-image: url(stock_todo.png); } .icon-menu-articles { background-image: url(edit-HC.gif) } diff --git a/public/images/icons-mime/event.png b/public/images/icons-mime/event.png new file mode 120000 index 0000000..c258d1d --- /dev/null +++ b/public/images/icons-mime/event.png @@ -0,0 +1 @@ +../calendar_date_select/calendar.png \ No newline at end of file diff --git a/test/functional/search_controller_test.rb b/test/functional/search_controller_test.rb index 41ca128..11c7d59 100644 --- a/test/functional/search_controller_test.rb +++ b/test/functional/search_controller_test.rb @@ -839,4 +839,74 @@ class SearchControllerTest < Test::Unit::TestCase assert_not_includes assigns(:regions), r2 assert_no_tag :tag => 'ul', :descendant => { :tag => 'li', :content => r2.name } end + + should 'search for events' do + person = create_user('teste').person + ev = create_event(person, :name => 'an event to be found') + + get 'index', :query => 'event found', :find_in => [ 'events' ] + + assert_includes assigns(:results)[:events], ev + end + + should 'search for events in a specific category' do + person = create_user('teste').person + + # in category + ev1 = create_event(person, :name => 'an event to be found') + ev1.categories << @category + ev1.save! + + # not in category + ev2 = create_event(person, :name => 'another event to be found') + ev2.save! + + get :index, :category_path => [ 'my-category' ], :query => 'event found', :find_in => [ 'events' ] + + assert_includes assigns(:results)[:events], ev1 + assert_not_includes assigns(:results)[:events], ev2 + end + + # 'assets' outside any category + should 'list events in general' do + person = create_user('testuser').person + person2 = create_user('anotheruser').person + + ev1 = create_event(person, :name => 'one event', :categories => [@category]) + + ev2 = create_event(person2, :name => 'two event', :categories => [@category]) + + get :assets, :asset => 'events' + + assert_includes assigns(:results)[:events], ev1 + assert_includes assigns(:results)[:events], ev2 + end + + # 'assets' inside a category + should 'list events in a specific category' do + person = create_user('testuser').person + + # in category + ev1 = create_event(person, :name => 'one event', :categories => [@category]) + ev2 = create_event(person, :name => 'other event', :categories => [@category]) + + # not in category + ev3 = create_event(person, :name => 'another event') + + get :assets, :asset => 'events', :category_path => ['my-category'] + + assert_includes assigns(:results)[:events], ev1 + assert_includes assigns(:results)[:events], ev2 + assert_not_includes assigns(:results)[:events], ev3 + end + + ################################################################## + ################################################################## + + def create_event(profile, options) + ev = Event.new({ :name => 'some event', :start_date => Date.new(2008,1,1) }.merge(options)) + ev.profile = profile + ev.save! + ev + end end diff --git a/test/unit/event_test.rb b/test/unit/event_test.rb index c50bee8..30332a3 100644 --- a/test/unit/event_test.rb +++ b/test/unit/event_test.rb @@ -24,6 +24,11 @@ class EventTest < ActiveSupport::TestCase assert_equal 'http://some.nice.site/', e.link end + should 'have an address' do + e = Event.new(:address => 'South Noosfero street, 88') + assert_equal 'South Noosfero street, 88', e.address + end + should 'have a start date' do e = Event.new e.start_date = Date.today -- libgit2 0.21.2