Skip to content

Commit

Permalink
Merge pull request #18938 from lpichler/add_styling_info_for_report_r…
Browse files Browse the repository at this point in the history
…esult_api

Expand value to hash format with styling information for Report result API

(cherry picked from commit e629182)

https://bugzilla.redhat.com/show_bug.cgi?id=1678150
  • Loading branch information
kbrock authored and simaishi committed Aug 5, 2019
1 parent 8a52cca commit a011894
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions app/models/miq_report.rb
Expand Up @@ -283,16 +283,16 @@ def col_format_hash
@col_format_hash ||= col_order.zip(col_formats).to_h
end

def format_row(row, allowed_columns = nil)
def format_row(row, allowed_columns = nil, expand_value_format = nil)
@tz ||= get_time_zone(Time.zone)

row.map do |key, _|
[key, allowed_columns.nil? || allowed_columns&.include?(key) ? format_column(key, row, @tz, col_format_hash[key]) : row[key]]
value = allowed_columns.nil? || allowed_columns&.include?(key) ? format_column(key, row, @tz, col_format_hash[key]) : row[key]
[key, expand_value_format.present? ? { :value => value, :style_class => get_style_class(key, row, @tz) } : value]
end.to_h
end

def format_result_set(result_set, skip_columns = nil)
result_set.map { |row| format_row(row, skip_columns) }
def format_result_set(result_set, skip_columns = nil, hash_value_format = nil)
result_set.map { |row| format_row(row, skip_columns, hash_value_format) }
end

def filter_result_set(result_set, options)
Expand Down
3 changes: 2 additions & 1 deletion app/models/miq_report_result/result_set_operations.rb
Expand Up @@ -10,6 +10,7 @@ def result_set_for_reporting(report_result, options)
report = report_result.report_or_miq_report
sorting_columns = report.validate_sorting_columns(options[:sort_by])
result_set = report_result.result_set

count_of_full_result_set = result_set.count
if result_set.present? && report
if options.key?(:filter_column) && options.key?(:filter_string)
Expand All @@ -22,7 +23,7 @@ def result_set_for_reporting(report_result, options)
result_set = apply_limit_and_offset(result_set, options)
end

{:result_set => report.format_result_set(result_set, allowed_columns_to_format), :count_of_full_result_set => count_of_full_result_set}
{:result_set => report.format_result_set(result_set, allowed_columns_to_format, options[:expand_value_format]), :count_of_full_result_set => count_of_full_result_set}
end
end
end

0 comments on commit a011894

Please sign in to comment.