mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-11 17:24:50 -04:00
This commit is contained in:
@@ -4,46 +4,45 @@ module SearchHarvests
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
searchkick merge_mappings: true,
|
||||
mappings: {
|
||||
properties: {
|
||||
created_at: { type: :integer },
|
||||
harvests_count: { type: :integer },
|
||||
photos_count: { type: :integer },
|
||||
harvested_at: { type: :date }
|
||||
}
|
||||
}
|
||||
searchkick merge_mappings: true, mappings: {
|
||||
properties: {
|
||||
created_at: { type: :integer },
|
||||
harvests_count: { type: :integer },
|
||||
photos_count: { type: :integer },
|
||||
harvested_at: { type: :date }
|
||||
}
|
||||
}
|
||||
|
||||
scope :search_import, -> { includes(:owner, :crop, :plant_part) }
|
||||
|
||||
def search_data
|
||||
{
|
||||
slug: slug,
|
||||
crop_id: crop_id,
|
||||
crop_name: crop_name,
|
||||
crop_slug: crop.slug,
|
||||
has_photos: photos.size.positive?,
|
||||
owner_id: owner_id,
|
||||
owner_slug: owner_slug,
|
||||
slug: slug,
|
||||
crop_id: crop_id,
|
||||
crop_name: crop_name,
|
||||
crop_slug: crop.slug,
|
||||
has_photos: photos.size.positive?,
|
||||
owner_id: owner_id,
|
||||
owner_login_name: owner_login_name,
|
||||
photos_count: photos.count,
|
||||
plant_part: plant_part&.name,
|
||||
planting_id: planting_id,
|
||||
quantity: quantity,
|
||||
thumbnail_url: default_photo&.thumbnail_url || crop.default_photo&.thumbnail_url,
|
||||
harvested_at: harvested_at,
|
||||
created_at: created_at.to_i
|
||||
owner_slug: owner_slug,
|
||||
photos_count: photos.count,
|
||||
plant_part_name: plant_part_name,
|
||||
planting_id: planting_id,
|
||||
quantity: quantity,
|
||||
thumbnail_url: default_photo&.thumbnail_url || crop.default_photo&.thumbnail_url,
|
||||
harvested_at: harvested_at,
|
||||
created_at: created_at.to_i
|
||||
}
|
||||
end
|
||||
|
||||
def self.homepage_records(limit)
|
||||
search('*',
|
||||
limit: limit,
|
||||
where: {
|
||||
limit: limit,
|
||||
where: {
|
||||
photos_count: { gt: 0 }
|
||||
},
|
||||
boost_by: [:created_at],
|
||||
load: false)
|
||||
load: false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,15 +12,15 @@ class Harvest < ApplicationRecord
|
||||
# Constants
|
||||
UNITS_VALUES = {
|
||||
"individual" => "individual",
|
||||
"bunches" => "bunch",
|
||||
"sprigs" => "sprig",
|
||||
"handfuls" => "handful",
|
||||
"litres" => "litre",
|
||||
"pints" => "pint",
|
||||
"quarts" => "quart",
|
||||
"buckets" => "bucket",
|
||||
"baskets" => "basket",
|
||||
"bushels" => "bushel"
|
||||
"bunches" => "bunch",
|
||||
"sprigs" => "sprig",
|
||||
"handfuls" => "handful",
|
||||
"litres" => "litre",
|
||||
"pints" => "pint",
|
||||
"quarts" => "quart",
|
||||
"buckets" => "bucket",
|
||||
"baskets" => "basket",
|
||||
"bushels" => "bushel"
|
||||
}.freeze
|
||||
|
||||
WEIGHT_UNITS_VALUES = {
|
||||
@@ -50,8 +50,9 @@ class Harvest < ApplicationRecord
|
||||
ON (m.id=h2.owner_id AND harvests.id < h2.id)").where("h2 IS NULL")
|
||||
}
|
||||
|
||||
delegate :name, to: :crop, prefix: true
|
||||
delegate :name, :slug, to: :crop, prefix: true
|
||||
delegate :login_name, :slug, to: :owner, prefix: true
|
||||
delegate :name, to: :plant_part, prefix: true
|
||||
|
||||
##
|
||||
## Validations
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
.card-body
|
||||
%h5
|
||||
%strong= link_to harvest.crop_name, harvest_path(slug: harvest.slug)
|
||||
%span.badge.badge-pill= harvest.plant_part
|
||||
%span.badge.badge-pill= harvest.plant_part_name
|
||||
.card-footer
|
||||
.float-right
|
||||
%span.chip.member-chip
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
%description
|
||||
:escaped
|
||||
<p>Crop: #{harvest.crop_name}</p>
|
||||
<p>Plant path: #{harvest.plant_part_name}</p>
|
||||
<p>Quantity: #{harvest.quantity ||= 'unknown' }</p>
|
||||
<p>Harvested on: #{harvest.harvested_at ||= 'unknown' }</p>
|
||||
%link= harvest_url(slug: harvest.slug)
|
||||
|
||||
Reference in New Issue
Block a user