Module: Tasks::CollectingEvents::Parse::Stepwise::DatesHelper

Defined in:
app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb

Instance Method Summary collapse

Instance Method Details

#make_dates_matching_table(*pieces, collection) ⇒ Object

“identical matches” result table

Parameters:

  • pieces (String)

    is either piece, or lat, long

  • collection (Scope)

    is a scope of CollectingEvent



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 59

def make_dates_matching_table(*pieces, collection)  # rubocop:disable Metrics/MethodLength
  columns = ['CEID', 'Match', 'Start Date', 'End Date', 'Verbatim Date', 'Select']

  thead = (:thead) do
    (:tr) do
      columns.collect { |column| concat (:th, column) }.join.html_safe
    end
  end

  tbody =  (:tbody) do
    collection.collect { |item|
       (:tr) do
        item_data = ''
        no_verbatim_date = false
        columns.collect.with_index { |column, dex|
          case dex
            when 0 #'CEID'
              item_data = link_to(item.id, item)
            when 1 #'Match'
              item_data = (:vl, pieces.join(' '))
            when 2 # 'Start Date'
              item_data = item.start_date_string
            when 3 # 'End Date'
              item_data = item.end_date_string
            when 4 #'Verbatim Date'
              item_data = (:vd, item.verbatim_date, data: {help: item.verbatim_label})
              no_verbatim_date = !item.verbatim_date.blank?
            when 5 #'Select'
              # check_box_tag(name, value = "1", checked = false, options = {}) public
              options_for = {disabled: no_verbatim_date}
              options_for[:class] = 'selectable_select' unless no_verbatim_date
              options_for[:data] = {help: item.verbatim_label}
              item_data = check_box_tag('selected[]', item.id, false, options_for)
          end
          concat (:td, item_data, align: 'center')
        }.to_s.html_safe
        # item.attributes.collect { |column|
        #   concat content_tag(:td, item.attributes[column])
        # }.to_s.html_safe
      end
    }.join().html_safe
  end

  (:table, thead.concat(tbody), {id: 'matching_table', border: '1'}).html_safe
end

#make_dates_method_headersObject



8
9
10
11
12
13
14
15
16
# File 'app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 8

def make_dates_method_headers
  list = Utilities::Dates::REGEXP_DATES
  selector_row = ''
  list.each_key {|kee|
    selector_row += (:th, Utilities::Dates::REGEXP_DATES[kee][:hdr],
                                data: {help: Utilities::Dates::REGEXP_DATES[kee][:hlp]})
  }
  selector_row.html_safe
end

#make_dates_rows(label, filters) ⇒ Object



30
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/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 30

def make_dates_rows(label, filters)
  return nil if label.nil?
  tests = Utilities::Dates.hunt_dates(label, filters)
  tests.keys.each_with_index do |kee, dex|
    trial = tests[kee]
    method = trial.delete(:method) # extract the method from the trial and save it
    next if trial.blank? # if this leaves the trial empty, skip
    # ActionController::Redirecting.redirect_to dates_index_task_path(collecting_event_id: next_collecting_event_id,
    #                                                                 filters: parse_filters(params))
    verbatim_date_piece = Utilities::Dates::make_verbatim_date_piece(label, trial[:piece])
    (:tr, class: :extract_row) do
      (:td, method, align: 'center', class: :method_value) +
          # content_tag(:td, kee == method ? '' : kee) +
          # content_tag(:td, trial[:piece], class: :piece_value, align: 'center') +
          (:td, verbatim_date_piece, class: :piece_value, align: 'center') +
          (:td, trial[:start_date], class: :start_date_value, align: 'center') +
          (:td, trial[:end_date], class: :end_date_value, align: 'center') +
          (:td, radio_button_tag('select', dex, false, class: :select_dates), align: 'center')
    end
  end.join.html_safe
  # tests.keys.each { |kee|
  # next if tests[kee]
  # }
  # @matching_items = {@collecting_event.id.to_s => tests.first[:piece]}
end

#make_dates_selected_method_boxes(filters = Utilities::Dates::REGEXP_DATES.keys) ⇒ Object

Parameters:

  • filters (Array) (defaults to: Utilities::Dates::REGEXP_DATES.keys)

    must be array of symbols from Utilities::Dates::REGEXP_DATES.keys (optional)



19
20
21
22
23
24
25
26
27
# File 'app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 19

def make_dates_selected_method_boxes(filters = Utilities::Dates::REGEXP_DATES.keys)
  list = Utilities::Dates::REGEXP_DATES
  box_row = ''
  list.each_key { |kee|
    checked = filters.include?(kee)
    box_row += (:td, check_box_tag('filters[]', kee.to_s, checked), align: 'center')
  }
  box_row.html_safe
end

#parse_date_skip(current_collecting_event_id, filters) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
# File 'app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 113

def parse_date_skip(current_collecting_event_id, filters)
  # TODO: Now this has to be bound to next hit
  # filters = Utilities::Geo::REGEXP_COORD.keys
  next_id = Queries::CollectingEventDatesExtractorQuery.new(
      collecting_event_id: current_collecting_event_id,
      filters: filters).all.with_project_id(sessions_current_project_id).first.try(:id)
  if next_id
    button_tag('Skip to next record', value: 'skip', id: 'skip')
  else
    (:span, 'no more matches')
  end + button_tag('Re-evaluate', value: 're_eval', id: 're_eval')
end

#parse_label(label) ⇒ Object



3
4
5
6
# File 'app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 3

def parse_label(label)
  retval = Utilities::Dates.hunt_wrapper(label)
  retval
end

#scan_c_eObject



126
127
128
129
130
131
132
133
134
135
# File 'app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 126

def scan_c_e
  pile = Queries::CollectingEventDatesExtractorQuery.new(
      collecting_event_id: 0,
      filters: []).all.with_project_id(sessions_current_project_id).order(:id)
  pile.each { |c_e|
    trials = Utilities::Dates.hunt_dates_full(c_e.verbatim_label)
    puts(c_e.id)
  }
  pile
end

#show_ce_vl(collecting_event) ⇒ Object



105
106
107
108
109
110
111
# File 'app/helpers/tasks/collecting_events/parse/stepwise/dates_helper.rb', line 105

def show_ce_vl(collecting_event)
  message = 'No collecting event available.'
  unless collecting_event.nil?
    message = collecting_event.verbatim_label
  end
  collecting_event_label_tag(message)
end