issue-filter-by-spent-time-3.diff

moves the position of "Spent time" filter - Go MAEDA, 2018-05-13 14:35

Download (2.69 KB)

View differences:

app/models/issue_query.rb
134 134
    add_available_filter "start_date", :type => :date
135 135
    add_available_filter "due_date", :type => :date
136 136
    add_available_filter "estimated_hours", :type => :float
137

  
138
    if User.current.allowed_to?(:view_time_entries, project, :global => true)
139
      add_available_filter "spent_time", :type => :float, :label => :label_spent_time
140
    end
141

  
137 142
    add_available_filter "done_ratio", :type => :integer
138 143

  
139 144
    if User.current.allowed_to?(:set_issues_private, nil, :global => true) ||
......
380 385
    "#{neg} EXISTS (#{subquery})"
381 386
  end
382 387

  
388
  def sql_for_spent_time_field(field, operator, value)
389
    first, second = value.first.to_f, value.second.to_f
390

  
391
    sql_op =
392
      case operator
393
      when "=", ">=", "<=" ;  "#{operator} #{first}"
394
      when "><"            ;  "BETWEEN #{first} AND #{second}"
395
      when "*"             ;  "> 0"
396
      when "!*"            ;  "= 0"
397
      else                 ; return nil
398
      end
399

  
400
    "COALESCE((" +
401
      "SELECT ROUND(CAST(SUM(hours) AS DECIMAL(30,3)), 2) " +
402
      "FROM #{TimeEntry.table_name} " +
403
      "WHERE issue_id = #{Issue.table_name}.id), 0) #{sql_op}"
404
  end
405

  
383 406
  def sql_for_watcher_id_field(field, operator, value)
384 407
    db_table = Watcher.table_name
385 408
    "#{Issue.table_name}.id #{ operator == '=' ? 'IN' : 'NOT IN' } (SELECT #{db_table}.watchable_id FROM #{db_table} WHERE #{db_table}.watchable_type='Issue' AND " +
test/unit/query_test.rb
2144 2144

  
2145 2145
    assert_equal ['1','2','3','4','5','6'], query.available_filters['status_id'][:values].map(&:second)
2146 2146
  end
2147

  
2148
  def test_issue_query_filter_by_spent_time
2149
    query = IssueQuery.new(:name => '_')
2150

  
2151
    query.filters = {'spent_time' => {:operator => '*', :values => ['']}}
2152
    assert_equal query.issues.pluck(:id), [3, 1]
2153

  
2154
    query.filters = {'spent_time' => {:operator => '!*', :values => ['']}}
2155
    assert_equal query.issues.pluck(:id), [13, 12, 11, 8, 7, 5, 2]
2156

  
2157
    query.filters = {'spent_time' => {:operator => '>=', :values => ['10']}}
2158
    assert_equal query.issues.pluck(:id), [1]
2159

  
2160
    query.filters = {'spent_time' => {:operator => '<=', :values => ['10']}}
2161
    assert_equal query.issues.pluck(:id), [13, 12, 11, 8, 7, 5, 3, 2]
2162

  
2163
    query.filters = {'spent_time' => {:operator => '><', :values => ['1', '2']}}
2164
    assert_equal query.issues.pluck(:id), [3]
2165
  end
2147 2166
end