summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2018-09-14 03:40:37 +0000
committerGo MAEDA <maeda@farend.jp>2018-09-14 03:40:37 +0000
commit156b8e2ee638428cfa1387d783237a82c573f9cd (patch)
treeec943afeb8236b06a695624befaaa3883b9774a0 /app
parentf288ccb9871fc4d5271b3d5c40a68f487c5b4ae5 (diff)
downloadredmine-156b8e2ee638428cfa1387d783237a82c573f9cd.tar.gz
redmine-156b8e2ee638428cfa1387d783237a82c573f9cd.zip
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
Diffstat (limited to 'app')
-rw-r--r--app/controllers/timelog_controller.rb12
-rw-r--r--app/helpers/application_helper.rb14
-rw-r--r--app/helpers/issues_helper.rb14
-rw-r--r--app/views/timelog/bulk_edit.html.erb62
-rw-r--r--app/views/timelog/bulk_edit.js.erb1
5 files changed, 83 insertions, 20 deletions
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
@@ -28,34 +28,42 @@
<div class="box tabular">
<div>
<p>
+ <label><%= l(:field_project) %></label>
+ <%= 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')}')" ) %>
+ </p>
+ <p>
<label for="time_entry_issue_id"><%= l(:field_issue) %></label>
<%= text_field :time_entry, :issue_id, :size => 6 %>
+ <label class="inline"><%= check_box_tag 'time_entry[issue_id]', 'none', (@time_entry_params[:issue_id] == 'none'), :id => nil, :data => {:disables => '#time_entry_issue_id'} %><%= l(:button_clear) %></label>
+ <span id="time_entry_issue"></span>
</p>
<p>
<label for="time_entry_spent_on"><%= l(:field_spent_on) %></label>
- <%= 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') %>
</p>
<p>
<label for="time_entry_hours"><%= l(:field_hours) %></label>
- <%= text_field :time_entry, :hours, :size => 6 %>
+ <%= text_field :time_entry, :hours, :size => 6, :value => @time_entry_params[:hours] %>
</p>
<% if @available_activities.any? %>
<p>
<label for="time_entry_activity_id"><%= l(:field_activity) %></label>
- <%= 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])) %>
</p>
<% end %>
<p>
<label for="time_entry_comments"><%= l(:field_comments) %></label>
- <%= text_field(:time_entry, :comments, :size => 100) %>
+ <%= text_field(:time_entry, :comments, :size => 100, :value => @time_entry_params[:comments]) %>
</p>
<% @custom_fields.each do |custom_field| %>
- <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @time_entries) %></p>
+ <p><label><%= h(custom_field.name) %></label> <%= custom_field_tag_for_bulk_edit('time_entry', custom_field, @time_entries, @time_entry_params[:custom_field_values][custom_field.id.to_s]) %></p>
<% end %>
<%= call_hook(:view_time_entries_bulk_edit_details_bottom, { :time_entries => @time_entries }) %>
@@ -64,3 +72,47 @@
<p><%= submit_tag l(:button_submit) %></p>
<% end %>
+
+<%= javascript_tag do %>
+ $(document).ready(function(){
+ $('#time_entry_project_id').change(function(){
+ <!-- $('#time_entry_issue_id').val(''); -->
+ $('#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]) %>');