From 0c259af3742441ea4ca044fd4e32540532e6c656 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 2 Dec 2013 15:09:25 -0500 Subject: [PATCH] FIX: Don't give weird progress numbers when there are deleted posts. --- .../discourse/controllers/topic_controller.js | 15 ++++++++------- .../javascripts/discourse/models/post_stream.js | 2 +- .../discourse/templates/topic.js.handlebars | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/topic_controller.js b/app/assets/javascripts/discourse/controllers/topic_controller.js index 7481e49f2d7..89ef1bca19c 100644 --- a/app/assets/javascripts/discourse/controllers/topic_controller.js +++ b/app/assets/javascripts/discourse/controllers/topic_controller.js @@ -220,12 +220,13 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected }, jumpTopDisabled: function() { - return (this.get('progressPosition') === 1); - }.property('postStream.filteredPostsCount', 'progressPosition'), + return (this.get('progressPosition') <= 3); + }.property('progressPosition'), jumpBottomDisabled: function() { - return this.get('progressPosition') >= this.get('postStream.filteredPostsCount'); - }.property('postStream.filteredPostsCount', 'progressPosition'), + return this.get('progressPosition') >= this.get('postStream.filteredPostsCount') || + this.get('progressPosition') >= this.get('highest_post_number'); + }.property('postStream.filteredPostsCount', 'highest_post_number', 'progressPosition'), canMergeTopic: function() { if (!this.get('details.can_move_posts')) return false; @@ -269,9 +270,9 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected streamPercentage: function() { if (!this.get('postStream.loaded')) { return 0; } - if (this.get('postStream.filteredPostsCount') === 0) { return 0; } - return this.get('progressPosition') / this.get('postStream.filteredPostsCount'); - }.property('postStream.loaded', 'progressPosition', 'postStream.filteredPostsCount'), + if (this.get('postStream.highest_post_number') === 0) { return 0; } + return this.get('progressPosition') / this.get('highest_post_number'); + }.property('postStream.loaded', 'progressPosition', 'highest_post_number'), multiSelectChanged: function() { // Deselect all posts when multi select is turned off diff --git a/app/assets/javascripts/discourse/models/post_stream.js b/app/assets/javascripts/discourse/models/post_stream.js index 6c22b9d8680..8b61983ae7e 100644 --- a/app/assets/javascripts/discourse/models/post_stream.js +++ b/app/assets/javascripts/discourse/models/post_stream.js @@ -188,7 +188,7 @@ Discourse.PostStream = Em.Object.extend({ var stream = this.get('stream'); var lastIndex = this.indexOf(lastLoadedPost); if (lastIndex === -1) { return []; } - if ((lastIndex + 1) >= this.get('filteredPostsCount')) { return []; } + if ((lastIndex + 1) >= this.get('highest_post_number')) { return []; } // find our window of posts return stream.slice(lastIndex+1, lastIndex+Discourse.SiteSettings.posts_per_page+1); diff --git a/app/assets/javascripts/discourse/templates/topic.js.handlebars b/app/assets/javascripts/discourse/templates/topic.js.handlebars index 45464c27c95..bd910af6a16 100644 --- a/app/assets/javascripts/discourse/templates/topic.js.handlebars +++ b/app/assets/javascripts/discourse/templates/topic.js.handlebars @@ -52,7 +52,7 @@