From 5b9df0d02013ee0b3d7ffce212390256e950e0e8 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Oct 2023 17:30:37 -0300 Subject: [PATCH] fix: locales --- app/models/metadata_locales.rb | 19 +++++++++++-------- app/models/metadata_related_posts.rb | 8 ++------ app/views/posts/attributes/_locales.haml | 1 - 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/app/models/metadata_locales.rb b/app/models/metadata_locales.rb index 85419da8..b4ddf485 100644 --- a/app/models/metadata_locales.rb +++ b/app/models/metadata_locales.rb @@ -6,11 +6,16 @@ class MetadataLocales < MetadataHasAndBelongsToMany # # @return { lang: { title: uuid } } def values - @values ||= site.locales.map do |locale| - [locale, posts.where(lang: locale).map do |post| - [title(post), post.uuid.value] - end.to_h] - end.to_h + @values ||= other_locales.to_h do |other_locale| + [ + other_locale, + posts.where(locale: other_locale).pluck(:title, :layout, :post_id).to_h do |row| + row.tap do |value| + value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})" + end + end + ] + end end # Siempre hay una relaciĆ³n inversa @@ -33,9 +38,7 @@ class MetadataLocales < MetadataHasAndBelongsToMany # # @return [Array] def other_locales - @other_locales ||= site.locales.reject do |other_locale| - other_locale.to_s == locale - end + @other_locales ||= site.locales - [locale] end # Obtiene todos los posts de los otros locales con el mismo layout diff --git a/app/models/metadata_related_posts.rb b/app/models/metadata_related_posts.rb index b1ebfe4e..50b8660e 100644 --- a/app/models/metadata_related_posts.rb +++ b/app/models/metadata_related_posts.rb @@ -8,11 +8,11 @@ class MetadataRelatedPosts < MetadataArray # # @return [Hash] def values - @values ||= posts.pluck(:title, :layout, :post_id).map do |row| + @values ||= posts.pluck(:title, :layout, :post_id).to_h do |row| row.tap do |value| value[0] = "#{value[0]} (#{site.layouts[value.delete_at(1)].humanized_name})" end - end.to_h + end end # Las relaciones nunca son privadas @@ -37,10 +37,6 @@ class MetadataRelatedPosts < MetadataArray site.indexed_posts.where(locale: locale).where.not(post_id: post.uuid.value).where(**filter) end - def title(post) - "#{post&.title&.value || post&.slug&.value} (#{post.layout.humanized_name})" - end - # Encuentra el filtro desde el esquema del atributo # # @return [Hash] diff --git a/app/views/posts/attributes/_locales.haml b/app/views/posts/attributes/_locales.haml index 4978f6b4..05592fbd 100644 --- a/app/views/posts/attributes/_locales.haml +++ b/app/views/posts/attributes/_locales.haml @@ -6,7 +6,6 @@ post: post, attribute: attribute, metadata: metadata - site.locales.each do |locale| - - next if post.lang.value == locale - locale_t = t("locales.#{locale}.name", default: locale.to_s.humanize) - value = metadata.value.find do |v| - metadata.values[locale].values.include? v