rm_1565_issues_from_custom_query.patch

Marius BALTEANU, 2017-02-27 22:42

Download (7.82 KB)

View differences:

app/controllers/my_controller.rb
27 27
  helper :issues
28 28
  helper :users
29 29
  helper :custom_fields
30
  helper :queries
31
  helper :sort
30 32

  
31 33
  def index
32 34
    page
app/helpers/my_helper.rb
98 98
    Issue.visible.open.on_active_project.watched_by(User.current.id).recently_updated.limit(10)
99 99
  end
100 100

  
101
  def issuequery_items(query_id)
102
    query = IssueQuery.visible.find_by_id(query_id)
103

  
104
    return query unless query
105

  
106
    sort_array = query.sort_criteria.empty? ? [['id', 'desc']] : query.sort_criteria
107
    sort_init(sort_array)
108
    sort_update(query.sortable_columns, 'issues_index_sort')
109

  
110
    issues = query.issues(:order => sort_clause, :limit => 10)
111

  
112
    return query, issues
113
  end
114

  
101 115
  def news_items
102 116
    News.visible.
103 117
      where(:project_id => User.current.projects.map(&:id)).
app/views/my/blocks/_issuescustomquery.html.erb
1
<%
2
query, issues = issuequery_items(settings[:query_id].to_i)
3
visible_queries = IssueQuery.visible.sorted
4
%>
5

  
6
<div class="contextual">
7
  <%= link_to_function l(:label_options), "$('#customquery-settings').toggle();", :class => 'icon-only icon-settings' %>
8
</div>
9

  
10
<h3>
11
  <% if query %>
12
  <%= link_to l(:label_issues_from_query, :query_name => query.name), {:controller => 'issues', :action => 'index', :project_id => query.project_id, :query_id => query} %>
13
  (<%= query.issue_count %>)
14
  <% else %>
15
    <%= l(:label_issues_from_custom_query) %>
16
  <% end %>
17
</h3>
18

  
19
<div id="customquery-settings" style="display:none;">
20
  <%= form_tag({}, :remote => true) do %>
21
    <div class="box">
22
      <p>
23
      <label>
24
        <%= l(:label_query) %>
25
        <%= select_tag 'settings[issuescustomquery][query_id]', content_tag("option") + options_from_collection_for_select(visible_queries, :id, :name, settings[:query_id]) %>
26
      </label>
27
      </p>
28
    </div>
29
    <p>
30
      <%= submit_tag l(:button_save) %>
31
      <%= link_to_function l(:button_cancel), "$('#customquery-settings').toggle();" %>
32
    </p>
33
  <% end %>
34
</div>
35

  
36
<% if query %>
37
  <%= render :partial => 'issues/list_simple', :locals => { :issues => issues } %>
38
<% else %>
39
  <p class="nodata"><%= l(:label_no_data) %></p>
40
<% end %>
config/locales/en.yml
1014 1014
  label_font_default: Default font
1015 1015
  label_font_monospace: Monospaced font
1016 1016
  label_font_proportional: Proportional font
1017
  label_issues_from_custom_query: Issues from custom query
1018
  label_issues_from_query: "Issues from query: %{query_name}"
1017 1019

  
1018 1020
  button_login: Login
1019 1021
  button_submit: Submit
lib/redmine/my_page.rb
23 23
        'issuesassignedtome' => :label_assigned_to_me_issues,
24 24
        'issuesreportedbyme' => :label_reported_issues,
25 25
        'issueswatched' => :label_watched_issues,
26
        'issuescustomquery' => :label_issues_from_custom_query,
26 27
        'news' => :label_news_latest,
27 28
        'calendar' => :label_calendar,
28 29
        'documents' => :label_document_plural,
test/functional/my_controller_test.rb
19 19

  
20 20
class MyControllerTest < Redmine::ControllerTest
21 21
  fixtures :users, :email_addresses, :user_preferences, :roles, :projects, :members, :member_roles,
22
  :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
22
  :issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources, :queries
23 23

  
24 24
  def setup
25 25
    @request.session[:user_id] = 2
......
51 51
    end
52 52
  end
53 53

  
54
  def test_page_with_issues_from_custom_query_block
55
    preferences = User.find(2).pref
56
    preferences[:my_page_layout] = {'top' => ['issuescustomquery']}
57
    preferences.save!
58

  
59
    get :page
60
    assert_response :success
61

  
62
    assert_select 'h3', :text => 'Issues from custom query'
63

  
64
    assert_select 'select[name=?]', 'settings[issuescustomquery][query_id]' do
65
      assert_select 'option', 8
66
      assert_select 'option', :text => ''
67
      assert_select 'option[value="1"]', :text => 'Multiple custom fields query'
68
      assert_select 'option[value="5"]', :text => 'Open issues by priority and tracker'
69
      assert_select 'option[value="9"]', :text => 'Open issues grouped by list custom field'
70
      assert_select 'option[value="6"]', :text => 'Open issues grouped by tracker'
71
      assert_select 'option[value="8"]', :text => 'Private query for project 2'
72
      assert_select 'option[value="4"]', :text => 'Public query for all projects'
73
      assert_select 'option[value="7"]', :text => 'Public query for project 2'
74
    end
75
  end
76

  
77

  
78
  def test_update_page_with_blank_preferences
79
    user = User.generate!(:language => 'en')
80
    @request.session[:user_id] = user.id
81

  
82
    xhr :post, :update_page, :settings => {'timelog' => {'days' => '14'}}
83
    assert_response :success
84
    assert_include '$("#block-timelog").html(', response.body
85
    assert_include '14 days', response.body
86

  
87
    assert_equal({:days => "14"}, user.reload.pref.my_page_settings('timelog'))
88
  end
89

  
90

  
91
  def test_page_with_issues_from_custom_query_block_with_selected_query
92
    preferences = User.find(2).pref
93
    preferences[:my_page_layout] = {'top' => ['issuescustomquery']}
94
    preferences[:my_page_settings] = {'issuescustomquery' => {:query_id => '5'}}
95
    preferences.save!
96

  
97
    get :page
98
    assert_response :success
99
    assert_select 'select[name=?]', 'settings[issuescustomquery][query_id]' do
100
      assert_select 'option', 8
101
      assert_select 'option[selected=selected][value="5"]', :text => 'Open issues by priority and tracker'
102
    end
103
    assert_select 'tr.issue', 10
104
  end
105

  
54 106
  def test_page_with_all_blocks
55 107
    blocks = Redmine::MyPage.blocks.keys
56 108
    preferences = User.find(2).pref
test/unit/helpers/my_helper_test.rb
20 20
class MyHelperTest < Redmine::HelperTest
21 21
  include ERB::Util
22 22
  include MyHelper
23

  
23
  include SortHelper
24 24

  
25 25
  fixtures :projects, :trackers, :issue_statuses, :issues,
26 26
           :enumerations, :users, :issue_categories,
......
46 46

  
47 47
    assert_include entry, timelog_items.first
48 48
  end
49

  
50
  def test_issuequery_items_should_return_query_and_ten_sorted_issues
51
    User.current = User.find(2)
52
    query, issues = issuequery_items(5)
53

  
54
    assert_equal query.name, "Open issues by priority and tracker"
55
    assert_equal [7, 9, 10, 14, 2, 1, 3, 4, 5, 6], issues.map(&:id)
56
  end
49 57
end