Commit 61452996bb4e0876fddc4a994207ded38157bc29

Authored by AntonioTerceiro
1 parent da85080a

ActionItem410: putting back several listings


git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1896 3f533792-8f58-4932-b0fe-aaf55b0a4547
app/controllers/public/search_controller.rb
... ... @@ -42,6 +42,46 @@ class SearchController < ApplicationController
42 42 end
43 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 85 public
46 86  
47 87 include SearchHelper
... ... @@ -87,6 +127,7 @@ class SearchController &lt; ApplicationController
87 127 if @results.keys.size == 1
88 128 specific_action = @results.keys.first
89 129 if respond_to?(specific_action)
  130 + @asset_name = gettext(@names[@results.keys.first])
90 131 send(specific_action)
91 132 render :action => specific_action
92 133 return
... ... @@ -98,37 +139,6 @@ class SearchController &lt; ApplicationController
98 139  
99 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 144 # view the summary of one category
... ... @@ -152,8 +162,6 @@ class SearchController &lt; ApplicationController
152 162  
153 163 def directory
154 164 @results = { @asset => @finder.find_by_initial(@asset, params[:initial]) }
155   -
156   - # FIXME remove this duplication with assets action
157 165 @asset_name = gettext(SEARCH_IN.find { |entry| entry.first == @asset }[1])
158 166 @names = { @asset => @asset_name }
159 167  
... ...
app/helpers/dates_helper.rb
... ... @@ -62,28 +62,16 @@ module DatesHelper
62 62 end
63 63  
64 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 '&larr; ' + show_month(year, month), :year => year, :month => month
  68 + link_to '&larr; ' + show_month(previous_month_date.year, previous_month_date.month), :year => previous_month_date.year, :month => previous_month_date.month
75 69 end
76 70  
77 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) + ' &rarr;', :year => year, :month => month
  75 + link_to show_month(next_month_date.year, next_month_date.month) + ' &rarr;', :year => next_month_date.year, :month => next_month_date.month
88 76 end
89 77 end
... ...
app/views/search/_directory.rhtml
1 1 <div style='text-align: center'>
2 2 <%= link_to_unless_current(_('Recent'), :action => 'index') %>
3 3 &nbsp;
4   - <%= (?a..?z).map { |initial| link_to_unless_current(('' << initial).upcase, :action => 'directory', :initial => ('' << initial)) }.join(' &nbsp; ') %>
  4 + <%= (?a..?z).map { |initial| link_to_unless_current(('' << initial).upcase, :action => 'directory', :asset => @asset, :initial => ('' << initial)) }.join(' &nbsp; ') %>
5 5 </div>
6 6 <br style='clear:both'/>
... ...
app/views/search/_display_results.rhtml
... ... @@ -12,12 +12,12 @@
12 12 <% if !results.nil? and !results.empty? %>
13 13 <div class="search-results-<%= name %> search-results-box <%= pos2 %> <%= 'col%s_of3' % pos3.to_s %>">
14 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 21 <% end %>
22 22 <% partial = partial_for_class results.first.class %>
23 23 <div class="search-results-innerbox search-results-type-<%= partial %> <%= 'common-profile-list-block' if partial == 'profile' %>">
... ... @@ -33,7 +33,9 @@
33 33 <% else %>
34 34 <div class="search-results-<%= name %> search-results-empty search-results-box <%= pos2 %> <%= 'col%s_of3' % pos3.to_s %>">
35 35 <% if @controller.action_name != 'assets' %>
36   - <h3><%= @names[name] %></h3>
  36 + <% if @results.size != 1 %>
  37 + <h3><%= @names[name] %></h3>
  38 + <% end %>
37 39 <% end %>
38 40 <div class="search-results-innerbox search-results-type-empty">
39 41 <div> <%= _('None') %> </div>
... ...
app/views/search/_search_form.rhtml
  1 +<div class='search-form'>
  2 +
1 3 <% simple_search = false unless defined? simple_search %>
2 4  
3 5 <% form_tag( { :action => 'index', :category_path => ( @category ? @category.explode_path : [] ) },
... ... @@ -53,3 +55,5 @@
53 55 <% end; end %>
54 56  
55 57 <% end %>
  58 +
  59 +</div> <!-- id="search-form" -->
... ...
app/views/search/articles.rhtml 0 → 120000
... ... @@ -0,0 +1 @@
  1 +people.rhtml
0 2 \ No newline at end of file
... ...
app/views/search/communities.rhtml 0 → 120000
... ... @@ -0,0 +1 @@
  1 +people.rhtml
0 2 \ No newline at end of file
... ...
app/views/search/enterprises.rhtml 0 → 120000
... ... @@ -0,0 +1 @@
  1 +people.rhtml
0 2 \ No newline at end of file
... ...
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 8 <div style='text-align: center; margin: 1em;'>
4 9 <%= link_to_previous_month(params[:year], params[:month]) %>
... ...
app/views/search/people.rhtml
1 1 <% if @query.blank? %>
2   - <h1><%= _('People') %></h1>
  2 + <h1><%= @asset_name %></h1>
3 3 <%= render :partial => 'directory' %>
4 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 6 <div style='text-align: center'>
7 7 <%= link_to _('Browse by name'), :action => 'index', :asset => 'people' %>
8 8 </div>
9 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 14 <%= render :partial => 'display_results' %>
17 15  
... ...
public/stylesheets/search.css
... ... @@ -24,7 +24,7 @@
24 24 font-size: 16px;
25 25 }
26 26  
27   -#search-popup .search-field {
  27 +#search-popup .search-field, .search-form {
28 28 text-align: center;
29 29 }
30 30  
... ... @@ -52,6 +52,10 @@
52 52 padding: 0px 5px;
53 53 }
54 54  
  55 +.search-options {
  56 + text-align: left;
  57 +}
  58 +
55 59 .search-options li {
56 60 float: left;
57 61 width: 33%;
... ...
test/unit/dates_helper_test.rb
... ... @@ -58,4 +58,16 @@ class DatesHelperTest &lt; Test::Unit::TestCase
58 58 link_to_next_month('2008', '12')
59 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 &rarr;', { :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('&larr; December 2007', { :year => 2007, :month => 12})
  70 + link_to_previous_month(nil, nil)
  71 + end
  72 +
61 73 end
... ...