mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-24 14:05:32 +08:00
Show snapshot rows in report
This commit is contained in:
parent
4dc3d352f7
commit
9536939b3b
3 changed files with 16 additions and 7 deletions
|
@ -226,6 +226,10 @@ class MyModule < ApplicationRecord
|
||||||
(live_repositories + selected_snapshots).sort_by { |r| r.name.downcase }
|
(live_repositories + selected_snapshots).sort_by { |r| r.name.downcase }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def selected_snapshot(repository_id)
|
||||||
|
repository_snapshots.where(parent_id: repository_id).selected.first
|
||||||
|
end
|
||||||
|
|
||||||
def unassigned_users
|
def unassigned_users
|
||||||
User.find_by_sql(
|
User.find_by_sql(
|
||||||
"SELECT DISTINCT users.id, users.full_name FROM users " +
|
"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
|
# in JSON form, suitable for display in handsontable.js
|
||||||
def repository_json_hot(repository_id, order)
|
def repository_json_hot(repository_id, order)
|
||||||
data = []
|
data = []
|
||||||
repository_rows
|
r = RepositoryBase.find(repository_id)
|
||||||
.includes(:created_by)
|
rows = if r.is_a?(RepositorySnapshot)
|
||||||
.where(repository_id: repository_id)
|
r.repository_rows.includes(:created_by).order(created_at: order)
|
||||||
.order(created_at: order).find_each do |row|
|
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_json << row.id
|
row_json << row.id
|
||||||
row_json << row.name
|
row_json << row.name
|
||||||
|
|
|
@ -13,6 +13,8 @@ class RepositorySnapshot < RepositoryBase
|
||||||
validates :status, presence: true
|
validates :status, presence: true
|
||||||
validate :only_one_selected_for_my_module, if: ->(obj) { obj.changed.include? :selected }
|
validate :only_one_selected_for_my_module, if: ->(obj) { obj.changed.include? :selected }
|
||||||
|
|
||||||
|
scope :selected, -> { where(selected: true) }
|
||||||
|
|
||||||
def default_columns_count
|
def default_columns_count
|
||||||
Constants::REPOSITORY_SNAPSHOT_TABLE_DEFAULT_STATE['length']
|
Constants::REPOSITORY_SNAPSHOT_TABLE_DEFAULT_STATE['length']
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<% repository ||= Repository.find(element_id) %>
|
|
||||||
<% if my_module.blank? and @my_module.present? then my_module = @my_module end %>
|
<% 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 %>
|
<% if order.blank? and @order.present? then order = @order end %>
|
||||||
<% timestamp = Time.current + 1.year - 1.days %>
|
<% timestamp = Time.current + 1.year - 1.days %>
|
||||||
<% rows_json = my_module.repository_json_hot(repository.id, order) %>
|
<% rows_json = my_module.repository_json_hot(repository.id, order) %>
|
||||||
|
@ -28,7 +27,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="report-element-body">
|
<div class="report-element-body">
|
||||||
<% if rows_json[:data].count > 0 %>
|
<% 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>
|
<div class="hot-table-container"></div>
|
||||||
<table class="report-common-table-format"></table>
|
<table class="report-common-table-format"></table>
|
||||||
<% else %>
|
<% else %>
|
||||||
|
|
Loading…
Add table
Reference in a new issue