add bulk edit and bulk update actions for time entries (#7996).
get bulk edit form action working by mapping permissions. Contributed by Adam Soltys. git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5313 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
ab31a114fd
commit
8a31517288
|
@ -19,6 +19,7 @@ class TimelogController < ApplicationController
|
|||
menu_item :issues
|
||||
before_filter :find_project, :only => [:new, :create]
|
||||
before_filter :find_time_entry, :only => [:show, :edit, :update, :destroy]
|
||||
before_filter :find_time_entries, :only => [:bulk_edit, :bulk_update]
|
||||
before_filter :authorize, :except => [:index]
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
accept_key_auth :index, :show, :create, :update, :destroy
|
||||
|
@ -160,6 +161,28 @@ class TimelogController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def bulk_edit
|
||||
@available_activities = TimeEntryActivity.shared.active
|
||||
@custom_fields = TimeEntry.first.available_custom_fields
|
||||
end
|
||||
|
||||
def bulk_update
|
||||
attributes = parse_params_for_bulk_time_entry_attributes(params)
|
||||
|
||||
unsaved_time_entry_ids = []
|
||||
@time_entries.each do |time_entry|
|
||||
time_entry.reload
|
||||
time_entry.attributes = attributes
|
||||
call_hook(:controller_time_entries_bulk_edit_before_save, { :params => params, :time_entry => time_entry })
|
||||
unless time_entry.save
|
||||
# Keep unsaved time_entry ids to display them in flash error
|
||||
unsaved_time_entry_ids << time_entry.id
|
||||
end
|
||||
end
|
||||
set_flash_from_bulk_time_entry_save(@time_entries, unsaved_time_entry_ids)
|
||||
redirect_back_or_default({:controller => 'timelog', :action => 'index', :project_id => @project})
|
||||
end
|
||||
|
||||
verify :method => :delete, :only => :destroy, :render => {:nothing => true, :status => :method_not_allowed }
|
||||
def destroy
|
||||
if @time_entry.destroy && @time_entry.destroyed?
|
||||
|
@ -195,6 +218,26 @@ private
|
|||
render_404
|
||||
end
|
||||
|
||||
def find_time_entries
|
||||
@time_entries = TimeEntry.find_all_by_id(params[:id] || params[:ids])
|
||||
raise ActiveRecord::RecordNotFound if @time_entries.empty?
|
||||
@projects = @time_entries.collect(&:project).compact.uniq
|
||||
@project = @projects.first if @projects.size == 1
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
def set_flash_from_bulk_time_entry_save(time_entries, unsaved_time_entry_ids)
|
||||
if unsaved_time_entry_ids.empty?
|
||||
flash[:notice] = l(:notice_successful_update) unless time_entries.empty?
|
||||
else
|
||||
flash[:error] = l(:notice_failed_to_save_time_entries,
|
||||
:count => unsaved_time_entry_ids.size,
|
||||
:total => time_entries.size,
|
||||
:ids => '#' + unsaved_time_entry_ids.join(', #'))
|
||||
end
|
||||
end
|
||||
|
||||
def find_project
|
||||
if (issue_id = (params[:issue_id] || params[:time_entry] && params[:time_entry][:issue_id])).present?
|
||||
@issue = Issue.find(issue_id)
|
||||
|
@ -265,4 +308,10 @@ private
|
|||
@to ||= (TimeEntry.latest_date_for_project(@project) || Date.today)
|
||||
end
|
||||
|
||||
def parse_params_for_bulk_time_entry_attributes(params)
|
||||
attributes = (params[:time_entry] || {}).reject {|k,v| v.blank?}
|
||||
attributes.keys.each {|k| attributes[k] = '' if attributes[k] == 'none'}
|
||||
attributes[:custom_field_values].reject! {|k,v| v.blank?} if attributes[:custom_field_values]
|
||||
attributes
|
||||
end
|
||||
end
|
||||
|
|
|
@ -431,6 +431,12 @@ class Project < ActiveRecord::Base
|
|||
def all_issue_custom_fields
|
||||
@all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort
|
||||
end
|
||||
|
||||
# Returns an array of all custom fields enabled for project time entries
|
||||
# (explictly associated custom fields and custom fields enabled for all projects)
|
||||
def all_time_entry_custom_fields
|
||||
@all_time_entry_custom_fields ||= (TimeEntryCustomField.for_all + time_entry_custom_fields).uniq.sort
|
||||
end
|
||||
|
||||
def project
|
||||
self
|
||||
|
|
|
@ -23,6 +23,13 @@ ActionController::Routing::Routes.draw do |map|
|
|||
time_report.connect 'time_entries/report.:format'
|
||||
end
|
||||
|
||||
map.bulk_edit_time_entry 'time_entries/bulk_edit',
|
||||
:controller => 'timelog', :action => 'bulk_edit', :conditions => { :method => :get }
|
||||
map.bulk_update_time_entry 'time_entries/bulk_edit',
|
||||
:controller => 'timelog', :action => 'bulk_update', :conditions => { :method => :post }
|
||||
map.time_entries_context_menu '/time_entries/context_menu',
|
||||
:controller => 'context_menus', :action => 'time_entries'
|
||||
# TODO: wasteful since this is also nested under issues, projects, and projects/issues
|
||||
map.resources :time_entries, :controller => 'timelog'
|
||||
|
||||
map.connect 'projects/:id/wiki', :controller => 'wikis', :action => 'edit', :conditions => {:method => :post}
|
||||
|
|
|
@ -86,10 +86,10 @@ Redmine::AccessControl.map do |map|
|
|||
end
|
||||
|
||||
map.project_module :time_tracking do |map|
|
||||
map.permission :log_time, {:timelog => [:new, :create, :edit, :update]}, :require => :loggedin
|
||||
map.permission :log_time, {:timelog => [:new, :create, :edit, :update, :bulk_edit, :bulk_update]}, :require => :loggedin
|
||||
map.permission :view_time_entries, :timelog => [:index, :show], :time_entry_reports => [:report]
|
||||
map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :member
|
||||
map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy]}, :require => :loggedin
|
||||
map.permission :edit_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy, :bulk_edit, :bulk_update]}, :require => :member
|
||||
map.permission :edit_own_time_entries, {:timelog => [:new, :create, :edit, :update, :destroy,:bulk_edit, :bulk_update]}, :require => :loggedin
|
||||
map.permission :manage_project_activities, {:project_enumerations => [:update, :destroy]}, :require => :member
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue