mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-24 14:26:22 +00:00
feat: poder configurar la fecha por defecto #17333
This commit is contained in:
parent
11e2353c2f
commit
b4027e6686
3 changed files with 20 additions and 3 deletions
|
@ -1,9 +1,26 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class MetadataDate < MetadataTemplate
|
class MetadataDate < MetadataTemplate
|
||||||
|
# La fecha de hoy si no hay nada
|
||||||
|
#
|
||||||
|
# @return [Date,nil]
|
||||||
def default_value
|
def default_value
|
||||||
|
case (dv = super)
|
||||||
|
when String
|
||||||
|
if dv.present?
|
||||||
|
begin
|
||||||
|
Date.parse(dv)
|
||||||
|
rescue Date::Error => e
|
||||||
|
ExceptionNotifier.notify_exception(e, data: { site: site.name, post: post.id, name:, type: })
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
else
|
||||||
Date.today
|
Date.today
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Devuelve una fecha, si no hay ninguna es la fecha de hoy.
|
# Devuelve una fecha, si no hay ninguna es la fecha de hoy.
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
%tr{ id: attribute }
|
%tr{ id: attribute }
|
||||||
%th= post_label_t(attribute, post: post)
|
%th= post_label_t(attribute, post: post)
|
||||||
%td{ dir: dir, lang: locale }= l metadata.value.to_date
|
%td{ dir: dir, lang: locale }= l metadata.value
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
.form-group
|
.form-group
|
||||||
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
|
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post)
|
||||||
= date_field base, attribute, value: metadata.value.to_date.strftime('%F'),
|
= date_field base, attribute, value: metadata.value&.strftime('%F'),
|
||||||
**field_options(attribute, metadata), pattern: '\d{4}-\d{2}-\d{2}',
|
**field_options(attribute, metadata), pattern: '\d{4}-\d{2}-\d{2}',
|
||||||
data: { 'pattern-mismatch': t('metadata.date.invalid_format') }
|
data: { 'pattern-mismatch': t('metadata.date.invalid_format') }
|
||||||
= render 'posts/attribute_feedback',
|
= render 'posts/attribute_feedback',
|
||||||
|
|
Loading…
Reference in a new issue