]> source.dussan.org Git - redmine.git/commitdiff
Let user display a custom query on "My page" (#1565).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 15 Mar 2017 17:59:31 +0000 (17:59 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Wed, 15 Mar 2017 17:59:31 +0000 (17:59 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@16406 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/my_helper.rb
app/views/my/blocks/_issues.erb
lib/redmine/my_page.rb
test/functional/my_controller_test.rb

index 5181def2de48c435eb5c91adcdadeeada48941a1..2fa1272265382eb60d9a0b1baa7daf31c7c775b2 100644 (file)
@@ -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)).
index 1b208a297b28851a750a9727478eedeba9223926..0174bac2e6e3472c844385891418e7dccaa2d782 100644 (file)
@@ -1,5 +1,6 @@
 <% 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>
                             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 %>
index 06f750f4e434d29010a994793f5f79c1193ac3ce..dc9c6928f52c89b3beb1d12e22502901f33f2b77 100644 (file)
@@ -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'},
index f6c9d5ab27a8921bc82df951625d8efa7af0a5a2..f6771a1f58dc465240250bf24a31f3b0b9c35cbb 100644 (file)
@@ -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