Show snapshot rows in report

This commit is contained in:
Urban Rotnik 2020-05-15 13:15:53 +02:00
parent 4dc3d352f7
commit 9536939b3b
3 changed files with 16 additions and 7 deletions

View file

@ -226,6 +226,10 @@ class MyModule < ApplicationRecord
(live_repositories + selected_snapshots).sort_by { |r| r.name.downcase }
end
def selected_snapshot(repository_id)
repository_snapshots.where(parent_id: repository_id).selected.first
end
def unassigned_users
User.find_by_sql(
"SELECT DISTINCT users.id, users.full_name FROM users " +
@ -400,10 +404,14 @@ class MyModule < ApplicationRecord
# in JSON form, suitable for display in handsontable.js
def repository_json_hot(repository_id, order)
data = []
repository_rows
.includes(:created_by)
.where(repository_id: repository_id)
.order(created_at: order).find_each do |row|
r = RepositoryBase.find(repository_id)
rows = if r.is_a?(RepositorySnapshot)
r.repository_rows.includes(:created_by).order(created_at: order)
else
repository_rows.includes(:created_by).where(repository_id: repository_id).order(created_at: order)
end
rows.find_each do |row|
row_json = []
row_json << row.id
row_json << row.name

View file

@ -13,6 +13,8 @@ class RepositorySnapshot < RepositoryBase
validates :status, presence: true
validate :only_one_selected_for_my_module, if: ->(obj) { obj.changed.include? :selected }
scope :selected, -> { where(selected: true) }
def default_columns_count
Constants::REPOSITORY_SNAPSHOT_TABLE_DEFAULT_STATE['length']
end

View file

@ -1,6 +1,5 @@
<% repository ||= Repository.find(element_id) %>
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
<% rows = my_module.repository_rows.where(repository: repository) %>
<% repository ||= my_module.selected_snapshot(element_id) || Repository.find(element_id) %>
<% if order.blank? and @order.present? then order = @order end %>
<% timestamp = Time.current + 1.year - 1.days %>
<% rows_json = my_module.repository_json_hot(repository.id, order) %>
@ -28,7 +27,7 @@
</div>
<div class="report-element-body">
<% if rows_json[:data].count > 0 %>
<input type="hidden" class="hot-table-contents hot-samples" value='<%= rows_json.to_json.force_encoding(Encoding::UTF_8) %>' />
<input type="hidden" class="hot-table-contents hot-samples" value='<%= rows_json.to_json.force_encoding(Encoding::UTF_8) %>' />
<div class="hot-table-container"></div>
<table class="report-common-table-format"></table>
<% else %>