mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-13 16:45:18 +08:00
Fix deletion of old reports [SCI-5751]
This commit is contained in:
parent
19300294e9
commit
70f0535dbd
5 changed files with 10 additions and 15 deletions
|
@ -26,9 +26,9 @@ module ReportsHelper
|
||||||
# Render no children
|
# Render no children
|
||||||
elsif element.result?
|
elsif element.result?
|
||||||
# Special handling for result comments
|
# Special handling for result comments
|
||||||
if element.has_children?
|
if element.children.active.present?
|
||||||
children_html.safe_concat render_new_element(true)
|
children_html.safe_concat render_new_element(true)
|
||||||
element.children.each do |child|
|
element.children.active.each do |child|
|
||||||
children_html
|
children_html
|
||||||
.safe_concat render_report_element(child, provided_locals)
|
.safe_concat render_report_element(child, provided_locals)
|
||||||
end
|
end
|
||||||
|
@ -36,8 +36,8 @@ module ReportsHelper
|
||||||
children_html.safe_concat render_new_element(false)
|
children_html.safe_concat render_new_element(false)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if element.has_children?
|
if element.children.active.present?
|
||||||
element.children.each do |child|
|
element.children.active.each do |child|
|
||||||
children_html.safe_concat render_new_element(false)
|
children_html.safe_concat render_new_element(false)
|
||||||
children_html
|
children_html
|
||||||
.safe_concat render_report_element(child, provided_locals)
|
.safe_concat render_report_element(child, provided_locals)
|
||||||
|
|
|
@ -31,10 +31,7 @@ class Report < ApplicationRecord
|
||||||
|
|
||||||
# Report either has many report elements (if grouped by timestamp),
|
# Report either has many report elements (if grouped by timestamp),
|
||||||
# or many module elements (if grouped by module)
|
# or many module elements (if grouped by module)
|
||||||
has_many :report_elements,
|
has_many :report_elements, inverse_of: :report, dependent: :delete_all
|
||||||
-> { where(type_of: ReportExtends::ACTIVE_REPORT_ELEMENTS) },
|
|
||||||
inverse_of: :report,
|
|
||||||
dependent: :delete_all
|
|
||||||
|
|
||||||
DEFAULT_SETTINGS = {
|
DEFAULT_SETTINGS = {
|
||||||
all_tasks: true,
|
all_tasks: true,
|
||||||
|
@ -93,7 +90,7 @@ class Report < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def root_elements
|
def root_elements
|
||||||
report_elements.order(:position).select { |el| el.parent.blank? }
|
report_elements.active.where(parent: nil).order(:position)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Clean report elements from report
|
# Clean report elements from report
|
||||||
|
|
|
@ -18,7 +18,7 @@ class ReportElement < ApplicationRecord
|
||||||
|
|
||||||
# Hierarchical structure representation
|
# Hierarchical structure representation
|
||||||
has_many :children,
|
has_many :children,
|
||||||
-> { where(type_of: ReportExtends::ACTIVE_REPORT_ELEMENTS).order(:position) },
|
-> { order(:position) },
|
||||||
class_name: 'ReportElement',
|
class_name: 'ReportElement',
|
||||||
foreign_key: 'parent_id',
|
foreign_key: 'parent_id',
|
||||||
dependent: :destroy
|
dependent: :destroy
|
||||||
|
@ -36,9 +36,7 @@ class ReportElement < ApplicationRecord
|
||||||
belongs_to :repository, inverse_of: :report_elements, optional: true,
|
belongs_to :repository, inverse_of: :report_elements, optional: true,
|
||||||
foreign_key: :repository_id, class_name: 'RepositoryBase'
|
foreign_key: :repository_id, class_name: 'RepositoryBase'
|
||||||
|
|
||||||
def has_children?
|
scope :active, -> { where(type_of: ReportExtends::ACTIVE_REPORT_ELEMENTS) }
|
||||||
children.length > 0
|
|
||||||
end
|
|
||||||
|
|
||||||
def result?
|
def result?
|
||||||
result_asset? or result_table? or result_text?
|
result_asset? or result_table? or result_text?
|
||||||
|
|
|
@ -25,7 +25,7 @@ module Reports::Docx::DrawExperiment
|
||||||
Reports::HtmlToWordConverter.new(@docx, { scinote_url: scinote_url,
|
Reports::HtmlToWordConverter.new(@docx, { scinote_url: scinote_url,
|
||||||
link_style: link_style }).html_to_word_converter(html)
|
link_style: link_style }).html_to_word_converter(html)
|
||||||
@docx.p
|
@docx.p
|
||||||
subject.children.each do |child|
|
subject.children.active.each do |child|
|
||||||
public_send("draw_#{child.type_of}", child)
|
public_send("draw_#{child.type_of}", child)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -89,7 +89,7 @@ module Reports::Docx::DrawMyModule
|
||||||
end
|
end
|
||||||
|
|
||||||
@docx.p
|
@docx.p
|
||||||
subject.children.each do |child|
|
subject.children.active.each do |child|
|
||||||
public_send("draw_#{child.type_of}", child)
|
public_send("draw_#{child.type_of}", child)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue