mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 05:04:35 +08:00
fixed step comment sorting
This commit is contained in:
parent
cd64e035c0
commit
0ca65aeca5
3 changed files with 18 additions and 9 deletions
|
@ -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 ) {
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue