Commit 3d756404 authored by jplang's avatar jplang

Let user display a custom query on "My page" (#1565).

git-svn-id: https://svn.redmine.org/redmine/trunk@16406 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 9232cb09
......@@ -118,6 +118,17 @@ module MyHelper
return issues, query
end
def issuequery_items(settings)
query = IssueQuery.visible.find_by_id(settings[:query_id])
return unless query
query.column_names = settings[:columns] if settings[:columns].present?
query.sort_criteria = settings[:sort] if settings[:sort].present?
issues = query.issues(:limit => 10)
return issues, query
end
def news_items
News.visible.
where(:project_id => User.current.projects.map(&:id)).
......
<% issues, query = issues_items(block, settings) %>
<% if query %>
<div class="contextual">
<%= link_to_function l(:label_options), "$('##{block}-settings').toggle();", :class => 'icon-only icon-settings', :title => l(:label_options) %>
</div>
......@@ -40,3 +41,28 @@
issues_path(query.as_params.merge(:format => 'atom', :key => User.current.rss_key)),
{:title => query.name}) %>
<% end %>
<% else %>
<% visible_queries = IssueQuery.visible.sorted %>
<h3>
<%= l(:label_issue_plural) %>
</h3>
<div id="<%= block %>-settings">
<%= form_tag(my_page_path, :remote => true) do %>
<div class="box">
<p>
<label>
<%= l(:label_query) %>
<%= select_tag 'settings[issuequery][query_id]', content_tag("option") + options_from_collection_for_select(visible_queries, :id, :name, settings[:query_id]) %>
</label>
</p>
</div>
<p>
<%= submit_tag l(:button_save) %>
</p>
<% end %>
</div>
<% end %>
......@@ -23,6 +23,7 @@ module Redmine
'issuesassignedtome' => {:label => :label_assigned_to_me_issues, :partial => 'my/blocks/issues'},
'issuesreportedbyme' => {:label => :label_reported_issues, :partial => 'my/blocks/issues'},
'issueswatched' => {:label => :label_watched_issues, :partial => 'my/blocks/issues'},
'issuequery' => {:label => :label_issue_plural, :partial => 'my/blocks/issues'},
'news' => {:label => :label_news_latest, :partial => 'my/blocks/news'},
'calendar' => {:label => :label_calendar, :partial => 'my/blocks/calendar'},
'documents' => {:label => :label_document_plural, :partial => 'my/blocks/documents'},
......
......@@ -19,7 +19,7 @@ require File.expand_path('../../test_helper', __FILE__)
class MyControllerTest < Redmine::ControllerTest
fixtures :users, :email_addresses, :user_preferences, :roles, :projects, :members, :member_roles,
:issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
:issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources, :queries
def setup
@request.session[:user_id] = 2
......@@ -91,6 +91,58 @@ class MyControllerTest < Redmine::ControllerTest
assert_select 'table.issues.sort-by-due-date'
end
end
def test_page_with_issuequery_block_and_no_settings
user = User.find(2)
user.pref.my_page_layout = {'top' => ['issuequery']}
user.pref.save!
get :page
assert_response :success
assert_select '#block-issuequery' do
assert_select 'h3', :text => 'Issues'
assert_select 'select[name=?]', 'settings[issuequery][query_id]' do
assert_select 'option[value="5"]', :text => 'Open issues by priority and tracker'
end
end
end
def test_page_with_issuequery_block_and_selected_query
user = User.find(2)
query = IssueQuery.create!(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
user.pref.my_page_layout = {'top' => ['issuequery']}
user.pref.my_page_settings = {'issuequery' => {:query_id => query.id}}
user.pref.save!
get :page
assert_response :success
assert_select '#block-issuequery' do
# assert number of columns (columns from query + id column + checkbox column)
assert_select 'table.issues th', 6
# assert results limit
assert_select 'table.issues tr.issue', 10
assert_select 'table.issues td.assigned_to'
end
end
def test_page_with_issuequery_block_and_selected_query_and_custom_columns
user = User.find(2)
query = IssueQuery.create!(:name => 'All issues', :user => user, :column_names => [:tracker, :subject, :status, :assigned_to])
user.pref.my_page_layout = {'top' => ['issuequery']}
user.pref.my_page_settings = {'issuequery' => {:query_id => query.id, :columns => [:subject, :due_date]}}
user.pref.save!
get :page
assert_response :success
assert_select '#block-issuequery' do
# assert number of columns (columns from query + id column + checkbox column)
assert_select 'table.issues th', 4
assert_select 'table.issues th', :text => 'Due date'
end
end
def test_page_with_all_blocks
blocks = Redmine::MyPage.blocks.keys
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment