This commit is contained in:
zmagod 2017-03-09 10:51:54 +01:00
parent 49f91184da
commit 9939d8df06
4 changed files with 16 additions and 16 deletions

View file

@ -1,7 +1,6 @@
module ReportActions
extend ActiveSupport::Concern
def in_params?(val)
params.include? val and params[val] == '1'
end
@ -83,7 +82,9 @@ module ReportActions
.singularize}_element.html.erb",
contents.parse_locals([report_el])
)
el[:children] = generate_step_contents_json(report_el) if contents.element == :step
if contents.element == :step
el[:children] = generate_step_contents_json(report_el)
end
el[:children] = generate_result_contents_json(report_el)
res << el
end

View file

@ -33,13 +33,16 @@ module ReportsHelper
end
file_name = element.type_of
file_name = "my_module_#{element.type_of}" if element.type_of.in? %w(step result_asset result_table result_text)
if element.type_of.in? %w(step result_asset result_table result_text)
file_name = "my_module_#{element.type_of.singularize}"
end
view = "reports/elements/#{file_name}_element.html.erb"
locals = provided_locals.nil? ? {} : provided_locals.clone
locals[:children] = children_html
# ReportExtends is located in config/initializers/extends/report_extends.rb
ReportElement.type_ofs.keys.each do |type|
next unless element.send("#{type}?")
local_sym = type.split('_').last.to_sym

View file

@ -15,8 +15,12 @@ class ReportElement < ActiveRecord::Base
belongs_to :report, inverse_of: :report_elements
# Hierarchical structure representation
has_many :children, -> { order(:position) }, class_name: "ReportElement", foreign_key: "parent_id", dependent: :destroy
belongs_to :parent, class_name: "ReportElement"
has_many :children,
-> { order(:position) },
class_name: 'ReportElement',
foreign_key: 'parent_id',
dependent: :destroy
belongs_to :parent, class_name: 'ReportElement'
# References to various report entities
belongs_to :project, inverse_of: :report_elements
@ -49,16 +53,6 @@ class ReportElement < ActiveRecord::Base
# Set the element reference (previously, element's type_of must be set)
def set_element_reference(ref_id)
# check = true
# ReportExtends::REFERENCE_ELEMENTS_IDS.each do |element|
# next unless check
# ReportExtends::SET_ELEMENT_REFERENCES_LIST.each do |el_ref|
# check = el_ref.check(self)
# next unless check
# check = false
# self.send("#{element}=", ref_id)
# end
# end
ReportExtends::SET_ELEMENT_REFERENCES_LIST.each do |el_ref|
check = el_ref.check(self)
next unless check
@ -97,7 +91,8 @@ class ReportElement < ActiveRecord::Base
table
].count { |r| r.present? }
if num_of_refs != 1
errors.add(:base, "Report element must have exactly one element reference.")
errors.add(:base,
'Report element must have exactly one element reference.')
end
end
end

View file

@ -78,6 +78,7 @@ module ReportExtends
# method: render_report_element
# adds :order local to listed elements views
# ADD REPORT ELEMENT TYPE WHICH YOU WANT TO PASS 'ORDER' LOCAL IN THE PARTIAL
SORTED_ELEMENTS = %w(my_module_activity
my_module_samples
step_comments