Module: FieldValueKrill
- Included in:
- FieldValue
- Defined in:
- app/krill/field_value_krill.rb
Instance Method Summary collapse
- #info ⇒ Object
- #make ⇒ Object
- #make_collection ⇒ Object
- #make_part(collection, r, c) ⇒ Object
- #part? ⇒ Boolean
- #retrieve ⇒ Object
Instance Method Details
#info ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/krill/field_value_krill.rb', line 76 def info si = 'No sample' ii = 'No Item' if child_sample_id sample = Sample.find_by(id: child_sample_id) si = if sample "#{sample.sample_type.name} #{sample.id} (#{sample.name})" else "Sample #{child_sample_id} not found!" end end if child_item_id item = Item.includes(:object_type).find_by(id: child_item_id) ii = if item "#{item.object_type.name} #{item.id} at #{item.location}" else "Item #{child_item_id} not found!" end end "#{name}: { sample: #{si}, item: #{ii}, array: #{field_type.array ? 'true' : 'false'}, part: #{field_type.part ? [row, column] : '-'} }" end |
#make ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/krill/field_value_krill.rb', line 38 def make if object_type && !child_item_id @item = Item.make({ quantity: 1, inuse: 0 }, sample: child_sample, object_type: object_type) @item.store if @item.location == 'Unknown' self.child_item_id = @item.id save elsif object_type && child_item_id Rails.logger.info "Item #{child_item_id} already assigned to field value" end @item end |
#make_collection ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'app/krill/field_value_krill.rb', line 51 def make_collection ot = object_type raise "Could not find object type: #{object_type}" unless ot = "Cannot make a new collection from object type '#{ot.name}' with handler '#{ot.handler}'" raise if ot.handler != 'collection' c = Collection.new_collection(object_type.name) c.store if c.location == 'Unknown' self.child_item_id = c.id save c end |
#make_part(collection, r, c) ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'app/krill/field_value_krill.rb', line 66 def make_part(collection, r, c) return unless collection collection.set(r, c, child_sample) self.child_item_id = collection.id self.row = r self.column = c save end |
#part? ⇒ Boolean
101 102 103 |
# File 'app/krill/field_value_krill.rb', line 101 def part? field_type && field_type.part end |
#retrieve ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/krill/field_value_krill.rb', line 7 def retrieve if child_item_id @item = Item.find_by(id: child_item_id) elsif !predecessors.empty? # TODO: THIS SHOULD USE THE ACTIVE PREDECESSOR, IN CASE THERE IS MORE THAN ONE # FILTER BY STATUS (e.g. "done")? copy_inventory(predecessors[0]) else items = if object_type && !field_type.part Item.where(sample_id: child_sample_id, object_type_id: object_type.id).reject(&:deleted?) elsif object_type && field_type.part Collection.containing(val, object_type).reject(&:deleted?) else Item.where(sample_id: child_sample_id).reject(&:deleted?) end unless items.empty? @item = items[0] self.child_item_id = @item.id if @item.class == Collection p = @item.position_as_hash child_sample self.row = p[:row] self.column = p[:column] end save end end @item end |