From ee7d21030ec1dcc5e24dc9adb737ea1254058ee0 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 21 Oct 2024 16:16:52 -0300 Subject: [PATCH 1/5] =?UTF-8?q?fix:=20pasar=20la=20relaci=C3=B3n=20inversa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/controllers/array_controller.js | 6 +++++- app/views/posts/_new_related_post.haml | 1 + app/views/posts/attributes/_new_belongs_to.haml | 2 +- .../posts/attributes/_new_has_and_belongs_to_many.haml | 4 ++-- app/views/posts/attributes/_new_has_many.haml | 2 +- app/views/posts/modal.haml | 7 +++++++ app/views/posts/new_related_post.haml | 2 +- 7 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/javascript/controllers/array_controller.js b/app/javascript/controllers/array_controller.js index 7b0ba8c4..5540e839 100644 --- a/app/javascript/controllers/array_controller.js +++ b/app/javascript/controllers/array_controller.js @@ -6,7 +6,11 @@ export default class extends Controller { connect() { // TODO: Stimulus >1 this.newArrayValueURL = new URL(window.location.origin); - this.newArrayValueURL.pathname = this.element.dataset.arrayNewArrayValue; + + const [ pathname, search ] = this.element.dataset.arrayNewArrayValue.split("?"); + + this.newArrayValueURL.pathname = pathname; + this.newArrayValueURL.search = `?${search}`; this.originalValue = JSON.parse(this.element.dataset.arrayOriginalValue); } diff --git a/app/views/posts/_new_related_post.haml b/app/views/posts/_new_related_post.haml index 7dcb264f..236abc42 100644 --- a/app/views/posts/_new_related_post.haml +++ b/app/views/posts/_new_related_post.haml @@ -26,6 +26,7 @@ - form_params[:modal_id] = form_params[:show] = modal_id = random_id -# Asociar un modal con una tarjeta - form_params[:result_id] = card_id + - form_params[:inverse] = local_assigns[:inverse] -# @todo Poder indicar en qué elemento queremos asociar lo descargado = render 'bootstrap/btn', content: t('.edit'), data: { controller: 'htmx', action: 'modal#showAnother htmx#getUrlOnce', 'modal-show-value': modal_id, 'htmx-get-url-param': site_posts_modal_path(post.site, **form_params) }, id: random_id diff --git a/app/views/posts/attributes/_new_belongs_to.haml b/app/views/posts/attributes/_new_belongs_to.haml index 7f9a66dd..849b3eff 100644 --- a/app/views/posts/attributes/_new_belongs_to.haml +++ b/app/views/posts/attributes/_new_belongs_to.haml @@ -46,7 +46,7 @@ .row.no-gutters.placeholder-glow{ data: { 'array-target': 'current' } } -# @todo issue-7537 - if !metadata.empty? && (indexed_post = site.indexed_posts.find_by(post_id: metadata.value)) - = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type + = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type, inverse: metadata.inverse = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do - content_for :"#{id}_header" 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 0859ae33..c5d91e7f 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 @@ -20,7 +20,7 @@ controllers = %w[modal array] controllers << 'required-checkbox' if metadata.required -%div{ id: modal_id, data: { controller: controllers.join(' '), 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_related_post_path(site) } } +%div{ id: modal_id, data: { controller: controllers.join(' '), 'array-original-value': metadata.value.to_json, 'array-new-array-value': site_posts_new_related_post_path(site, inverse: metadata.inverse) } } %template{ data: { 'array-target': 'placeholder' } } .col.p-3{ 'aria-hidden': 'true' } %span.placeholder.w-100 @@ -48,7 +48,7 @@ -# @todo issue-7537 - metadata.value.each do |uuid| - if (indexed_post = site.indexed_posts.find_by(post_id: uuid)) - = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type + = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type, inverse: metadata.inverse = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do - content_for :"#{id}_header" do diff --git a/app/views/posts/attributes/_new_has_many.haml b/app/views/posts/attributes/_new_has_many.haml index ff657359..e2d9d758 100644 --- a/app/views/posts/attributes/_new_has_many.haml +++ b/app/views/posts/attributes/_new_has_many.haml @@ -47,7 +47,7 @@ -# @todo issue-7537 - metadata.value.each do |uuid| - if (indexed_post = site.indexed_posts.find_by(post_id: uuid)) - = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type + = render 'posts/new_related_post', post: indexed_post, attribute: metadata.type, inverse: metadata.inverse = render 'bootstrap/modal', id: id, modal_content_attributes: { class: 'h-100' }, hide_actions: ['array#cancel'], keydown_actions: %w[keydown->array#cancelWithEscape] do - content_for :"#{id}_header" do diff --git a/app/views/posts/modal.haml b/app/views/posts/modal.haml index 14836118..2b50e41c 100644 --- a/app/views/posts/modal.haml +++ b/app/views/posts/modal.haml @@ -16,6 +16,11 @@ result_id = pluck_param(:result_id) form_id = random_id except = %i[date] + + if (inverse = pluck_param(:inverse, optional: true)) + except << inverse.to_sym + end + options = { id: form_id, multipart: true, @@ -45,6 +50,8 @@ = hidden_field_tag 'result_id', result_id = hidden_field_tag 'modal_id', modal_id = hidden_field_tag "#{base}[layout]", post.layout.name + - if inverse + = hidden_field_tag 'inverse', inverse = render 'errors', post: post = render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale, except: except diff --git a/app/views/posts/new_related_post.haml b/app/views/posts/new_related_post.haml index 11fdf3af..1b173fa9 100644 --- a/app/views/posts/new_related_post.haml +++ b/app/views/posts/new_related_post.haml @@ -1 +1 @@ -= render 'posts/new_related_post', post: @indexed_post, modal_id: pluck_param(:modal_id, optional: true) += render 'posts/new_related_post', post: @indexed_post, modal_id: pluck_param(:modal_id, optional: true), inverse: pluck_param(:inverse, optional: true) From 795256f80363f66d1fe8e51c48c21b5c5f18a80c Mon Sep 17 00:00:00 2001 From: f Date: Mon, 21 Oct 2024 16:18:27 -0300 Subject: [PATCH 2/5] fix: poder vaciar el predefined value --- app/models/metadata_new_predefined_value.rb | 6 +++++- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/models/metadata_new_predefined_value.rb b/app/models/metadata_new_predefined_value.rb index ff839759..929934b2 100644 --- a/app/models/metadata_new_predefined_value.rb +++ b/app/models/metadata_new_predefined_value.rb @@ -1,4 +1,8 @@ # frozen_string_literal: true # Nueva interfaz -class MetadataNewPredefinedValue < MetadataPredefinedValue; end +class MetadataNewPredefinedValue < MetadataPredefinedValue + def values + @values ||= (required ? {} : { I18n.t('posts.attributes.new_predefined_value.empty') => '' }).merge(super) + end +end diff --git a/config/locales/en.yml b/config/locales/en.yml index ec5b34a9..955f3d20 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -761,6 +761,8 @@ en: edit: "Edit" new_predefined_array: edit: "Edit" + new_predefined_value: + empty: "(Empty)" new_array: edit: "Edit" new_has_one: diff --git a/config/locales/es.yml b/config/locales/es.yml index 61c645a0..6f567933 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -768,8 +768,10 @@ es: new_has_and_belongs_to_many: edit: "Editar" new_predefined_array: + empty: "(Vacío)" edit: "Editar" new_predefined_value: + empty: "(Vacío)" edit: "Editar" new_array: edit: "Editar" From 48085be16297b1a1cec9e1a47f9ffd11424bf53d Mon Sep 17 00:00:00 2001 From: f Date: Mon, 21 Oct 2024 16:30:04 -0300 Subject: [PATCH 3/5] fix: mismos niveles de titulo --- app/views/posts/attributes/_new_array.haml | 2 +- app/views/posts/attributes/_new_has_and_belongs_to_many.haml | 2 +- app/views/posts/attributes/_new_predefined_array.haml | 2 +- app/views/posts/attributes/_new_predefined_value.haml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/posts/attributes/_new_array.haml b/app/views/posts/attributes/_new_array.haml index 56899fe3..1ed82e98 100644 --- a/app/views/posts/attributes/_new_array.haml +++ b/app/views/posts/attributes/_new_array.haml @@ -19,7 +19,7 @@ como obligatorio al validar el formulario. .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post), class: 'mb-0' + = label_tag id, post_label_t(attribute, post: post), class: 'mb-0 h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty? = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' -# Mostramos la lista de valores actuales. 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 c5d91e7f..17603b29 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 @@ -29,7 +29,7 @@ = hidden_field_tag name, '' .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post) + = label_tag id, post_label_t(attribute, post: post), class: 'h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty? = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' diff --git a/app/views/posts/attributes/_new_predefined_array.haml b/app/views/posts/attributes/_new_predefined_array.haml index 68856daa..0afa253d 100644 --- a/app/views/posts/attributes/_new_predefined_array.haml +++ b/app/views/posts/attributes/_new_predefined_array.haml @@ -18,7 +18,7 @@ = hidden_field_tag name, '' .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post) + = label_tag id, post_label_t(attribute, post: post), class: 'h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty? = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' diff --git a/app/views/posts/attributes/_new_predefined_value.haml b/app/views/posts/attributes/_new_predefined_value.haml index 2eb11335..20bd5d0b 100644 --- a/app/views/posts/attributes/_new_predefined_value.haml +++ b/app/views/posts/attributes/_new_predefined_value.haml @@ -29,7 +29,7 @@ = hidden_field_tag name, '' .d-flex.align-items-center.justify-content-between %div - = label_tag id, post_label_t(attribute, post: post) + = label_tag id, post_label_t(attribute, post: post), class: 'h3' = render 'posts/required_checkbox', required: metadata.required, name: name, initial: metadata.empty?, type: 'radio' = render 'bootstrap/btn', content: t('.edit'), action: 'modal#show' From 379f4ab31fb1cd97498838f11773c93a8a1565c9 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 21 Oct 2024 16:32:51 -0300 Subject: [PATCH 4/5] fix: ocultar el modal al guardar --- app/views/posts/attributes/_new_has_and_belongs_to_many.haml | 1 + app/views/posts/modal.haml | 2 ++ 2 files changed, 3 insertions(+) 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 17603b29..6959ecf7 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 @@ -91,6 +91,7 @@ para que sea externo al formulario actual. - content_for :post_form do %form{ id: post_form_id, 'hx-get': site_posts_form_path(site), 'hx-target': "##{post_form_loaded_id}" } + %input{ type: 'hidden', name: 'modal_id', value: modal_id } %input{ type: 'hidden', name: 'show', value: post_modal_id } %input{ type: 'hidden', name: 'hide', value: modal_id } %input{ type: 'hidden', name: 'target', value: value_list_id } diff --git a/app/views/posts/modal.haml b/app/views/posts/modal.haml index 2b50e41c..6875cea8 100644 --- a/app/views/posts/modal.haml +++ b/app/views/posts/modal.haml @@ -50,6 +50,8 @@ = hidden_field_tag 'result_id', result_id = hidden_field_tag 'modal_id', modal_id = hidden_field_tag "#{base}[layout]", post.layout.name + = hidden_field_tag 'hide', pluck_param((post.errors.empty? ? :show : :hide), optional: true) || pluck_param(:modal_id, optional: true) + = hidden_field_tag 'show', pluck_param((post.errors.empty? ? :hide : :show), optional: true) - if inverse = hidden_field_tag 'inverse', inverse From 256a8b1da0cf73c95c2718ceb45d03ea40ffdf2c Mon Sep 17 00:00:00 2001 From: f Date: Mon, 21 Oct 2024 16:42:28 -0300 Subject: [PATCH 5/5] =?UTF-8?q?fix:=20no=20enviar=20valores=20inversos=20v?= =?UTF-8?q?ac=C3=ADos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/posts/modal.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/posts/modal.haml b/app/views/posts/modal.haml index 6875cea8..e589dfa8 100644 --- a/app/views/posts/modal.haml +++ b/app/views/posts/modal.haml @@ -59,7 +59,8 @@ = render 'posts/attributes', site: site, post: post, dir: dir, base: base, locale: locale, except: except -# @todo Volver obligatorios? - except.each do |attr| - %input{ type: 'hidden', name: "#{base}[#{attr}]", value: pluck_param(attr, optional: true) } + - if (value = pluck_param(attr, optional: true)) + = hidden_field_tag "#{base}[#{attr}]", value - content_for :"#{modal_id}_footer" do -# = render 'posts/validation', site: site, invalid: { id: invalid_id }, submitting: { id: submitting_id }