mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
fixed project and task comments + fixed date issue
This commit is contained in:
parent
0d322eba13
commit
2235778110
7 changed files with 46 additions and 36 deletions
|
@ -54,6 +54,13 @@ var Comments = (function() {
|
|||
var list = $(this).parents('ul');
|
||||
var moreBtn = list.find('.btn-more-comments');
|
||||
var listItem = moreBtn.parents('li');
|
||||
// removes duplicated dates
|
||||
if ( list.find($('.comment-date-separator'))
|
||||
.first().find('p').text() ===
|
||||
$(data.html).first().find('p').text() ) {
|
||||
list.find($('.comment-date-separator'))[0].remove();
|
||||
}
|
||||
|
||||
$(data.html).insertAfter(listItem);
|
||||
if (data.results_number < data.per_page) {
|
||||
moreBtn.remove();
|
||||
|
@ -234,6 +241,7 @@ var Comments = (function() {
|
|||
|
||||
function initEditComments(parent) {
|
||||
$(parent).on('click', '[data-action=edit-comment]', function() {
|
||||
console.log("edit");
|
||||
var $this = $(this);
|
||||
$.ajax({
|
||||
url: $this.attr('data-url'),
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class MyModuleCommentsController < 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]
|
||||
|
||||
|
@ -9,31 +9,32 @@ class MyModuleCommentsController < ApplicationController
|
|||
@comments = @my_module.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(my_module_my_module_comments_url(@my_module,
|
||||
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({
|
||||
html: render_to_string(
|
||||
partial: partial,
|
||||
locals: {
|
||||
comments: @comments,
|
||||
more_comments_url: more_url
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class ProjectCommentsController < 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]
|
||||
|
||||
|
@ -9,30 +9,31 @@ class ProjectCommentsController < ApplicationController
|
|||
@comments = @project.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(project_project_comments_url(format: :json,
|
||||
from: @comments.last.id))
|
||||
from: @comments
|
||||
.first.id))
|
||||
end
|
||||
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
|
||||
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
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
<% comments.each do |comment| %>
|
||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
||||
<% if comment_day < current_day and comment_day < day %>
|
||||
<% if comment_day < current_day && comment_day > day %>
|
||||
<% day = comment.created_at.strftime('%j').to_i %>
|
||||
<li class="comment-date-separator">
|
||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<% current_day = DateTime.current.strftime('%j').to_i %>
|
||||
<% comments.each do |comment| %>
|
||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
||||
<% if comment_day < current_day && comment_day < day %>
|
||||
<% if comment_day < current_day && comment_day > day %>
|
||||
<% day = comment.created_at.strftime('%j').to_i %>
|
||||
<li class="comment-date-separator">
|
||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<% day = 366 %>
|
||||
<% day = 0 %>
|
||||
<% current_day = DateTime.current.strftime('%j').to_i %>
|
||||
|
||||
<% comments.each do |comment| %>
|
||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
||||
<% if comment_day < current_day and comment_day < day %>
|
||||
<% if comment_day < current_day && comment_day > day %>
|
||||
<% day = comment.created_at.strftime('%j').to_i %>
|
||||
<li class="comment-date-separator">
|
||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<% day = 366 %>
|
||||
<% day = 0 %>
|
||||
<% current_day = DateTime.current.strftime('%j').to_i %>
|
||||
|
||||
<% comments.each do |comment| %>
|
||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
||||
<% if comment_day < current_day and comment_day < day %>
|
||||
<% if comment_day < current_day && comment_day > day %>
|
||||
<% day = comment.created_at.strftime('%j').to_i %>
|
||||
<li class="comment-date-separator">
|
||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
||||
|
|
Loading…
Reference in a new issue