From 0cf2ec04ba9b54c4e74001923003dc308a60ca04 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 17 Apr 2024 18:09:55 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20poder=20anidar=20un=20art=C3=ADculo=20#?= =?UTF-8?q?15066?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/metadata_has_one_nested.rb | 11 +++++++++++ app/views/posts/_attributes.haml | 16 ++++++++++++++++ app/views/posts/_attributes_nested.haml | 19 +++++++++++++++++++ app/views/posts/_form.haml | 11 +---------- .../posts/attribute_ro/_has_one_nested.haml | 6 ++++++ .../posts/attributes/_has_one_nested.haml | 6 ++++++ 6 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 app/models/metadata_has_one_nested.rb create mode 100644 app/views/posts/_attributes.haml create mode 100644 app/views/posts/_attributes_nested.haml create mode 100644 app/views/posts/attribute_ro/_has_one_nested.haml create mode 100644 app/views/posts/attributes/_has_one_nested.haml diff --git a/app/models/metadata_has_one_nested.rb b/app/models/metadata_has_one_nested.rb new file mode 100644 index 00000000..ed509013 --- /dev/null +++ b/app/models/metadata_has_one_nested.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +class MetadataHasOneNested < MetadataHasOne + def nested + @nested ||= layout.metadata.dig(name, 'nested') + end + + def nested? + true + end +end diff --git a/app/views/posts/_attributes.haml b/app/views/posts/_attributes.haml new file mode 100644 index 00000000..ed958d08 --- /dev/null +++ b/app/views/posts/_attributes.haml @@ -0,0 +1,16 @@ +-# + @param base [String] + @param locale [String] + @param post [Post] + @param site [Site] + @param dir [String] +- post.attributes.each do |attribute| + - metadata = post[attribute] + - type = metadata.type + + - cache [metadata, I18n.locale] do + = render("posts/attributes/#{type}", + base: base, post: post, attribute: attribute, + metadata: metadata, site: site, + dir: dir, locale: locale, + autofocus: (post.attributes.first == attribute)) diff --git a/app/views/posts/_attributes_nested.haml b/app/views/posts/_attributes_nested.haml new file mode 100644 index 00000000..33996aa3 --- /dev/null +++ b/app/views/posts/_attributes_nested.haml @@ -0,0 +1,19 @@ +-# + @param inverse [Symbol] + @param base [String] + @param locale [String] + @param post [Post] + @param site [Site] + @param dir [String] +- post.attributes.each do |attribute| + - next if attribute == :date + - next if attribute == :draft + - next if attribute == inverse + - metadata = post[attribute] + - type = metadata.type + + - cache [metadata, I18n.locale] do + = render "posts/attributes/#{type}", + base: base, post: post, attribute: attribute, + metadata: metadata, site: site, + dir: dir, locale: locale, autofocus: false diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index 7de0ea79..92bee939 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -41,16 +41,7 @@ = hidden_field_tag 'post[layout]', post.layout.name -# Dibuja cada atributo - - post.attributes.each do |attribute| - - metadata = post[attribute] - - type = metadata.type - - - cache [metadata, I18n.locale] do - = render("posts/attributes/#{type}", - base: 'post', post: post, attribute: attribute, - metadata: metadata, site: site, - dir: dir, locale: @locale, - autofocus: (post.attributes.first == attribute)) + = render 'posts/attributes', site: site, post: post, dir: dir, base: 'post', locale: @locale -# Botones de guardado = render 'posts/submit', site: site, post: post diff --git a/app/views/posts/attribute_ro/_has_one_nested.haml b/app/views/posts/attribute_ro/_has_one_nested.haml new file mode 100644 index 00000000..425e659e --- /dev/null +++ b/app/views/posts/attribute_ro/_has_one_nested.haml @@ -0,0 +1,6 @@ +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td{ dir: dir, lang: locale } + - p = metadata.has_one + - if p + = link_to p.title.value, site_post_path(site, p.id) diff --git a/app/views/posts/attributes/_has_one_nested.haml b/app/views/posts/attributes/_has_one_nested.haml new file mode 100644 index 00000000..e98bff47 --- /dev/null +++ b/app/views/posts/attributes/_has_one_nested.haml @@ -0,0 +1,6 @@ +- new_post = site.posts(lang: locale).build(layout: metadata.nested) +- base = "#{base}[#{metadata.name}]" + +.form-group + = render 'layouts/details', id: metadata.nested, summary: site.layouts[metadata.nested].humanized_name do + = render 'posts/attributes_nested', site: site, post: new_post, dir: dir, base: base, locale: locale, inverse: metadata.inverse