Commit 43a5b25562c90ee74d201847d986233e6fc9d70e
1 parent
a29cb0b0
Exists in
staging
and in
42 other branches
ActionItem26: several things to integrate events
* in the search * editing * etc git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1880 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
12 changed files
with
114 additions
and
7 deletions
Show diff stats
app/controllers/public/search_controller.rb
... | ... | @@ -54,7 +54,8 @@ class SearchController < ApplicationController |
54 | 54 | [ :enterprises, N_('Enterprises') ], |
55 | 55 | [ :people, N_('People') ], |
56 | 56 | [ :communities, N_('Communities') ], |
57 | - [ :products, N_('Products') ] | |
57 | + [ :products, N_('Products') ], | |
58 | + [ :events, N_('Events') ] | |
58 | 59 | ] |
59 | 60 | |
60 | 61 | # TODO don't hardcode like this >:-( | ... | ... |
app/helpers/assets_helper.rb
... | ... | @@ -10,6 +10,7 @@ module AssetsHelper |
10 | 10 | [ options.merge(:asset => 'enterprises'), "icon-menu-enterprise", _('Enterprises') ], |
11 | 11 | [ options.merge(:asset => 'communities'), "icon-menu-community", _('Communities') ], |
12 | 12 | [ options.merge(:asset => 'comments'), "icon-menu-comments", _('Comments') ], |
13 | + [ options.merge(:asset => 'events'), "icon-menu-events", _('Events') ], | |
13 | 14 | |
14 | 15 | ].map do |target,css_class,name| |
15 | 16 | content_tag('li', | ... | ... |
app/models/category_finder.rb
... | ... | @@ -50,7 +50,7 @@ class CategoryFinder |
50 | 50 | {: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) |
51 | 51 | when 'Product' |
52 | 52 | {: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) |
53 | - when 'Article', 'Person', 'Community', 'Enterprise' | |
53 | + when 'Article', 'Person', 'Community', 'Enterprise', 'Event' | |
54 | 54 | {:include => 'categories', :conditions => ['categories.id IN (?)', category_ids]}.merge!(options) |
55 | 55 | else |
56 | 56 | raise "unreconized class #{klass.name}" | ... | ... |
app/models/environment.rb
... | ... | @@ -218,6 +218,8 @@ class Environment < ActiveRecord::Base |
218 | 218 | self.articles.recent(limit) |
219 | 219 | end |
220 | 220 | |
221 | + has_many :events, :through => :profiles, :source => :articles, :class_name => 'Event' | |
222 | + | |
221 | 223 | # FIXME is this the better/faster way to do this? |
222 | 224 | has_many :comments, :through => :articles |
223 | 225 | ... | ... |
app/models/event.rb
... | ... | @@ -4,9 +4,7 @@ class Event < Article |
4 | 4 | |
5 | 5 | settings_items :description, :type => :string |
6 | 6 | settings_items :link, :type => :string |
7 | - | |
8 | - settings_items :start_date, :type => :date | |
9 | - settings_items :end_date, :type => :date | |
7 | + settings_items :address, :type => :string | |
10 | 8 | |
11 | 9 | validates_presence_of :title, :start_date |
12 | 10 | ... | ... |
app/views/cms/_event.rhtml
... | ... | @@ -5,8 +5,13 @@ |
5 | 5 | |
6 | 6 | <%= f.text_field('name', :size => '64') %> |
7 | 7 | |
8 | -<%= labelled_form_field(_('Description:'), text_area(:article, :description, :cols => 64)) %> | |
9 | - | |
10 | 8 | <%= labelled_form_field(_('Start date'), calendar_date_select(:article, :start_date)) %> |
11 | 9 | |
12 | 10 | <%= labelled_form_field(_('End date'), calendar_date_select(:article, :end_date)) %> |
11 | + | |
12 | +<%= labelled_form_field(_('Event website:'), text_field(:article, :link)) %> | |
13 | + | |
14 | +<%= labelled_form_field(_('Address:'), text_field(:article, :address)) %> | |
15 | + | |
16 | +<%= labelled_form_field(_('Information about the event:'), text_area(:article, :description, :cols => 64)) %> | |
17 | + | ... | ... |
... | ... | @@ -0,0 +1,22 @@ |
1 | +class AddDatesToArticles < ActiveRecord::Migration | |
2 | + | |
3 | + def self.each_table | |
4 | + [ :articles, :article_versions ].each do |table| | |
5 | + yield(table) | |
6 | + end | |
7 | + end | |
8 | + | |
9 | + def self.up | |
10 | + each_table do |table| | |
11 | + add_column table, :start_date, :type => :date | |
12 | + add_column table, :end_date, :type => :date | |
13 | + end | |
14 | + end | |
15 | + | |
16 | + def self.down | |
17 | + each_table do |table| | |
18 | + remove_column table, :start_date | |
19 | + remove_column table, :end_date | |
20 | + end | |
21 | + end | |
22 | +end | ... | ... |
public/designs/icons/default/style.css
... | ... | @@ -37,6 +37,7 @@ |
37 | 37 | .icon-menu-logout { background-image: url(exit-HC.gif) } |
38 | 38 | .icon-menu-search { background-image: url(search-HC.gif) } |
39 | 39 | .icon-menu-ed-design { background-image: url(edit-design-HC.gif) } |
40 | +.icon-menu-events { background-image: url(calendar.gif) } | |
40 | 41 | .icon-todo { background-image: url(stock_todo.png); } |
41 | 42 | |
42 | 43 | .icon-menu-articles { background-image: url(edit-HC.gif) } | ... | ... |
test/functional/search_controller_test.rb
... | ... | @@ -839,4 +839,74 @@ class SearchControllerTest < Test::Unit::TestCase |
839 | 839 | assert_not_includes assigns(:regions), r2 |
840 | 840 | assert_no_tag :tag => 'ul', :descendant => { :tag => 'li', :content => r2.name } |
841 | 841 | end |
842 | + | |
843 | + should 'search for events' do | |
844 | + person = create_user('teste').person | |
845 | + ev = create_event(person, :name => 'an event to be found') | |
846 | + | |
847 | + get 'index', :query => 'event found', :find_in => [ 'events' ] | |
848 | + | |
849 | + assert_includes assigns(:results)[:events], ev | |
850 | + end | |
851 | + | |
852 | + should 'search for events in a specific category' do | |
853 | + person = create_user('teste').person | |
854 | + | |
855 | + # in category | |
856 | + ev1 = create_event(person, :name => 'an event to be found') | |
857 | + ev1.categories << @category | |
858 | + ev1.save! | |
859 | + | |
860 | + # not in category | |
861 | + ev2 = create_event(person, :name => 'another event to be found') | |
862 | + ev2.save! | |
863 | + | |
864 | + get :index, :category_path => [ 'my-category' ], :query => 'event found', :find_in => [ 'events' ] | |
865 | + | |
866 | + assert_includes assigns(:results)[:events], ev1 | |
867 | + assert_not_includes assigns(:results)[:events], ev2 | |
868 | + end | |
869 | + | |
870 | + # 'assets' outside any category | |
871 | + should 'list events in general' do | |
872 | + person = create_user('testuser').person | |
873 | + person2 = create_user('anotheruser').person | |
874 | + | |
875 | + ev1 = create_event(person, :name => 'one event', :categories => [@category]) | |
876 | + | |
877 | + ev2 = create_event(person2, :name => 'two event', :categories => [@category]) | |
878 | + | |
879 | + get :assets, :asset => 'events' | |
880 | + | |
881 | + assert_includes assigns(:results)[:events], ev1 | |
882 | + assert_includes assigns(:results)[:events], ev2 | |
883 | + end | |
884 | + | |
885 | + # 'assets' inside a category | |
886 | + should 'list events in a specific category' do | |
887 | + person = create_user('testuser').person | |
888 | + | |
889 | + # in category | |
890 | + ev1 = create_event(person, :name => 'one event', :categories => [@category]) | |
891 | + ev2 = create_event(person, :name => 'other event', :categories => [@category]) | |
892 | + | |
893 | + # not in category | |
894 | + ev3 = create_event(person, :name => 'another event') | |
895 | + | |
896 | + get :assets, :asset => 'events', :category_path => ['my-category'] | |
897 | + | |
898 | + assert_includes assigns(:results)[:events], ev1 | |
899 | + assert_includes assigns(:results)[:events], ev2 | |
900 | + assert_not_includes assigns(:results)[:events], ev3 | |
901 | + end | |
902 | + | |
903 | + ################################################################## | |
904 | + ################################################################## | |
905 | + | |
906 | + def create_event(profile, options) | |
907 | + ev = Event.new({ :name => 'some event', :start_date => Date.new(2008,1,1) }.merge(options)) | |
908 | + ev.profile = profile | |
909 | + ev.save! | |
910 | + ev | |
911 | + end | |
842 | 912 | end | ... | ... |
test/unit/event_test.rb
... | ... | @@ -24,6 +24,11 @@ class EventTest < ActiveSupport::TestCase |
24 | 24 | assert_equal 'http://some.nice.site/', e.link |
25 | 25 | end |
26 | 26 | |
27 | + should 'have an address' do | |
28 | + e = Event.new(:address => 'South Noosfero street, 88') | |
29 | + assert_equal 'South Noosfero street, 88', e.address | |
30 | + end | |
31 | + | |
27 | 32 | should 'have a start date' do |
28 | 33 | e = Event.new |
29 | 34 | e.start_date = Date.today | ... | ... |