From d5ce99deee63e54d90e44dce8481dfb7882c3d18 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 22 Oct 2024 13:30:02 -0300 Subject: [PATCH 1/2] fix: no es necesario para new_has_one --- app/models/metadata_new_has_one.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/models/metadata_new_has_one.rb b/app/models/metadata_new_has_one.rb index 642273e3..b75b14ae 100644 --- a/app/models/metadata_new_has_one.rb +++ b/app/models/metadata_new_has_one.rb @@ -1,6 +1,4 @@ # frozen_string_literal: true # Nueva interfaz para relaciones 1:1 -class MetadataNewHasOne < MetadataHasOne - include Metadata::UnusedValuesConcern -end +class MetadataNewHasOne < MetadataHasOne; end From c82203a9f6a0fef81218960f7411e54e648a3b89 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 22 Oct 2024 13:30:25 -0300 Subject: [PATCH 2/2] =?UTF-8?q?fix:=20mostrar=20la=20relaci=C3=B3n=20desha?= =?UTF-8?q?bilitada=20#17616?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../concerns/metadata/unused_values_concern.rb | 18 +++++++++++------- app/views/bootstrap/_custom_checkbox.haml | 2 +- .../posts/attributes/_new_belongs_to.haml | 5 +++-- app/views/posts/attributes/_new_has_many.haml | 5 +++-- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 6 files changed, 22 insertions(+), 12 deletions(-) diff --git a/app/models/concerns/metadata/unused_values_concern.rb b/app/models/concerns/metadata/unused_values_concern.rb index 6f0a0bf1..79cdbe65 100644 --- a/app/models/concerns/metadata/unused_values_concern.rb +++ b/app/models/concerns/metadata/unused_values_concern.rb @@ -9,18 +9,22 @@ module Metadata extend ActiveSupport::Concern included do - # Genera un Hash de { title | slug => uuid }, excluyendo el Post - # actual y todos los que ya tengan una relación inversa, para no - # romperla. + # Excluye el Post actual y todos los que ya tengan una relación + # inversa, para no romperla. # - # @return [Hash] + # @return [Array] def values @values ||= posts.map do |p| next if p.uuid.value == post.uuid.value - next unless inverse? && (p[inverse].empty? || [p[inverse].value].flatten.include?(post.uuid.value)) - [title(p), p.uuid.value] - end.compact.to_h + disabled = false + + if inverse? + disabled = p[inverse].empty? || ![p[inverse].value].flatten.include?(post.uuid.value) + end + + [title(p), p.uuid.value, disabled] + end.compact end end end diff --git a/app/views/bootstrap/_custom_checkbox.haml b/app/views/bootstrap/_custom_checkbox.haml index 73910a6f..dbef7516 100644 --- a/app/views/bootstrap/_custom_checkbox.haml +++ b/app/views/bootstrap/_custom_checkbox.haml @@ -1,6 +1,6 @@ :ruby help_id = "#{id}_help" - checkbox_attributes = local_assigns.slice(:id, :type, :name, :value, :required, :checked, :data) + checkbox_attributes = local_assigns.slice(:id, :type, :name, :value, :required, :checked, :data, :disabled) checkbox_attributes[:type] ||= 'checkbox' .custom-control{ class: "custom-#{checkbox_attributes[:type]}" } diff --git a/app/views/posts/attributes/_new_belongs_to.haml b/app/views/posts/attributes/_new_belongs_to.haml index 849b3eff..661f3d27 100644 --- a/app/views/posts/attributes/_new_belongs_to.haml +++ b/app/views/posts/attributes/_new_belongs_to.haml @@ -56,9 +56,10 @@ - content_for :"#{id}_body" do .form-group.mb-0{ id: value_list_id } - - metadata.values.each_pair do |value, uuid| + - metadata.values.each do |(value, uuid, disabled)| = render 'targets/array/item', value: uuid, 'send-value': uuid, 'human-value': value, class: 'mb-2' do - = render 'bootstrap/custom_checkbox', name: name, id: random_id, value: uuid, checked: metadata.value.include?(uuid), content: value, type: 'radio' + = render 'bootstrap/custom_checkbox', name: name, id: random_id, value: uuid, checked: metadata.value.include?(uuid), content: value, type: 'radio', disabled: disabled do + = t('posts.attributes.new_belongs_to.disabled') if disabled -# Según la definición del campo, si hay un filtro, tenemos que poder diff --git a/app/views/posts/attributes/_new_has_many.haml b/app/views/posts/attributes/_new_has_many.haml index e2d9d758..c46bc84a 100644 --- a/app/views/posts/attributes/_new_has_many.haml +++ b/app/views/posts/attributes/_new_has_many.haml @@ -57,9 +57,10 @@ - content_for :"#{id}_body" do .form-group.mb-0{ id: value_list_id } - - metadata.values.each_pair do |value, uuid| + - metadata.values.each do |(value, uuid, disabled)| = render 'targets/array/item', value: uuid, 'send-value': uuid, 'human-value': value, class: 'mb-2' do - = render 'bootstrap/custom_checkbox', name: name, id: random_id, value: uuid, checked: metadata.value.include?(uuid), content: value, data: { action: 'required-checkbox#change', 'required-checkbox-target': 'checkbox' } + = render 'bootstrap/custom_checkbox', name: name, id: random_id, value: uuid, checked: metadata.value.include?(uuid), content: value, data: { action: 'required-checkbox#change', 'required-checkbox-target': 'checkbox' }, disabled: disabled do + = t('posts.attributes.new_has_many.disabled') if disabled -# Según la definición del campo, si hay un filtro, tenemos que poder diff --git a/config/locales/en.yml b/config/locales/en.yml index 955f3d20..c348d73b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -757,6 +757,7 @@ en: label: Draft new_has_many: edit: "Edit" + disabled: "It's already associated to an article." new_has_and_belongs_to_many: edit: "Edit" new_predefined_array: @@ -769,6 +770,7 @@ en: edit: "Edit" new_belongs_to: edit: "Edit" + disabled: "It's already associated to an article." required_checkbox: required: "Please select at least one option." reorder: diff --git a/config/locales/es.yml b/config/locales/es.yml index 6f567933..e9a52019 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -765,6 +765,7 @@ es: label: Borrador new_has_many: edit: "Editar" + disabled: "Ya está relacionado con otro artículo." new_has_and_belongs_to_many: edit: "Editar" new_predefined_array: @@ -779,6 +780,7 @@ es: edit: "Editar" new_belongs_to: edit: "Editar" + disabled: "Ya está relacionado con otro artículo." required_checkbox: required: "Seleccioná al menos una opción." reorder: