From 6b1eccade35aec862160950549123f59be7d1fe7 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 13 Sep 2023 17:52:21 -0300 Subject: [PATCH] =?UTF-8?q?feat:=20fecha=20de=20creaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/metadata_created_at.rb | 14 ++++++++++++++ app/models/post.rb | 8 ++++++-- app/views/posts/attribute_ro/_created_at.haml | 4 ++++ app/views/posts/attributes/_created_at.haml | 1 + config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 6 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 app/models/metadata_created_at.rb create mode 100644 app/views/posts/attribute_ro/_created_at.haml create mode 100644 app/views/posts/attributes/_created_at.haml diff --git a/app/models/metadata_created_at.rb b/app/models/metadata_created_at.rb new file mode 100644 index 00000000..2a7c07ed --- /dev/null +++ b/app/models/metadata_created_at.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +# Fecha y hora de creación +class MetadataCreatedAt < MetadataTemplate + # Por defecto la hora actual + def default_value + Time.now + end + + # Nunca cambia + def value=(new_value) + value + end +end diff --git a/app/models/post.rb b/app/models/post.rb index 36a0b02e..8bd5dab3 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -12,7 +12,7 @@ class Post DEFAULT_ATTRIBUTES = %i[site document layout].freeze # Otros atributos que no vienen en los metadatos PRIVATE_ATTRIBUTES = %i[path slug attributes errors].freeze - PUBLIC_ATTRIBUTES = %i[lang date uuid].freeze + PUBLIC_ATTRIBUTES = %i[lang date uuid created_at].freeze ATTR_SUFFIXES = %w[? =].freeze attr_reader :attributes, :errors, :layout, :site, :document @@ -217,6 +217,11 @@ class Post post: self, required: true) end + # La fecha de creación inmodificable del post + def created_at + @metadata[:created_at] ||= MetadataCreatedAt.new(document: document, site: site, layout: layout, name: :created_at, type: :timestamp, post: self, required: true) + end + # Detecta si es un atributo válido o no, a partir de la tabla de la # plantilla def attribute?(mid) @@ -267,7 +272,6 @@ class Post # Y que no se procese liquid yaml['liquid'] = false yaml['usuaries'] = usuaries.map(&:id).uniq - yaml['created_at'] ||= modified_at.dup yaml['last_modified_at'] = modified_at "#{yaml.to_yaml}---\n\n#{body}" diff --git a/app/views/posts/attribute_ro/_created_at.haml b/app/views/posts/attribute_ro/_created_at.haml new file mode 100644 index 00000000..04f6d716 --- /dev/null +++ b/app/views/posts/attribute_ro/_created_at.haml @@ -0,0 +1,4 @@ +%tr{ id: attribute } + %th= post_label_t(attribute, post: post) + %td{ dir: dir, lang: locale } + %time{ datetime: metadata.value.xmlschema }= l metadata.value diff --git a/app/views/posts/attributes/_created_at.haml b/app/views/posts/attributes/_created_at.haml new file mode 100644 index 00000000..0aab9802 --- /dev/null +++ b/app/views/posts/attributes/_created_at.haml @@ -0,0 +1 @@ +-# nada diff --git a/config/locales/en.yml b/config/locales/en.yml index 0dad2e68..5c00701c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -524,6 +524,8 @@ en: feedback: 'This field cannot be empty!' uuid: label: 'Unique identifier' + created_at: + label: 'Created at' geo: uri: 'Open in app' osm: 'Open in web map' diff --git a/config/locales/es.yml b/config/locales/es.yml index d899b99c..0ff7e1c8 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -532,6 +532,8 @@ es: feedback: '¡Este campo no puede estar vacío!' uuid: label: 'Identificador único' + created_at: + label: 'Fecha de creación' geo: uri: 'Abrir en aplicación' osm: 'Abrir en mapa web'