Class: Labimotion::Element
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- Labimotion::Element
show all
- Includes:
- Collectable, ElementUIStateScopes, GenericRevisions, Segmentable, PgSearch, Taggable
- Defined in:
- lib/labimotion/models/element.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#create_vault, #delete_attachments, #save_to_vault
#copy_segments, #save_segments
Instance Attribute Details
#can_copy ⇒ Object
Returns the value of attribute can_copy.
21
22
23
|
# File 'lib/labimotion/models/element.rb', line 21
def can_copy
@can_copy
end
|
Class Method Details
.get_associated_elements(element_ids) ⇒ Object
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
# File 'lib/labimotion/models/element.rb', line 84
def self.get_associated_elements(element_ids)
pids = Labimotion::Element.where(id: element_ids).pluck :id
get_ids = proc do |eids|
eids.each do |p|
cs = Labimotion::Element.find_by(id: p)&.elements.where.not(id: pids).pluck :id
next if cs.empty?
pids = (pids << cs).flatten.uniq
get_ids.call(cs)
end
end
get_ids.call(pids)
pids
end
|
.get_associated_samples(element_ids) ⇒ Object
61
62
63
|
# File 'lib/labimotion/models/element.rb', line 61
def self.get_associated_samples(element_ids)
Labimotion::ElementsSample.where(element_id: element_ids).pluck(:sample_id)
end
|
Instance Method Details
#analyses ⇒ Object
65
66
67
|
# File 'lib/labimotion/models/element.rb', line 65
def analyses
container ? container.analyses : []
end
|
#attachments ⇒ Object
57
58
59
|
# File 'lib/labimotion/models/element.rb', line 57
def attachments
Attachment.where(attachable_id: self.id, attachable_type: 'Element')
end
|
#auto_set_short_label ⇒ Object
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/labimotion/models/element.rb', line 69
def auto_set_short_label
prefix = element_klass.klass_prefix
if creator.counters[element_klass.name].nil?
creator.counters[element_klass.name] = '0'
creator.update_columns(counters: creator.counters)
creator.reload
end
counter = creator.counters[element_klass.name].to_i.succ
self.short_label = "#{creator.initials}-#{prefix}#{counter}"
end
|
#thumb_svg ⇒ Object
99
100
101
102
103
104
105
106
107
|
# File 'lib/labimotion/models/element.rb', line 99
def thumb_svg
image_atts = attachments.select do |a_img|
a_img&.content_type&.match(Regexp.union(%w[jpg jpeg png tiff tif]))
end
attachment = image_atts[0] || attachments[0]
preview = attachment.read_thumbnail if attachment
preview && Base64.encode64(preview) || 'not available'
end
|
#update_counter ⇒ Object
80
81
82
|
# File 'lib/labimotion/models/element.rb', line 80
def update_counter
creator.increment_counter element_klass.name
end
|