fixed step comment sorting

This commit is contained in:
zmagod 2016-09-20 13:31:50 +02:00
parent cd64e035c0
commit 0ca65aeca5
3 changed files with 18 additions and 9 deletions

View file

@ -64,7 +64,7 @@
var list = $(this).parents("ul");
var moreBtn = list.find(".btn-more-comments");
var listItem = moreBtn.parents('li');
$(data.html).insertBefore(listItem);
$(data.html).insertAfter(listItem);
if (data.results_number < data.per_page) {
moreBtn.remove();
} else {
@ -111,6 +111,10 @@
// });
// }
/**
* Initializes the steps comments
*
*/
function initializeComments(){
var steps = $(".step-comment");
$.each(steps, function(){
@ -164,6 +168,10 @@
});
}
/**
* Listen for ajax POST request and trigger the
* refreshComment when the comment is successfully posted
*/
function bindCommentAjax(id){
$(id)
.on('ajax:success', function() {
@ -181,7 +189,7 @@
});
}
// Updates the comments when new comment is created
function updateCommentHTML(parent, data) {
var id;
if ( $(parent.find(".comment-form")).attr("id") !== undefined ) {

View file

@ -20,7 +20,7 @@ class StepCommentsController < ApplicationController
if @comments.count > 0
more_url = url_for(step_step_comments_path(@step,
format: :json,
from: @comments.last.id))
from: @comments.first.id))
end
render :json => {
per_page: @per_page,

View file

@ -88,12 +88,13 @@ class Step < ActiveRecord::Base
end
def last_comments(last_id = 1, per_page = 20)
last_id = 9999999999999 if last_id <= 1
Comment.joins(:step_comment)
.where(step_comments: { step_id: id })
.where('comments.id < ?', last_id)
.order(created_at: :asc)
.limit(per_page)
last_id = 9999999999 if last_id <= 1
comments = Comment.joins(:step_comment)
.where(step_comments: { step_id: id })
.where('comments.id < ?', last_id)
.order(created_at: :desc)
.limit(per_page)
comments.reverse
end
def save(current_user=nil)