Merge pull request #103 from Ducz0r/bb_edit_delete_comments

Edit&delete comments
This commit is contained in:
Luka Murn 2016-08-25 17:18:48 +02:00 committed by GitHub
commit 8018cff02e
31 changed files with 911 additions and 43 deletions

View file

@ -0,0 +1,136 @@
function initCommentOptions(scrollableContainer, useParentOffset = true) {
scrollCommentOptions($(".dropdown-comment"), useParentOffset);
document.addEventListener('scroll', function (event) {
var $target = $(event.target);
var parent = $(scrollableContainer);
if ($target.length) {
scrollCommentOptions(parent.find(".dropdown-comment"), useParentOffset);
}
}, true);
}
function scrollCommentOptions(selector, useParentOffset = true) {
_.each(selector, function(el) {
var $el = $(el);
var offset = useParentOffset ? $el.offset().top : $el.position().top;
$el.find(".dropdown-menu-fixed")
.offset({ top: (offset + 20) });
});
}
function initDeleteComments(parent) {
$(parent).on("click", "[data-action=delete-comment]", function(e) {
var $this = $(this);
if (confirm($this.attr("data-confirm-message"))) {
$.ajax({
url: $this.attr("data-url"),
type: "DELETE",
dataType: "json",
success: function(data) {
// There are 3 possible actions:
// - (A) comment is the last comment in project
// - (B) comment is the last comment inside specific date (remove the date separator)
// - (C) comment is a usual comment
var commentEl = $this.closest(".comment");
// Case A
if (commentEl.prevAll(".comment").length == 0 && commentEl.next().length == 0) {
commentEl.after("<li class='no-comments'><em>" + I18n.t("projects.index.no_comments") + "</em></li>");
}
// Case B
if (commentEl.prev(".comment-date-separator").length > 0 && commentEl.next(".comment").length == 0) {
commentEl.prev(".comment-date-separator").remove();
}
commentEl.remove();
scrollCommentOptions($(parent).find(".dropdown-comment"));
},
error: function(data) {
// Display alert
alert(data.responseJSON.message);
}
});
}
});
}
function initEditComments(parent) {
$(parent).on("click", "[data-action=edit-comment]", function(e) {
var $this = $(this);
$.ajax({
url: $this.attr("data-url"),
type: "GET",
dataType: "json",
success: function(data) {
var commentEl = $this.closest(".comment");
var container = commentEl.find("[data-role=comment-message-container]");
var oldMessage = container.find("[data-role=comment-message]");
var optionsBtn = commentEl.find("[data-role=comment-options]");
// Hide old message, append new HTML
oldMessage.hide();
optionsBtn.hide();
container.append(data.html);
var form = container.find("[data-role=edit-comment-message-form]");
var input = form.find("input[data-role=message-input]");
var submitBtn = form.find("[data-action=save]");
var cancelBtn = form.find("[data-action=cancel]");
input.focus();
form
.on("ajax:send", function() {
input.attr("readonly", true);
})
.on("ajax:success", function(e, data) {
var newMessage = input.val();
oldMessage.html(newMessage);
form.off("ajax:send ajax:success ajax:error ajax:complete");
submitBtn.off("click");
cancelBtn.off("click");
form.remove();
oldMessage.show();
optionsBtn.show();
})
.on("ajax:error", function(ev, xhr) {
if (xhr.status === 422) {
var messageError = xhr.responseJSON.errors.message;
if (messageError) {
$(".form-group", form)
.addClass("has-error");
$(".help-block", form)
.html(messageError[0])
.removeClass("hide")
.after(" |");
}
}
})
.on("ajax:complete", function() {
input.attr("readonly", false).focus();
});
submitBtn.on("click", function() {
form.submit();
});
cancelBtn.on("click", function() {
form.off("ajax:send ajax:success ajax:error ajax:complete");
submitBtn.off("click");
cancelBtn.off("click");
form.remove();
oldMessage.show();
optionsBtn.show();
});
},
error: function(data) {
// TODO
}
});
});
}

View file

