From b4027e66869ef62e3e489655a4e4a82e5eb82c56 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 9 Sep 2024 11:02:27 -0300 Subject: [PATCH] feat: poder configurar la fecha por defecto #17333 --- app/models/metadata_date.rb | 19 ++++++++++++++++++- app/views/posts/attribute_ro/_date.haml | 2 +- app/views/posts/attributes/_date.haml | 2 +- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/models/metadata_date.rb b/app/models/metadata_date.rb index 9e655d4c..cdde77ce 100644 --- a/app/models/metadata_date.rb +++ b/app/models/metadata_date.rb @@ -1,8 +1,25 @@ # frozen_string_literal: true class MetadataDate < MetadataTemplate + # La fecha de hoy si no hay nada + # + # @return [Date,nil] def default_value - Date.today + 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 + end end # Devuelve una fecha, si no hay ninguna es la fecha de hoy. diff --git a/app/views/posts/attribute_ro/_date.haml b/app/views/posts/attribute_ro/_date.haml index cf8ea8ac..d7e275c7 100644 --- a/app/views/posts/attribute_ro/_date.haml +++ b/app/views/posts/attribute_ro/_date.haml @@ -1,3 +1,3 @@ %tr{ id: attribute } %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 diff --git a/app/views/posts/attributes/_date.haml b/app/views/posts/attributes/_date.haml index 1347c59c..f875c53e 100644 --- a/app/views/posts/attributes/_date.haml +++ b/app/views/posts/attributes/_date.haml @@ -1,6 +1,6 @@ .form-group = 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}', data: { 'pattern-mismatch': t('metadata.date.invalid_format') } = render 'posts/attribute_feedback',