diff --git a/Gemfile.lock b/Gemfile.lock index 676949fd..ce9198f0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -129,7 +129,7 @@ GEM dotenv (= 2.7.5) railties (>= 3.2, < 6.1) ed25519 (1.2.4) - editorial-autogestiva-jekyll-theme (0.1.0) + editorial-autogestiva-jekyll-theme (0.2.2) jekyll (~> 4.0) jekyll-data (~> 1.1) jekyll-feed (~> 0.9) diff --git a/app/models/metadata_predefined_array.rb b/app/models/metadata_predefined_array.rb new file mode 100644 index 00000000..a6e2105f --- /dev/null +++ b/app/models/metadata_predefined_array.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +# Una lista de valores predefinidos +class MetadataPredefinedArray < MetadataArray + def values + @values ||= layout[:metadata][name]['values'].map do |k, v| + { v[I18n.locale.to_s] => k } + end.inject(&:merge) + end +end diff --git a/app/models/metadata_related_posts.rb b/app/models/metadata_related_posts.rb index 7d2273a0..0ebc8a02 100644 --- a/app/models/metadata_related_posts.rb +++ b/app/models/metadata_related_posts.rb @@ -5,7 +5,7 @@ class MetadataRelatedPosts < MetadataArray # Genera un Hash de { title | slug => uuid } def values - site.posts(lang: lang).map do |p| + @values ||= site.posts(lang: lang).map do |p| { title(p) => p.uuid.value } end.inject(:merge) end diff --git a/app/views/posts/attribute_ro/_predefined_array.haml b/app/views/posts/attribute_ro/_predefined_array.haml new file mode 100644 index 00000000..d5d13b2c --- /dev/null +++ b/app/views/posts/attribute_ro/_predefined_array.haml @@ -0,0 +1,5 @@ +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td + - metadata.value.each do |v| + %span.badge.badge-primary= metadata.values.key v diff --git a/app/views/posts/attributes/_predefined_array.haml b/app/views/posts/attributes/_predefined_array.haml new file mode 100644 index 00000000..8984cb4e --- /dev/null +++ b/app/views/posts/attributes/_predefined_array.haml @@ -0,0 +1,19 @@ +.form-group + = label_tag "post_#{attribute}", post_label_t(attribute, post: post) + + .mapable{ data: { values: metadata.value.to_json, + 'default-values': metadata.values.to_json, + name: "post[#{attribute}][]", list: id_for_datalist(attribute), + remove: 'false', legend: post_label_t(attribute, post: post), + described: id_for_help(attribute) } } + + = text_field(*field_name_for('post', attribute, '[]'), + value: metadata.value.join(', '), + **field_options(attribute, metadata)) + + = render 'posts/attribute_feedback', + post: post, attribute: attribute, metadata: metadata + + %datalist{ id: id_for_datalist(attribute) } + - metadata.values.keys.each do |value| + %option{ value: value }