summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2014-07-29 17:52:27 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2014-07-29 17:52:27 +0000
commitefc05bc73cf53e2c9d57147f7226f9b17a6350ce (patch)
tree3f7f5f239bf1e1a298f1d26cf459d0524fad3e4a
parent41e7210210b5e50bf57bbcf41259a4d343bba1f0 (diff)
downloadredmine-efc05bc73cf53e2c9d57147f7226f9b17a6350ce.tar.gz
redmine-efc05bc73cf53e2c9d57147f7226f9b17a6350ce.zip
Add time entries custom fields to the context menu for quick bulk edit (#17484).
git-svn-id: http://svn.redmine.org/redmine/trunk@13335 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r--app/controllers/context_menus_controller.rb15
-rw-r--r--app/helpers/context_menus_helper.rb7
-rw-r--r--app/models/time_entry.rb10
-rw-r--r--app/views/context_menus/time_entries.html.erb14
-rw-r--r--test/functional/context_menus_controller_test.rb17
5 files changed, 63 insertions, 0 deletions
diff --git a/app/controllers/context_menus_controller.rb b/app/controllers/context_menus_controller.rb
index 2b174c016..36cb13f26 100644
--- a/app/controllers/context_menus_controller.rb
+++ b/app/controllers/context_menus_controller.rb
@@ -71,6 +71,9 @@ class ContextMenusController < ApplicationController
def time_entries
@time_entries = TimeEntry.where(:id => params[:ids]).preload(:project).to_a
(render_404; return) unless @time_entries.present?
+ if (@time_entries.size == 1)
+ @time_entry = @time_entries.first
+ end
@projects = @time_entries.collect(&:project).compact.uniq
@project = @projects.first if @projects.size == 1
@@ -79,6 +82,18 @@ class ContextMenusController < ApplicationController
:delete => User.current.allowed_to?(:edit_time_entries, @projects)
}
@back = back_url
+
+ @options_by_custom_field = {}
+ if @can[:edit]
+ custom_fields = @time_entries.map(&:editable_custom_fields).reduce(:&).reject(&:multiple?)
+ custom_fields.each do |field|
+ values = field.possible_values_options(@projects)
+ if values.present?
+ @options_by_custom_field[field] = values
+ end
+ end
+ end
+
render :layout => false
end
end
diff --git a/app/helpers/context_menus_helper.rb b/app/helpers/context_menus_helper.rb
index 9dcfbc144..b97d9844a 100644
--- a/app/helpers/context_menus_helper.rb
+++ b/app/helpers/context_menus_helper.rb
@@ -40,4 +40,11 @@ module ContextMenusHelper
:method => :post,
:selected => (@issue && @issue.custom_field_value(field) == value)
end
+
+ def bulk_update_time_entry_custom_field_context_menu_link(field, text, value)
+ context_menu_link h(text),
+ bulk_update_time_entries_path(:ids => @time_entries.map(&:id), :time_entry => {'custom_field_values' => {field.id => value}}, :back_url => @back),
+ :method => :post,
+ :selected => (@time_entry && @time_entry.custom_field_value(field) == value)
+ end
end
diff --git a/app/models/time_entry.rb b/app/models/time_entry.rb
index cfca47639..103d5ae62 100644
--- a/app/models/time_entry.rb
+++ b/app/models/time_entry.rb
@@ -126,4 +126,14 @@ class TimeEntry < ActiveRecord::Base
def editable_by?(usr)
(usr == user && usr.allowed_to?(:edit_own_time_entries, project)) || usr.allowed_to?(:edit_time_entries, project)
end
+
+ # Returns the custom_field_values that can be edited by the given user
+ def editable_custom_field_values(user=nil)
+ visible_custom_field_values
+ end
+
+ # Returns the custom fields that can be edited by the given user
+ def editable_custom_fields(user=nil)
+ editable_custom_field_values(user).map(&:custom_field).uniq
+ end
end
diff --git a/app/views/context_menus/time_entries.html.erb b/app/views/context_menus/time_entries.html.erb
index 10dbcafd2..3ab8d07aa 100644
--- a/app/views/context_menus/time_entries.html.erb
+++ b/app/views/context_menus/time_entries.html.erb
@@ -23,6 +23,20 @@
</li>
<% end %>
+ <% @options_by_custom_field.each do |field, options| %>
+ <li class="folder cf_<%= field.id %>">
+ <a href="#" class="submenu"><%= h(field.name) %></a>
+ <ul>
+ <% options.each do |text, value| %>
+ <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, text, value || text) %></li>
+ <% end %>
+ <% unless field.is_required? %>
+ <li><%= bulk_update_time_entry_custom_field_context_menu_link(field, l(:label_none), '__none__') %></li>
+ <% end %>
+ </ul>
+ </li>
+ <% end %>
+
<%= call_hook(:view_time_entries_context_menu_end, {:time_entries => @time_entries, :can => @can, :back => @back }) %>
<li>
diff --git a/test/functional/context_menus_controller_test.rb b/test/functional/context_menus_controller_test.rb
index b83c2d696..6670927cd 100644
--- a/test/functional/context_menus_controller_test.rb
+++ b/test/functional/context_menus_controller_test.rb
@@ -250,6 +250,23 @@ class ContextMenusControllerTest < ActionController::TestCase
assert_select 'a:not(.disabled)', :text => 'Edit'
end
+ def test_time_entries_context_menu_should_include_custom_fields
+ field = TimeEntryCustomField.generate!(:name => "Field", :field_format => "list", :possible_values => ["foo", "bar"])
+
+ @request.session[:user_id] = 2
+ get :time_entries, :ids => [1, 2]
+ assert_response :success
+ assert_select "li.cf_#{field.id}" do
+ assert_select 'a[href=#]', :text => "Field"
+ assert_select 'ul' do
+ assert_select 'a', 3
+ assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=foo", :text => 'foo'
+ assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=bar", :text => 'bar'
+ assert_select 'a[href=?]', "/time_entries/bulk_update?ids%5B%5D=1&amp;ids%5B%5D=2&amp;time_entry%5Bcustom_field_values%5D%5B#{field.id}%5D=__none__", :text => 'none'
+ end
+ end
+ end
+
def test_time_entries_context_menu_without_edit_permission
@request.session[:user_id] = 2
Role.find_by_name('Manager').remove_permission! :edit_time_entries