mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +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 list = $(this).parents('ul');
|
||||||
var moreBtn = list.find('.btn-more-comments');
|
var moreBtn = list.find('.btn-more-comments');
|
||||||
var listItem = moreBtn.parents('li');
|
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);
|
$(data.html).insertAfter(listItem);
|
||||||
if (data.results_number < data.per_page) {
|
if (data.results_number < data.per_page) {
|
||||||
moreBtn.remove();
|
moreBtn.remove();
|
||||||
|
@ -234,6 +241,7 @@ var Comments = (function() {
|
||||||
|
|
||||||
function initEditComments(parent) {
|
function initEditComments(parent) {
|
||||||
$(parent).on('click', '[data-action=edit-comment]', function() {
|
$(parent).on('click', '[data-action=edit-comment]', function() {
|
||||||
|
console.log("edit");
|
||||||
var $this = $(this);
|
var $this = $(this);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: $this.attr('data-url'),
|
url: $this.attr('data-url'),
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class MyModuleCommentsController < ApplicationController
|
class MyModuleCommentsController < ApplicationController
|
||||||
before_action :load_vars
|
before_action :load_vars
|
||||||
before_action :check_view_permissions, only: [ :index ]
|
before_action :check_view_permissions, only: :index
|
||||||
before_action :check_add_permissions, only: [ :new, :create ]
|
before_action :check_add_permissions, only: [:new, :create]
|
||||||
before_action :check_edit_permissions, only: [:edit, :update]
|
before_action :check_edit_permissions, only: [:edit, :update]
|
||||||
before_action :check_destroy_permissions, only: [:destroy]
|
before_action :check_destroy_permissions, only: [:destroy]
|
||||||
|
|
||||||
|
@ -9,31 +9,32 @@ class MyModuleCommentsController < ApplicationController
|
||||||
@comments = @my_module.last_comments(@last_comment_id, @per_page)
|
@comments = @my_module.last_comments(@last_comment_id, @per_page)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json {
|
format.json do
|
||||||
# 'index' partial includes header and form for adding new
|
# 'index' partial includes header and form for adding new
|
||||||
# messages. 'list' partial is used for showing more
|
# messages. 'list' partial is used for showing more
|
||||||
# comments.
|
# comments.
|
||||||
partial = "index.html.erb"
|
partial = 'index.html.erb'
|
||||||
partial = "list.html.erb" if @last_comment_id > 0
|
partial = 'list.html.erb' if @last_comment_id > 0
|
||||||
more_url = ""
|
more_url = ''
|
||||||
if @comments.count > 0
|
if @comments.count > 0
|
||||||
more_url = url_for(my_module_my_module_comments_url(@my_module,
|
more_url = url_for(my_module_my_module_comments_url(@my_module,
|
||||||
format: :json,
|
format: :json,
|
||||||
from: @comments.last.id))
|
from: @comments
|
||||||
|
.first.id))
|
||||||
end
|
end
|
||||||
render :json => {
|
render json: {
|
||||||
per_page: @per_page,
|
per_page: @per_page,
|
||||||
results_number: @comments.length,
|
results_number: @comments.length,
|
||||||
more_url: more_url,
|
more_url: more_url,
|
||||||
html: render_to_string({
|
html: render_to_string(
|
||||||
partial: partial,
|
partial: partial,
|
||||||
locals: {
|
locals: {
|
||||||
comments: @comments,
|
comments: @comments,
|
||||||
more_comments_url: more_url
|
more_comments_url: more_url
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class ProjectCommentsController < ApplicationController
|
class ProjectCommentsController < ApplicationController
|
||||||
before_action :load_vars
|
before_action :load_vars
|
||||||
before_action :check_view_permissions, only: [ :index ]
|
before_action :check_view_permissions, only: :index
|
||||||
before_action :check_add_permissions, only: [ :new, :create ]
|
before_action :check_add_permissions, only: [:new, :create]
|
||||||
before_action :check_edit_permissions, only: [:edit, :update]
|
before_action :check_edit_permissions, only: [:edit, :update]
|
||||||
before_action :check_destroy_permissions, only: [:destroy]
|
before_action :check_destroy_permissions, only: [:destroy]
|
||||||
|
|
||||||
|
@ -9,30 +9,31 @@ class ProjectCommentsController < ApplicationController
|
||||||
@comments = @project.last_comments(@last_comment_id, @per_page)
|
@comments = @project.last_comments(@last_comment_id, @per_page)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json {
|
format.json do
|
||||||
# 'index' partial includes header and form for adding new
|
# 'index' partial includes header and form for adding new
|
||||||
# messages. 'list' partial is used for showing more
|
# messages. 'list' partial is used for showing more
|
||||||
# comments.
|
# comments.
|
||||||
partial = "index.html.erb"
|
partial = 'index.html.erb'
|
||||||
partial = "list.html.erb" if @last_comment_id > 0
|
partial = 'list.html.erb' if @last_comment_id > 0
|
||||||
more_url = ""
|
more_url = ''
|
||||||
if @comments.count > 0
|
if @comments.count > 0
|
||||||
more_url = url_for(project_project_comments_url(format: :json,
|
more_url = url_for(project_project_comments_url(format: :json,
|
||||||
from: @comments.last.id))
|
from: @comments
|
||||||
|
.first.id))
|
||||||
end
|
end
|
||||||
render :json => {
|
render json: {
|
||||||
:per_page => @per_page,
|
per_page: @per_page,
|
||||||
:results_number => @comments.length,
|
results_number: @comments.length,
|
||||||
:more_url => more_url,
|
more_url: more_url,
|
||||||
:html => render_to_string({
|
html: render_to_string(
|
||||||
:partial => partial,
|
partial: partial,
|
||||||
:locals => {
|
locals: {
|
||||||
:comments => @comments,
|
comments: @comments,
|
||||||
:more_comments_url => more_url
|
more_comments_url: more_url
|
||||||
}
|
}
|
||||||
})
|
)
|
||||||
}
|
}
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
<% comments.each do |comment| %>
|
<% comments.each do |comment| %>
|
||||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
<% 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 %>
|
<% day = comment.created_at.strftime('%j').to_i %>
|
||||||
<li class="comment-date-separator">
|
<li class="comment-date-separator">
|
||||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
<% current_day = DateTime.current.strftime('%j').to_i %>
|
<% current_day = DateTime.current.strftime('%j').to_i %>
|
||||||
<% comments.each do |comment| %>
|
<% comments.each do |comment| %>
|
||||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
<% 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 %>
|
<% day = comment.created_at.strftime('%j').to_i %>
|
||||||
<li class="comment-date-separator">
|
<li class="comment-date-separator">
|
||||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
<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 %>
|
<% current_day = DateTime.current.strftime('%j').to_i %>
|
||||||
|
|
||||||
<% comments.each do |comment| %>
|
<% comments.each do |comment| %>
|
||||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
<% 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 %>
|
<% day = comment.created_at.strftime('%j').to_i %>
|
||||||
<li class="comment-date-separator">
|
<li class="comment-date-separator">
|
||||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
<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 %>
|
<% current_day = DateTime.current.strftime('%j').to_i %>
|
||||||
|
|
||||||
<% comments.each do |comment| %>
|
<% comments.each do |comment| %>
|
||||||
<% comment_day = comment.created_at.strftime('%j').to_i %>
|
<% 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 %>
|
<% day = comment.created_at.strftime('%j').to_i %>
|
||||||
<li class="comment-date-separator">
|
<li class="comment-date-separator">
|
||||||
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
<p class="text-center"><%= comment.created_at.strftime('%d.%m.%Y') %></p>
|
||||||
|
|
Loading…
Add table
Reference in a new issue