diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index ce2e39fac5b8dfafb3f77f80cffade850729e747..ab1cb3e1b4e6d14aedc0f4073cedbe6d6920fdd4 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 b359898f0b7483e6808e5b3ac2b8daafe7729b85..53c346dc8fe301c809b009ba558eddd3712402d0 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 0000000000000000000000000000000000000000..32e486feee1e7e857cb6039c41326f6e364efae0 --- /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 diff --git a/db/migrate/025_add_search_permission.rb b/db/migrate/025_add_search_permission.rb new file mode 100644 index 0000000000000000000000000000000000000000..212a4dc59c0024925469a4d9b6105f1757830133 --- /dev/null +++ b/db/migrate/025_add_search_permission.rb @@ -0,0 +1,9 @@ +class AddSearchPermission < ActiveRecord::Migration + def self.up + Permission.create :controller => "projects", :action => "search", :description => "label_search", :sort => 130, :is_public => true, :mail_option => 0, :mail_enabled => 0 + end + + def self.down + Permission.find_by_controller_and_action('projects', 'roadmap').destroy + end +end diff --git a/lang/de.yml b/lang/de.yml index 2bee78a3c2361d6eec653520962a3bfb1fefc053..4339cad97359f6e66dab00864ca6da3df440f211 100644 --- a/lang/de.yml +++ b/lang/de.yml @@ -315,6 +315,9 @@ label_sort_higher: Aufzurichten label_sort_lower: Herabzusteigen label_sort_lowest: Letzter label_roadmap: Roadmap +label_search: Suche +label_result: %d Resultat +label_result_plural: %d Resultate button_login: Einloggen button_submit: Einreichen diff --git a/lang/en.yml b/lang/en.yml index 0696bda562c39fba51e56bf54e0ae3b86af73ccf..27e3cb77f98e88ab96703132ff20469d6352db22 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -315,6 +315,9 @@ label_sort_higher: Move up label_sort_lower: Move down label_sort_lowest: Move to bottom label_roadmap: Roadmap +label_search: Search +label_result: %d result +label_result_plural: %d results button_login: Login button_submit: Submit diff --git a/lang/es.yml b/lang/es.yml index 9e7cbe9d17d7144aa515c86dae3902e6d1984452..d09f58bbbe390f51474fe5549e333de8b4376fa6 100644 --- a/lang/es.yml +++ b/lang/es.yml @@ -315,6 +315,9 @@ label_sort_higher: Subir label_sort_lower: Bajar label_sort_lowest: Último label_roadmap: Roadmap +label_search: Búsqueda +label_result: %d resultado +label_result_plural: %d resultados button_login: Conexión button_submit: Someter diff --git a/lang/fr.yml b/lang/fr.yml index 77cd839d9b76b90e6c8428f1c993fb7b28fbcf10..30a4fb2d90de08e514844afb6edafb3edad00696 100644 --- a/lang/fr.yml +++ b/lang/fr.yml @@ -315,6 +315,9 @@ label_sort_higher: Remonter label_sort_lower: Descendre label_sort_lowest: Descendre en dernier label_roadmap: Roadmap +label_search: Recherche +label_result: %d résultat +label_result_plural: %d résultats button_login: Connexion button_submit: Soumettre diff --git a/lang/ja.yml b/lang/ja.yml index 93d9e766b6bde293eb84eb0480409b7ba14d5fa9..7336c5781ca498eb5da75520ac275ff8e7fad866 100644 --- a/lang/ja.yml +++ b/lang/ja.yml @@ -316,6 +316,9 @@ label_sort_higher: 上㸠label_sort_lower: 下㸠label_sort_lowest: 一番下㸠label_roadmap: ãƒãƒ¼ãƒ‰ãƒžãƒƒãƒ— +label_search: Search +label_result: %d result +label_result_plural: %d results button_login: ãƒã‚°ã‚¤ãƒ³ button_submit: 変更 diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 2f20c8e9999d6a39b13e892a1a5a66ede5f2092b..aaf332a1858aa59923e5af66963398d79b3c4a3c 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -243,6 +243,8 @@ legend {color: #505050;} hr { border:none; border-bottom: dotted 1px #c0c0c0; } table p {margin:0; padding:0;} +strong.highlight { background-color: #FCFD8D;} + div.square { border: 1px solid #999; float: left;