rm_1565_issues_from_custom_query.patch

Marius BALTEANU, 2017-03-10 09:20

Download (8.03 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
97 97
    Issue.visible.open.on_active_project.watched_by(User.current.id).recently_updated.limit(10)
98 98
  end
99 99

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

  
103
    return query unless query
104

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

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

  
111
    return query, issues
112
  end
113

  
100 114
  def news_items
101 115
    News.visible.
102 116
      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', :locals => { :issues => issues, :query => query } %>
38
<% else %>
39
  <p class="nodata"><%= l(:label_no_data) %></p>
40
<% end %>
config/locales/en.yml
1013 1013
  label_font_monospace: Monospaced font
1014 1014
  label_font_proportional: Proportional font
1015 1015
  label_last_notes: Last notes
1016
  label_issues_from_custom_query: Issues from custom query
1017
  label_issues_from_query: "Issues from query: %{query_name}"
1016 1018

  
1017 1019
  button_login: Login
1018 1020
  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,
public/stylesheets/application.css
1129 1129
  color:#505050;
1130 1130
  line-height:1.5em;
1131 1131
}
1132

  
1132
.block-receiver .list .checkbox {display: none;}
1133 1133
.handle {cursor: move;}
1134 1134

  
1135 1135
/***** Gantt chart *****/
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
  def test_page_with_issues_from_custom_query_block_with_selected_query
78
    user = User.find(2)
79

  
80
    q = IssueQuery.new(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
81
    q.save!
82

  
83
    preferences = user.pref
84
    preferences[:my_page_layout] = {'top' => ['issuescustomquery']}
85
    preferences[:my_page_settings] = {'issuescustomquery' => {:query_id => q.id}}
86
    preferences.save!
87

  
88
    get :page
89
    assert_response :success
90

  
91
    assert_select 'select[name=?]', 'settings[issuescustomquery][query_id]' do
92
      assert_select 'option', 9
93
      assert_select 'option[selected=selected][value=?]', q.id.to_s, :text => q.name
94
    end
95

  
96
    # assert number of columns (columns from query + id column + checkbox column)
97
    assert_select '#block-issuescustomquery table.issues th', 6
98
    # assert results limit
99
    assert_select '#block-issuescustomquery table.issues tr.issue', 10
100
    assert_select '#block-issuescustomquery table.issues td.assigned_to'
101
  end
102

  
54 103
  def test_page_with_all_blocks
55 104
    blocks = Redmine::MyPage.blocks.keys
56 105
    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