Merge pull request #259 from okriuchykhin/ok_SCI_605

Added additional activities [SCI-605]
This commit is contained in:
okriuchykhin 2016-11-07 10:01:16 +01:00 committed by GitHub
commit fd805f4072
6 changed files with 157 additions and 6 deletions

View file

@ -39,6 +39,16 @@ class ExperimentsController < ApplicationController
@experiment.last_modified_by = current_user
@experiment.project = @project
if @experiment.save
Activity.create(
type_of: :create_experiment,
project: @experiment.project,
user: current_user,
message: I18n.t(
'activities.create_experiment',
user: current_user.full_name,
experiment: @experiment.name
)
)
flash[:success] = t('experiments.create.success_flash',
experiment: @experiment.name)
respond_to do |format|
@ -76,6 +86,16 @@ class ExperimentsController < ApplicationController
@experiment.update_attributes(experiment_params)
@experiment.last_modified_by = current_user
if @experiment.save
Activity.create(
type_of: :edit_experiment,
project: @experiment.project,
user: current_user,
message: I18n.t(
'activities.edit_experiment',
user: current_user.full_name,
experiment: @experiment.name
)
)
@experiment.touch(:workflowimg_updated_at)
flash[:success] = t('experiments.update.success_flash',
experiment: @experiment.name)
@ -106,6 +126,16 @@ class ExperimentsController < ApplicationController
@experiment.archived_by = current_user
@experiment.archived_on = DateTime.now
if @experiment.save
Activity.create(
type_of: :archive_experiment,
project: @experiment.project,
user: current_user,
message: I18n.t(
'activities.archive_experiment',
user: current_user.full_name,
experiment: @experiment.name
)
)
flash[:success] = t('experiments.archive.success_flash',
experiment: @experiment.name)

View file

@ -271,9 +271,26 @@ class MyModulesController < ApplicationController
end
end
task_names = []
new_samples = []
@my_module.get_downstream_modules.each do |my_module|
new_samples = samples.select { |el| my_module.samples.exclude?(el) }
my_module.samples.push(*new_samples)
task_names << my_module.name
end
if new_samples.any?
Activity.create(
type_of: :assign_sample,
project: @my_module.experiment.project,
my_module: @my_module,
user: current_user,
message: I18n.t(
'activities.assign_sample',
user: current_user.full_name,
tasks: task_names.join(', '),
samples: new_samples.map(&:name).join(', ')
)
)
end
end
redirect_to samples_my_module_path(@my_module)
@ -288,14 +305,30 @@ class MyModulesController < ApplicationController
sample.last_modified_by = current_user
sample.save
if sample
if sample && @my_module.samples.include?(sample)
samples << sample
end
end
task_names = []
@my_module.get_downstream_modules.each do |my_module|
task_names << my_module.name
my_module.samples.destroy(samples & my_module.samples)
end
if samples.any?
Activity.create(
type_of: :unassign_sample,
project: @my_module.experiment.project,
my_module: @my_module,
user: current_user,
message: I18n.t(
'activities.unassign_sample',
user: current_user.full_name,
tasks: task_names.join(', '),
samples: samples.map(&:name).join(', ')
)
)
end
end
redirect_to samples_my_module_path(@my_module)
end

View file

@ -364,7 +364,18 @@ class ProtocolsController < ApplicationController
status: :bad_request
}
else
# Everything good, display flash & render 200
# Everything good, record activity, display flash & render 200
Activity.create(
type_of: :revert_protocol,
project: @protocol.my_module.experiment.project,
my_module: @protocol.my_module,
user: current_user,
message: I18n.t(
'activities.revert_protocol',
user: current_user.full_name,
protocol: @protocol.name
)
)
flash[:success] = t(
"my_modules.protocols.update_parent_flash",
)
@ -426,7 +437,18 @@ class ProtocolsController < ApplicationController
status: :bad_request
}
else
# Everything good, display flash & render 200
# Everything good, record activity, display flash & render 200
Activity.create(
type_of: :load_protocol_from_repository,
project: @protocol.my_module.experiment.project,
my_module: @protocol.my_module,
user: current_user,
message: I18n.t(
'activities.load_protocol_from_repository',
user: current_user.full_name,
protocol: @source.name
)
)
flash[:success] = t(
"my_modules.protocols.load_from_repository_flash",
)
@ -454,7 +476,18 @@ class ProtocolsController < ApplicationController
render json: { status: :error }, status: :bad_request
}
else
# Everything good, display flash & render 200
# Everything good, record activity, display flash & render 200
Activity.create(
type_of: :load_protocol_from_file,
project: @protocol.my_module.experiment.project,
my_module: @protocol.my_module,
user: current_user,
message: I18n.t(
'activities.load_protocol_from_file',
user: current_user.full_name,
protocol: @protocol_json[:name]
)
)
flash[:success] = t(
"my_modules.protocols.load_from_file_flash",
)

