@@ -1,42 +1,44 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2012 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | class AutoCompletesController < ApplicationController |
|
19 | 19 | before_filter :find_project |
|
20 | 20 | |
|
21 | 21 | def issues |
|
22 | 22 | @issues = [] |
|
23 | 23 | q = (params[:q] || params[:term]).to_s.strip |
|
24 | 24 | if q.present? |
|
25 | scope = (params[:scope] == "all" ? Issue : @project.issues).visible | |
|
25 | scope = (params[:scope] == "all" || @project.nil? ? Issue : @project.issues).visible | |
|
26 | 26 | if q.match(/^\d+$/) |
|
27 | 27 | @issues << scope.find_by_id(q.to_i) |
|
28 | 28 | end |
|
29 | 29 | @issues += scope.where("LOWER(#{Issue.table_name}.subject) LIKE ?", "%#{q.downcase}%").order("#{Issue.table_name}.id DESC").limit(10).all |
|
30 | 30 | @issues.compact! |
|
31 | 31 | end |
|
32 | 32 | render :layout => false |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | private |
|
36 | 36 | |
|
37 | 37 | def find_project |
|
38 | if params[:project_id].present? | |
|
38 | 39 | @project = Project.find(params[:project_id]) |
|
40 | end | |
|
39 | 41 | rescue ActiveRecord::RecordNotFound |
|
40 | 42 | render_404 |
|
41 | 43 | end |
|
42 | 44 | end |
@@ -1,21 +1,23 | |||
|
1 | 1 | <%= error_messages_for 'time_entry' %> |
|
2 | 2 | <%= back_url_hidden_field_tag %> |
|
3 | 3 | |
|
4 | 4 | <div class="box tabular"> |
|
5 | 5 | <% if @time_entry.new_record? %> |
|
6 | 6 | <% if params[:project_id] %> |
|
7 | 7 | <%= f.hidden_field :project_id %> |
|
8 | 8 | <% else %> |
|
9 | 9 | <p><%= f.select :project_id, project_tree_options_for_select(Project.allowed_to(:log_time).all, :selected => @time_entry.project), :required => true %></p> |
|
10 | 10 | <% end %> |
|
11 | 11 | <% end %> |
|
12 | 12 | <p><%= f.text_field :issue_id, :size => 6 %> <em><%= h("#{@time_entry.issue.tracker.name} ##{@time_entry.issue.id}: #{@time_entry.issue.subject}") if @time_entry.issue %></em></p> |
|
13 | 13 | <p><%= f.text_field :spent_on, :size => 10, :required => true %><%= calendar_for('time_entry_spent_on') %></p> |
|
14 | 14 | <p><%= f.text_field :hours, :size => 6, :required => true %></p> |
|
15 | 15 | <p><%= f.text_field :comments, :size => 100 %></p> |
|
16 | 16 | <p><%= f.select :activity_id, activity_collection_for_select_options(@time_entry), :required => true %></p> |
|
17 | 17 | <% @time_entry.custom_field_values.each do |value| %> |
|
18 | 18 | <p><%= custom_field_tag_with_label :time_entry, value %></p> |
|
19 | 19 | <% end %> |
|
20 | 20 | <%= call_hook(:view_timelog_edit_form_bottom, { :time_entry => @time_entry, :form => f }) %> |
|
21 | 21 | </div> |
|
22 | ||
|
23 | <%= javascript_tag "observeAutocompleteField('time_entry_issue_id', '#{escape_javascript auto_complete_issues_path(:project_id => @project, :scope => (@project ? nil : 'all'))}')" %> |
@@ -1,60 +1,67 | |||
|
1 | 1 | require File.expand_path('../../test_helper', __FILE__) |
|
2 | 2 | |
|
3 | 3 | class AutoCompletesControllerTest < ActionController::TestCase |
|
4 | 4 | fixtures :projects, :issues, :issue_statuses, |
|
5 | 5 | :enumerations, :users, :issue_categories, |
|
6 | 6 | :trackers, |
|
7 | 7 | :projects_trackers, |
|
8 | 8 | :roles, |
|
9 | 9 | :member_roles, |
|
10 | 10 | :members, |
|
11 | 11 | :enabled_modules, |
|
12 | 12 | :workflows, |
|
13 | 13 | :journals, :journal_details |
|
14 | 14 | |
|
15 | 15 | def test_issues_should_not_be_case_sensitive |
|
16 | 16 | get :issues, :project_id => 'ecookbook', :q => 'ReCiPe' |
|
17 | 17 | assert_response :success |
|
18 | 18 | assert_not_nil assigns(:issues) |
|
19 | 19 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def test_issues_should_accept_term_param |
|
23 | 23 | get :issues, :project_id => 'ecookbook', :term => 'ReCiPe' |
|
24 | 24 | assert_response :success |
|
25 | 25 | assert_not_nil assigns(:issues) |
|
26 | 26 | assert assigns(:issues).detect {|issue| issue.subject.match /recipe/} |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | def test_issues_should_return_issue_with_given_id |
|
30 | 30 | get :issues, :project_id => 'subproject1', :q => '13' |
|
31 | 31 | assert_response :success |
|
32 | 32 | assert_not_nil assigns(:issues) |
|
33 | 33 | assert assigns(:issues).include?(Issue.find(13)) |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def test_auto_complete_with_scope_all_should_search_other_projects |
|
37 | 37 | get :issues, :project_id => 'ecookbook', :q => '13', :scope => 'all' |
|
38 | 38 | assert_response :success |
|
39 | 39 | assert_not_nil assigns(:issues) |
|
40 | 40 | assert assigns(:issues).include?(Issue.find(13)) |
|
41 | 41 | end |
|
42 | 42 | |
|
43 | def test_auto_complete_without_project_should_search_all_projects | |
|
44 | get :issues, :q => '13' | |
|
45 | assert_response :success | |
|
46 | assert_not_nil assigns(:issues) | |
|
47 | assert assigns(:issues).include?(Issue.find(13)) | |
|
48 | end | |
|
49 | ||
|
43 | 50 | def test_auto_complete_without_scope_all_should_not_search_other_projects |
|
44 | 51 | get :issues, :project_id => 'ecookbook', :q => '13' |
|
45 | 52 | assert_response :success |
|
46 | 53 | assert_equal [], assigns(:issues) |
|
47 | 54 | end |
|
48 | 55 | |
|
49 | 56 | def test_issues_should_return_json |
|
50 | 57 | get :issues, :project_id => 'subproject1', :q => '13' |
|
51 | 58 | assert_response :success |
|
52 | 59 | json = ActiveSupport::JSON.decode(response.body) |
|
53 | 60 | assert_kind_of Array, json |
|
54 | 61 | issue = json.first |
|
55 | 62 | assert_kind_of Hash, issue |
|
56 | 63 | assert_equal 13, issue['id'] |
|
57 | 64 | assert_equal 13, issue['value'] |
|
58 | 65 | assert_equal 'Bug #13: Subproject issue two', issue['label'] |
|
59 | 66 | end |
|
60 | 67 | end |
General Comments 0
You need to be logged in to leave comments.
Login now