Bläddra i källkod

Unnecessary database access when IssueQuery class is defined (#33290).

Patch by Kevin Fischer.


git-svn-id: http://svn.redmine.org/redmine/trunk@20830 e93f8b46-1217-0410-a6f0-8f06a7374b81
tags/4.2.0
Go MAEDA 3 år sedan
förälder
incheckning
7c7d29e33c
1 ändrade filer med 28 tillägg och 13 borttagningar
  1. 28
    13
      app/models/query.rb

+ 28
- 13
app/models/query.rb Visa fil

require 'redmine/sort_criteria' require 'redmine/sort_criteria'


class QueryColumn class QueryColumn
attr_accessor :name, :groupable, :totalable, :default_order
attr_writer :sortable
attr_accessor :name, :totalable, :default_order
attr_writer :sortable, :groupable

include Redmine::I18n include Redmine::I18n


def initialize(name, options={}) def initialize(name, options={})
self.name = name self.name = name
self.sortable = options[:sortable] self.sortable = options[:sortable]
self.groupable = options[:groupable] || false self.groupable = options[:groupable] || false
if groupable == true
self.groupable = name.to_s
end
self.totalable = options[:totalable] || false self.totalable = options[:totalable] || false
self.default_order = options[:default_order] self.default_order = options[:default_order]
@inline = options.key?(:inline) ? options[:inline] : true @inline = options.key?(:inline) ? options[:inline] : true
end end
end end


def groupable?
@groupable
end

# Returns true if the column is sortable, otherwise false # Returns true if the column is sortable, otherwise false
def sortable? def sortable?
@sortable.present? @sortable.present?
def css_classes def css_classes
name name
end end

def group_by_statement
name.to_s
end
end end


class TimestampQueryColumn < QueryColumn class TimestampQueryColumn < QueryColumn
def groupable
if @groupable
Redmine::Database.timestamp_to_date(sortable, User.current.time_zone)
end
def groupable?
group_by_statement.present?
end

def group_by_statement
Redmine::Database.timestamp_to_date(sortable, User.current.time_zone)
end end


def group_value(object) def group_value(object)
def initialize(custom_field, options={}) def initialize(custom_field, options={})
self.name = "cf_#{custom_field.id}".to_sym self.name = "cf_#{custom_field.id}".to_sym
self.sortable = custom_field.order_statement || false self.sortable = custom_field.order_statement || false
self.groupable = custom_field.group_statement || false
self.totalable = options.key?(:totalable) ? !!options[:totalable] : custom_field.totalable? self.totalable = options.key?(:totalable) ? !!options[:totalable] : custom_field.totalable?
@inline = custom_field.full_width_layout? ? false : true @inline = custom_field.full_width_layout? ? false : true
@cf = custom_field @cf = custom_field
end end


def groupable?
group_by_statement.present?
end

def group_by_statement
@cf.group_statement
end

def caption def caption
@cf.name @cf.name
end end


# Returns an array of columns that can be used to group the results # Returns an array of columns that can be used to group the results
def groupable_columns def groupable_columns
available_columns.select {|c| c.groupable}
available_columns.select(&:groupable?)
end end


# Returns a Hash of columns and the key for sorting # Returns a Hash of columns and the key for sorting
end end


def group_by_column def group_by_column
groupable_columns.detect {|c| c.groupable && c.name.to_s == group_by}
groupable_columns.detect {|c| c.groupable? && c.name.to_s == group_by}
end end


def group_by_statement def group_by_statement
group_by_column.try(:groupable)
group_by_column.try(:group_by_statement)
end end


def project_statement def project_statement

Laddar…
Avbryt
Spara