View file

@ -84,6 +84,17 @@ class ReportsController < ApplicationController
@report.last_modified_by = current_user
if continue and @report.save_with_contents(report_contents)
# record an activity
Activity.create(
type_of: :create_report,
project: @report.project,
user: current_user,
message: I18n.t(
'activities.create_report',
user: current_user.full_name,
report: @report.name
)
)
respond_to do |format|
format.json {
render json: { url: project_reports_path(@project) }, status: :ok
@ -119,6 +130,17 @@ class ReportsController < ApplicationController
@report.assign_attributes(report_params)
if continue and @report.save_with_contents(report_contents)
# record an activity
Activity.create(
type_of: :edit_report,
project: @report.project,
user: current_user,
message: I18n.t(
'activities.edit_report',
user: current_user.full_name,
report: @report.name
)
)
respond_to do |format|
format.json {
render json: { url: project_reports_path(@project) }, status: :ok
@ -149,6 +171,17 @@ class ReportsController < ApplicationController
report = Report.find_by_id(report_id)
if report.present?
# record an activity
Activity.create(
type_of: :delete_report,
project: report.project,
user: current_user,
message: I18n.t(
'activities.delete_report',
user: current_user.full_name,
report: report.name
)
)
report.destroy
end
end

View file

@ -29,6 +29,9 @@ class Activity < ActiveRecord::Base
:add_comment_to_result,
:archive_result,
:edit_result,
:create_experiment,
:edit_experiment,
:archive_experiment,
:clone_experiment,
:move_experiment,
:add_comment_to_project,
@ -41,7 +44,15 @@ class Activity < ActiveRecord::Base
:delete_step_comment,
:edit_result_comment,
:delete_result_comment,
:destroy_result
:destroy_result,
:load_protocol_from_file,
:load_protocol_from_repository,
:revert_protocol,
:create_report,
:delete_report,
:edit_report,
:assign_sample,
:unassign_sample
]
validates :type_of, presence: true

View file

@ -1038,7 +1038,10 @@ en:
edit_asset_result: "<i>%{user}</i> edited file result <strong>%{result}</strong>."
edit_text_result: "<i>%{user}</i> edited text result <strong>%{result}</strong>."
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>."
archive_experiment: "<i>%{user}</i> archived experiment <strong>%{experiment}</strong>."
create_experiment: "<i>%{user}</i> created experiment <strong>%{experiment}</strong>."
edit_experiment: "<i>%{user}</i> edited experiment <strong>%{experiment}</strong>."
clone_experiment: "<i>%{user}</i> cloned experiment <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>."
@ -1050,6 +1053,14 @@ en:
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>."
load_protocol_from_file: "<i>%{user}</i> loaded protocol <strong>%{protocol}</strong> from file."
load_protocol_from_repository: "<i>%{user}</i> loaded protocol <strong>%{protocol}</strong> from repository."
revert_protocol: "<i>%{user}</i> reverted protocol <strong>%{protocol}</strong> from repository."
create_report: "<i>%{user}</i> created report <strong>%{report}</strong>."
delete_report: "<i>%{user}</i> deleted report <strong>%{report}</strong>."
edit_report: "<i>%{user}</i> edited report <strong>%{report}</strong>."
assign_sample: "<i>%{user}</i> assigned sample(s) <strong>%{samples}</strong> to task(s) <strong>%{tasks}</strong>."
unassign_sample: "<i>%{user}</i> unassigned sample(s) <strong>%{samples}</strong> from task(s) <strong>%{tasks}</strong>."
user_my_modules:
new: