Class: Depiction
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Depiction
- Includes:
- Housekeeping, Shared::DataAttributes, Shared::IsData, Shared::PolymorphicAnnotator, Shared::Tags
- Defined in:
- app/models/depiction.rb
Overview
A depiction is the linkage between an image and a data object. For example an image may depiction a ColletingEvent, CollectionObject, or OTU.
Instance Attribute Summary collapse
-
#depiction_object_id ⇒ Integer
The id of the object being depicted.
-
#depiction_object_type ⇒ String
The type of object being depicted, a TW class that can be depicted (e.g. CollectionObject, CollectingEvent).
-
#image_id ⇒ Integer
The id of the image that stores the depiction.
-
#is_metadata_depiction ⇒ Boolean?
If true then this depiction depicts data that describes the entity, rather than the entity itself.
-
#project_id ⇒ Integer
The project ID.
-
#sled_image_id ⇒ Integer
If present this depiction was derived from sled.
-
#sled_image_x_position ⇒ Integer
Not null if sled_image_is present.
-
#sled_image_y_position ⇒ Integer
Not null if sled_image_is present.
-
#svg_clip ⇒ xml?
A clipping mask to isolate some portion of the picture.
-
#svg_view_box ⇒ String?
Sets the clipping box, identical dimensions to clip for rectangles.
Instance Method Summary collapse
- #destroy_image_stub_collection_object ⇒ Object private
- #from_sled? ⇒ Boolean
- #normalize_image ⇒ Object
- #remove_media_observation ⇒ Object private
- #remove_media_observation2 ⇒ Object private
- #sled_extraction_path(size = :thumb) ⇒ Object
Methods included from Shared::PolymorphicAnnotator
#annotated_object_is_persisted?
Methods included from Shared::IsData
#errors_excepting, #full_error_messages_excepting, #identical, #is_community?, #is_destroyable?, #is_editable?, #is_in_use?, #is_in_users_projects?, #metamorphosize, #similar
Methods included from Shared::DataAttributes
#import_attributes, #internal_attributes, #keyword_value_hash, #reject_data_attributes
Methods included from Shared::Tags
#reject_tags, #tag_with, #tagged?, #tagged_with?
Methods included from Housekeeping
#has_polymorphic_relationship?
Methods inherited from ApplicationRecord
Instance Attribute Details
#depiction_object_id ⇒ Integer
Returns the id of the object being depicted.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#depiction_object_type ⇒ String
Returns the type of object being depicted, a TW class that can be depicted (e.g. CollectionObject, CollectingEvent).
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#image_id ⇒ Integer
Returns the id of the image that stores the depiction.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#is_metadata_depiction ⇒ Boolean?
Returns If true then this depiction depicts data that describes the entity, rather than the entity itself. For example, a CollectionObject depiction of a insect, vs. a picture of some text that says “the specimen is blue”.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#project_id ⇒ Integer
Returns the project ID.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#sled_image_id ⇒ Integer
Returns If present this depiction was derived from sled.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#sled_image_x_position ⇒ Integer
Returns Not null if sled_image_is present. The column (top left 0,0) derived from.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#sled_image_y_position ⇒ Integer
Returns Not null if sled_image_is present. The row (top left 0,0) derived from.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#svg_clip ⇒ xml?
Returns a clipping mask to isolate some portion of the picture.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
#svg_view_box ⇒ String?
Returns sets the clipping box, identical dimensions to clip for rectangles.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'app/models/depiction.rb', line 45 class Depiction < ApplicationRecord include Housekeeping include Shared::Tags include Shared::DataAttributes include Shared::IsData include Shared::PolymorphicAnnotator polymorphic_annotates(:depiction_object) acts_as_list scope: [:project_id, :depiction_object_type, :depiction_object_id] belongs_to :image, inverse_of: :depictions belongs_to :sled_image, inverse_of: :depictions has_one :sqed_depiction, dependent: :destroy # handle duplicate images here!! accepts_nested_attributes_for :image accepts_nested_attributes_for :sqed_depiction, allow_destroy: true validates_presence_of :depiction_object validates_uniqueness_of :sled_image_id, scope: [:project_id, :sled_image_x_position, :sled_image_y_position], allow_nil: true, if: Proc.new {|n| !n.sled_image_id.nil?} before_validation :normalize_image after_update :remove_media_observation2, if: Proc.new {|d| d.depiction_object_type_previously_was == 'Observation' && d.depiction_object.respond_to?(:type_was) && d.depiction_object.type_was == 'Observation::Media' } after_destroy :remove_media_observation, if: Proc.new {|d| d.depiction_object_type == 'Observation' && d.depiction_object.type == 'Observation::Media' } after_update :destroy_image_stub_collection_object, if: Proc.new {|d| d.depiction_object_type_previously_was == 'CollectionObject' && d.depiction_object_type == 'CollectionObject' } def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end def from_sled? !sled_image_id.nil? end def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end private def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end end |
Instance Method Details
#destroy_image_stub_collection_object ⇒ Object (private)
121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/depiction.rb', line 121 def destroy_image_stub_collection_object if sqed_depiction.present? if v = depiction_object_id_previously_was o = CollectionObject.find(v) if o.is_image_stub? o.destroy! end end end end |
#from_sled? ⇒ Boolean
80 81 82 |
# File 'app/models/depiction.rb', line 80 def from_sled? !sled_image_id.nil? end |
#normalize_image ⇒ Object
74 75 76 77 78 |
# File 'app/models/depiction.rb', line 74 def normalize_image if o = Image.where(project_id: Current.project_id, image_file_fingerprint: image.image_file_fingerprint).first self.image = o end end |
#remove_media_observation ⇒ Object (private)
115 116 117 118 119 |
# File 'app/models/depiction.rb', line 115 def remove_media_observation if depiction_object.depictions.size == 0 depiction_object.destroy! end end |
#remove_media_observation2 ⇒ Object (private)
106 107 108 109 110 111 112 113 |
# File 'app/models/depiction.rb', line 106 def remove_media_observation2 if v = depiction_object_id_previously_was o = Observation::Media.find(v) if o.depictions.size == 0 o.destroy! end end end |
#sled_extraction_path(size = :thumb) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/depiction.rb', line 84 def sled_extraction_path(size = :thumb) if from_sled? x, y, w, h = svg_view_box.split(' ') box_width, box_height = nil, nil case size when :thumb, :medium box_width = Image::DEFAULT_SIZES[size][:width] box_height = Image::DEFAULT_SIZES[size][:height] when :original box_width = w.to_i box_height = h.to_i end "#{image_id}/scale_to_box/#{x.to_i}/#{y.to_i}/#{w.to_i}/#{h.to_i}/#{box_width}/#{box_height}" else raise 'This is not a sled derived depiction' end end |