Project

General

Profile

User story #1161 » issue_query_prepend.diff

Redmine Smile, 2016-06-07 12:05

View differences:

plugins/scrum/init.rb
15 15
ApplicationHelper.send(:include, Scrum::ApplicationHelperPatch)
16 16
CalendarsController.send(:include, Scrum::CalendarsControllerPatch)
17 17
Issue.send(:include, Scrum::IssuePatch)
18
IssueQuery.send(:include, Scrum::IssueQueryPatch)
18
IssueQuery.send(:prepend, Scrum::IssueQueryPatch)
19 19
IssuesController.send(:include, Scrum::IssuesControllerPatch)
20 20
IssueStatus.send(:include, Scrum::IssueStatusPatch)
21 21
Journal.send(:include, Scrum::JournalPatch)
plugins/scrum/lib/scrum/issue_query_patch.rb
9 9

  
10 10
module Scrum
11 11
  module IssueQueryPatch
12
    def self.included(base)
12
    def self.prepended(base)
13 13
      base.class_eval do
14 14

  
15
        # Transparent Overload
15 16
        self.available_columns << QueryColumn.new(:sprint,
16 17
                                                  :sortable => lambda {Sprint.fields_for_order_statement},
17 18
                                                  :groupable => true)
19
        # Transparent Overload
18 20
        self.available_columns << QueryColumn.new(:position,
19 21
                                                  :sortable => "#{Issue.table_name}.position")
22
      end
20 23

  
21
        def initialize_available_filters_with_scrum
22
          filters = initialize_available_filters_without_scrum
23
          if project
24
            sprints = project.sprints_and_product_backlog
25
            if sprints.any?
26
              add_available_filter "sprint_id",
27
                                   :type => :list_optional,
28
                                   :values => sprints.sort.collect{|s| [s.name, s.id.to_s]}
29
              add_available_filter "position",
30
                                   :type => :integer
31
              add_associations_custom_fields_filters :sprint
32
            end
24
      def initialize_available_filters
25
        filters = super
26
        if project
27
          sprints = project.sprints_and_product_backlog
28
          if sprints.any?
29
            add_available_filter "sprint_id",
30
                                 :type => :list_optional,
31
                                 :values => sprints.sort.collect{|s| [s.name, s.id.to_s]}
32
            add_available_filter "position",
33
                                 :type => :integer
34
            add_associations_custom_fields_filters :sprint
33 35
          end
34
          filters
35 36
        end
36
        alias_method_chain :initialize_available_filters, :scrum
37
        filters
38
      end
37 39

  
38
        def issues_with_scrum(options = {})
39
          options[:include] ||= {}
40
          options[:include] << :sprint
41
          issues_without_scrum(options)
42
        end
43
        alias_method_chain :issues, :scrum
40
      # Transparent Overload
41
      def issues(options = {})
42
        options[:include] ||= {}
43
        options[:include] << :sprint
44
        super(options)
45
      end
44 46

  
45
        def issue_ids_with_scrum(options = {})
46
          options[:include] ||= {}
47
          options[:include] << :sprint
48
          issue_ids_without_scrum(options)
49
        end
50
        alias_method_chain :issue_ids, :scrum
47
      # Transparent Overload
48
      def issue_ids(options = {})
49
        options[:include] ||= {}
50
        options[:include] << :sprint
51
        super(options)
52
      end
51 53

  
52
        def available_columns_with_scrum()
53
          if !@available_columns
54
            @available_columns = available_columns_without_scrum
55
            index = nil
56
            @available_columns.each_with_index {|column, i| index = i if column.name == :estimated_hours}
57
            index = (index ? index + 1 : -1)
58
            # insert the column after estimated_hours or at the end
59
            @available_columns.insert index, QueryColumn.new(:pending_effort,
60
              :sortable => "COALESCE((SELECT effort FROM #{PendingEffort.table_name} WHERE #{PendingEffort.table_name}.issue_id = #{Issue.table_name}.id ORDER BY #{PendingEffort.table_name}.date DESC LIMIT 1), 0)",
61
              :default_order => 'desc'
62
            )
63
          end
64
          return @available_columns
65
        end
66
        alias_method_chain :available_columns, :scrum
54
      def available_columns
55
        if !@available_columns
56
          @available_columns = super
57
          index = nil
58
          @available_columns.each_with_index {|column, i| index = i if column.name == :estimated_hours}
59
          index = (index ? index + 1 : -1)
67 60

  
61
          # insert the pending_effort column after estimated_hours or at the end
62
          @available_columns.insert index, QueryColumn.new(:pending_effort,
63
            :sortable => "COALESCE((SELECT effort FROM #{PendingEffort.table_name} WHERE #{PendingEffort.table_name}.issue_id = #{Issue.table_name}.id ORDER BY #{PendingEffort.table_name}.date DESC LIMIT 1), 0)",
64
            :default_order => 'desc'
65
          )
66
        end
67
        return @available_columns
68 68
      end
69 69
    end
70 70
  end
    (1-1/1)