Sha256: 3451866106f4166d73d994d4601d4e8a5c0c2b54640230a76bb43991d6a277ca

Contents?: true

Size: 1.67 KB

Versions: 62

Compression:

Stored size: 1.67 KB

Contents

module Workarea
  module Admin
    module ImportsHelper
      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? ? content_tag(:ul, results) : ''
      end

      def render_field_validation_for(validator)
        name = validator.class.name.demodulize.gsub(/Validator/, '')
        attr_content = content_tag(: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?

        content_tag(:li, result)
      end

      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 = content_tag(:code, name)
        content_tag(:li, "#{name_content}: #{content}".html_safe) if content.present?
      end

      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
    end
  end
end

Version data entries

62 entries across 62 versions & 1 rubygems

Version Path
workarea-admin-3.4.13 app/helpers/workarea/admin/imports_helper.rb
workarea-admin-3.4.12 app/helpers/workarea/admin/imports_helper.rb