Generate activities when editing/deleting comments

This commit is contained in:
Luka Murn 2016-08-25 13:33:42 +02:00
parent 24dd25d9f5
commit b0d7b9dc75
6 changed files with 146 additions and 1 deletions

View file

@ -50,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",
@ -98,6 +111,18 @@ class MyModuleCommentsController < ApplicationController
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) },
@ -111,6 +136,18 @@ class MyModuleCommentsController < ApplicationController
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') },

View file

@ -50,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",
@ -97,6 +109,17 @@ class ProjectCommentsController < ApplicationController
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) },
@ -110,6 +133,17 @@ class ProjectCommentsController < ApplicationController
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') },

View file

@ -112,6 +112,18 @@ class ResultCommentsController < ApplicationController
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) },
@ -125,6 +137,18 @@ class ResultCommentsController < ApplicationController
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') },

View file

@ -116,6 +116,21 @@ class StepCommentsController < ApplicationController
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) },
@ -129,6 +144,21 @@ class StepCommentsController < ApplicationController
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') },

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

@ -1030,6 +1030,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: