Module: SqedDepictionsHelper

Defined in:
app/helpers/sqed_depictions_helper.rb

Instance Method Summary (collapse)

Instance Method Details



91
92
93
# File 'app/helpers/sqed_depictions_helper.rb', line 91

def sqed_card_link(sqed_depiction)
  link_to(sqed_depiction.id, sqed_depiction_breakdown_task_path(sqed_depiction), 'data-turbolinks' => 'false') 
end

- (Object) sqed_depiction_collecting_event_label_thumb_preview(sqed_depiction)



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

def sqed_depiction_collecting_event_label_thumb_preview(sqed_depiction)
  return (:div, 'no depiction provided', class: :warning) if sqed_depiction.nil?
  section = sqed_depiction.collecting_event_sections.first
  return (:div, 'no collecting event label data imaged', class: :warning) if section.nil?

  begin
    result = SqedToTaxonworks::Result.new(
      depiction_id: sqed_depiction.depiction.id,
    )

   return image_tag(result.image_path_for_large_image(section), id: 'little1', class: 'little_image clickable') 
  rescue
    return (:div, link_to('Error parsing.', depiction_path(sqed_depiction.depiction)), class: :warning) 
  end
end


10
11
12
13
# File 'app/helpers/sqed_depictions_helper.rb', line 10

def sqed_depiction_link(sqed_depiction)
  return nil if sqed_depiction.nil?
  link_to(sqed_depiction_tag(sqed_depiction), sqed_depiction.depiction)
end

- (Object) sqed_depiction_tag(sqed_depiction)



5
6
7
8
# File 'app/helpers/sqed_depictions_helper.rb', line 5

def sqed_depiction_tag(sqed_depiction)
  return nil if sqed_depiction.nil?
  image_tag(sqed_depiction.depiction.image.image_file.url(:thumb)) + ' on ' + object_tag(sqed_depiction.depiction.depiction_object.metamorphosize)
end

- (Object) sqed_depiction_thumb_navigator(sqed_depiction, before = 3, after = 3)



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

def sqed_depiction_thumb_navigator(sqed_depiction, before = 3, after = 3)
  around = sqed_depiction.nearby_sqed_depictions(before, after)
  
  around[:before].reverse.collect{|s| 
    link_to(sqed_depiction_collecting_event_label_thumb_preview(s), collection_object_buffered_data_breakdown_task_path(s.depiction.depiction_object))  
  }.join().html_safe +
  
  (:div, ' this record ', class: 'sqed_thumb_nav_current') +
 
  around[:after].collect{|s| 
    link_to(sqed_depiction_collecting_event_label_thumb_preview(s), collection_object_buffered_data_breakdown_task_path(s.depiction.depiction_object), 'data-turbolinks' => 'false')  
  }.join().html_safe 
end

- (Object) sqed_done_tag(project_id)



45
46
47
# File 'app/helpers/sqed_depictions_helper.rb', line 45

def sqed_done_tag(project_id)
  SqedDepiction.where(project_id: project_id).count - SqedDepiction.without_collection_object_data.where(project_id: project_id).count
end

- (Object) sqed_first_with_data_tag(project_id)



83
84
85
86
87
88
89
# File 'app/helpers/sqed_depictions_helper.rb', line 83

def sqed_first_with_data_tag(project_id)
  if o = SqedDepiction.where(project_id: sessions_current_project_id).with_collection_object_data.first
    (:span, ('First with data: ' + sqed_card_link(o)).html_safe, class: [:feedback, 'feedback-success', 'feedback-thin'])
  else
    nil
  end
end

- (Object) sqed_first_without_data_tag(project_id)



75
76
77
78
79
80
81
# File 'app/helpers/sqed_depictions_helper.rb', line 75

def sqed_first_without_data_tag(project_id)
  if o = SqedDepiction.where(project_id: sessions_current_project_id).without_collection_object_data.first
    (:span, ('First without data: ' + sqed_card_link(o)).html_safe, class: [:feedback, 'feedback-warning', 'feedback-thin'])
  else
    nil
  end
end

- (Object) sqed_last_with_data_tag(project_id)



59
60
61
62
63
64
65
# File 'app/helpers/sqed_depictions_helper.rb', line 59

def sqed_last_with_data_tag(project_id)
  if o = SqedDepiction.with_collection_object_data.where(project_id: project_id).last
    (:span, ('Last with data: ' + sqed_card_link(o)).html_safe, class: [:feedback, 'feedback-success', 'feedback-thin'])
  else
    nil
  end
