From 85ef3696de7dd2a9d53d2c137b8984e304bc6520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Tue, 12 Sep 2017 15:37:47 +0200 Subject: [PATCH] UX: show date of last edit on wiki topics --- .../discourse/lib/transform-post.js.es6 | 1 + .../javascripts/discourse/widgets/post.js.es6 | 23 +++++++++++-------- .../stylesheets/common/base/topic-post.scss | 3 ++- app/serializers/post_serializer.rb | 11 ++++++++- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/transform-post.js.es6 b/app/assets/javascripts/discourse/lib/transform-post.js.es6 index 7df3954b302..5faac346ece 100644 --- a/app/assets/javascripts/discourse/lib/transform-post.js.es6 +++ b/app/assets/javascripts/discourse/lib/transform-post.js.es6 @@ -35,6 +35,7 @@ export function transformBasicPost(post) { primary_group_flair_bg_color: post.primary_group_flair_bg_color, primary_group_flair_color: post.primary_group_flair_color, wiki: post.wiki, + lastWikiEdit: post.last_wiki_edit, firstPost: post.post_number === 1, post_number: post.post_number, cooked: post.cooked, diff --git a/app/assets/javascripts/discourse/widgets/post.js.es6 b/app/assets/javascripts/discourse/widgets/post.js.es6 index 20d6168e8ca..4b5acec52d8 100644 --- a/app/assets/javascripts/discourse/widgets/post.js.es6 +++ b/app/assets/javascripts/discourse/widgets/post.js.es6 @@ -171,19 +171,22 @@ createWidget('post-meta-data', { }, iconNode('eye-slash'))); } + const lastWikiEdit = attrs.wiki && attrs.lastWikiEdit && new Date(attrs.lastWikiEdit); const createdAt = new Date(attrs.created_at); - if (createdAt) { - result.push(h('div.post-info', - h('a.post-date', { - attributes: { - href: attrs.shareUrl, - 'data-share-url': attrs.shareUrl, - 'data-post-number': attrs.post_number, - } - }, dateNode(createdAt)) - )); + const date = lastWikiEdit ? dateNode(lastWikiEdit) : dateNode(createdAt); + const attributes = { + class: "post-date", + href: attrs.shareUrl, + 'data-share-url': attrs.shareUrl, + 'data-post-number': attrs.post_number + }; + + if (lastWikiEdit) { + attributes["class"] += " last-wiki-edit"; } + result.push(h('div.post-info', h('a', { attributes }, date))); + if (attrs.via_email) { result.push(this.attach('post-email-indicator', attrs)); } diff --git a/app/assets/stylesheets/common/base/topic-post.scss b/app/assets/stylesheets/common/base/topic-post.scss index 1485257753c..40b80677e1f 100644 --- a/app/assets/stylesheets/common/base/topic-post.scss +++ b/app/assets/stylesheets/common/base/topic-post.scss @@ -247,7 +247,8 @@ aside.quote { } } - .wiki { + .wiki, + .last-wiki-edit { color: green !important; } diff --git a/app/serializers/post_serializer.rb b/app/serializers/post_serializer.rb index e03d7891056..87ba9d365e6 100644 --- a/app/serializers/post_serializer.rb +++ b/app/serializers/post_serializer.rb @@ -68,7 +68,8 @@ class PostSerializer < BasicPostSerializer :via_email, :is_auto_generated, :action_code, - :action_code_who + :action_code_who, + :last_wiki_edit def initialize(object, opts) super(object, opts) @@ -353,6 +354,14 @@ class PostSerializer < BasicPostSerializer include_action_code? && action_code_who.present? end + def last_wiki_edit + object.revisions.last.updated_at + end + + def include_last_wiki_edit? + object.wiki && object.post_number == 1 + end + private def post_actions