mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-17 09:16:10 +08:00
Add activity for moving
This commit is contained in:
parent
e55c66b3d0
commit
042a33f2c7
4 changed files with 39 additions and 18 deletions
|
@ -93,7 +93,7 @@ class ExperimentsController < ApplicationController
|
||||||
|
|
||||||
# GET: clone_modal_experiment_path(id)
|
# GET: clone_modal_experiment_path(id)
|
||||||
def clone_modal
|
def clone_modal
|
||||||
@projects = projects_with_role_above_user(true)
|
@projects = @experiment.projects_with_role_above_user(current_user)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render json: {
|
render json: {
|
||||||
|
@ -111,7 +111,7 @@ class ExperimentsController < ApplicationController
|
||||||
|
|
||||||
# Try to clone the experiment
|
# Try to clone the experiment
|
||||||
success = true
|
success = true
|
||||||
if projects_with_role_above_user(true).include?(project)
|
if @experiment.projects_with_role_above_user(current_user).include?(project)
|
||||||
cloned_experiment = @experiment.deep_clone_to_project(current_user,
|
cloned_experiment = @experiment.deep_clone_to_project(current_user,
|
||||||
project)
|
project)
|
||||||
success = cloned_experiment.valid?
|
success = cloned_experiment.valid?
|
||||||
|
@ -144,7 +144,7 @@ class ExperimentsController < ApplicationController
|
||||||
|
|
||||||
# GET: move_modal_experiment_path(id)
|
# GET: move_modal_experiment_path(id)
|
||||||
def move_modal
|
def move_modal
|
||||||
@projects = projects_with_role_above_user(false)
|
@projects = @experiment.moveable_projects(current_user)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.json do
|
format.json do
|
||||||
render json: {
|
render json: {
|
||||||
|
@ -158,8 +158,31 @@ class ExperimentsController < ApplicationController
|
||||||
|
|
||||||
# POST: move_experiment(id)
|
# POST: move_experiment(id)
|
||||||
def move
|
def move
|
||||||
|
project = Project.find_by_id(params[:experiment][:project_id])
|
||||||
|
old_project = @experiment.project
|
||||||
|
|
||||||
|
# Try to move the experiment
|
||||||
success = true
|
success = true
|
||||||
|
if @experiment.moveable_projects(current_user).include?(project)
|
||||||
|
success = @experiment.move_to_project(project)
|
||||||
|
else
|
||||||
|
success = false
|
||||||
|
end
|
||||||
|
|
||||||
if success
|
if success
|
||||||
|
Activity.create(
|
||||||
|
type_of: :move_experiment,
|
||||||
|
project: project,
|
||||||
|
user: current_user,
|
||||||
|
message: I18n.t(
|
||||||
|
"activities.move_experiment",
|
||||||
|
user: current_user.full_name,
|
||||||
|
experiment: @experiment.name,
|
||||||
|
project_new: project.name,
|
||||||
|
project_original: old_project.name
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
flash[:success] = t('experiments.move.success_flash',
|
flash[:success] = t('experiments.move.success_flash',
|
||||||
experiment: @experiment.name)
|
experiment: @experiment.name)
|
||||||
redirect_to canvas_experiment_path(@experiment)
|
redirect_to canvas_experiment_path(@experiment)
|
||||||
|
@ -230,18 +253,4 @@ class ExperimentsController < ApplicationController
|
||||||
action_name.in?(%w(index archive)) ? 'main' : 'fluid'
|
action_name.in?(%w(index archive)) ? 'main' : 'fluid'
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get projects where user is either owner or user in the same organization
|
|
||||||
# as this experiment
|
|
||||||
# - include_this_project: whether to include project from @experiment
|
|
||||||
def projects_with_role_above_user(include_this_project)
|
|
||||||
organization = @experiment.project.organization
|
|
||||||
projects = organization.projects.where(archived: false)
|
|
||||||
projects = projects
|
|
||||||
.where.not(id: @experiment.project.id) unless include_this_project
|
|
||||||
|
|
||||||
current_user.user_projects
|
|
||||||
.where(project: projects)
|
|
||||||
.where('role < 2')
|
|
||||||
.map(&:project)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,8 @@ class Activity < ActiveRecord::Base
|
||||||
:add_comment_to_result,
|
:add_comment_to_result,
|
||||||
:archive_result,
|
:archive_result,
|
||||||
:edit_result,
|
:edit_result,
|
||||||
:clone_experiment
|
:clone_experiment,
|
||||||
|
:move_experiment
|
||||||
]
|
]
|
||||||
|
|
||||||
validates :type_of, presence: true
|
validates :type_of, presence: true
|
||||||
|
|
|
@ -43,4 +43,14 @@ class Tag < ActiveRecord::Base
|
||||||
.offset((page - 1) * SEARCH_LIMIT)
|
.offset((page - 1) * SEARCH_LIMIT)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def deep_clone_to_project(project)
|
||||||
|
Tag.create(
|
||||||
|
name: name,
|
||||||
|
color: color,
|
||||||
|
created_by: created_by,
|
||||||
|
last_modified_by: last_modified_by,
|
||||||
|
project: project
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1005,6 +1005,7 @@ en:
|
||||||
edit_text_result: "<i>%{user}</i> edited text 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>."
|
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>."
|
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>."
|
||||||
|
|
||||||
user_my_modules:
|
user_my_modules:
|
||||||
new:
|
new:
|
||||||
|
|
Loading…
Add table
Reference in a new issue