Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/edavis10/redmine
Browse files Browse the repository at this point in the history
  • Loading branch information
endersonmaia committed Sep 5, 2010
2 parents 4a19d9a + cbe2660 commit 0c516f2
Show file tree
Hide file tree
Showing 83 changed files with 1,970 additions and 828 deletions.
59 changes: 59 additions & 0 deletions app/controllers/activities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
class ActivitiesController < ApplicationController
menu_item :activity
before_filter :find_optional_project
accept_key_auth :index

def index
@days = Setting.activity_days_default.to_i

if params[:from]
begin; @date_to = params[:from].to_date + 1; rescue; end
end

@date_to ||= Date.today + 1
@date_from = @date_to - @days
@with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
@author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id]))

@activity = Redmine::Activity::Fetcher.new(User.current, :project => @project,
:with_subprojects => @with_subprojects,
:author => @author)
@activity.scope_select {|t| !params["show_#{t}"].nil?}
@activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty?

events = @activity.events(@date_from, @date_to)

if events.empty? || stale?(:etag => [events.first, User.current])
respond_to do |format|
format.html {
@events_by_day = events.group_by(&:event_date)
render :layout => false if request.xhr?
}
format.atom {
title = l(:label_activity)
if @author
title = @author.name
elsif @activity.scope.size == 1
title = l("label_#{@activity.scope.first.singularize}_plural")
end
render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
}
end
end

rescue ActiveRecord::RecordNotFound
render_404
end

private

# TODO: refactor, duplicated in projects_controller
def find_optional_project
return true unless params[:id]
@project = Project.find(params[:id])
authorize
rescue ActiveRecord::RecordNotFound
render_404
end

end
5 changes: 4 additions & 1 deletion app/controllers/calendars_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@ def show
@calendar.events = events
end

render :layout => false if request.xhr?
render :action => 'show', :layout => false if request.xhr?
end

def update
show
end

end
10 changes: 8 additions & 2 deletions app/controllers/context_menus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ def issues
if (@issues.size == 1)
@issue = @issues.first
@allowed_statuses = @issue.new_statuses_allowed_to(User.current)
else
@allowed_statuses = @issues.map do |i|
i.new_statuses_allowed_to(User.current)
end.inject do |memo,s|
memo & s
end
end
projects = @issues.collect(&:project).compact.uniq
@project = projects.first if projects.size == 1
@projects = @issues.collect(&:project).compact.uniq
@project = @projects.first if @projects.size == 1

@can = {:edit => (@project && User.current.allowed_to?(:edit_issues, @project)),
:log_time => (@project && User.current.allowed_to?(:log_time, @project)),
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/files_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class FilesController < ApplicationController
menu_item :files

before_filter :find_project
before_filter :authorize

helper :sort
include SortHelper

def index
sort_init 'filename', 'asc'
sort_update 'filename' => "#{Attachment.table_name}.filename",
'created_on' => "#{Attachment.table_name}.created_on",
'size' => "#{Attachment.table_name}.filesize",
'downloads' => "#{Attachment.table_name}.downloads"

@containers = [ Project.find(@project.id, :include => :attachments, :order => sort_clause)]
@containers += @project.versions.find(:all, :include => :attachments, :order => sort_clause).sort.reverse
render :layout => !request.xhr?
end

# TODO: split method into new (GET) and create (POST)
def new
if request.post?
container = (params[:version_id].blank? ? @project : @project.versions.find_by_id(params[:version_id]))
attachments = Attachment.attach_files(container, params[:attachments])
render_attachment_warning_if_needed(container)

if !attachments.empty? && Setting.notified_events.include?('file_added')
Mailer.deliver_attachments_added(attachments[:files])
end
redirect_to :controller => 'files', :action => 'index', :id => @project
return
end
@versions = @project.versions.sort
end
end
4 changes: 4 additions & 0 deletions app/controllers/gantts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ def show
end
end

def update
show
end

end
51 changes: 29 additions & 22 deletions app/controllers/issues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IssuesController < ApplicationController
default_search_scope :issues

before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issues, :only => [:bulk_edit, :move, :perform_move, :destroy]
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
before_filter :find_project, :only => [:new, :create]
before_filter :authorize, :except => [:index]
before_filter :find_optional_project, :only => [:index]
Expand Down Expand Up @@ -54,6 +54,7 @@ class IssuesController < ApplicationController
:render => { :nothing => true, :status => :method_not_allowed }

verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }

def index
Expand Down Expand Up @@ -191,29 +192,28 @@ def update
# Bulk edit a set of issues
def bulk_edit
@issues.sort!
if request.post?
attributes = (params[:issue] || {}).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]

unsaved_issue_ids = []
@issues.each do |issue|
issue.reload
journal = issue.init_journal(User.current, params[:notes])
issue.safe_attributes = attributes
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
unless issue.save
# Keep unsaved issue ids to display them in flash error
unsaved_issue_ids << issue.id
end
end
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
return
end
@available_statuses = Workflow.available_statuses(@project)
@custom_fields = @project.all_issue_custom_fields
end

def bulk_update
@issues.sort!
attributes = parse_params_for_bulk_issue_attributes(params)

unsaved_issue_ids = []
@issues.each do |issue|
issue.reload
journal = issue.init_journal(User.current, params[:notes])
issue.safe_attributes = attributes
call_hook(:controller_issues_bulk_edit_before_save, { :params => params, :issue => issue })
unless issue.save
# Keep unsaved issue ids to display them in flash error
unsaved_issue_ids << issue.id
end
end
set_flash_from_bulk_issue_save(@issues, unsaved_issue_ids)
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
end

def destroy
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
Expand Down Expand Up @@ -270,7 +270,7 @@ def update_issue_from_params
@edit_allowed = User.current.allowed_to?(:edit_issues, @project)
@time_entry = TimeEntry.new

@notes = params[:notes]
@notes = params[:notes] || (params[:issue].present? ? params[:issue][:notes] : nil)
@issue.init_journal(User.current, @notes)
# User can change issue attributes only if he has :edit permission or if a workflow transition is allowed
if (@edit_allowed || !@allowed_statuses.empty?) && params[:issue]
Expand Down Expand Up @@ -315,4 +315,11 @@ def check_for_default_issue_status
return false
end
end

def parse_params_for_bulk_issue_attributes(params)
attributes = (params[:issue] || {}).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
26 changes: 26 additions & 0 deletions app/controllers/project_enumerations_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class ProjectEnumerationsController < ApplicationController
before_filter :find_project
before_filter :authorize

def save
if request.post? && params[:enumerations]
Project.transaction do
params[:enumerations].each do |id, activity|
@project.update_or_create_time_entry_activity(id, activity)
end
end
flash[:notice] = l(:notice_successful_update)
end

redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
end

def destroy
@project.time_entry_activities.each do |time_entry_activity|
time_entry_activity.destroy(time_entry_activity.parent)
end
flash[:notice] = l(:notice_successful_update)
redirect_to :controller => 'projects', :action => 'settings', :tab => 'activities', :id => @project
end

end
Loading

0 comments on commit 0c516f2

Please sign in to comment.