diff --git a/app/models/metadata_file.rb b/app/models/metadata_file.rb index 61aea897..fb5082f4 100644 --- a/app/models/metadata_file.rb +++ b/app/models/metadata_file.rb @@ -18,6 +18,18 @@ class MetadataFile < MetadataTemplate # XXX: Esto ayuda a deserializar en {Site#everything_of} def values; end + # Usar la descripción + def titleize? + true + end + + # Devolver la descripción + # + # @return [String] + def to_s + value['description'].to_s + end + def validate super diff --git a/app/models/metadata_predefined_array.rb b/app/models/metadata_predefined_array.rb index b8e5050e..566a491b 100644 --- a/app/models/metadata_predefined_array.rb +++ b/app/models/metadata_predefined_array.rb @@ -7,4 +7,13 @@ class MetadataPredefinedArray < MetadataArray [v[I18n.locale.to_s], k] end&.to_h end + + # Devolver los valores legibles por humanes + # + # @todo Debería devolver los valores en el idioma del post, no de le + # usuarie + # @return [String] + def to_s + values.invert.select { |x, k| value.include?(x) }.values.join(', ') + end end diff --git a/app/models/metadata_title.rb b/app/models/metadata_title.rb index 729a71fd..6d6b1bde 100644 --- a/app/models/metadata_title.rb +++ b/app/models/metadata_title.rb @@ -7,6 +7,11 @@ class MetadataTitle < MetadataString false end + # Siempre recalcular el título + def value + self[:value] = default_value + end + # Obtener todos los valores de texto del artículo y generar un título # en base a eso. # diff --git a/app/views/posts/_htmx_form.haml b/app/views/posts/_htmx_form.haml index 1a8c0597..f6704695 100644 --- a/app/views/posts/_htmx_form.haml +++ b/app/views/posts/_htmx_form.haml @@ -85,11 +85,13 @@ = hidden_field_tag "#{base}[layout]", post.layout.name - -# Dibuja cada atributo + -# Dibuja cada atributo, excepto algunos = render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale, except: except - -# Enviamos valores vacíos para los atributos ocultos + -# + Enviamos valores vacíos o arrastrados desde el formulario anterior + para los atributos ignorados - except.each do |attr| - %input{ type: 'hidden', name: "#{base}[#{attr}]", value: "" } + %input{ type: 'hidden', name: "#{base}[#{attr}]", value: params[attr].presence } = yield(:post_form) diff --git a/app/views/posts/attributes/_new_belongs_to.haml b/app/views/posts/attributes/_new_belongs_to.haml index b083e55e..a187e9ea 100644 --- a/app/views/posts/attributes/_new_belongs_to.haml +++ b/app/views/posts/attributes/_new_belongs_to.haml @@ -100,6 +100,7 @@ %input{ type: 'hidden', name: 'attribute', value: metadata.type } - if metadata.inverse? %input{ type: 'hidden', name: 'inverse', value: metadata.inverse } + %input{ type: 'hidden', name: metadata.inverse, value: post.uuid.value } %div{ id: post_modal_id, data: { controller: 'modal' } } = render 'bootstrap/modal', id: post_id, modal_content_attributes: { class: 'h-100' } do - content_for :"#{post_id}_body" do diff --git a/app/views/posts/attributes/_new_has_and_belongs_to_many.haml b/app/views/posts/attributes/_new_has_and_belongs_to_many.haml index 1142c3b9..5dd1039b 100644 --- a/app/views/posts/attributes/_new_has_and_belongs_to_many.haml +++ b/app/views/posts/attributes/_new_has_and_belongs_to_many.haml @@ -101,6 +101,7 @@ %input{ type: 'hidden', name: 'attribute', value: metadata.type } - if metadata.inverse? %input{ type: 'hidden', name: 'inverse', value: metadata.inverse } + %input{ type: 'hidden', name: metadata.inverse, value: post.uuid.value } %div{ id: post_modal_id, data: { controller: 'modal' } } = render 'bootstrap/modal', id: post_id, modal_content_attributes: { class: 'h-100' } do - content_for :"#{post_id}_body" do diff --git a/app/views/posts/attributes/_new_has_many.haml b/app/views/posts/attributes/_new_has_many.haml index 9910e078..805636da 100644 --- a/app/views/posts/attributes/_new_has_many.haml +++ b/app/views/posts/attributes/_new_has_many.haml @@ -99,8 +99,10 @@ %input{ type: 'hidden', name: 'name', value: name } %input{ type: 'hidden', name: 'form', value: form_id } %input{ type: 'hidden', name: 'attribute', value: metadata.type } + -# @todo Forma genérica de arrastrar valores desde un formulario al siguiente - if metadata.inverse? %input{ type: 'hidden', name: 'inverse', value: metadata.inverse } + %input{ type: 'hidden', name: metadata.inverse, value: post.uuid.value } %div{ id: post_modal_id, data: { controller: 'modal' } } = render 'bootstrap/modal', id: post_id, modal_content_attributes: { class: 'h-100' } do - content_for :"#{post_id}_body" do diff --git a/app/views/posts/attributes/_new_has_one.haml b/app/views/posts/attributes/_new_has_one.haml index 1d0bb380..c082da6d 100644 --- a/app/views/posts/attributes/_new_has_one.haml +++ b/app/views/posts/attributes/_new_has_one.haml @@ -46,7 +46,7 @@ = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' } do - content_for :"#{id}_body" do -# @todo ocultar el modal después de guardar - .placeholder-glow{ 'hx-get': site_posts_form_path(site, layout: layout, base: id, name: name, form: form_id, swap: 'innerHTML', target: target_id, attribute: 'new_has_one', hide: modal_id, uuid: metadata.value, invalid: invalid_id, submitting: submitting_id, saved: saved_id), 'hx-trigger': 'load' } + .placeholder-glow{ 'hx-get': site_posts_form_path(site, layout: layout, base: id, name: name, form: form_id, swap: 'innerHTML', target: target_id, attribute: 'new_has_one', hide: modal_id, uuid: metadata.value, invalid: invalid_id, submitting: submitting_id, saved: saved_id, inverse: metadata.inverse, metadata.inverse => post.uuid.value), 'hx-trigger': 'load' } %span.placeholder.w-100.h-100 - content_for :"#{id}_footer" do diff --git a/app/views/posts/attributes/_new_predefined_array.haml b/app/views/posts/attributes/_new_predefined_array.haml index d5f2110e..3b251bcb 100644 --- a/app/views/posts/attributes/_new_predefined_array.haml +++ b/app/views/posts/attributes/_new_predefined_array.haml @@ -34,7 +34,7 @@ Para poder cancelar, mantenemos el estado original y desactivamos o activamos los ítemes según estén incluidos en esa lista o no. %ul.placeholder-glow{ data: { target: 'array.current' } } - - metadata.values.slice(*metadata.value).each_key do |value| + - metadata.values.invert.slice(*metadata.value).each_value do |value| = render 'posts/new_array_value', value: value = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do