@ -1,3 +1,5 @@
//= require comments
function initHandsOnTables(root) {
root.find("div.hot-table").each(function() {
var $container = $(this).find(".step-result-hot-table");
@ -56,6 +58,9 @@ function initResultCommentForm($el) {
$(".help-block", $form)
.html("")
.addClass("hide");
scrollCommentOptions(
list.parent().find(".content-comments .dropdown-comment")
);
}
})
.on("ajax:error", function (ev, xhr) {
@ -93,6 +98,9 @@ function initResultCommentsLink($el) {
} else {
moreBtn.attr("href", data.more_url);
}
// Reposition dropdown comment options
scrollCommentOptions(listItem.closest(".content-comments").find(".dropdown-comment"));
}
});
}
@ -186,6 +194,10 @@ expandAllResults();
initTutorial();
applyCollapseLinkCallBack();
initCommentOptions("ul.content-comments");
initEditComments("#results");
initDeleteComments("#results");
$(function () {
$("#results-collapse-btn").click(function () {
$('.result .panel-collapse').collapse('hide');

View file

@ -1,3 +1,5 @@
//= require comments
//************************************
// CONSTANTS
//************************************
@ -321,6 +323,11 @@ function initializeFullZoom() {
// Restore draggable position
restoreDraggablePosition($("#diagram"), $("#canvas-container"));
// Initialize comments
initCommentOptions("ul.content-comments", false);
initEditComments(".panel.module-large .tab-content");
initDeleteComments(".panel.module-large .tab-content");
}
function destroyFullZoom() {
@ -337,6 +344,13 @@ function destroyFullZoom() {
$("li[data-module-id]").off("mouseenter mouseleave");
$("li[data-module-id] > span > a.canvas-center-on").off("click");
// Clean up comments listeners
$(document).off("scroll");
$(".panel.module-large .tab-content")
.off("click", "[data-action=edit-comment]");
$(".panel.module-large .tab-content")
.off("click", "[data-action=delete-comment]");
// Remember the draggable position
rememberDraggablePosition($("#diagram"), $("#canvas-container"));
}
@ -691,6 +705,10 @@ function bindFullZoomAjaxTabs() {
$(".help-block", $form)
.html("")
.addClass("hide");
scrollCommentOptions(
list.parent().find(".content-comments .dropdown-comment"),
false
);
}
})
.on("ajax:error", function (ev, xhr) {
@ -728,6 +746,12 @@ function bindFullZoomAjaxTabs() {
} else {
moreBtn.attr("href", data.more_url);
}
// Reposition dropdown comment options
scrollCommentOptions(
listItem.closest(".content-comments").find(".dropdown-comment"),
false
);
}
});
}

View file

@ -7,6 +7,7 @@
// - refresh project users tab after manage user modal is closed
// - refactor view handling using library, ex. backbone.js
//= require comments
(function () {
var newProjectModal = null;
@ -230,6 +231,9 @@
$(".help-block", $form)
.html("")
.addClass("hide");
scrollCommentOptions(
list.parent().find(".content-comments .dropdown-comment")
);
}
})
.on("ajax:error", function (ev, xhr) {
@ -267,6 +271,9 @@
} else {
moreBtn.attr("href", data.more_url);
}
// Reposition dropdown comment options
scrollCommentOptions(listItem.closest(".content-comments").find(".dropdown-comment"));
}
});
}
@ -332,7 +339,6 @@
initUserRoleForms();
}
function init() {
newProjectModal = $("#new-project-modal");
@ -352,6 +358,9 @@
initNewProjectModal();
initEditProjectModal();
initManageUsersModal();
initCommentOptions("ul.content-comments");
initEditComments(".panel-project .tab-content");
initDeleteComments(".panel-project .tab-content");
// initialize project tab remote loading
$(".panel-project .panel-footer [role=tab]")

View file

@ -3,6 +3,7 @@
//= require canvas-to-blob.min
//= require direct-upload
//= require assets
//= require comments
// Sets callbacks for toggling checkboxes
function applyCheckboxCallBack() {
@ -401,6 +402,9 @@ function initStepCommentForm($el) {
$(".help-block", $form)
.html("")
.addClass("hide");
scrollCommentOptions(
list.parent().find(".content-comments .dropdown-comment")
);
}
})
.on("ajax:error", function (ev, xhr) {
@ -425,7 +429,6 @@ function initStepCommentForm($el) {
// Initialize show more comments link.
function initStepCommentsLink($el) {
$el.find(".btn-more-comments")
.on("ajax:success", function (e, data) {
if (data.html) {
@ -438,6 +441,10 @@ function initStepCommentsLink($el) {
} else {
moreBtn.attr("href", data.more_url);
}
// Reposition dropdown comment options
scrollCommentOptions(listItem.closest(".content-comments")
.find(".dropdown-comment"));
}
});
}
@ -645,6 +652,11 @@ initHandsOnTable($(document));
expandAllSteps();
setupAssetsLoading();
// Init comments edit/delete
initCommentOptions("ul.content-comments");
initEditComments("#steps");
initDeleteComments("#steps");
$(function () {
$("[data-action='collapse-steps']").click(function () {

View file

@ -6,6 +6,7 @@ $color-theme-dark: #6d6e71;
// Grayscales
$color-white: #fff;
$color-alabaster: #fcfcfc;
$color-wild-sand: #f5f5f5;
$color-concrete: #f2f2f2;
$color-gallery: #EEE;
$color-alto: #d2d2d2;

View file

@ -1169,3 +1169,29 @@ html.turbolinks-progress-bar::before {
display: inline-block;
margin-right: 5px;
}
// Comments
.dropdown.dropdown-comment {
display: inline-block;
[data-role="comment-options"] {
color: $color-emperor;
}
}
.dropdown-menu.dropdown-menu-fixed {
left: auto;
position: fixed;
top: auto;
li:not(.dropdown-header):hover {
background-color: $color-wild-sand;
}
}
.edit-comment-form {
.help-block {
display: inline;
}
}

View file

@ -2,6 +2,8 @@ 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_edit_permissions, only: [:edit, :update]
before_action :check_destroy_permissions, only: [:destroy]
def index
@comments = @my_module.last_comments(@last_comment_id, @per_page)
@ -48,6 +50,19 @@ class MyModuleCommentsController < ApplicationController
respond_to do |format|
if (@comment.valid? && @my_module.comments << @comment)
# Generate activity
Activity.create(
type_of: :add_comment_to_module,
user: current_user,
project: @my_module.experiment.project,
my_module: @my_module,
message: t(
'activities.add_comment_to_module',
user: current_user.full_name,
module: @my_module.name
)
)
format.html {
flash[:success] = t(
"my_module_comments.create.success_flash",
@ -77,6 +92,71 @@ class MyModuleCommentsController < ApplicationController
end
end
def edit
@update_url =
my_module_my_module_comment_path(@my_module, @comment, format: :json)
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: '/comments/edit.html.erb'
)
}
end
end
end
def update
@comment.message = comment_params[:message]
respond_to do |format|
format.json do
if @comment.save
# Generate activity
Activity.create(
type_of: :edit_module_comment,
user: current_user,
project: @my_module.experiment.project,
my_module: @my_module,
message: t(
'activities.edit_module_comment',
user: current_user.full_name,
module: @my_module.name
)
)
render json: {}, status: :ok
else
render json: { errors: @comment.errors.to_hash(true) },
status: :unprocessable_entity
end
end
end
end
def destroy
respond_to do |format|
format.json do
if @comment.destroy
# Generate activity
Activity.create(
type_of: :delete_module_comment,
user: current_user,
project: @my_module.experiment.project,
my_module: @my_module,
message: t(
'activities.delete_module_comment',
user: current_user.full_name,
module: @my_module.name
)
)
render json: {}, status: :ok
else
render json: { message: I18n.t('comments.delete_error') },
status: :unprocessable_entity
end
end
end
end
private
def load_vars
@ -101,6 +181,15 @@ class MyModuleCommentsController < ApplicationController
end
end
def check_edit_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? && can_edit_module_comment(@comment)
end
def check_destroy_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? && can_delete_module_comment(@comment)
end
def comment_params
params.require(:comment).permit(:message)

View file

@ -2,6 +2,8 @@ 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_edit_permissions, only: [:edit, :update]
before_action :check_destroy_permissions, only: [:destroy]
def index
@comments = @project.last_comments(@last_comment_id, @per_page)
@ -48,6 +50,18 @@ class ProjectCommentsController < ApplicationController
respond_to do |format|
if (@comment.valid? && @project.comments << @comment)
# Generate activity
Activity.create(
type_of: :add_comment_to_project,
user: current_user,
project: @project,
message: t(
'activities.add_comment_to_project',
user: current_user.full_name,
project: @project.name
)
)
format.html {
flash[:success] = t(
"project_comments.create.success_flash",
@ -76,6 +90,69 @@ class ProjectCommentsController < ApplicationController
end
end
def edit
@update_url =
project_project_comment_path(@project, @comment, format: :json)
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: '/comments/edit.html.erb'
)
}
end
end
end
def update
@comment.message = comment_params[:message]
respond_to do |format|
format.json do
if @comment.save
# Generate activity
Activity.create(
type_of: :edit_project_comment,
user: current_user,
project: @project,
message: t(
'activities.edit_project_comment',
user: current_user.full_name,
project: @project.name
)
)
render json: {}, status: :ok
else
render json: { errors: @comment.errors.to_hash(true) },
status: :unprocessable_entity
end
end
end
end
def destroy
respond_to do |format|
format.json do
if @comment.destroy
# Generate activity
Activity.create(
type_of: :delete_project_comment,
user: current_user,
project: @project,
message: t(
'activities.delete_project_comment',
user: current_user.full_name,
project: @project.name
)
)
render json: {}, status: :ok
else
render json: { message: I18n.t('comments.delete_error') },
status: :unprocessable_entity
end
end
end
end
private
def load_vars
@ -100,6 +177,16 @@ class ProjectCommentsController < ApplicationController
end
end
def check_edit_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? && can_edit_project_comment(@comment)
end
def check_destroy_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? && can_delete_project_comment(@comment)
end
def comment_params
params.require(:comment).permit(:message)
end

View file

@ -3,6 +3,8 @@ class ResultCommentsController < ApplicationController
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]
def index
@comments = @result.last_comments(@last_comment_id, @per_page)
@ -54,7 +56,7 @@ class ResultCommentsController < ApplicationController
Activity.create(
type_of: :add_comment_to_result,
user: current_user,
project: @result.my_module.project,
project: @result.my_module.experiment.project,
my_module: @result.my_module,
message: t(
"activities.add_comment_to_result",
@ -91,6 +93,71 @@ class ResultCommentsController < ApplicationController
end
end
def edit
@update_url =
result_result_comment_path(@result, @comment, format: :json)
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: '/comments/edit.html.erb'
)
}
end
end
end
def update
@comment.message = comment_params[:message]
respond_to do |format|
format.json do
if @comment.save
# Generate activity
Activity.create(
type_of: :edit_result_comment,
user: current_user,
project: @result.my_module.experiment.project,
my_module: @result.my_module,
message: t(
'activities.edit_result_comment',
user: current_user.full_name,
result: @result.name
)
)
render json: {}, status: :ok
else
render json: { errors: @comment.errors.to_hash(true) },
status: :unprocessable_entity
end
end
end
end
def destroy
respond_to do |format|
format.json do
if @comment.destroy
# Generate activity
Activity.create(
type_of: :delete_result_comment,
user: current_user,
project: @result.my_module.experiment.project,
my_module: @result.my_module,
message: t(
'activities.delete_result_comment',
user: current_user.full_name,
result: @result.name
)
)
render json: {}, status: :ok
else
render json: { message: I18n.t('comments.delete_error') },
status: :unprocessable_entity
end
end
end
end
private
def load_vars
@ -116,6 +183,18 @@ class ResultCommentsController < ApplicationController
end
end
def check_edit_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? &&
can_edit_result_comment_in_module(@comment)
end
def check_destroy_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? &&
can_delete_result_comment_in_module(@comment)
end
def comment_params
params.require(:comment).permit(:message)
end

View file

@ -3,6 +3,8 @@ class StepCommentsController < ApplicationController
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]
def index
@comments = @step.last_comments(@last_comment_id, @per_page)
@ -96,6 +98,76 @@ class StepCommentsController < ApplicationController
end
end
def edit
@update_url = step_step_comment_path(@step, @comment, format: :json)
respond_to do |format|
format.json do
render json: {
html: render_to_string(
partial: '/comments/edit.html.erb'
)
}
end
end
end
def update
@comment.message = comment_params[:message]
respond_to do |format|
format.json do
if @comment.save
# Generate activity
if @protocol.in_module?
Activity.create(
type_of: :edit_step_comment,
user: current_user,
project: @step.my_module.experiment.project,
my_module: @step.my_module,
message: t(
'activities.edit_step_comment',
user: current_user.full_name,
step: @step.position + 1,
step_name: @step.name
)
)
end
render json: {}, status: :ok
else
render json: { errors: @comment.errors.to_hash(true) },
status: :unprocessable_entity
end
end
end
end
def destroy
respond_to do |format|
format.json do
if @comment.destroy
# Generate activity
if @protocol.in_module?
Activity.create(
type_of: :delete_step_comment,
user: current_user,
project: @step.my_module.experiment.project,
my_module: @step.my_module,
message: t(
'activities.delete_step_comment',
user: current_user.full_name,
step: @step.position + 1,
step_name: @step.name
)
)
end
render json: {}, status: :ok
else
render json: { message: I18n.t('comments.delete_error') },
status: :unprocessable_entity
end
end
end
end
private
def load_vars
@ -121,8 +193,19 @@ class StepCommentsController < ApplicationController
end
end
def check_edit_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? &&
can_edit_step_comment_in_protocol(@comment)
end
def check_destroy_permissions
@comment = Comment.find_by_id(params[:id])
render_403 unless @comment.present? &&
can_delete_step_comment_in_protocol(@comment)
end
def comment_params
params.require(:comment).permit(:message)
end
end

View file

@ -302,6 +302,22 @@ module PermissionHelper
is_technician_or_higher_of_project(project)
end
def can_edit_project_comment(comment)
comment.project_comment.present? &&
(
comment.user == current_user ||
is_owner_of_project(comment.project_comment.project)
)
end
def can_delete_project_comment(comment)
comment.project_comment.present? &&
(
comment.user == current_user ||
is_owner_of_project(comment.project_comment.project)
)
end
def can_restore_archived_modules(project)
is_user_or_higher_of_project(project)
end
@ -475,6 +491,26 @@ module PermissionHelper
is_technician_or_higher_of_project(my_module.experiment.project)
end
def can_edit_module_comment(comment)
comment.my_module_comment.present? &&
(
comment.user == current_user ||
is_owner_of_project(
comment.my_module_comment.my_module.experiment.project
)
)
end
def can_delete_module_comment(comment)
comment.my_module_comment.present? &&
(
comment.user == current_user ||
is_owner_of_project(
comment.my_module_comment.my_module.experiment.project
)
)
end
def can_view_module_samples(my_module)
can_view_module(my_module) and
can_view_samples(my_module.experiment.project.organization)
@ -502,6 +538,26 @@ module PermissionHelper
is_technician_or_higher_of_project(my_module.experiment.project)
end
def can_edit_result_comment_in_module(comment)
comment.result_comment.present? &&
(
comment.user == current_user ||
is_owner_of_project(
comment.result_comment.result.my_module.experiment.project
)
)
end
def can_delete_result_comment_in_module(comment)
comment.result_comment.present? &&
(
comment.user == current_user ||
is_owner_of_project(
comment.result_comment.result.my_module.experiment.project
)
)
end
# ---- RESULT TEXT PERMISSIONS ----
def can_create_result_text_in_module(my_module)
@ -874,6 +930,34 @@ module PermissionHelper
end
end
def can_edit_step_comment_in_protocol(comment)
return false if comment.step_comment.blank?
protocol = comment.step_comment.step.protocol
if protocol.in_module?
comment.user == current_user ||
is_owner_of_project(
protocol.my_module.experiment.project
)
else
false
end
end
def can_delete_step_comment_in_protocol(comment)
return false if comment.step_comment.blank?
protocol = comment.step_comment.step.protocol
if protocol.in_module?
comment.user == current_user ||
is_owner_of_project(
protocol.my_module.experiment.project
)
else
false
end
end
def can_view_or_download_step_assets(protocol)
if protocol.in_module?
my_module = protocol.my_module

View file

@ -28,7 +28,17 @@ class Activity < ActiveRecord::Base
:archive_result,
:edit_result,
:clone_experiment,
:move_experiment
:move_experiment,
:add_comment_to_project,
:edit_project_comment,
:delete_project_comment,
:add_comment_to_module,
:edit_module_comment,
:delete_module_comment,
:edit_step_comment,
:delete_step_comment,
:edit_result_comment,
:delete_result_comment
]
validates :type_of, presence: true

View file

@ -11,11 +11,11 @@ class Comment < ActiveRecord::Base
belongs_to :user, inverse_of: :comments
belongs_to :last_modified_by, foreign_key: 'last_modified_by_id', class_name: 'User'
has_one :step_comment, inverse_of: :comment
has_one :my_module_comment, inverse_of: :comment
has_one :result_comment, inverse_of: :comment
has_one :sample_comment, inverse_of: :comment
has_one :project_comment, inverse_of: :comment
has_one :step_comment, inverse_of: :comment, dependent: :destroy
has_one :my_module_comment, inverse_of: :comment, dependent: :destroy
has_one :result_comment, inverse_of: :comment, dependent: :destroy
has_one :sample_comment, inverse_of: :comment, dependent: :destroy
has_one :project_comment, inverse_of: :comment, dependent: :destroy
def self.search(
user,

View file

@ -4,6 +4,5 @@ class ResultComment < ActiveRecord::Base
belongs_to :result, inverse_of: :result_comments
belongs_to :comment,
inverse_of: :result_comment,
dependent: :destroy
inverse_of: :result_comment
end

View file

@ -0,0 +1,14 @@
<%= bootstrap_form_for(@comment, url: @update_url, remote: true, html: { method: :put, class: 'edit-comment-form' }, data: { role: 'edit-comment-message-form' }) do |f| %>
<div class="form-group">
<div class="input-group">
<%= f.text_field :message, autofocus: true, hide_label: true, data: { role: 'message-input' }, value: @comment.message %>
<span class="input-group-btn">
<a class="btn btn-default" data-action="save">
<span class="glyphicon glyphicon-ok"></span>
</a>
</span>
</div>
<span class="help-block hide"></span>
<a data-action="cancel" href="#"><%= t('general.cancel') %></a>
</div>
<% end %>

View file

@ -1,3 +1,43 @@
<span class="text-muted pull-right"><%= l comment.created_at, format: '%H:%M' %></span>
<div class="pull-right">
<span class="text-muted"><%= l comment.created_at, format: '%H:%M' %></span>
<% if can_edit_module_comment(comment) || can_delete_module_comment(comment) %>
<div class="dropdown dropdown-comment">
<a href="#"
class="dropdown-toggle"
data-role="comment-options"
type="button"
id="comment-<%= comment.id %>-dropdown"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true">
<span class="caret"></span>
</a>
<ul class="dropdown-menu dropdown-menu-fixed" aria-labelledby="comment-<%= comment.id %>-dropdown">
<li class="dropdown-header"><%= I18n.t('comments.options_dropdown.header') %></li>
<% if can_edit_module_comment(comment) %>
<li>
<a href="#"
data-action="edit-comment"
data-url="<%= edit_my_module_my_module_comment_path(comment.my_module_comment.my_module, comment, format: :json) %>">
<%= t('comments.options_dropdown.edit') %>
</a>
</li>
<% end %>
<% if can_delete_module_comment(comment) %>
<li>
<a href="#"
data-action="delete-comment"
data-url="<%= my_module_my_module_comment_path(comment.my_module_comment.my_module, comment, format: :json) %>"
data-confirm-message="<%= t('comments.delete_confirm') %>">
<%= t('comments.options_dropdown.delete') %>
</a>
</li>
<% end %>
</ul>
</div>
<% end %>
</div>
<strong><%= comment.user.full_name %>:</strong>
<p><span><%= comment.message %></p>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= comment.message %></p>
</div>

View file

@ -7,7 +7,7 @@
<%= render 'my_module_comments/list.html.erb', comments: @comments %>
<% end %>
<% if @comments.length == @per_page %>
<li class="text-center">
<li class="comment-more text-center">
<a class="btn btn-default btn-more-comments" href="<%= more_comments_url %>" data-remote="true">
<%=t "experiments.canvas.popups.more_comments" %>
</a>

View file

@ -2,11 +2,14 @@
<% current_day = DateTime.current.strftime('%j').to_i %>
<% comments.each do |comment| %>
<li class="comment">
<% comment_day = comment.created_at.strftime('%j').to_i %>
<% if comment_day < current_day and 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>
</li>
<% end %>
<%= render 'project_comments/comment.html.erb', comment: comment %></li>
<li class="comment">
<%= render 'my_module_comments/comment.html.erb', comment: comment %>
</li>
<% end %>

View file

@ -1,3 +1,43 @@
<span class="text-muted pull-right"><%= l comment.created_at, format: '%H:%M' %></span>
<div class="pull-right">
<span class="text-muted"><%= l comment.created_at, format: '%H:%M' %></span>
<% if can_edit_project_comment(comment) || can_delete_project_comment(comment) %>
<div class="dropdown dropdown-comment">
<a href="#"
class="dropdown-toggle"
data-role="comment-options"
type="button"
id="comment-<%= comment.id %>-dropdown"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true">
<span class="caret"></span>
</a>
<ul class="dropdown-menu dropdown-menu-fixed" aria-labelledby="comment-<%= comment.id %>-dropdown">
<li class="dropdown-header"><%= I18n.t('comments.options_dropdown.header') %></li>
<% if can_edit_project_comment(comment) %>
<li>
<a href="#"
data-action="edit-comment"
data-url="<%= edit_project_project_comment_path(comment.project_comment.project, comment, format: :json) %>">
<%= t('comments.options_dropdown.edit') %>
</a>
</li>
<% end %>
<% if can_delete_project_comment(comment) %>
<li>
<a href="#"
data-action="delete-comment"
data-url="<%= project_project_comment_path(comment.project_comment.project, comment, format: :json) %>"
data-confirm-message="<%= t('comments.delete_confirm') %>">
<%= t('comments.options_dropdown.delete') %>
</a>
</li>
<% end %>
</ul>
</div>
<% end %>
</div>
<strong><%= comment.user.full_name %>:</strong>
<p><span><%= comment.message %></p>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= comment.message %></p>
</div>

View file

@ -7,7 +7,7 @@
<%= render 'project_comments/list.html.erb', comments: @comments %>
<% end %>
<% if @comments.length == @per_page %>
<li class="text-center">
<li class="comment-more text-center">
<a class="btn btn-default btn-more-comments" href="<%= more_comments_url %>" data-remote="true">
<%= t'projects.index.more_comments' %></a>
</li>

View file

@ -3,14 +3,17 @@
current_day = DateTime.current.strftime('%j').to_i
%>
<% comments.each do |comment| %>
<li class="comment">
<%
comment_day = comment.created_at.strftime('%j').to_i
if comment_day < current_day and comment_day < day then
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>
</li>
<% end %>
<%= render 'project_comments/comment.html.erb', comment: comment %></li>
<li class="comment">
<%= render 'project_comments/comment.html.erb', comment: comment %>
</li>
<% end %>

View file

@ -1,2 +1,44 @@
<strong><%=t "my_modules.results.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %></strong>
<p><span><%= comment.message %></p>
<div>
<strong>
<%=t "my_modules.results.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %>
</strong>
<% if can_edit_result_comment_in_module(comment) || can_delete_result_comment_in_module(comment) %>
<div class="dropdown dropdown-comment">
<a href="#"
class="dropdown-toggle"
data-role="comment-options"
type="button"
id="comment-<%= comment.id %>-dropdown"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true">
<span class="caret"></span>
</a>
<ul class="dropdown-menu dropdown-menu-fixed" aria-labelledby="comment-<%= comment.id %>-dropdown">
<li class="dropdown-header"><%= I18n.t('comments.options_dropdown.header') %></li>
<% if can_edit_result_comment_in_module(comment) %>
<li>
<a href="#"
data-action="edit-comment"
data-url="<%= edit_result_result_comment_path(comment.result_comment.result, comment, format: :json) %>">
<%= t('comments.options_dropdown.edit') %>
</a>
</li>
<% end %>
<% if can_delete_result_comment_in_module(comment) %>
<li>
<a href="#"
data-action="delete-comment"
data-url="<%= result_result_comment_path(comment.result_comment.result, comment, format: :json) %>"
data-confirm-message="<%= t('comments.delete_confirm') %>">
<%= t('comments.options_dropdown.delete') %>
</a>
</li>
<% end %>
</ul>
</div>
<% end %>
</div>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= comment.message %></p>
</div>

View file

@ -7,7 +7,7 @@
<%= render 'result_comments/list.html.erb', comments: @comments %>
<% end %>
<% if @comments.length == @per_page %>
<li class="text-center">
<li class="comment-more text-center">
<a class="btn btn-default btn-more-comments" href="<%= more_comments_url %>" data-remote="true">
<%=t "general.more_comments" %>
</a>

View file

@ -2,11 +2,14 @@
<% current_day = DateTime.current.strftime('%j').to_i %>
<% comments.each do |comment| %>
<li class="comment">
<% comment_day = comment.created_at.strftime('%j').to_i %>
<% if comment_day < current_day and 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>
</li>
<% end %>
<%= render 'result_comments/comment.html.erb', comment: comment %></li>
<li class="comment">
<%= render 'result_comments/comment.html.erb', comment: comment %>
</li>
<% end %>

View file

@ -1,2 +1,44 @@
<strong><%=t "protocols.steps.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %></strong>
<p><span><%= comment.message %></p>
<div>
<strong>
<%=t "protocols.steps.comment_title", user: comment.user.full_name, time: l(comment.created_at, format: :time) %>
</strong>
<% if can_edit_step_comment_in_protocol(comment) || can_delete_step_comment_in_protocol(comment) %>
<div class="dropdown dropdown-comment">
<a href="#"
class="dropdown-toggle"
data-role="comment-options"
type="button"
id="comment-<%= comment.id %>-dropdown"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="true">
<span class="caret"></span>
</a>
<ul class="dropdown-menu dropdown-menu-fixed" aria-labelledby="comment-<%= comment.id %>-dropdown">
<li class="dropdown-header"><%= I18n.t('comments.options_dropdown.header') %></li>
<% if can_edit_step_comment_in_protocol(comment) %>
<li>
<a href="#"
data-action="edit-comment"
data-url="<%= edit_step_step_comment_path(comment.step_comment.step, comment, format: :json) %>">
<%= t('comments.options_dropdown.edit') %>
</a>
</li>
<% end %>
<% if can_delete_step_comment_in_protocol(comment) %>
<li>
<a href="#"
data-action="delete-comment"
data-url="<%= step_step_comment_path(comment.step_comment.step, comment, format: :json) %>"
data-confirm-message="<%= t('comments.delete_confirm') %>">
<%= t('comments.options_dropdown.delete') %>
</a>
</li>
<% end %>
</ul>
</div>
<% end %>
</div>
<div data-role="comment-message-container">
<p data-role="comment-message"><%= comment.message %></p>
</div>

View file

@ -7,7 +7,7 @@
<%= render 'step_comments/list.html.erb', comments: @comments %>
<% end %>
<% if @comments.length == @per_page %>
<li class="text-center">
<li class="comment-more text-center">
<a class="btn btn-default btn-more-comments" href="<%= more_comments_url %>" data-remote="true">
<%=t "general.more_comments" %>
</a>

View file

@ -2,11 +2,14 @@
<% current_day = DateTime.current.strftime('%j').to_i %>
<% comments.each do |comment| %>
<li class="comment">
<% comment_day = comment.created_at.strftime('%j').to_i %>
<% if comment_day < current_day and 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>
</li>
<% end %>
<%= render 'step_comments/comment.html.erb', comment: comment %></li>
<li class="comment">
<%= render 'step_comments/comment.html.erb', comment: comment %>
</li>
<% end %>

View file

@ -56,4 +56,5 @@ Rails.application.config.assets.precompile += %w( Sortable.min.js )
Rails.application.config.assets.precompile += %w( reports_pdf.css )
Rails.application.config.assets.precompile += %w( jszip.min.js )
Rails.application.config.assets.precompile += %w( assets.js )
Rails.application.config.assets.precompile += %w( comments.js )
Rails.application.config.assets.precompile += %w( projects/show.js )

View file

@ -139,6 +139,14 @@ en:
step: "Step comment"
result: "Result comment"
comments:
options_dropdown:
header: "Comment options"
edit: "Edit"
delete: "Delete"
delete_confirm: "Are you sure you wish to delete this comment?"
delete_error: "Error occured while deleting comment."
projects:
index:
head_title: "Home"
@ -1024,6 +1032,16 @@ en:
edit_table_result: "<i>%{user}</i> edited table result <strong>%{result}</strong>."
clone_experiment: "<i>%{user}</i> cloned <strong>%{experiment_new}</strong> from <strong>%{experiment_original}</strong>."
move_experiment: "<i>%{user}</i> moved experiment <strong>%{experiment}</strong> from project <strong>%{project_original}</strong> to project <strong>%{project_new}</strong>."
add_comment_to_project: "<i>%{user}</i> commented on project <strong>%{project}</strong>."
edit_project_comment: "<i>%{user}</i> edited comment on project <strong>%{project}</strong>."
delete_project_comment: "<i>%{user}</i> deleted comment on project <strong>%{project}</strong>."
add_comment_to_module: "<i>%{user}</i> commented on module <strong>%{module}</strong>."
edit_module_comment: "<i>%{user}</i> edited comment on module <strong>%{module}</strong>."
delete_module_comment: "<i>%{user}</i> deleted comment on module <strong>%{module}</strong>."
edit_step_comment: "<i>%{user}</i> edited comment on Step %{step} <strong>%{step_name}</strong>."
delete_step_comment: "<i>%{user}</i> deleted comment on Step %{step} <strong>%{step_name}</strong>."
edit_result_comment: "<i>%{user}</i> edited comment on result <strong>%{result}</strong>."
delete_result_comment: "<i>%{user}</i> deleted comment on result <strong>%{result}</strong>."
user_my_modules:
new:

View file

@ -49,7 +49,9 @@ Rails.application.routes.draw do
resources :projects, except: [:new, :destroy] do
resources :user_projects, path: "/users", only: [:new, :create, :index, :edit, :update, :destroy]
resources :project_comments, path: "/comments", only: [:new, :create, :index]
resources :project_comments,
path: '/comments',
only: [:new, :create, :index, :edit, :update, :destroy]
# Activities popup (JSON) for individual project in projects index,
# as well as all activities page for single project (HTML)
resources :project_activities, path: "/activities", only: [:index]
@ -145,7 +147,9 @@ Rails.application.routes.draw do
resources :my_modules, path: "/modules", only: [:show, :edit, :update, :destroy] do
resources :my_module_tags, path: "/tags", only: [:index, :create, :update, :destroy]
resources :user_my_modules, path: "/users", only: [:index, :new, :create, :destroy]
resources :my_module_comments, path: "/comments", only: [:index, :new, :create]
resources :my_module_comments,
path: '/comments',
only: [:index, :new, :create, :edit, :update, :destroy]
resources :sample_my_modules, path: "/samples_index", only: [:index]
resources :result_texts, only: [:new, :create]
resources :result_assets, only: [:new, :create]
@ -173,7 +177,9 @@ Rails.application.routes.draw do
end
resources :steps, only: [:edit, :update, :destroy, :show] do
resources :step_comments, path: "/comments", only: [:new, :create, :index]
resources :step_comments,
path: '/comments',
only: [:new, :create, :index, :edit, :update, :destroy]
member do
post 'checklistitem_state'
post 'toggle_step_state'
@ -183,7 +189,9 @@ Rails.application.routes.draw do
end
resources :results, only: [:update] do
resources :result_comments, path: "/comments", only: [:new, :create, :index]
resources :result_comments,
path: '/comments',
only: [:new, :create, :index, :edit, :update, :destroy]
end
resources :samples, only: [:edit, :update, :destroy]