Class: Labimotion::Element
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#detach_properties
#create_vault, #delete_attachments, #save_to_vault
#copy_segments, #save_segments, #touch_analyses_properties, #touch_element_properties, #touch_properties_for_object, #touch_segments_properties, #touch_vocabulary
Methods included from Workflow
#split_workflow
Instance Attribute Details
#can_copy ⇒ Object
Returns the value of attribute can_copy.
24
25
26
|
# File 'lib/labimotion/models/element.rb', line 24
def can_copy
@can_copy
end
|
Class Method Details
.get_associated_elements(element_ids) ⇒ Object
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/labimotion/models/element.rb', line 98
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
71
72
73
|
# File 'lib/labimotion/models/element.rb', line 71
def self.get_associated_samples(element_ids)
Labimotion::ElementsSample.where(element_id: element_ids).pluck(:sample_id)
end
|
Instance Method Details
#analyses ⇒ Object
75
76
77
|
# File 'lib/labimotion/models/element.rb', line 75
def analyses
container ? container.analyses : Container.none
end
|
#attachments ⇒ Object
67
68
69
|
# File 'lib/labimotion/models/element.rb', line 67
def attachments
Attachment.where(attachable_id: self.id, attachable_type: self.class.name)
end
|
#auto_set_short_label ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/labimotion/models/element.rb', line 79
def auto_set_short_label
return if short_label && !short_label_changed?
return if parent && (self.short_label = "#{parent.short_label}-#{parent.children.with_deleted.count.to_i.succ}")
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
|
#migrate_workflow ⇒ Object
133
134
135
136
137
138
139
140
|
# File 'lib/labimotion/models/element.rb', line 133
def migrate_workflow
return if properties.nil? || properties_release.nil?
return if properties['flow'].nil? && properties_release['flow'].nil?
update_column(:properties, split_workflow(properties)) if properties['flow']
update_column(:properties_release, split_workflow(properties_release)) if properties_release['flow']
end
|
#split(user, col_ids) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/labimotion/models/element.rb', line 120
def split(user, col_ids)
subelement = self.dup
subelement.name = self.name if self.name.present?
subelement.parent = self
subelement.properties = detach_properties(properties)
subelement.created_by = user.id
collections = (Collection.where(id: col_ids) | Collection.where(user_id: user, label: 'All', is_locked: true))
subelement.collections << collections
subelement.container = Container.create_root_container
subelement.save!
subelement
end
|
#thumb_svg ⇒ Object
113
114
115
116
117
118
|
# File 'lib/labimotion/models/element.rb', line 113
def thumb_svg
image_atts = attachments.select(&:type_image?)
attachment = image_atts[0] || attachments[0]
preview = attachment&.read_thumbnail
(preview && Base64.encode64(preview)) || 'not available'
end
|
#update_counter ⇒ Object
94
95
96
|
# File 'lib/labimotion/models/element.rb', line 94
def update_counter
creator.increment_counter element_klass.name
end
|
#user_labels ⇒ Object
63
64
65
|
# File 'lib/labimotion/models/element.rb', line 63
def user_labels
tag&.taggable_data&.fetch('user_labels', nil)
end
|