mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-14 22:38:20 +00:00
Merge branch 'issue-15066' into production.panel.sutty.nl
This commit is contained in:
commit
12d943eda1
8 changed files with 54 additions and 37 deletions
|
@ -8,4 +8,9 @@ class MetadataHasOneNested < MetadataHasOne
|
|||
def nested?
|
||||
true
|
||||
end
|
||||
|
||||
# No tener conflictos con related
|
||||
def related_methods
|
||||
@related_methods ||= [].freeze
|
||||
end
|
||||
end
|
||||
|
|
|
@ -52,6 +52,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
|||
rm = []
|
||||
rm << post.path.value_was if post.path.changed?
|
||||
|
||||
create_nested_posts! post, params[:post]
|
||||
update_related_posts
|
||||
|
||||
# Es importante que el artículo se guarde primero y luego los
|
||||
|
@ -181,7 +182,7 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
|||
post.nested_attributes.each do |nested_attribute|
|
||||
nested_metadata = post[nested_attribute]
|
||||
# @todo find_or_initialize
|
||||
nested_post = site.posts(lang: post.lang.value).build(layout: nested_metadata.nested)
|
||||
nested_post = nested_metadata.has_one || site.posts(lang: post.lang.value).build(layout: nested_metadata.nested)
|
||||
nested_params = params.require(nested_attribute).permit(nested_post.params).to_hash
|
||||
|
||||
# Completa la relación 1:1
|
||||
|
|
|
@ -7,8 +7,9 @@
|
|||
@param :summary_class [String] Clases para el summary
|
||||
|
||||
- local_assigns[:summary_class] ||= 'h3'
|
||||
- local_assigns[:details_class] ||= 'py-2'
|
||||
|
||||
%details.details.py-2{ id: local_assigns[:id], data: { controller: 'details', action: 'toggle->details#store' } }
|
||||
%details.details{ id: local_assigns[:id], class: local_assigns[:details_class], data: { controller: 'details', action: 'toggle->details#store' } }
|
||||
%summary.d-flex.flex-row.align-items-center.justify-content-between{ class: local_assigns[:summary_class] }
|
||||
%span= summary
|
||||
%span.hide-when-open ▶
|
||||
|
|
|
@ -10,10 +10,9 @@
|
|||
- next if attribute == :draft
|
||||
- next if attribute == inverse
|
||||
- metadata = post[attribute]
|
||||
- type = metadata.type
|
||||
|
||||
- cache [metadata, I18n.locale] do
|
||||
= render "posts/attributes/#{type}",
|
||||
- cache [post, metadata, I18n.locale] do
|
||||
= render "posts/attributes/#{metadata.type}",
|
||||
base: base, post: post, attribute: attribute,
|
||||
metadata: metadata, site: site,
|
||||
dir: dir, locale: locale, autofocus: false
|
||||
|
|
34
app/views/posts/_table.haml
Normal file
34
app/views/posts/_table.haml
Normal file
|
@ -0,0 +1,34 @@
|
|||
-#
|
||||
Muestra una tabla con todos los atributos de un post
|
||||
|
||||
@param site [Site]
|
||||
@param locale [Symbol]
|
||||
@param dir [String]
|
||||
@param post [Post]
|
||||
@param title [String]
|
||||
|
||||
%table.table.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th.text-center{ colspan: 2 }= title
|
||||
%tbody
|
||||
- post.attributes.each do |attr|
|
||||
- metadata = post[attr]
|
||||
- next unless metadata.front_matter?
|
||||
|
||||
- cache [post, metadata, I18n.locale] do
|
||||
= render("posts/attribute_ro/#{metadata.type}",
|
||||
post: post, attribute: attr,
|
||||
metadata: metadata,
|
||||
site: site,
|
||||
locale: locale,
|
||||
dir: dir)
|
||||
|
||||
-# Mostrar todo lo que no va en el front_matter (el contenido)
|
||||
- post.attributes.each do |attr|
|
||||
- metadata = post[attr]
|
||||
- next if metadata.front_matter?
|
||||
|
||||
- cache [post, metadata, I18n.locale] do
|
||||
%section.content.pb-3{ id: attr, dir: dir }
|
||||
= metadata.to_s.html_safe
|
|
@ -1,6 +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)
|
||||
%td{ dir: dir, lang: locale, colspan: 2 }
|
||||
- if (p = metadata.has_one)
|
||||
= render 'layouts/details', details_class: '', summary_class: 'font-weight-bold', summary: post_label_t(attribute, post: post) do
|
||||
.mt-3
|
||||
= render 'posts/table', site: site, post: p, dir: dir, locale: locale, title: p.layout.humanized_name
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
- new_post = site.posts(lang: locale).build(layout: metadata.nested)
|
||||
- nested_post = metadata.has_one || 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
|
||||
= render 'posts/attributes_nested', site: site, post: nested_post, dir: dir, base: base, locale: locale, inverse: metadata.inverse
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
- dir = @site.data.dig(params[:locale], 'dir')
|
||||
|
||||
.row.justify-content-center
|
||||
.col-12.col-lg-8
|
||||
%article.content.table-responsive-md
|
||||
|
@ -6,28 +7,4 @@
|
|||
edit_site_post_path(@site, @post.id),
|
||||
class: 'btn btn-secondary btn-block'
|
||||
|
||||
%table.table.table-condensed
|
||||
%thead
|
||||
%tr
|
||||
%th.text-center{ colspan: 2 }= t('.front_matter')
|
||||
%tbody
|
||||
- @post.attributes.each do |attr|
|
||||
- metadata = @post[attr]
|
||||
- next unless metadata.front_matter?
|
||||
|
||||
- cache [metadata, I18n.locale] do
|
||||
= render("posts/attribute_ro/#{metadata.type}",
|
||||
post: @post, attribute: attr,
|
||||
metadata: metadata,
|
||||
site: @site,
|
||||
locale: @locale,
|
||||
dir: dir)
|
||||
|
||||
-# Mostrar todo lo que no va en el front_matter (el contenido)
|
||||
- @post.attributes.each do |attr|
|
||||
- metadata = @post[attr]
|
||||
- next if metadata.front_matter?
|
||||
|
||||
- cache [metadata, I18n.locale] do
|
||||
%section.content.pb-3{ id: attr, dir: dir }
|
||||
= @post.public_send(attr).to_s.html_safe
|
||||
= render 'table', dir: dir, site: @site, locale: @locale, post: @post, title: t('.front_matter')
|
||||
|
|
Loading…
Reference in a new issue