Merge pull request #3357 from okriuchykhin/ok_SCI_5751

Fix deletion of old reports [SCI-5751]
This commit is contained in:
Alex Kriuchykhin 2021-05-28 13:59:36 +02:00 committed by GitHub
commit cdbcbd0409
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 10 additions and 15 deletions

View file

@ -26,9 +26,9 @@ module ReportsHelper
# Render no children
elsif element.result?
# Special handling for result comments
if element.has_children?
if element.children.active.present?
children_html.safe_concat render_new_element(true)
element.children.each do |child|
element.children.active.each do |child|
children_html
.safe_concat render_report_element(child, provided_locals)
end
@ -36,8 +36,8 @@ module ReportsHelper
children_html.safe_concat render_new_element(false)
end
else
if element.has_children?
element.children.each do |child|
if element.children.active.present?
element.children.active.each do |child|
children_html.safe_concat render_new_element(false)
children_html
.safe_concat render_report_element(child, provided_locals)

View file

@ -31,10 +31,7 @@ class Report < ApplicationRecord
# Report either has many report elements (if grouped by timestamp),
# or many module elements (if grouped by module)
has_many :report_elements,
-> { where(type_of: ReportExtends::ACTIVE_REPORT_ELEMENTS) },
inverse_of: :report,
dependent: :delete_all
has_many :report_elements, inverse_of: :report, dependent: :delete_all
DEFAULT_SETTINGS = {
all_tasks: true,
@ -93,7 +90,7 @@ class Report < ApplicationRecord
end
def root_elements
report_elements.order(:position).select { |el| el.parent.blank? }
report_elements.active.where(parent: nil).order(:position)
end
# Clean report elements from report

View file

@ -18,7 +18,7 @@ class ReportElement < ApplicationRecord
# Hierarchical structure representation
has_many :children,
-> { where(type_of: ReportExtends::ACTIVE_REPORT_ELEMENTS).order(:position) },
-> { order(:position) },
class_name: 'ReportElement',
foreign_key: 'parent_id',
dependent: :destroy
@ -36,9 +36,7 @@ class ReportElement < ApplicationRecord
belongs_to :repository, inverse_of: :report_elements, optional: true,
foreign_key: :repository_id, class_name: 'RepositoryBase'
def has_children?
children.length > 0
end
scope :active, -> { where(type_of: ReportExtends::ACTIVE_REPORT_ELEMENTS) }
def result?
result_asset? or result_table? or result_text?

View file

@ -25,7 +25,7 @@ module Reports::Docx::DrawExperiment
Reports::HtmlToWordConverter.new(@docx, { scinote_url: scinote_url,
link_style: link_style }).html_to_word_converter(html)
@docx.p
subject.children.each do |child|
subject.children.active.each do |child|
public_send("draw_#{child.type_of}", child)
end
end

View file

@ -89,7 +89,7 @@ module Reports::Docx::DrawMyModule
end
@docx.p
subject.children.each do |child|
subject.children.active.each do |child|
public_send("draw_#{child.type_of}", child)
end