Module: ConveyancesHelper

Includes:
RecordNavigationHelper
Defined in:
app/helpers/conveyances_helper.rb

Instance Method Summary collapse

Methods included from RecordNavigationHelper

for, #parent_records

Instance Method Details

#conveyance_autocomplete_tag(conveyance) ⇒ Object



9
10
11
# File 'app/helpers/conveyances_helper.rb', line 9

def conveyance_autocomplete_tag(conveyance)
  conveyance_tag(conveyance)
end

#conveyance_tag(conveyance) ⇒ Object



4
5
6
7
# File 'app/helpers/conveyances_helper.rb', line 4

def conveyance_tag(conveyance)
  return nil if conveyance.nil?
  [ sound_tag(conveyance.sound), 'on', object_tag(conveyance.conveyance_object)  ].compact.join(' ').html_safe
end

#conveyances_list_tag(object) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/conveyances_helper.rb', line 18

def conveyances_list_tag(object)
  if object.conveyances.any?
    object.conveyances.collect{|c|
      (:div) do
        safe_join([
          player_for_sound(c.sound),
          (:div, conveyance_tag(c))
        ])
      end
    }.join.html_safe
  end
end

#label_for_conveyance(conveyance) ⇒ Object



13
14
15
16
# File 'app/helpers/conveyances_helper.rb', line 13

def label_for_conveyance(conveyance)
  return nil if conveyance.nil?
  [ label_for_sound(conveyance.sound), 'on', label_for(conveyance.conveyance_object)  ].compact.join(' ')
end

#next_records(conveyance) ⇒ Object

Returns !!Array!!.

Returns:

  • !!Array!!



62
63
64
65
66
67
68
69
70
71
72
# File 'app/helpers/conveyances_helper.rb', line 62

def next_records(conveyance)
  # !! Note we only return conveyances on Otus currently.
  c = ::Conveyance
    .joins("JOIN otus ON conveyances.conveyance_object_type = 'Otu' AND conveyances.conveyance_object_id = otus.id")
    .where(project_id: conveyance.project_id)
    .where('conveyances.id > ?', conveyance.id)
    .order(:id)
    .first

  [c].compact
end

#player_for_sound(sound) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/helpers/conveyances_helper.rb', line 31

def player_for_sound(sound)
  sound_path =
    ActiveStorage::Blob.service.path_for(sound.sound_file.attachment.key)
  if File.exist?(sound_path)
    audio_tag(sound.sound_file, controls: true)
  else
    if Rails.env.production?
      raise TaxonWorks::Error,
        "Sound #{sound.id} missing its sound file at '#{sound.sound_file}'"
    else
      (:div, style: 'color: red') do
        'Missing sound file'
      end
    end
  end
end

#previous_records(conveyance) ⇒ Object

Returns !!Array!!.

Returns:

  • !!Array!!



49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/conveyances_helper.rb', line 49

def previous_records(conveyance)
  # !! Note we only return conveyances on Otus currently.
  c = ::Conveyance
    .joins("JOIN otus ON conveyances.conveyance_object_type = 'Otu' AND conveyances.conveyance_object_id = otus.id")
    .where(project_id: conveyance.project_id)
    .where('conveyances.id < ?', conveyance.id)
    .order(id: :desc)
    .first

  [c].compact
end