mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 13:14:29 +08:00
Hound is love, Hound is life
This commit is contained in:
parent
9e45d197df
commit
42f7b4f68d
3 changed files with 43 additions and 19 deletions
|
@ -77,7 +77,7 @@ module ReportActions
|
||||||
elements = elements.select{|_,v| v == '1'}.keys
|
elements = elements.select{|_,v| v == '1'}.keys
|
||||||
elements.map!{|el| el.gsub('module_', '')}.map!{|el| el.split('_')}
|
elements.map!{|el| el.gsub('module_', '')}.map!{|el| el.split('_')}
|
||||||
elements.map!{|el| [el[0].to_sym, el[1].to_i]}
|
elements.map!{|el| [el[0].to_sym, el[1].to_i]}
|
||||||
break if elements.size > 0
|
break unless elements.empty?
|
||||||
else
|
else
|
||||||
present = in_params?("module_#{element}".to_sym) ||
|
present = in_params?("module_#{element}".to_sym) ||
|
||||||
in_params?(element.to_sym)
|
in_params?(element.to_sym)
|
||||||
|
@ -87,14 +87,14 @@ module ReportActions
|
||||||
end
|
end
|
||||||
end
|
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
|
if contents.children
|
||||||
contents.collection(my_module, params).each do |report_el|
|
contents.collection(my_module, params).each do |report_el|
|
||||||
res << generate_new_el(false)
|
res << generate_new_el(false)
|
||||||
locals = contents.parse_locals([report_el])
|
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(
|
el = generate_el(
|
||||||
"reports/elements/my_module_#{contents.element.to_s.singularize}"\
|
"reports/elements/my_module_#{contents.element.to_s.singularize}"\
|
||||||
"_element.html.erb",
|
"_element.html.erb",
|
||||||
|
@ -112,7 +112,7 @@ module ReportActions
|
||||||
file_name = contents.element if contents.element == :samples
|
file_name = contents.element if contents.element == :samples
|
||||||
res << generate_new_el(false)
|
res << generate_new_el(false)
|
||||||
locals = contents.parse_locals([my_module, :asc])
|
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(
|
res << generate_el(
|
||||||
"reports/elements/my_module_#{file_name}_element.html.erb",
|
"reports/elements/my_module_#{file_name}_element.html.erb",
|
||||||
locals
|
locals
|
||||||
|
|
|
@ -48,7 +48,9 @@ class ReportElement < ActiveRecord::Base
|
||||||
# Get the referenced elements (previously, element's type_of must be set)
|
# Get the referenced elements (previously, element's type_of must be set)
|
||||||
def element_references
|
def element_references
|
||||||
ReportExtends::ELEMENT_REFERENCES.each do |el_ref|
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -67,7 +69,15 @@ class ReportElement < ActiveRecord::Base
|
||||||
# removes element that are archived or deleted
|
# removes element that are archived or deleted
|
||||||
def clean_removed_or_archived_elements
|
def clean_removed_or_archived_elements
|
||||||
parent_model = ''
|
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|
|
.each do |el|
|
||||||
parent_model = el if send el
|
parent_model = el if send el
|
||||||
end
|
end
|
||||||
|
@ -85,11 +95,10 @@ class ReportElement < ActiveRecord::Base
|
||||||
|
|
||||||
def has_one_of_referenced_elements
|
def has_one_of_referenced_elements
|
||||||
element_references.each do |el|
|
element_references.each do |el|
|
||||||
if el.nil?
|
next unless el.nil?
|
||||||
errors.add(:base,
|
errors.add(:base,
|
||||||
'Report element doesn\'t have correct element references.')
|
'Report element doesn\'t have correct element references.')
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,8 +19,8 @@ module ReportExtends
|
||||||
# collection of elements
|
# collection of elements
|
||||||
# :singular => true by defaut; change the enum type to singular - needed when
|
# :singular => true by defaut; change the enum type to singular - needed when
|
||||||
# querying partials by name
|
# querying partials by name
|
||||||
# :has_many => false by default; whether the element can have many manifestations,
|
# :has_many => false by default; whether the element can have many
|
||||||
# and its id will be appended.
|
# manifestations, and its id will be appended.
|
||||||
|
|
||||||
ModuleElement = Struct.new(:values,
|
ModuleElement = Struct.new(:values,
|
||||||
:element,
|
:element,
|
||||||
|
@ -29,7 +29,13 @@ module ReportExtends
|
||||||
:coll,
|
:coll,
|
||||||
:singular,
|
:singular,
|
||||||
:has_many) do
|
: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)
|
super(values, element, children, locals, coll, singular, has_many)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -87,7 +93,7 @@ module ReportExtends
|
||||||
ModuleElement.new([:activity],
|
ModuleElement.new([:activity],
|
||||||
:activity,
|
:activity,
|
||||||
false,
|
false,
|
||||||
[:my_module, :order]),
|
%i(my_module order)),
|
||||||
ModuleElement.new([:samples],
|
ModuleElement.new([:samples],
|
||||||
:samples,
|
:samples,
|
||||||
false,
|
false,
|
||||||
|
@ -112,7 +118,10 @@ module ReportExtends
|
||||||
step_comments
|
step_comments
|
||||||
result_comments)
|
result_comments)
|
||||||
# sets local :my_module to the listed my_module child elements
|
# 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
|
# sets local name to first element of the listed elements
|
||||||
FIRST_PART_ELEMENTS = %w(result_comments
|
FIRST_PART_ELEMENTS = %w(result_comments
|
||||||
|
@ -153,7 +162,10 @@ module ReportExtends
|
||||||
end,
|
end,
|
||||||
['my_module_id']
|
['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(
|
ElementReference.new(
|
||||||
proc do |report_element|
|
proc do |report_element|
|
||||||
report_element.step? || report_element.step_comments?
|
report_element.step? || report_element.step_comments?
|
||||||
|
@ -195,7 +207,10 @@ module ReportExtends
|
||||||
end,
|
end,
|
||||||
['my_module_id']
|
['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(
|
ElementReference.new(
|
||||||
proc do |report_element|
|
proc do |report_element|
|
||||||
report_element.step? ||
|
report_element.step? ||
|
||||||
|
|
Loading…
Add table
Reference in a new issue