diff --git a/app/assets/javascripts/my_modules/results.js b/app/assets/javascripts/my_modules/results.js
index 8853fc3ce..61246ecbf 100644
--- a/app/assets/javascripts/my_modules/results.js
+++ b/app/assets/javascripts/my_modules/results.js
@@ -1,5 +1,4 @@
//= require comments
-
function initHandsOnTables(root) {
root.find("div.hot-table").each(function() {
var $container = $(this).find(".step-result-hot-table");
@@ -49,7 +48,7 @@ function initResultCommentForm($el) {
.find("li.no-comments").remove();
list.parent().find(".content-comments")
- .prepend("
")
+ .append("")
.scrollTop(0);
list.parents("ul").find("> li.comment:gt(8)").remove();
$("#comment_message", $form).val("");
@@ -58,9 +57,7 @@ function initResultCommentForm($el) {
$(".help-block", $form)
.html("")
.addClass("hide");
- scrollCommentOptions(
- list.parent().find(".content-comments .dropdown-comment")
- );
+ scrollBottom($el);
}
})
.on("ajax:error", function (ev, xhr) {
@@ -77,6 +74,7 @@ function initResultCommentForm($el) {
}
})
.on("ajax:complete", function () {
+ scrollBottom($("#comment_message", $form));
$("#comment_message", $form)
.attr("readonly", false)
.focus();
@@ -92,7 +90,7 @@ function initResultCommentsLink($el) {
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 {
@@ -106,38 +104,72 @@ function initResultCommentsLink($el) {
});
}
-function initResultCommentTabAjax() {
- $(".comment-tab-link")
- .on("ajax:before", function (e) {
- var $this = $(this);
- var parentNode = $this.parents("li");
- var targetId = $this.attr("aria-controls");
+// function initResultCommentTabAjax(element) {
+// debugger;
+// $(element)
+// .on("ajax:before", function (e) {
+// debugger;
+// var $this = $(this);
+// var parentNode = $this.parents("li");
+// var targetId = $this.attr("aria-controls");
+//
+// if (parentNode.hasClass("active")) {
+// return false;
+// }
+// })
+// .on("ajax:success", function (e, data) {
+// if (data.html) {
+// var $this = $(this);
+// var targetId = $this.attr("aria-controls");
+// var target = $("#" + targetId);
+// var parentNode = $this.parents("ul").parent();
+//
+// target.html(data.html);
+// initResultCommentForm(parentNode);
+// initResultCommentsLink(parentNode);
+//
+// parentNode.find(".active").removeClass("active");
+// $this.parents("li").addClass("active");
+// target.addClass("active");
+// }
+// })
+// .on("ajax:error", function(e, xhr, status, error) {
+// // TODO
+// });
+// }
- if (parentNode.hasClass("active")) {
- return false;
- }
- })
- .on("ajax:success", function (e, data) {
- if (data.html) {
- var $this = $(this);
- var targetId = $this.attr("aria-controls");
- var target = $("#" + targetId);
- var parentNode = $this.parents("ul").parent();
-
- target.html(data.html);
- initResultCommentForm(parentNode);
- initResultCommentsLink(parentNode);
-
- parentNode.find(".active").removeClass("active");
- $this.parents("li").addClass("active");
- target.addClass("active");
- }
- })
- .on("ajax:error", function(e, xhr, status, error) {
- // TODO
+function loadCommentsIn() {
+ $.each($(".result-comment"), function() {
+ var that = $(this);
+ var link = that.attr("data-href");
+ $.ajax({ method: 'GET',
+ url: link,
+ beforeSend: animateSpinner(that, true) })
+ .done(function(data) {
+ that.html(data.html);
+ initResultCommentForm(that);
+ initResultCommentsLink(that);
+ scrollBottom(that.find(".content-comments"));
+ animateSpinner(that, false);
+ })
+ .always(function(data) {
+ animateSpinner(that, false);
+ });
});
}
+function scrollBottom(id) {
+ var list;
+ if ( id.hasClass("content-comments")) {
+ list = id;
+ } else {
+ list = id.find(".content-comments");
+ }
+ if ( list && list.length > 0) {
+ list.scrollTop($(list)[0].scrollHeight);
+ }
+}
+
function applyCollapseLinkCallBack() {
$(".result-panel-collapse-link")
.on("ajax:success", function() {
@@ -183,8 +215,9 @@ function expandResult(result) {
initHandsOnTables($(document));
-initResultCommentTabAjax();
+//initResultCommentTabAjax();
expandAllResults();
+loadCommentsIn();
initTutorial();
applyCollapseLinkCallBack();
diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss
index 39bef0b34..6c3a428d8 100644
--- a/app/assets/stylesheets/themes/scinote.scss
+++ b/app/assets/stylesheets/themes/scinote.scss
@@ -911,6 +911,10 @@ ul.content-module-activities {
margin-left: 38px;
}
+ .row {
+ padding: 0 20px;
+ }
+
.badge-num {
position: absolute;
@@ -1178,6 +1182,9 @@ html.turbolinks-progress-bar::before {
// Comments
+.comment-more {
+ margin-left: 15px;
+}
.dropdown.dropdown-comment {
display: inline-block;
diff --git a/app/controllers/result_comments_controller.rb b/app/controllers/result_comments_controller.rb
index 9ab162fe3..e0b2e8088 100644
--- a/app/controllers/result_comments_controller.rb
+++ b/app/controllers/result_comments_controller.rb
@@ -1,8 +1,8 @@
class ResultCommentsController < ApplicationController
before_action :load_vars
- before_action :check_view_permissions, only: [ :index ]
- before_action :check_add_permissions, only: [ :new, :create ]
+ before_action :check_view_permissions, only: [:index]
+ before_action :check_add_permissions, only: [:new, :create]
before_action :check_edit_permissions, only: [:edit, :update]
before_action :check_destroy_permissions, only: [:destroy]
@@ -10,31 +10,28 @@ class ResultCommentsController < ApplicationController
@comments = @result.last_comments(@last_comment_id, @per_page)
respond_to do |format|
- format.json {
+ format.json do
# 'index' partial includes header and form for adding new
# messages. 'list' partial is used for showing more
# comments.
- partial = "index.html.erb"
- partial = "list.html.erb" if @last_comment_id > 0
- more_url = ""
+ partial = 'index.html.erb'
+ partial = 'list.html.erb' if @last_comment_id > 0
+ more_url = ''
if @comments.count > 0
more_url = url_for(result_result_comments_path(@result,
- format: :json,
- from: @comments.last.id))
+ format: :json,
+ from: @comments
+ .first.id))
end
- render :json => {
+ render json: {
per_page: @per_page,
results_number: @comments.length,
more_url: more_url,
- html: render_to_string({
- partial: partial,
- locals: {
- comments: @comments,
- more_comments_url: more_url
- }
- })
+ html: render_to_string(partial: partial,
+ locals: { comments: @comments,
+ more_comments_url: more_url })
}
- }
+ end
end
end
diff --git a/app/models/result.rb b/app/models/result.rb
index ab60b05db..a940acfd2 100644
--- a/app/models/result.rb
+++ b/app/models/result.rb
@@ -74,11 +74,12 @@ class Result < ActiveRecord::Base
def last_comments(last_id = 1, per_page = 20)
last_id = 9999999999999 if last_id <= 1
- Comment.joins(:result_comment)
- .where(result_comments: {result_id: id})
- .where('comments.id < ?', last_id)
- .order(created_at: :desc)
- .limit(per_page)
+ comments = Comment.joins(:result_comment)
+ .where(result_comments: { result_id: id })
+ .where('comments.id < ?', last_id)
+ .order(created_at: :desc)
+ .limit(per_page)
+ comments.reverse
end
def is_text
diff --git a/app/models/step.rb b/app/models/step.rb
index 28393d221..f54792177 100644
--- a/app/models/step.rb
+++ b/app/models/step.rb
@@ -88,7 +88,7 @@ class Step < ActiveRecord::Base
end
def last_comments(last_id = 1, per_page = 20)
- last_id = 9999999999 if last_id <= 1
+ last_id = 9999999999999 if last_id <= 1
comments = Comment.joins(:step_comment)
.where(step_comments: { step_id: id })
.where('comments.id < ?', last_id)
diff --git a/app/views/my_modules/_result.html.erb b/app/views/my_modules/_result.html.erb
index 1daf0b471..6bb0e7ecb 100644
--- a/app/views/my_modules/_result.html.erb
+++ b/app/views/my_modules/_result.html.erb
@@ -41,7 +41,7 @@
<%= t'my_modules.results.info_tab' %>
- <% if can_view_result_comments(@my_module) %>
+ <% if false %>