Module: Workarea::Admin::ImportsHelper

Defined in:
app/helpers/workarea/admin/imports_helper.rb

Instance Method Summary collapse

Instance Method Details

#render_embedded_validation_for(klass, validator) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'app/helpers/workarea/admin/imports_helper.rb', line 32

def render_embedded_validation_for(klass, validator)
  name = validator.attributes.first.to_s
  relation = klass.relations[name]

  return unless relation.embedded?

  content = render_validations_for(relation.klass)
  name_content = (:code, name)
  (:li, "#{name_content}: #{content}".html_safe) if content.present?
end

#render_field_validation_for(validator) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/helpers/workarea/admin/imports_helper.rb', line 17

def render_field_validation_for(validator)
  name = validator.class.name.demodulize.gsub(/Validator/, '')
  attr_content = (:code, validator.attributes.to_sentence)

  result = t(
    'workarea.admin.imports_helper.field_validation_html',
    type: name.downcase,
    field: attr_content
  ).html_safe

  result << " #{validator.options}" if validator.options.present?

  (:li, result)
end

#render_import_format_notes_for(format) ⇒ Object



43
44
45
46
47
# File 'app/helpers/workarea/admin/imports_helper.rb', line 43

def render_import_format_notes_for(format)
  render("workarea/admin/data_file_imports/#{format.slug}_notes")
rescue ActionView::MissingTemplate
  # It's ok if there aren't any notes to render
end

#render_validations_for(klass) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/helpers/workarea/admin/imports_helper.rb', line 4

def render_validations_for(klass)
  results = ''.html_safe
  embedded_validators = klass.validators.select do |valiator|
    valiator.is_a?(Mongoid::Validatable::AssociatedValidator)
  end
  field_validators = klass.validators - embedded_validators

  field_validators.each { |v| results << render_field_validation_for(v) }
  embedded_validators.each { |v| results << render_embedded_validation_for(klass, v).to_s }

  results.present? ? (:ul, results) : ''
end