Change the start date of gantt chart
Added by Alice Etchegaray over 8 years ago
Hello,
Is anyone can tell me how to change the default start date of gantt chart ?
By default, the value is the current month, but I wish it was the start date of the project...
Thank in advance for your help,
Cheers,
Alice.
Replies (8)
RE: Change the start date of gantt chart
-
Added by Martin Denizet (redmine.org team member) over 8 years ago
Hi Alice,
I think you would have to do a plugin.
It seems the date is set by retrieve_query
in source:trunk/app/controllers/gantts_controller.rb
I don't have my IDE available right now so I'm not able to tell where is the definition of retrieve_query
.
I guess you would have to wrap retrieve_query
such as, if the date is not specified, you use the project's start date.
Make plugins rather than editing Redmine's code otherwise you won't be able to update to newer releases. Actually plugins can also break with updates but it's still far better.
Cheer,
RE: Change the start date of gantt chart
-
Added by Alice Etchegaray over 8 years ago
I found the definition of retrieve_query, but I don't know if it's the method for the start date...
# Retrieve query from session or build a new query
def retrieve_query
if !params[:query_id].blank?
cond = "project_id IS NULL"
cond << " OR project_id = #{@project.id}" if Herve Harster
@query = IssueQuery.where(cond).find(params[:query_id])
raise ::Unauthorized unless @query.visible?
@query.project = Herve Harster
session[:query] = {:id => @query.id, :project_id => @query.project_id}
sort_clear
elsif api_request? || params[:set_filter] || session[:query].nil? || session[:query][:project_id] != (Herve Harster ? @project.id : nil)
# Give it a name, required to be valid
@query = IssueQuery.new(:name => "_")
@query.project = Herve Harster
@query.build_from_params(params)
session[:query] = {:project_id => @query.project_id, :filters => @query.filters, :group_by => @query.group_by, :column_names => @query.column_names}
else
# retrieve from session
@query = nil
@query = IssueQuery.find_by_id(session[:query][:id]) if session[:query][:id]
@query ||= IssueQuery.new(:name => "_", :filters => session[:query][:filters], :group_by => session[:query][:group_by], :column_names => session[:query][:column_names])
@query.project = Herve Harster
end
end
RE: Change the start date of gantt chart
-
Added by Alice Etchegaray over 8 years ago
I have found the method for this (it's in lib\redmine\helpers\gantt.rb) :
@month_from ||= Project.start_date.month
@year_from ||= Date.today.year
But with this, I have this error :
NoMethodError (undefined method `start_date' for #<Class:0x2b6b0a8>):
lib/redmine/helpers/gantt.rb:59:in `initialize'
app/controllers/gantts_controller.rb:34:in `new'
app/controllers/gantts_controller.rb:34:in `show'
Can you help me please ?
RE: Change the start date of gantt chart
-
Added by Martin Denizet (redmine.org team member) over 8 years ago
Is there a way I can see your entire code? Maybe you have it on Github?
Cheers,
RE: Change the start date of gantt chart
-
Added by Alice Etchegaray over 8 years ago
Hi,
Finally, I didn't wrote the plugin.
I just tried to change @month_from ||= Date.today.month (in lib/redmine/helpers/gantt.rb) by project.start_date but it didn't work.
So, I give up..
RE: Change the start date of gantt chart
-
Added by Markus Boremski over 3 years ago
Looking for a similar thing.
In Gantt-Diagramm I'd like to see minimum one month in the past to review open issues.
Anyone able to give a hint?
RE: Change the start date of gantt chart
-
Added by Sunding Wei about 2 years ago
I would like to change the Gantt to start from Project.start_date too, I have to workaround by starting from previous month for now
diff --git a/lib/redmine/helpers/gantt.rb b/lib/redmine/helpers/gantt.rb
index 9b68f32c2..5d5fa117a 100644
--- a/lib/redmine/helpers/gantt.rb
+++ b/lib/redmine/helpers/gantt.rb
@@ -63,8 +63,8 @@ module Redmine
@month_from = 1
end
else
- @month_from ||= User.current.today.month
- @year_from ||= User.current.today.year
+ @month_from ||= (User.current.today - 1.month).month
+ @year_from ||= (User.current.today - 1.month).year
end
zoom = (options[:zoom] || User.current.pref[:gantt_zoom]).to_i
@zoom = (zoom > 0 && zoom < 5) ? zoom : 2