Commit 61452996bb4e0876fddc4a994207ded38157bc29
1 parent
da85080a
Exists in
master
and in
29 other branches
ActionItem410: putting back several listings
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1896 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
12 changed files
with
90 additions
and
66 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -42,6 +42,46 @@ class SearchController < ApplicationController | @@ -42,6 +42,46 @@ class SearchController < ApplicationController | ||
42 | end | 42 | end |
43 | end | 43 | end |
44 | 44 | ||
45 | + def events | ||
46 | + @events = @results[:events] | ||
47 | + @calendar = Event.date_range(params[:year], params[:month]).map do |date| | ||
48 | + [ | ||
49 | + # the day itself | ||
50 | + date, | ||
51 | + # list of events of that day | ||
52 | + @events.select do |event| | ||
53 | + event.date_range.include?(date) | ||
54 | + end, | ||
55 | + # is this date in the current month? | ||
56 | + true | ||
57 | + ] | ||
58 | + end | ||
59 | + | ||
60 | + # pad with days before | ||
61 | + while @calendar.first.first.wday != 0 | ||
62 | + @calendar.unshift([@calendar.first.first - 1.day, [], false]) | ||
63 | + end | ||
64 | + | ||
65 | + # pad with days after (until Saturday) | ||
66 | + while @calendar.last.first.wday != 6 | ||
67 | + @calendar << [@calendar.last.first + 1.day, [], false] | ||
68 | + end | ||
69 | + | ||
70 | + end | ||
71 | + | ||
72 | + def people | ||
73 | + #nothing, just to enable | ||
74 | + end | ||
75 | + def enterprises | ||
76 | + #nothing, just to enable | ||
77 | + end | ||
78 | + def communities | ||
79 | + #nothing, just to enable | ||
80 | + end | ||
81 | + def articles | ||
82 | + #nothins, just to enable | ||
83 | + end | ||
84 | + | ||
45 | public | 85 | public |
46 | 86 | ||
47 | include SearchHelper | 87 | include SearchHelper |
@@ -87,6 +127,7 @@ class SearchController < ApplicationController | @@ -87,6 +127,7 @@ class SearchController < ApplicationController | ||
87 | if @results.keys.size == 1 | 127 | if @results.keys.size == 1 |
88 | specific_action = @results.keys.first | 128 | specific_action = @results.keys.first |
89 | if respond_to?(specific_action) | 129 | if respond_to?(specific_action) |
130 | + @asset_name = gettext(@names[@results.keys.first]) | ||
90 | send(specific_action) | 131 | send(specific_action) |
91 | render :action => specific_action | 132 | render :action => specific_action |
92 | return | 133 | return |
@@ -98,37 +139,6 @@ class SearchController < ApplicationController | @@ -98,37 +139,6 @@ class SearchController < ApplicationController | ||
98 | 139 | ||
99 | alias :assets :index | 140 | alias :assets :index |
100 | 141 | ||
101 | - def events | ||
102 | - @events = @results[:events] | ||
103 | - @calendar = Event.date_range(params[:year], params[:month]).map do |date| | ||
104 | - [ | ||
105 | - # the day itself | ||
106 | - date, | ||
107 | - # list of events of that day | ||
108 | - @events.select do |event| | ||
109 | - event.date_range.include?(date) | ||
110 | - end, | ||
111 | - # is this date in the current month? | ||
112 | - true | ||
113 | - ] | ||
114 | - end | ||
115 | - | ||
116 | - # pad with days before | ||
117 | - while @calendar.first.first.wday != 0 | ||
118 | - @calendar.unshift([@calendar.first.first - 1.day, [], false]) | ||
119 | - end | ||
120 | - | ||
121 | - # pad with days after (until Saturday) | ||
122 | - while @calendar.last.first.wday != 6 | ||
123 | - @calendar << [@calendar.last.first + 1.day, [], false] | ||
124 | - end | ||
125 | - | ||
126 | - end | ||
127 | - | ||
128 | - def people | ||
129 | - #nothing, just to enable | ||
130 | - end | ||
131 | - | ||
132 | ####################################################### | 142 | ####################################################### |
133 | 143 | ||
134 | # view the summary of one category | 144 | # view the summary of one category |
@@ -152,8 +162,6 @@ class SearchController < ApplicationController | @@ -152,8 +162,6 @@ class SearchController < ApplicationController | ||
152 | 162 | ||
153 | def directory | 163 | def directory |
154 | @results = { @asset => @finder.find_by_initial(@asset, params[:initial]) } | 164 | @results = { @asset => @finder.find_by_initial(@asset, params[:initial]) } |
155 | - | ||
156 | - # FIXME remove this duplication with assets action | ||
157 | @asset_name = gettext(SEARCH_IN.find { |entry| entry.first == @asset }[1]) | 165 | @asset_name = gettext(SEARCH_IN.find { |entry| entry.first == @asset }[1]) |
158 | @names = { @asset => @asset_name } | 166 | @names = { @asset => @asset_name } |
159 | 167 |
app/helpers/dates_helper.rb
@@ -62,28 +62,16 @@ module DatesHelper | @@ -62,28 +62,16 @@ module DatesHelper | ||
62 | end | 62 | end |
63 | 63 | ||
64 | def link_to_previous_month(year, month) | 64 | def link_to_previous_month(year, month) |
65 | - year = year.to_i | ||
66 | - month = month.to_i | ||
67 | - if month == 1 | ||
68 | - year -= 1 | ||
69 | - month = 12 | ||
70 | - else | ||
71 | - month -= 1 | ||
72 | - end | 65 | + date = (year.blank? || month.blank?) ? Date.today : Date.new(year.to_i, month.to_i, 1) |
66 | + previous_month_date = date - 1.month | ||
73 | 67 | ||
74 | - link_to '← ' + show_month(year, month), :year => year, :month => month | 68 | + link_to '← ' + show_month(previous_month_date.year, previous_month_date.month), :year => previous_month_date.year, :month => previous_month_date.month |
75 | end | 69 | end |
76 | 70 | ||
77 | def link_to_next_month(year, month) | 71 | def link_to_next_month(year, month) |
78 | - year = year.to_i | ||
79 | - month = month.to_i | ||
80 | - if month == 12 | ||
81 | - year += 1 | ||
82 | - month = 1 | ||
83 | - else | ||
84 | - month += 1 | ||
85 | - end | 72 | + date = (year.blank? || month.blank?) ? Date.today : Date.new(year.to_i, month.to_i, 1) |
73 | + next_month_date = date + 1.month | ||
86 | 74 | ||
87 | - link_to show_month(year, month) + ' →', :year => year, :month => month | 75 | + link_to show_month(next_month_date.year, next_month_date.month) + ' →', :year => next_month_date.year, :month => next_month_date.month |
88 | end | 76 | end |
89 | end | 77 | end |
app/views/search/_directory.rhtml
1 | <div style='text-align: center'> | 1 | <div style='text-align: center'> |
2 | <%= link_to_unless_current(_('Recent'), :action => 'index') %> | 2 | <%= link_to_unless_current(_('Recent'), :action => 'index') %> |
3 | | 3 | |
4 | - <%= (?a..?z).map { |initial| link_to_unless_current(('' << initial).upcase, :action => 'directory', :initial => ('' << initial)) }.join(' ') %> | 4 | + <%= (?a..?z).map { |initial| link_to_unless_current(('' << initial).upcase, :action => 'directory', :asset => @asset, :initial => ('' << initial)) }.join(' ') %> |
5 | </div> | 5 | </div> |
6 | <br style='clear:both'/> | 6 | <br style='clear:both'/> |
app/views/search/_display_results.rhtml
@@ -12,12 +12,12 @@ | @@ -12,12 +12,12 @@ | ||
12 | <% if !results.nil? and !results.empty? %> | 12 | <% if !results.nil? and !results.empty? %> |
13 | <div class="search-results-<%= name %> search-results-box <%= pos2 %> <%= 'col%s_of3' % pos3.to_s %>"> | 13 | <div class="search-results-<%= name %> search-results-box <%= pos2 %> <%= 'col%s_of3' % pos3.to_s %>"> |
14 | <% if @controller.action_name != 'assets' %> | 14 | <% if @controller.action_name != 'assets' %> |
15 | - <h3> | ||
16 | - <%= @names[name] %> | ||
17 | - <% if @results.size != 1 %> | ||
18 | - <%= link_to _('(see more ...)'), params.merge(:action => 'index', :find_in => [ name ]) %> | ||
19 | - <% end %> | ||
20 | - </h3> | 15 | + <% if @results.size != 1 %> |
16 | + <h3> | ||
17 | + <%= @names[name] %> | ||
18 | + <%= link_to _('(more ...)'), params.merge(:action => 'index', :find_in => [ name ]) %> | ||
19 | + </h3> | ||
20 | + <% end %> | ||
21 | <% end %> | 21 | <% end %> |
22 | <% partial = partial_for_class results.first.class %> | 22 | <% partial = partial_for_class results.first.class %> |
23 | <div class="search-results-innerbox search-results-type-<%= partial %> <%= 'common-profile-list-block' if partial == 'profile' %>"> | 23 | <div class="search-results-innerbox search-results-type-<%= partial %> <%= 'common-profile-list-block' if partial == 'profile' %>"> |
@@ -33,7 +33,9 @@ | @@ -33,7 +33,9 @@ | ||
33 | <% else %> | 33 | <% else %> |
34 | <div class="search-results-<%= name %> search-results-empty search-results-box <%= pos2 %> <%= 'col%s_of3' % pos3.to_s %>"> | 34 | <div class="search-results-<%= name %> search-results-empty search-results-box <%= pos2 %> <%= 'col%s_of3' % pos3.to_s %>"> |
35 | <% if @controller.action_name != 'assets' %> | 35 | <% if @controller.action_name != 'assets' %> |
36 | - <h3><%= @names[name] %></h3> | 36 | + <% if @results.size != 1 %> |
37 | + <h3><%= @names[name] %></h3> | ||
38 | + <% end %> | ||
37 | <% end %> | 39 | <% end %> |
38 | <div class="search-results-innerbox search-results-type-empty"> | 40 | <div class="search-results-innerbox search-results-type-empty"> |
39 | <div> <%= _('None') %> </div> | 41 | <div> <%= _('None') %> </div> |
app/views/search/_search_form.rhtml
1 | +<div class='search-form'> | ||
2 | + | ||
1 | <% simple_search = false unless defined? simple_search %> | 3 | <% simple_search = false unless defined? simple_search %> |
2 | 4 | ||
3 | <% form_tag( { :action => 'index', :category_path => ( @category ? @category.explode_path : [] ) }, | 5 | <% form_tag( { :action => 'index', :category_path => ( @category ? @category.explode_path : [] ) }, |
@@ -53,3 +55,5 @@ | @@ -53,3 +55,5 @@ | ||
53 | <% end; end %> | 55 | <% end; end %> |
54 | 56 | ||
55 | <% end %> | 57 | <% end %> |
58 | + | ||
59 | +</div> <!-- id="search-form" --> |
app/views/search/events.rhtml
1 | -<h1><%= show_month(params[:year], params[:month]) %></h1> | 1 | +<h1> |
2 | + <% if @category %> | ||
3 | + <%= @category.name %>: | ||
4 | + <% end %> | ||
5 | + <%= show_month(params[:year], params[:month]) %> | ||
6 | +</h1> | ||
2 | 7 | ||
3 | <div style='text-align: center; margin: 1em;'> | 8 | <div style='text-align: center; margin: 1em;'> |
4 | <%= link_to_previous_month(params[:year], params[:month]) %> | 9 | <%= link_to_previous_month(params[:year], params[:month]) %> |
app/views/search/people.rhtml
1 | <% if @query.blank? %> | 1 | <% if @query.blank? %> |
2 | - <h1><%= _('People') %></h1> | 2 | + <h1><%= @asset_name %></h1> |
3 | <%= render :partial => 'directory' %> | 3 | <%= render :partial => 'directory' %> |
4 | <% else %> | 4 | <% else %> |
5 | - <h1> <%= h(@category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query)) %> </h1> | 5 | + <h1> <%= @asset_name %>: <%= h(@category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query)) %> </h1> |
6 | <div style='text-align: center'> | 6 | <div style='text-align: center'> |
7 | <%= link_to _('Browse by name'), :action => 'index', :asset => 'people' %> | 7 | <%= link_to _('Browse by name'), :action => 'index', :asset => 'people' %> |
8 | </div> | 8 | </div> |
9 | <% end %> | 9 | <% end %> |
10 | 10 | ||
11 | 11 | ||
12 | -<div style='text-align: center'> | ||
13 | - <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> | ||
14 | -</div> | 12 | +<%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> |
15 | 13 | ||
16 | <%= render :partial => 'display_results' %> | 14 | <%= render :partial => 'display_results' %> |
17 | 15 |
public/stylesheets/search.css
@@ -24,7 +24,7 @@ | @@ -24,7 +24,7 @@ | ||
24 | font-size: 16px; | 24 | font-size: 16px; |
25 | } | 25 | } |
26 | 26 | ||
27 | -#search-popup .search-field { | 27 | +#search-popup .search-field, .search-form { |
28 | text-align: center; | 28 | text-align: center; |
29 | } | 29 | } |
30 | 30 | ||
@@ -52,6 +52,10 @@ | @@ -52,6 +52,10 @@ | ||
52 | padding: 0px 5px; | 52 | padding: 0px 5px; |
53 | } | 53 | } |
54 | 54 | ||
55 | +.search-options { | ||
56 | + text-align: left; | ||
57 | +} | ||
58 | + | ||
55 | .search-options li { | 59 | .search-options li { |
56 | float: left; | 60 | float: left; |
57 | width: 33%; | 61 | width: 33%; |
test/unit/dates_helper_test.rb
@@ -58,4 +58,16 @@ class DatesHelperTest < Test::Unit::TestCase | @@ -58,4 +58,16 @@ class DatesHelperTest < Test::Unit::TestCase | ||
58 | link_to_next_month('2008', '12') | 58 | link_to_next_month('2008', '12') |
59 | end | 59 | end |
60 | 60 | ||
61 | + should 'get current date when year and month are not informed for next month' do | ||
62 | + Date.expects(:today).returns(Date.new(2008,1,1)) | ||
63 | + expects(:link_to).with('February 2008 →', { :year => 2008, :month => 2}) | ||
64 | + link_to_next_month(nil, nil) | ||
65 | + end | ||
66 | + | ||
67 | + should 'get current date when year and month are not informed for previous month' do | ||
68 | + Date.expects(:today).returns(Date.new(2008,1,1)) | ||
69 | + expects(:link_to).with('← December 2007', { :year => 2007, :month => 12}) | ||
70 | + link_to_previous_month(nil, nil) | ||
71 | + end | ||
72 | + | ||
61 | end | 73 | end |