mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 11:46:22 +00:00
Merge branch 'issue-12985' into issue-7537
This commit is contained in:
commit
5078d39d58
3 changed files with 42 additions and 0 deletions
29
app/models/metadata_has_one.rb
Normal file
29
app/models/metadata_has_one.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class MetadataHasOne < MetadataBelongsTo
|
||||||
|
alias has_one belongs_to
|
||||||
|
alias had_one belonged_to
|
||||||
|
|
||||||
|
def save
|
||||||
|
# XXX: DRY
|
||||||
|
if !changed?
|
||||||
|
self[:value] = document_value
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
self[:value] = sanitize value
|
||||||
|
|
||||||
|
return true unless changed?
|
||||||
|
return true unless inverse?
|
||||||
|
|
||||||
|
had_one[inverse]&.value = '' if had_one
|
||||||
|
has_one[inverse]&.value = post.uuid.value if has_one
|
||||||
|
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def related_methods
|
||||||
|
@related_methods ||= %i[has_one had_one].freeze
|
||||||
|
end
|
||||||
|
end
|
6
app/views/posts/attribute_ro/_has_one.haml
Normal file
6
app/views/posts/attribute_ro/_has_one.haml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
%tr{ id: attribute }
|
||||||
|
%th= post_label_t(attribute, post: post)
|
||||||
|
%td{ dir: dir, lang: locale }
|
||||||
|
- p = metadata.has_one
|
||||||
|
- if p
|
||||||
|
= link_to p.title.value, site_post_path(site, p.id)
|
7
app/views/posts/attributes/_has_one.haml
Normal file
7
app/views/posts/attributes/_has_one.haml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
.form-group
|
||||||
|
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
|
||||||
|
= select_tag(plain_field_name_for(base, attribute),
|
||||||
|
options_for_select(metadata.values, metadata.value),
|
||||||
|
**field_options(attribute, metadata), include_blank: t('.empty'))
|
||||||
|
= render 'posts/attribute_feedback',
|
||||||
|
post: post, attribute: attribute, metadata: metadata
|
Loading…
Reference in a new issue