mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-15 03:41:41 +00:00
poder elegir valores de una lista predefinida
This commit is contained in:
parent
b0c2896f5f
commit
0485774507
5 changed files with 36 additions and 2 deletions
|
@ -129,7 +129,7 @@ GEM
|
||||||
dotenv (= 2.7.5)
|
dotenv (= 2.7.5)
|
||||||
railties (>= 3.2, < 6.1)
|
railties (>= 3.2, < 6.1)
|
||||||
ed25519 (1.2.4)
|
ed25519 (1.2.4)
|
||||||
editorial-autogestiva-jekyll-theme (0.1.0)
|
editorial-autogestiva-jekyll-theme (0.2.2)
|
||||||
jekyll (~> 4.0)
|
jekyll (~> 4.0)
|
||||||
jekyll-data (~> 1.1)
|
jekyll-data (~> 1.1)
|
||||||
jekyll-feed (~> 0.9)
|
jekyll-feed (~> 0.9)
|
||||||
|
|
10
app/models/metadata_predefined_array.rb
Normal file
10
app/models/metadata_predefined_array.rb
Normal file
|
@ -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
|
|
@ -5,7 +5,7 @@
|
||||||
class MetadataRelatedPosts < MetadataArray
|
class MetadataRelatedPosts < MetadataArray
|
||||||
# Genera un Hash de { title | slug => uuid }
|
# Genera un Hash de { title | slug => uuid }
|
||||||
def values
|
def values
|
||||||
site.posts(lang: lang).map do |p|
|
@values ||= site.posts(lang: lang).map do |p|
|
||||||
{ title(p) => p.uuid.value }
|
{ title(p) => p.uuid.value }
|
||||||
end.inject(:merge)
|
end.inject(:merge)
|
||||||
end
|
end
|
||||||
|
|
5
app/views/posts/attribute_ro/_predefined_array.haml
Normal file
5
app/views/posts/attribute_ro/_predefined_array.haml
Normal file
|
@ -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
|
19
app/views/posts/attributes/_predefined_array.haml
Normal file
19
app/views/posts/attributes/_predefined_array.haml
Normal file
|
@ -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 }
|
Loading…
Reference in a new issue