Hound is love, Hound is life

This commit is contained in:
Luka Murn 2017-06-07 18:22:15 +02:00
parent 9e45d197df
commit 42f7b4f68d
3 changed files with 43 additions and 19 deletions

View file

@ -77,7 +77,7 @@ module ReportActions
elements = elements.select{|_,v| v == '1'}.keys
elements.map!{|el| el.gsub('module_', '')}.map!{|el| el.split('_')}
elements.map!{|el| [el[0].to_sym, el[1].to_i]}
break if elements.size > 0
break unless elements.empty?
else
present = in_params?("module_#{element}".to_sym) ||
in_params?(element.to_sym)
@ -87,14 +87,14 @@ module ReportActions
end
end
end
next unless elements.size > 0
next if elements.empty?
elements.each do |element, el_id|
elements.each do |_, el_id|
if contents.children
contents.collection(my_module, params).each do |report_el|
res << generate_new_el(false)
locals = contents.parse_locals([report_el])
locals.merge!({ element_id: el_id }) if el_id
locals[:element_id] = el_id if el_id
el = generate_el(
"reports/elements/my_module_#{contents.element.to_s.singularize}"\
"_element.html.erb",
@ -112,7 +112,7 @@ module ReportActions
file_name = contents.element if contents.element == :samples
res << generate_new_el(false)
locals = contents.parse_locals([my_module, :asc])
locals.merge!({ element_id: el_id }) if el_id
locals[:element_id] = el_id if el_id
res << generate_el(
"reports/elements/my_module_#{file_name}_element.html.erb",
locals

View file

@ -48,7 +48,9 @@ class ReportElement < ActiveRecord::Base
# Get the referenced elements (previously, element's type_of must be set)
def element_references
ReportExtends::ELEMENT_REFERENCES.each do |el_ref|
return el_ref.elements.map { |el| eval(el.gsub('_id', '')) } if el_ref.check(self)
if el_ref.check(self)
return el_ref.elements.map { |el| eval(el.gsub('_id', '')) }
end
end
end
@ -67,7 +69,15 @@ class ReportElement < ActiveRecord::Base
# removes element that are archived or deleted
def clean_removed_or_archived_elements
parent_model = ''
%w(project experiment my_module step result checklist asset table repository)
%w(project
experiment
my_module
step
result
checklist
asset
table
repository)
.each do |el|
parent_model = el if send el
end
@ -85,11 +95,10 @@ class ReportElement < ActiveRecord::Base
def has_one_of_referenced_elements
element_references.each do |el|
if el.nil?
errors.add(:base,
'Report element doesn\'t have correct element references.')
break
end
next unless el.nil?
errors.add(:base,
'Report element doesn\'t have correct element references.')
break
end
end
end

View file

@ -19,8 +19,8 @@ module ReportExtends
# collection of elements
# :singular => true by defaut; change the enum type to singular - needed when
# querying partials by name
# :has_many => false by default; whether the element can have many manifestations,
# and its id will be appended.
# :has_many => false by default; whether the element can have many
# manifestations, and its id will be appended.
ModuleElement = Struct.new(:values,
:element,
@ -29,7 +29,13 @@ module ReportExtends
:coll,
:singular,
:has_many) do
def initialize(values, element, children, locals, coll = nil, singular = true, has_many = false)
def initialize(values,
element,
children,
locals,
coll = nil,
singular = true,
has_many = false)
super(values, element, children, locals, coll, singular, has_many)
end
@ -87,7 +93,7 @@ module ReportExtends
ModuleElement.new([:activity],
:activity,
false,
[:my_module, :order]),
%i(my_module order)),
ModuleElement.new([:samples],
:samples,
false,
@ -112,7 +118,10 @@ module ReportExtends
step_comments
result_comments)
# sets local :my_module to the listed my_module child elements
MY_MODULE_ELEMENTS = %w(my_module my_module_activity my_module_samples my_module_repository)
MY_MODULE_ELEMENTS = %w(my_module
my_module_activity
my_module_samples
my_module_repository)
# sets local name to first element of the listed elements
FIRST_PART_ELEMENTS = %w(result_comments
@ -153,7 +162,10 @@ module ReportExtends
end,
['my_module_id']
),
ElementReference.new(proc(&:my_module_repository?), ['my_module_id', 'repository_id']),
ElementReference.new(
proc(&:my_module_repository?),
%w(my_module_id repository_id)
),
ElementReference.new(
proc do |report_element|
report_element.step? || report_element.step_comments?
@ -195,7 +207,10 @@ module ReportExtends
end,
['my_module_id']
),
ElementReference.new(proc(&:my_module_repository?), ['my_module_id', 'repository_id']),
ElementReference.new(
proc(&:my_module_repository?),
%w(my_module_id repository_id)
),
ElementReference.new(
proc do |report_element|
report_element.step? ||