From 9536939b3b5d36e77786e74630ee16da56cb9afa Mon Sep 17 00:00:00 2001 From: Urban Rotnik Date: Fri, 15 May 2020 13:15:53 +0200 Subject: [PATCH] Show snapshot rows in report --- app/models/my_module.rb | 16 ++++++++++++---- app/models/repository_snapshot.rb | 2 ++ .../_my_module_repository_element.html.erb | 5 ++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/models/my_module.rb b/app/models/my_module.rb index 43c7b765d..be9586c1f 100644 --- a/app/models/my_module.rb +++ b/app/models/my_module.rb @@ -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 diff --git a/app/models/repository_snapshot.rb b/app/models/repository_snapshot.rb index b0bacbc62..eb1fff240 100644 --- a/app/models/repository_snapshot.rb +++ b/app/models/repository_snapshot.rb @@ -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 diff --git a/app/views/reports/elements/_my_module_repository_element.html.erb b/app/views/reports/elements/_my_module_repository_element.html.erb index 3badd3ede..c47eb62c9 100644 --- a/app/views/reports/elements/_my_module_repository_element.html.erb +++ b/app/views/reports/elements/_my_module_repository_element.html.erb @@ -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 @@
<% if rows_json[:data].count > 0 %> - +
<% else %>