当前位置:  开发笔记 > 开发工具 > 正文

Redmine - 为问题显示添加"花费时间"字段

如何解决《Redmine-为问题显示添加"花费时间"字段》经验,为你挑选了2个好方法。

我如何将"花费时间"添加为要在问题列表中显示的列?



1> user2067021..:

巩固Eric和Joel的答案,这就是我需要做的就是在Redmine 1.0.3中添加一个"花费时间"列.不确定是否有更好的方法来添加翻译文本.

要为新字段指定一个本地化名称,请在字段定义末尾的第299行添加到config/locales/en.yml:

  field_spent_hours: Spent time

要添加新列,请使用内容创建lib/spent_time_query_patch.rb:

# Based on http://github.com/edavis10/question_plugin/blob/master/lib/question_query_patch.rb
require_dependency 'query'

module QueryPatch
  def self.included(base) # :nodoc:
    base.extend(ClassMethods)

    # Same as typing in the class
    base.class_eval do
      unloadable # Send unloadable so it will not be unloaded in development
      base.add_available_column(QueryColumn.new(:spent_hours))
    end

  end

  module ClassMethods
    unless Query.respond_to?(:available_columns=)
      # Setter for +available_columns+ that isn't provided by the core.
      def available_columns=(v)
        self.available_columns = (v)
      end
    end

    unless Query.respond_to?(:add_available_column)
      # Method to add a column to the +available_columns+ that isn't provided by the core.
      def add_available_column(column)
        self.available_columns << (column)
      end
    end
  end
end

要使上面的spent_time_query_patch实际加载,请创建包含内容的config/initializers/spent_time_query_patch.rb:

require 'spent_time_query_patch'

Query.class_eval do
  include QueryPatch
end



2> Eric Davis..:

您也可以通过在运行时添加列来完成此操作.这将添加花费的小时列而不修改Redmine核心.只需将以下代码放入lib /中的文件中

改编自:

Redmine预算插件

Redmine问题插件

require_dependency 'query'

module QueryPatch
  def self.included(base) # :nodoc:
    base.extend(ClassMethods)

    # Same as typing in the class
    base.class_eval do
      unloadable # Send unloadable so it will not be unloaded in development
      base.add_available_column(QueryColumn.new(:spent_hours))
    end

  end

  module ClassMethods

    unless Query.respond_to?(:available_columns=)
      # Setter for +available_columns+ that isn't provided by the core.
      def available_columns=(v)
        self.available_columns = (v)
      end
    end

    unless Query.respond_to?(:add_available_column)
      # Method to add a column to the +available_columns+ that isn't provided by the core.
      def add_available_column(column)
        self.available_columns 


由于这个答案越来越老,我想在尝试之前我应该​​问:你知道这是否适用于Redmine 0.9.3?
推荐阅读
360691894_8a5c48
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有