From 61452996bb4e0876fddc4a994207ded38157bc29 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Fri, 6 Jun 2008 21:31:04 +0000 Subject: [PATCH] ActionItem410: putting back several listings --- app/controllers/public/search_controller.rb | 74 +++++++++++++++++++++++++++++++++++++++++--------------------------------- app/helpers/dates_helper.rb | 24 ++++++------------------ app/views/search/_directory.rhtml | 2 +- app/views/search/_display_results.rhtml | 16 +++++++++------- app/views/search/_search_form.rhtml | 4 ++++ app/views/search/articles.rhtml | 1 + app/views/search/communities.rhtml | 1 + app/views/search/enterprises.rhtml | 1 + app/views/search/events.rhtml | 7 ++++++- app/views/search/people.rhtml | 8 +++----- public/stylesheets/search.css | 6 +++++- test/unit/dates_helper_test.rb | 12 ++++++++++++ 12 files changed, 90 insertions(+), 66 deletions(-) create mode 120000 app/views/search/articles.rhtml create mode 120000 app/views/search/communities.rhtml create mode 120000 app/views/search/enterprises.rhtml diff --git a/app/controllers/public/search_controller.rb b/app/controllers/public/search_controller.rb index b1880a8..ab1d5a9 100644 --- a/app/controllers/public/search_controller.rb +++ b/app/controllers/public/search_controller.rb @@ -42,6 +42,46 @@ class SearchController < ApplicationController end end + def events + @events = @results[:events] + @calendar = Event.date_range(params[:year], params[:month]).map do |date| + [ + # the day itself + date, + # list of events of that day + @events.select do |event| + event.date_range.include?(date) + end, + # is this date in the current month? + true + ] + end + + # pad with days before + while @calendar.first.first.wday != 0 + @calendar.unshift([@calendar.first.first - 1.day, [], false]) + end + + # pad with days after (until Saturday) + while @calendar.last.first.wday != 6 + @calendar << [@calendar.last.first + 1.day, [], false] + end + + end + + def people + #nothing, just to enable + end + def enterprises + #nothing, just to enable + end + def communities + #nothing, just to enable + end + def articles + #nothins, just to enable + end + public include SearchHelper @@ -87,6 +127,7 @@ class SearchController < ApplicationController if @results.keys.size == 1 specific_action = @results.keys.first if respond_to?(specific_action) + @asset_name = gettext(@names[@results.keys.first]) send(specific_action) render :action => specific_action return @@ -98,37 +139,6 @@ class SearchController < ApplicationController alias :assets :index - def events - @events = @results[:events] - @calendar = Event.date_range(params[:year], params[:month]).map do |date| - [ - # the day itself - date, - # list of events of that day - @events.select do |event| - event.date_range.include?(date) - end, - # is this date in the current month? - true - ] - end - - # pad with days before - while @calendar.first.first.wday != 0 - @calendar.unshift([@calendar.first.first - 1.day, [], false]) - end - - # pad with days after (until Saturday) - while @calendar.last.first.wday != 6 - @calendar << [@calendar.last.first + 1.day, [], false] - end - - end - - def people - #nothing, just to enable - end - ####################################################### # view the summary of one category @@ -152,8 +162,6 @@ class SearchController < ApplicationController def directory @results = { @asset => @finder.find_by_initial(@asset, params[:initial]) } - - # FIXME remove this duplication with assets action @asset_name = gettext(SEARCH_IN.find { |entry| entry.first == @asset }[1]) @names = { @asset => @asset_name } diff --git a/app/helpers/dates_helper.rb b/app/helpers/dates_helper.rb index 5824b05..9cd6625 100644 --- a/app/helpers/dates_helper.rb +++ b/app/helpers/dates_helper.rb @@ -62,28 +62,16 @@ module DatesHelper end def link_to_previous_month(year, month) - year = year.to_i - month = month.to_i - if month == 1 - year -= 1 - month = 12 - else - month -= 1 - end + date = (year.blank? || month.blank?) ? Date.today : Date.new(year.to_i, month.to_i, 1) + previous_month_date = date - 1.month - link_to '← ' + show_month(year, month), :year => year, :month => month + link_to '← ' + show_month(previous_month_date.year, previous_month_date.month), :year => previous_month_date.year, :month => previous_month_date.month end def link_to_next_month(year, month) - year = year.to_i - month = month.to_i - if month == 12 - year += 1 - month = 1 - else - month += 1 - end + date = (year.blank? || month.blank?) ? Date.today : Date.new(year.to_i, month.to_i, 1) + next_month_date = date + 1.month - link_to show_month(year, month) + ' →', :year => year, :month => month + link_to show_month(next_month_date.year, next_month_date.month) + ' →', :year => next_month_date.year, :month => next_month_date.month end end diff --git a/app/views/search/_directory.rhtml b/app/views/search/_directory.rhtml index 6af2623..4ba29ad 100644 --- a/app/views/search/_directory.rhtml +++ b/app/views/search/_directory.rhtml @@ -1,6 +1,6 @@
<%= link_to_unless_current(_('Recent'), :action => 'index') %>   - <%= (?a..?z).map { |initial| link_to_unless_current(('' << initial).upcase, :action => 'directory', :initial => ('' << initial)) }.join('   ') %> + <%= (?a..?z).map { |initial| link_to_unless_current(('' << initial).upcase, :action => 'directory', :asset => @asset, :initial => ('' << initial)) }.join('   ') %>

diff --git a/app/views/search/_display_results.rhtml b/app/views/search/_display_results.rhtml index 043375b..6691b6f 100644 --- a/app/views/search/_display_results.rhtml +++ b/app/views/search/_display_results.rhtml @@ -12,12 +12,12 @@ <% if !results.nil? and !results.empty? %>
<% if @controller.action_name != 'assets' %> -

- <%= @names[name] %> - <% if @results.size != 1 %> - <%= link_to _('(see more ...)'), params.merge(:action => 'index', :find_in => [ name ]) %> - <% end %> -

+ <% if @results.size != 1 %> +

+ <%= @names[name] %> + <%= link_to _('(more ...)'), params.merge(:action => 'index', :find_in => [ name ]) %> +

+ <% end %> <% end %> <% partial = partial_for_class results.first.class %>
@@ -33,7 +33,9 @@ <% else %>
<% if @controller.action_name != 'assets' %> -

<%= @names[name] %>

+ <% if @results.size != 1 %> +

<%= @names[name] %>

+ <% end %> <% end %>
<%= _('None') %>
diff --git a/app/views/search/_search_form.rhtml b/app/views/search/_search_form.rhtml index f68f27a..20381c5 100644 --- a/app/views/search/_search_form.rhtml +++ b/app/views/search/_search_form.rhtml @@ -1,3 +1,5 @@ +
+ <% simple_search = false unless defined? simple_search %> <% form_tag( { :action => 'index', :category_path => ( @category ? @category.explode_path : [] ) }, @@ -53,3 +55,5 @@ <% end; end %> <% end %> + +
diff --git a/app/views/search/articles.rhtml b/app/views/search/articles.rhtml new file mode 120000 index 0000000..aba8524 --- /dev/null +++ b/app/views/search/articles.rhtml @@ -0,0 +1 @@ +people.rhtml \ No newline at end of file diff --git a/app/views/search/communities.rhtml b/app/views/search/communities.rhtml new file mode 120000 index 0000000..aba8524 --- /dev/null +++ b/app/views/search/communities.rhtml @@ -0,0 +1 @@ +people.rhtml \ No newline at end of file diff --git a/app/views/search/enterprises.rhtml b/app/views/search/enterprises.rhtml new file mode 120000 index 0000000..aba8524 --- /dev/null +++ b/app/views/search/enterprises.rhtml @@ -0,0 +1 @@ +people.rhtml \ No newline at end of file diff --git a/app/views/search/events.rhtml b/app/views/search/events.rhtml index ffc5d15..4383ba2 100644 --- a/app/views/search/events.rhtml +++ b/app/views/search/events.rhtml @@ -1,4 +1,9 @@ -

<%= show_month(params[:year], params[:month]) %>

+

+ <% if @category %> + <%= @category.name %>: + <% end %> + <%= show_month(params[:year], params[:month]) %> +

<%= link_to_previous_month(params[:year], params[:month]) %> diff --git a/app/views/search/people.rhtml b/app/views/search/people.rhtml index 3e977a7..aaa97ff 100644 --- a/app/views/search/people.rhtml +++ b/app/views/search/people.rhtml @@ -1,17 +1,15 @@ <% if @query.blank? %> -

<%= _('People') %>

+

<%= @asset_name %>

<%= render :partial => 'directory' %> <% else %> -

<%= h(@category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query)) %>

+

<%= @asset_name %>: <%= h(@category ? (_('Search results for "%{query}" in "%{category}"') % { :query => @query, :category => @category.name}) : (_('Search results for "%s"') % @query)) %>

<%= link_to _('Browse by name'), :action => 'index', :asset => 'people' %>
<% end %> -
- <%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> -
+<%= render :partial => 'search_form', :locals => { :form_title => @query.blank? ? _('Search') : _("Refine your search"), :simple_search => true } %> <%= render :partial => 'display_results' %> diff --git a/public/stylesheets/search.css b/public/stylesheets/search.css index ffa7f5c..0d44717 100644 --- a/public/stylesheets/search.css +++ b/public/stylesheets/search.css @@ -24,7 +24,7 @@ font-size: 16px; } -#search-popup .search-field { +#search-popup .search-field, .search-form { text-align: center; } @@ -52,6 +52,10 @@ padding: 0px 5px; } +.search-options { + text-align: left; +} + .search-options li { float: left; width: 33%; diff --git a/test/unit/dates_helper_test.rb b/test/unit/dates_helper_test.rb index 5947cc9..b83958e 100644 --- a/test/unit/dates_helper_test.rb +++ b/test/unit/dates_helper_test.rb @@ -58,4 +58,16 @@ class DatesHelperTest < Test::Unit::TestCase link_to_next_month('2008', '12') end + should 'get current date when year and month are not informed for next month' do + Date.expects(:today).returns(Date.new(2008,1,1)) + expects(:link_to).with('February 2008 →', { :year => 2008, :month => 2}) + link_to_next_month(nil, nil) + end + + should 'get current date when year and month are not informed for previous month' do + Date.expects(:today).returns(Date.new(2008,1,1)) + expects(:link_to).with('← December 2007', { :year => 2007, :month => 12}) + link_to_previous_month(nil, nil) + end + end -- libgit2 0.21.2