Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Refactor: Move gantts to a separate controller.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@3695 e93f8b46-1217-0410-a6f0-8f06a7374b81
- Loading branch information
Showing
10 changed files
with
131 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
class GanttsController < ApplicationController | ||
before_filter :find_optional_project | ||
|
||
rescue_from Query::StatementInvalid, :with => :query_statement_invalid | ||
|
||
helper :issues | ||
helper :projects | ||
helper :queries | ||
include QueriesHelper | ||
include Redmine::Export::PDF | ||
|
||
def show | ||
@gantt = Redmine::Helpers::Gantt.new(params) | ||
retrieve_query | ||
@query.group_by = nil | ||
if @query.valid? | ||
events = [] | ||
# Issues that have start and due dates | ||
events += @query.issues(:include => [:tracker, :assigned_to, :priority], | ||
:order => "start_date, due_date", | ||
:conditions => ["(((start_date>=? and start_date<=?) or (due_date>=? and due_date<=?) or (start_date<? and due_date>?)) and start_date is not null and due_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] | ||
) | ||
# Issues that don't have a due date but that are assigned to a version with a date | ||
events += @query.issues(:include => [:tracker, :assigned_to, :priority, :fixed_version], | ||
:order => "start_date, effective_date", | ||
:conditions => ["(((start_date>=? and start_date<=?) or (effective_date>=? and effective_date<=?) or (start_date<? and effective_date>?)) and start_date is not null and due_date is null and effective_date is not null)", @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to, @gantt.date_from, @gantt.date_to] | ||
) | ||
# Versions | ||
events += @query.versions(:conditions => ["effective_date BETWEEN ? AND ?", @gantt.date_from, @gantt.date_to]) | ||
|
||
@gantt.events = events | ||
end | ||
|
||
basename = (@project ? "#{@project.identifier}-" : '') + 'gantt' | ||
|
||
respond_to do |format| | ||
format.html { render :action => "show", :layout => !request.xhr? } | ||
format.png { send_data(@gantt.to_image, :disposition => 'inline', :type => 'image/png', :filename => "#{basename}.png") } if @gantt.respond_to?('to_image') | ||
format.pdf { send_data(gantt_to_pdf(@gantt, @project), :type => 'application/pdf', :filename => "#{basename}.pdf") } | ||
end | ||
end | ||
|
||
private | ||
|
||
# Rescues an invalid query statement. Just in case... | ||
# TODO: Refactor, move to ApplicationController with IssuesController | ||
def query_statement_invalid(exception) | ||
logger.error "Query::StatementInvalid: #{exception.message}" if logger | ||
session.delete(:query) | ||
sort_clear | ||
render_error "An error occurred while executing the query and has been logged. Please report this error to your Redmine administrator." | ||
end | ||
|
||
# TODO: Refactor, duplicates IssuesController | ||
def find_optional_project | ||
@project = Project.find(params[:project_id]) unless params[:project_id].blank? | ||
allowed = User.current.allowed_to?({:controller => params[:controller], :action => params[:action]}, @project, :global => true) | ||
allowed ? true : deny_access | ||
rescue ActiveRecord::RecordNotFound | ||
render_404 | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'test_helper' | ||
|
||
class GanttsControllerTest < ActionController::TestCase | ||
fixtures :all | ||
|
||
context "#gantt" do | ||
should "work" do | ||
get :show, :project_id => 1 | ||
assert_response :success | ||
assert_template 'show.html.erb' | ||
assert_not_nil assigns(:gantt) | ||
events = assigns(:gantt).events | ||
assert_not_nil events | ||
# Issue with start and due dates | ||
i = Issue.find(1) | ||
assert_not_nil i.due_date | ||
assert events.include?(Issue.find(1)) | ||
# Issue with without due date but targeted to a version with date | ||
i = Issue.find(2) | ||
assert_nil i.due_date | ||
assert events.include?(i) | ||
end | ||
|
||
should "work cross project" do | ||
get :show | ||
assert_response :success | ||
assert_template 'show.html.erb' | ||
assert_not_nil assigns(:gantt) | ||
events = assigns(:gantt).events | ||
assert_not_nil events | ||
end | ||
|
||
should "export to pdf" do | ||
get :show, :project_id => 1, :format => 'pdf' | ||
assert_response :success | ||
assert_equal 'application/pdf', @response.content_type | ||
assert @response.body.starts_with?('%PDF') | ||
assert_not_nil assigns(:gantt) | ||
end | ||
|
||
should "export to pdf cross project" do | ||
get :show, :format => 'pdf' | ||
assert_response :success | ||
assert_equal 'application/pdf', @response.content_type | ||
assert @response.body.starts_with?('%PDF') | ||
assert_not_nil assigns(:gantt) | ||
end | ||
|
||
should "export to png" do | ||
get :show, :project_id => 1, :format => 'png' | ||
assert_response :success | ||
assert_equal 'image/png', @response.content_type | ||
end if Object.const_defined?(:Magick) | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters