Project

General

Profile

Modify default start date in Gantt Chart

Added by A F 10 months ago

Hi!

I have been trying to modify the Gantt Chart in order to start with the earliest issue date rather than the actual date. For that, I have been changing the file Gantt.rb located in redmine/lib/redmine/helpers without much success. The idea is to modify lines 66 and 67 of the code:

           @month_from ||= User.current.today.month
          @year_from ||= User.current.today.year

I have tried some ideas seen in old posts but have had no luck. My other thought was to get the matrix used to sort issues (line 698) in the Gantt chart and get the earliest date from there:

def sort_issue_logic(issue)
          julian_date = Date.new
          ancesters_start_date = []
          current_issue = issue
          begin
            ancesters_start_date.unshift([current_issue.start_date || julian_date, current_issue.id])
            current_issue = current_issue.parent
          end while (current_issue)
          ancesters_start_date
        end

The only problem that I have is that I am not sure if this is possible, and if it is how I should write it (I am not sure in which format is the date given in the matrix and which format is required for the input).

Any help would be tremendously thankful! :)

AF


Replies (3)

RE: Modify default start date in Gantt Chart - Added by A F 10 months ago

Update:
This is my updated file. The only problem I am facing right now is getting the values from the ancestors_start_date to be converted into integers. My idea was to get the first value of the array with

fechas = ancestors_start_date[0]

Obtaining the string of the oldest issue. Note: I assume the format given for the date is the same as issues "01/01/2023".

After that, the idea is to convert the string part that contains the months into an integer using the following line:

(fechas[3,2]).to_i

The code would be like this but it is not working at all.


      def initialize(options={})

      # Returns issues that will be rendered
        def issues
          @issues ||= @query.issues(
            :order => ["#{Project.table_name}.lft ASC", "#{Issue.table_name}.id ASC"],
            :limit => @max_rows
          )
        end

        def sort_issue_logic(issue)
          julian_date = Date.new
          ancesters_start_date = []
          current_issue = issue
          begin
            ancesters_start_date.unshift([current_issue.start_date || julian_date, current_issue.id])
            current_issue = current_issue.parent
          end while (current_issue)
          ancesters_start_date
          @fechas = ancesters_start_date[0]
        end
        options = options.dup
        if options[:year] && options[:year].to_i >0
          @year_from = options[:year].to_i
          if options[:month] && options[:month].to_i >=1 && options[:month].to_i <= 12
            @month_from = options[:month].to_i
          else
            @month_from = 1
          end
        else
          @month_from ||= (fechas[3,2]).to_i
          @year_from ||= User.current.today.year

RE: Modify default start date in Gantt Chart - Added by A F 9 months ago

I made some tests in irb and I can assure that the methodology described should work ( I attach an image to this post). But in fact, it is not working on my Redmine server. I have come up with a couple of hypotheses why this could be happening:

1. Ancesters_start_date matrix does not contain the values in the format I expected "dd/MM/yyyy"

2. I am not referencing correctly the variables to store de data (local variables, instance variables, class variables or global variables) and in fact the data is not correctly being displayed.

3. Both problems at the same time.

I would really appreciate any type or help that you could bring me.

Thanks

AF

RE: Modify default start date in Gantt Chart - Added by Felix Schäfer 9 months ago

A F wrote in RE: Modify default start date in Gantt Chart:

The code would be like this but it is not working at all.
[...]

This code does not make much sense regarding where code is located and so, and I can't find the code you are using in gantt.rb. Which version of Redmine do you use?

Furthermore I am not sure this is the right place to change the shown period of time for the Gantt chart, what you seem to be changing is the timeframe for which issues are fetched from the DB, not the timeframe which will be shown in the UI. I am not sure this is an "easy" change, as there are multiple other things that influence the Gantt chart display, for example the user's preferences.

    (1-3/3)