Skip to content

Commit

Permalink
Preliminary implementation of dashboard-level search
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesu committed Sep 23, 2008
1 parent ea46829 commit 3965c6c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 4 deletions.
25 changes: 25 additions & 0 deletions app/controllers/dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,29 @@ def my_tasks

@content_for_sidebar = 'my_tasks_sidebar'
end

def search
@current_search = params[:search_id]

unless @current_search.nil?
@last_search = @current_search

current_page = params[:page].to_i
current_page = 1 unless current_page > 0

@search_results, @total_search_results = Project.search(@last_search, @logged_user, {:page => current_page, :per_page => AppConfig.search_results_per_page})

@tag_names, @total_search_tags = Project.search(@last_search, @logged_user, {}, true)
@pagination = []
@start_search_results = AppConfig.search_results_per_page * (current_page-1)
(@total_search_results.to_f / AppConfig.search_results_per_page).ceil.times {|page| @pagination << page+1}
else
@last_search = :search_box_default.l
@search_results = []

@tag_names = Tag.find(:all, :conditions => (!@logged_user.member_of_owner? ? ['is_private = ?', false] : nil))
end

@content_for_sidebar = 'project/search_sidebar'
end
end
2 changes: 1 addition & 1 deletion app/controllers/project_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def search
@start_search_results = AppConfig.search_results_per_page * (current_page-1)
(@total_search_results.to_f / AppConfig.search_results_per_page).ceil.times {|page| @pagination << page+1}
else
@last_search = 'Search...'
@last_search = :search_box_default.l
@search_results = []

@tag_names = Tag.list_by_project(@project, !@logged_user.member_of_owner?, false)
Expand Down
18 changes: 18 additions & 0 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,24 @@ def search(query, is_private, options={}, tag_search=false)
return results, results.total_hits
end

def self.search(query, user, options={}, tag_search=false)
results = []
is_private = user.member_of_owner?
return results, 0 unless AppConfig.search_enabled

project_ids = user.active_projects.collect { |project| project.id }.join('|')
real_query = is_private ?
"is_private:false project_id:#{project_ids} #{query}" :
"project_id:\"#{project_ids}\" #{query}"

real_opts = { }.merge(options)
real_opts[:multi] = FERRETABLE_MODELS[1...FERRETABLE_MODELS.length].map { |model_name| Kernel.const_get(model_name) } unless tag_search

results = Kernel.const_get(FERRETABLE_MODELS[tag_search ? 0 : 1]).find_by_contents(real_query, real_opts)

return results, results.total_hits
end

# Core Permissions

def self.can_be_created_by(user)
Expand Down
37 changes: 37 additions & 0 deletions app/views/dashboard/search.rhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%
@page_title = :search_results.l

@tabbed_navigation_items = dashboard_tabbed_navigation(:overview)
@bread_crumbs = dashboard_crumbs(:search_results)

@page_actions = []

@additional_stylesheets = ['project/search_results.css']
%>
<div id="searchForm">
<%= form_tag :action => 'search' %>
<%= text_field_tag 'search_id', @last_search %>
<button class="submit" type="submit"><%= :search.l %></button>
</form>
</div>

<% if !@search_results.empty? %>
<p><%= :search_displaying_results_for.l_with_args({:start => @start_search_results,
:finish => @start_search_results+@search_results.length,
:total => @total_search_results,
:search => h(@current_search)}) %></p>
<ul>
<% @search_results.each do |obj| -%>
<li><%= :search_dashboard.l_with_args(:type => obj.class.to_s.to_sym.l,
:name => link_to(obj.object_name, obj.object_url),
:project => link_to(obj.project.object_name, obj.project.object_url)) %></li>
<% end %>
</ul>

<div id="searchPagination">
<%= pagination_links "/project/#{@active_project.id}/search?search_id=#{CGI::escape(@last_search)}&", @pagination unless @pagination.length <= 1 %>
</div>

<% elsif !@current_search.nil? %>
<p><%= :search_no_matching_objects.l_with_args({:search => h(@current_search)}) %></p>
<% end %>
20 changes: 19 additions & 1 deletion app/views/layouts/dashboard.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,25 @@
<div id="crumbsWrapper">
<div id="crumbsBlock">
<%= render :partial => 'layouts/crumbs' if not @bread_crumbs.nil? %>
</div>

<% if AppConfig.search_enabled %>
<div id="searchBox">
<%= form_tag :controller => 'dashboard', :action => 'search' %>
<div>
<%
@search_field_default_value = :search_box_default.l
@last_search ||= @search_field_default_value
@search_field_attrs = {
:onfocus => "if (event.target.value == '#{@search_field_default_value}') event.target.value=''",
:onblur => "if (event.target.value == '#{@search_field_default_value}') event.target.value=''"
}
%>
<%= text_field_tag 'search_id', (h @last_search), @search_field_attrs %><button type="submit"><%= :go.l %></button>
</div>
</form>
</div>
<% end %>
</div>
</div>

<!-- content wrapper -->
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/project_website.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
:onblur => "if (event.target.value == '#{@search_field_default_value}') event.target.value=''"
}
%>
<%= text_field_tag 'search_id', (h @last_search), @search_field_attrs %><button type="submit"><%= "Go" %></button>
<%= text_field_tag 'search_id', (h @last_search), @search_field_attrs %><button type="submit"><%= :go.l %></button>
</div>
</form>
</div>
Expand Down
3 changes: 2 additions & 1 deletion app/views/project/search.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
:search => h(@current_search)}) %></p>
<ul>
<% @search_results.each do |obj| -%>
<li><%= obj.class.to_s %>: <a href="<%= obj.object_url %>"><%= h obj.object_name %></a></li>
<li><%= :search_project.l_with_args(:type => obj.class.to_s.to_sym.l,
:name => link_to(obj.object_name, obj.object_url)) %></li>
<% end %>
</ul>

Expand Down
15 changes: 15 additions & 0 deletions lang/ui/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ hint: Hint
hint_permissions_info: "Check project to give access permissions for this company. Note that you'll also need to specify access permissions for company members that you want to be able to access and manage selected projects (you can do that through the projects people page or user profiles)."
project_completed_on: "Completed on {date} by {user}"
all: All
go: Go

# Forms
success_message: Success message
Expand Down Expand Up @@ -682,6 +683,20 @@ notifier_new_account_access_login: "Then login using the username '{login}'."
notifier_new_account_credentials: "To access this account, simply visit {site} and login using the following credentials:"
author: Author


# Search models
Tag: Tag
Comment: Comment
ProjectMessage: Message
ProjectTime: Time
ProjectTask: Task
ProjectTaskList: Task list
ProjectMilestone: Milestone
ProjectFile: File
ProjectFileRevision: File revision

search_dashboard: "{type}: {name} in {project}"
search_project: "{type}: {name}"
# system

product_signature: "Powered by <a href=\"http://rubyforge.org/projects/railscollab\">RailsCollab</a>"

0 comments on commit 3965c6c

Please sign in to comment.