diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-02-27 21:03:15 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2007-02-27 21:03:15 +0000 |
commit | 75324e48592fbe141a66ba7e5dbda8553bbd2db1 (patch) | |
tree | 5193ae090dfe3ac07c6e6cd2672813f7d89eee4b /app | |
parent | 93f07c78d6bb53a4e3c71953211c8beb011155f4 (diff) | |
download | redmine-75324e48592fbe141a66ba7e5dbda8553bbd2db1.tar.gz redmine-75324e48592fbe141a66ba7e5dbda8553bbd2db1.zip |
added a simple search engine. left to do:
- full content search (only subject/titles for now)
- pagination
- results presentation improvement
git-svn-id: http://redmine.rubyforge.org/svn/trunk@279 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/projects_controller.rb | 12 | ||||
-rw-r--r-- | app/views/layouts/base.rhtml | 2 | ||||
-rw-r--r-- | app/views/projects/search.rhtml | 32 |
3 files changed, 46 insertions, 0 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ce2e39fac..ab1cb3e1b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -539,6 +539,18 @@ class ProjectsController < ApplicationController end
end
+ def search
+ @token = params[:token]
+ @scope = params[:scope] || (params[:submit] ? [] : %w(issues news documents) )
+
+ if @token and @token.length > 2
+ @results = []
+ @results += @project.issues.find(:all, :include => :author, :conditions => ["issues.subject like ?", "%#{@token}%"] ) if @scope.include? 'issues'
+ @results += @project.news.find(:all, :conditions => ["news.title like ?", "%#{@token}%"], :include => :author ) if @scope.include? 'news'
+ @results += @project.documents.find(:all, :conditions => ["title like ?", "%#{@token}%"] ) if @scope.include? 'documents'
+ end
+ end
+
private
# Find project of id params[:id]
# if not found, redirect to project list
diff --git a/app/views/layouts/base.rhtml b/app/views/layouts/base.rhtml index b359898f0..53c346dc8 100644 --- a/app/views/layouts/base.rhtml +++ b/app/views/layouts/base.rhtml @@ -93,6 +93,7 @@ <%= link_to l(:label_document_plural), {:controller => 'projects', :action => 'list_documents', :id => @project }, :class => "menuItem" %>
<%= link_to l(:label_member_plural), {:controller => 'projects', :action => 'list_members', :id => @project }, :class => "menuItem" %>
<%= link_to l(:label_attachment_plural), {:controller => 'projects', :action => 'list_files', :id => @project }, :class => "menuItem" %>
+ <%= link_to l(:label_search), {:controller => 'projects', :action => 'search', :id => @project }, :class => "menuItem" %>
<%= link_to l(:label_repository), {:controller => 'repositories', :action => 'show', :id => @project}, :class => "menuItem" if @project.repository and !@project.repository.new_record? %>
<%= link_to_if_authorized l(:label_settings), {:controller => 'projects', :action => 'settings', :id => @project }, :class => "menuItem" %>
</div>
@@ -116,6 +117,7 @@ <li><%= link_to l(:label_document_plural), :controller => 'projects', :action => 'list_documents', :id => @project %></li>
<li><%= link_to l(:label_member_plural), :controller => 'projects', :action => 'list_members', :id => @project %></li>
<li><%= link_to l(:label_attachment_plural), :controller => 'projects', :action => 'list_files', :id => @project %></li>
+ <li><%= link_to l(:label_search), :controller => 'projects', :action => 'search', :id => @project %></li>
<li><%= link_to l(:label_repository), :controller => 'repositories', :action => 'show', :id => @project if @project.repository and !@project.repository.new_record? %></li>
<li><%= link_to_if_authorized l(:label_settings), :controller => 'projects', :action => 'settings', :id => @project %></li>
</ul>
diff --git a/app/views/projects/search.rhtml b/app/views/projects/search.rhtml new file mode 100644 index 000000000..32e486fee --- /dev/null +++ b/app/views/projects/search.rhtml @@ -0,0 +1,32 @@ +<h2><%= l(:label_search) %></h2>
+
+<div class="box">
+<% form_tag({:action => 'search', :id => @project}, :method => :get) do %>
+<p><%= text_field_tag 'token', @token, :size => 30 %>
+<%= check_box_tag 'scope[]', 'issues', (@scope.include? 'issues') %> <label><%= l(:label_issue_plural) %></label>
+<%= check_box_tag 'scope[]', 'news', (@scope.include? 'news') %> <label><%= l(:label_news_plural) %></label>
+<%= check_box_tag 'scope[]', 'documents', (@scope.include? 'documents') %> <label><%= l(:label_document_plural) %></label></p>
+<%= submit_tag l(:button_submit), :name => 'submit' %>
+<% end %>
+</div>
+
+<% if @results %>
+ <h3><%= lwr(:label_result, @results.length) %></h3>
+ <ul>
+ <% @results.each do |e| %>
+ <li><p>
+ <% if e.is_a? Issue %>
+ <%= link_to "#{e.tracker.name} ##{e.id}", :controller => 'issues', :action => 'show', :id => e %>: <%= highlight(h(e.subject), @token) %><br />
+ <i><%= e.author.name %>, <%= format_time(e.created_on) %></i>
+ <% elsif e.is_a? News %>
+ <%=l(:label_news)%>: <%= link_to highlight(h(e.title), @token), :controller => 'news', :action => 'show', :id => e %><br />
+ <% unless e.summary.empty? %><%=h e.summary %><br /><% end %>
+ <i><%= e.author.name %>, <%= format_time(e.created_on) %></i>
+ <% elsif e.is_a? Document %>
+ <%=l(:label_document)%>: <%= link_to highlight(h(e.title), @token), :controller => 'documents', :action => 'show', :id => e %><br />
+ <i><%= format_time(e.created_on) %></i>
+ <% end %>
+ </p></li>
+ <% end %>
+ </ul>
+<% end %>
\ No newline at end of file |