Module: BatchLoad::BatchLoadHelper

Defined in:
app/helpers/batch_load/batch_load_helper.rb

Instance Method Summary collapse

Instance Method Details

#batch_all_objects_count_td(rp) ⇒ Object



64
65
66
# File 'app/helpers/batch_load/batch_load_helper.rb', line 64

def batch_all_objects_count_td(rp)
  (:td, rp.total_objects)
end

#batch_data_created_td(rp) ⇒ Object

Parameters:

  • rp


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/batch_load/batch_load_helper.rb', line 13

def batch_data_created_td(rp)
   :td do
     :table do
      rp.objects.collect { |klass, objs|
        (:tr, (:td, klass), class: 'underlined_elements') +
          objs.collect { |o| (
            :tr,
            (
              :td,
              o.persisted? ? object_link(o) : (:span, object_tag(o), class: 'feedback feedback-warning')
            )
          )
          }.join.html_safe
      }.join.html_safe
    end
  end
end

#batch_data_errors_td(rp, sep = '; ') ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/batch_load/batch_load_helper.rb', line 31

def batch_data_errors_td(rp, sep = '; ')

  errors = {}
  rp.objects.each do |klass, objs| 
    objs.each do |o|
      if !o.valid?
        errors[klass] ||= []
        errors[klass].push o.errors.full_messages.join(sep)
      end
    end
  end

  (:td) do
    (:table, border: true) do
      errors.collect { |klass, objs|
        (:tr, (:th, klass) +
                    objs.collect { |o|
                      (:tr, (:td, o, class: 'feedback feedback-thin feedback-warning').html_safe)
                    }.join.html_safe
                   )
      }.join.html_safe
    end
  end
end


68
69
70
# File 'app/helpers/batch_load/batch_load_helper.rb', line 68

def batch_line_link_td(line)
  (:td, link_to(line, "#line_#{line}", id: "parse_#{line}", data: {'turbolinks': false}).html_safe)
end

#batch_otu_name_td(otu) ⇒ Object



72
73
74
75
76
77
78
# File 'app/helpers/batch_load/batch_load_helper.rb', line 72

def batch_otu_name_td(otu)
  if otu.present?
    (:td, "'#{otu.name}'" + (otu.new_record? ? '<br>(New)' : '').html_safe)
  else
    ('<td></td>').html_safe
  end
end

#batch_parse_errors_td(rp, sep = '; ') ⇒ Object



56
57
58
# File 'app/helpers/batch_load/batch_load_helper.rb', line 56

def batch_parse_errors_td(rp, sep = '; ')
  (:td, rp.parse_errors.join(sep).html_safe)
end

#batch_valid_objects_td(rp) ⇒ Object



60
61
62
# File 'app/helpers/batch_load/batch_load_helper.rb', line 60

def batch_valid_objects_td(rp)
  (:td, rp.has_valid_objects? ? rp.valid_objects.length : 0)
end

#warn_level_input(result) ⇒ Object



3
4
5
6
7
8
9
10
# File 'app/helpers/batch_load/batch_load_helper.rb', line 3

def warn_level_input(result)
  str = 'Import level:<br>&nbsp;'
  options = [radio_button_tag(:import_level, :warn, selected: true) + ' warn']
  options << radio_button_tag(:import_level, :line_strict) + ' line strict' if result.line_strict_level_ok?
  options << radio_button_tag(:import_level, :strict) + ' strict' if result.strict_level_ok?
  str += options.join('<br>&nbsp;').html_safe
  (:div, str.html_safe)
end