From 156b8e2ee638428cfa1387d783237a82c573f9cd Mon Sep 17 00:00:00 2001 From: Go MAEDA Date: Fri, 14 Sep 2018 03:40:37 +0000 Subject: Allow project bulk edit of time entries (#26534). Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@17482 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/controllers/timelog_controller.rb | 12 ++++++- app/helpers/application_helper.rb | 14 ++++++++ app/helpers/issues_helper.rb | 14 -------- app/views/timelog/bulk_edit.html.erb | 62 ++++++++++++++++++++++++++++++++--- app/views/timelog/bulk_edit.js.erb | 1 + 5 files changed, 83 insertions(+), 20 deletions(-) create mode 100644 app/views/timelog/bulk_edit.js.erb (limited to 'app') diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb index c23e47713..50fcab2f7 100644 --- a/app/controllers/timelog_controller.rb +++ b/app/controllers/timelog_controller.rb @@ -165,8 +165,18 @@ class TimelogController < ApplicationController end def bulk_edit - @available_activities = @projects.map(&:activities).reduce(:&) + @target_projects = Project.allowed_to(:log_time).to_a @custom_fields = TimeEntry.first.available_custom_fields.select {|field| field.format.bulk_edit_supported} + if params[:time_entry] + @target_project = @target_projects.detect {|p| p.id.to_s == params[:time_entry][:project_id].to_s} + end + if @target_project + @available_activities = @target_project.activities + else + @available_activities = @projects.map(&:activities).reduce(:&) + end + @time_entry_params = params[:time_entry] || {} + @time_entry_params[:custom_field_values] ||= {} end def bulk_update diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 546080386..b535d9d1b 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1562,6 +1562,20 @@ module ApplicationHelper end end + # Returns an array of error messages for bulk edited items (issues, time entries) + def bulk_edit_error_messages(items) + messages = {} + items.each do |item| + item.errors.full_messages.each do |message| + messages[message] ||= [] + messages[message] << item + end + end + messages.map { |message, items| + "#{message}: " + items.map {|i| "##{i.id}"}.join(', ') + } + end + private def wiki_helper diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index d1fb28961..e6654d908 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -166,20 +166,6 @@ module IssuesHelper end end - # Returns an array of error messages for bulk edited issues - def bulk_edit_error_messages(issues) - messages = {} - issues.each do |issue| - issue.errors.full_messages.each do |message| - messages[message] ||= [] - messages[message] << issue - end - end - messages.map { |message, issues| - "#{message}: " + issues.map {|i| "##{i.id}"}.join(', ') - } - end - # Returns a link for adding a new subtask to the given issue def link_to_new_subtask(issue) attrs = { diff --git a/app/views/timelog/bulk_edit.html.erb b/app/views/timelog/bulk_edit.html.erb index 96c953151..5d82c54d5 100644 --- a/app/views/timelog/bulk_edit.html.erb +++ b/app/views/timelog/bulk_edit.html.erb @@ -27,35 +27,43 @@ <%= @time_entries.collect {|i| hidden_field_tag('ids[]', i.id, :id => nil)}.join.html_safe %>
+

+ + <%= select_tag('time_entry[project_id]', project_tree_options_for_select(@target_projects, + :include_blank => l(:label_no_change_option), :selected => @target_project), + :onchange => "updateBulkEditFrom('#{escape_javascript url_for(:action => 'bulk_edit', :format => 'js')}')" ) %> +

<%= text_field :time_entry, :issue_id, :size => 6 %> + +

- <%= date_field :time_entry, :spent_on, :size => 10 %><%= calendar_for('time_entry_spent_on') %> + <%= date_field :time_entry, :spent_on, :size => 10, :value => @time_entry_params[:spent_on] %><%= calendar_for('time_entry_spent_on') %>

- <%= text_field :time_entry, :hours, :size => 6 %> + <%= text_field :time_entry, :hours, :size => 6, :value => @time_entry_params[:hours] %>

<% if @available_activities.any? %>

- <%= select_tag('time_entry[activity_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_activities, :id, :name)) %> + <%= select_tag('time_entry[activity_id]', content_tag('option', l(:label_no_change_option), :value => '') + options_from_collection_for_select(@available_activities, :id, :name, @time_entry_params[:activity_id])) %>

<% end %>

- <%= text_field(:time_entry, :comments, :size => 100) %> + <%= text_field(:time_entry, :comments, :size => 100, :value => @time_entry_params[:comments]) %>

<% @custom_fields.each do |custom_field| %> -

<%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @time_entries) %>

+

<%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @time_entries, @time_entry_params[:custom_field_values][custom_field.id.to_s]) %>

<% end %> <%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %> @@ -64,3 +72,47 @@

<%= submit_tag l(:button_submit) %>

<% end %> + +<%= javascript_tag do %> + $(document).ready(function(){ + $('#time_entry_project_id').change(function(){ + + $('#time_entry_issue').text(''); + }); + }); + + <% if @project || @target_project %> + observeAutocompleteField('time_entry_issue_id', + function(request, callback) { + var url = '<%= j auto_complete_issues_path %>'; + var data = { + term: request.term + }; + var project_id; + <% if @project %> + project_id = '<%= @project.id %>'; + <% end %> + + current_project_id = $('#time_entry_project_id').val(); + if(current_project_id === ''){ + data['project_id'] = project_id; + } else { + data['project_id'] = current_project_id; + } + + $.get(url, data, null, 'json') + .done(function(data){ + callback(data); + }) + .fail(function(jqXHR, status, error){ + callback([]); + }); + }, + { + select: function(event, ui, data) { + $('#time_entry_issue').text(ui.item.label); + } + } + ); + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/timelog/bulk_edit.js.erb b/app/views/timelog/bulk_edit.js.erb new file mode 100644 index 000000000..ab07f011a --- /dev/null +++ b/app/views/timelog/bulk_edit.js.erb @@ -0,0 +1 @@ +$('#content').html('<%= escape_javascript(render :template => 'timelog/bulk_edit', :formats => [:html]) %>'); -- cgit v1.2.3