From 1c3804934ec855eccdbfdbf84dff01771e257188 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 6 Aug 2013 17:42:36 -0400 Subject: [PATCH] Show the entire history of replies above a post when you expend "in reply to" --- .../discourse/controllers/topic_controller.js | 21 ++++++- .../javascripts/discourse/models/post.js | 10 ++-- .../discourse/models/post_stream.js | 20 +++++++ .../templates/embedded_post.js.handlebars | 4 +- .../discourse/templates/post.js.handlebars | 12 ++-- .../templates/reply_history.js.handlebars | 1 + .../discourse/views/parent_view.js | 29 ---------- .../discourse/views/post_menu_view.js | 11 +++- .../javascripts/discourse/views/post_view.js | 56 +------------------ .../discourse/views/replies_view.js | 18 +----- .../discourse/views/reply_history.js | 17 ++++++ .../application/topic-post.css.scss | 12 ++-- app/controllers/posts_controller.rb | 9 ++- app/models/post.rb | 15 +++++ config/routes.rb | 1 + spec/controllers/posts_controller_spec.rb | 20 ++++++- spec/models/post_spec.rb | 15 ++++- test/javascripts/models/post_stream_test.js | 16 ++++++ test/javascripts/models/post_test.js | 1 + 19 files changed, 158 insertions(+), 130 deletions(-) create mode 100644 app/assets/javascripts/discourse/templates/reply_history.js.handlebars delete mode 100644 app/assets/javascripts/discourse/views/parent_view.js create mode 100644 app/assets/javascripts/discourse/views/reply_history.js diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 4832b06b5d8..0533d47eed1 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -253,10 +253,29 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, // Toggle the star on the topic - toggleStar: function(e) { + toggleStar: function() { this.get('content').toggleStar(); }, + /** + Toggle the replies this post is a reply to + + @method showReplyHistory + **/ + toggleReplyHistory: function(post) { + var replyHistory = post.get('replyHistory'), + topicController = this; + + if (replyHistory.length > 0) { + replyHistory.clear(); + } else { + post.set('loadingReplyHistory', true); + topicController.get('postStream').findReplyHistory(post).then(function () { + post.set('loadingReplyHistory', false); + }); + } + }, + /** Clears the pin from a topic for the currently logged in user diff --git a/app/assets/javascripts/discourse/models/post.js b/app/assets/javascripts/discourse/models/post.js index 420a11acdee..bec021326eb 100644 --- a/app/assets/javascripts/discourse/models/post.js +++ b/app/assets/javascripts/discourse/models/post.js @@ -8,6 +8,10 @@ **/ Discourse.Post = Discourse.Model.extend({ + init: function() { + this.set('replyHistory', []); + }, + shareUrl: function() { var user = Discourse.User.current(); var userSuffix = user ? '?u=' + user.get('username_lower') : ''; @@ -383,12 +387,6 @@ Discourse.Post.reopenClass({ }); }, - loadByPostNumber: function(topicId, postId) { - return Discourse.ajax("/posts/by_number/" + topicId + "/" + postId + ".json").then(function (result) { - return Discourse.Post.create(result); - }); - }, - loadQuote: function(postId) { return Discourse.ajax("/posts/" + postId + ".json").then(function(result) { var post = Discourse.Post.create(result); diff --git a/app/assets/javascripts/discourse/models/post_stream.js b/app/assets/javascripts/discourse/models/post_stream.js index bc251c6e683..c8c6636fd9f 100644 --- a/app/assets/javascripts/discourse/models/post_stream.js +++ b/app/assets/javascripts/discourse/models/post_stream.js @@ -459,6 +459,26 @@ Discourse.PostStream = Em.Object.extend({ } }, + /** + Returns the "thread" of posts in the history of a post. + + @method findReplyHistory + @param {Discourse.Post} post the post whose history we want + @returns {Array} the posts in the history. + **/ + findReplyHistory: function(post) { + var postStream = this, + url = "/posts/" + post.get('id') + "/reply-history.json"; + + return Discourse.ajax(url).then(function(result) { + return result.map(function (p) { + return postStream.storePost(Discourse.Post.create(p)); + }); + }).then(function (replyHistory) { + post.set('replyHistory', replyHistory); + }); + }, + /** Returns the closest post number given a postNumber that may not exist in the stream. For example, if the user asks for a post that's deleted or otherwise outside the range. diff --git a/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars b/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars index 0b1d9a70f09..a5d0be4e201 100644 --- a/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/embedded_post.js.handlebars @@ -10,9 +10,9 @@
{{{unbound cooked}}} - {{#unless view.previousPost}}{{/unless}} + {{#unless view.parentView.previousPost}}{{/unless}}
diff --git a/app/assets/javascripts/discourse/templates/post.js.handlebars b/app/assets/javascripts/discourse/templates/post.js.handlebars index c5a490d7baa..efb2f3a08ca 100644 --- a/app/assets/javascripts/discourse/templates/post.js.handlebars +++ b/app/assets/javascripts/discourse/templates/post.js.handlebars @@ -1,16 +1,12 @@
- + {{view Discourse.ReplyHistory contentBinding="replyHistory"}}
{{#if showUserReplyTab}} - - {{#if loadingParent}} + + {{#if loadingReplyHistory}} {{i18n loading}} {{else}} {{i18n post.in_reply_to}} @@ -31,7 +27,7 @@
-
+
{{#unless controller.multiSelect}}