2020-01-28 21:05:59 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Devuelve una lista de títulos y UUID de todos los posts del mismo
|
|
|
|
# idioma que el actual, para usar con input-map.js
|
|
|
|
class MetadataRelatedPosts < MetadataArray
|
2023-10-06 13:11:30 +00:00
|
|
|
# Genera un Hash de { title (schema) => uuid } para usar en
|
|
|
|
# options_for_select
|
|
|
|
#
|
2020-11-07 23:51:00 +00:00
|
|
|
# @return [Hash]
|
2020-01-28 21:05:59 +00:00
|
|
|
def values
|
2023-10-19 15:46:54 +00:00
|
|
|
@values ||= posts.pluck(:title, :created_at, :layout, :post_id).to_h do |row|
|
2023-10-06 13:11:30 +00:00
|
|
|
row.tap do |value|
|
2023-10-19 15:46:54 +00:00
|
|
|
value[0] = "#{value[0]} #{value.delete_at(1).strftime('%F')} (#{site.layouts[value.delete_at(1)].humanized_name})"
|
2023-10-06 13:11:30 +00:00
|
|
|
end
|
2023-10-06 20:30:37 +00:00
|
|
|
end
|
2020-01-28 21:05:59 +00:00
|
|
|
end
|
|
|
|
|
2020-08-20 23:38:31 +00:00
|
|
|
# Las relaciones nunca son privadas
|
|
|
|
def private?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2021-05-06 15:33:28 +00:00
|
|
|
def indexable?
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2021-05-06 16:00:05 +00:00
|
|
|
def indexable_values
|
2023-10-06 13:11:30 +00:00
|
|
|
posts.where(post_id: value).pluck(:title)
|
2021-05-06 16:00:05 +00:00
|
|
|
end
|
|
|
|
|
2020-01-28 21:05:59 +00:00
|
|
|
private
|
|
|
|
|
2023-10-06 13:11:30 +00:00
|
|
|
# Obtiene todos los posts menos el actual y opcionalmente los filtra
|
|
|
|
#
|
|
|
|
# @return [IndexedPost::ActiveRecord_AssociationRelation]
|
2020-07-02 13:59:58 +00:00
|
|
|
def posts
|
2023-10-20 15:23:01 +00:00
|
|
|
site.indexed_posts.where(locale: locale).where.not(post_id: post.uuid.value).where(filter)
|
2020-01-28 21:05:59 +00:00
|
|
|
end
|
|
|
|
|
2023-10-06 13:11:30 +00:00
|
|
|
# Encuentra el filtro desde el esquema del atributo
|
|
|
|
#
|
2023-10-20 15:23:01 +00:00
|
|
|
# @return [Hash,nil]
|
2020-07-02 13:59:58 +00:00
|
|
|
def filter
|
2023-10-20 15:23:01 +00:00
|
|
|
layout.metadata.dig(name, 'filter')&.to_h&.symbolize_keys
|
2020-07-02 13:59:58 +00:00
|
|
|
end
|
2021-02-11 19:16:25 +00:00
|
|
|
|
|
|
|
def sanitize(uuid)
|
|
|
|
super(uuid.map do |u|
|
|
|
|
u.to_s.gsub(/[^a-f0-9\-]/i, '')
|
|
|
|
end)
|
|
|
|
end
|
2020-01-28 21:05:59 +00:00
|
|
|
end
|