end

- (Object) sqed_last_without_data_tag(project_id)



67
68
69
70
71
72
73
# File 'app/helpers/sqed_depictions_helper.rb', line 67

def sqed_last_without_data_tag(project_id)
  if o = SqedDepiction.where(project_id: sessions_current_project_id).without_collection_object_data.last
    (:span, ('Last without data: ' + sqed_card_link(o)).html_safe, class: [:feedback, 'feedback-warning', 'feedback-thin'])
  else
    nil
  end
end

- (Object) sqed_not_done_tag(project_id)



49
50
51
# File 'app/helpers/sqed_depictions_helper.rb', line 49

def sqed_not_done_tag(project_id)
  SqedDepiction.without_collection_object_data.where(project_id: project_id).count
end


53
54
55
56
57
# File 'app/helpers/sqed_depictions_helper.rb', line 53

def sqed_previous_next_links(sqed_depiction)
  around = sqed_depiction.nearby_sqed_depictions(1, 1)
  (link_to('Previous', sqed_depiction_breakdown_task_path(around[:before].first), 'data-turbolinks' => 'false') + ' | '.html_safe +
   link_to('Next', sqed_depiction_breakdown_task_path(around[:after].first), 'data-turbolinks' => 'false')).html_safe
end

- (Object) sqed_waxy_legend_section_tag(position, label)



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'app/helpers/sqed_depictions_helper.rb', line 132

def (position, label)
  layout = Waxy::Geometry::Layout.new(
    Waxy::Geometry::Orientation::LAYOUT_POINTY,
    Waxy::Geometry::Point.new(15,15), # size
    Waxy::Geometry::Point.new(15,15), # start
  )

  a = Waxy::Meta.new
  a.stroke = 'grey'
  a.size = (0..5).collect{|s| position == s ? 1.0 : 0 }
  meta = [a]

  c = Waxy::Render::Svg::Canvas.new(35, 35)
  c.body << Waxy::Render::Svg.rectangle(layout, meta)

  (:figure) do
    c.to_svg.html_safe +
      (:figcaption, label)
  end
end

- (Object) sqed_waxy_legend_tag



153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'app/helpers/sqed_depictions_helper.rb', line 153

def sqed_waxy_legend_tag
  l = ''
  {
    0 => 'identifier(s)',
    1 => 'buffered collecting event',
    2 => 'buffered deterimination',
    3 => 'buffered other labels',
    4 => 'collecting event',
    5 => 'taxon deterimination(s)'
  }.each do |i,label|
    l << (i, label)
  end
  (:div) do
    (:h3, 'Legend') +
      (:p, (:em, 'Triangle indicates data presence')) +
      (:div, l.html_safe)
  end
end

- (Object) sqed_waxy_metadata(sqed_depiction)

Returns Array lenght 6

Returns:

  • Array lenght 6



120
121
122
123
124
125
126
127
128
129
130
# File 'app/helpers/sqed_depictions_helper.rb', line 120

def (sqed_depiction)
  o = sqed_depiction.depiction_object
  [
    (o.identifiers.any? ? 1 : 0),
    (o.buffered_collecting_event.blank? ? 0 : 1),
    (o.buffered_determinations.blank? ? 0 : 1),
    (o.buffered_other_labels.blank? ? 0 : 1),
    (o.collecting_event_id ? 1 : 0),
    (o.taxon_determinations.any? ? 1 : 0)
  ]
end

- (Object) waxy_layout(sqed_depictions)



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/helpers/sqed_depictions_helper.rb', line 95

def waxy_layout(sqed_depictions)
  layout = Waxy::Geometry::Layout.new(
    Waxy::Geometry::Orientation::LAYOUT_POINTY,
    Waxy::Geometry::Point.new(20,20), # size
    Waxy::Geometry::Point.new(20,20), # start
    9 # padding
  ) 

  meta = []

  sqed_depictions.each do |i|
    a = Waxy::Meta.new
    a.size = (i)
    a.stroke = 'grey'
    a.link = sqed_depiction_breakdown_task_path(i).html_safe
    a.link_title = "#{i.id.to_s} created #{time_ago_in_words(i.created_at)} ago by #{user_tag(i.creator)}"
    meta.unshift a
  end

  c = Waxy::Render::Svg::Canvas.new(600, 400)
  c.body << Waxy::Render::Svg.rectangle(layout, meta, 9)
  c.to_svg.html_safe
end