LoginSignup
1
3

More than 3 years have passed since last update.

redmineのガントチャートの開始月がイケていないので直してみた

Last updated at Posted at 2020-06-15

redmineのガントチャートの開始月は、当月開始なので、月初めは前月のタスクが見えなくて使いづらい。なので、開始月を前月からのスタートにするように設定を変更します。

下記サイトを参考にしました。
https://blog.kakakikikeke.com/2012/09/redmine.html

ソースコードの変更

変更するファイルは/usr/src/redmine/lib/redmine/helpers/gantt.rbです。
initialize関数の中のelseが変更対象で、オプションが特に指定されていない(デフォルトの状態)のときは現在の月と年を取得しています。

      def initialize(options={})
        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 ||= User.current.today.month
          @year_from ||= User.current.today.year
        end

この記述を、下記の通り修正します。@month_fromの値を-1することで、前月からの開始月の表示になります。また、1月にこの処理を実行すると、@month_fromの値が0になってしまうので、12に修正のうえ、@year_fromを前年(-1)にします。

      def initialize(options={})
        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 ||= User.current.today.month - 1
          @year_from ||= User.current.today.year
          if @month_from == 0
            @month_from = 12
            @year_from = User.current.today.year - 1
          end
#          @month_from ||= User.current.today.month
#          @year_from ||= User.current.today.year
        end

参考文献

1
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
3