mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 00:11:22 +08:00
Add query for moveable projects
This commit is contained in:
parent
c387439fb2
commit
e55c66b3d0
2 changed files with 43 additions and 2 deletions
|
|
@ -340,6 +340,48 @@ class Experiment < ActiveRecord::Base
|
||||||
clone
|
clone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def move_to_project(project)
|
||||||
|
self.project = project
|
||||||
|
|
||||||
|
my_modules.each do |m|
|
||||||
|
new_tags = []
|
||||||
|
m.tags.each do |t|
|
||||||
|
new_tags << t.deep_clone_to_project(project)
|
||||||
|
end
|
||||||
|
m.my_module_tags.destroy_all
|
||||||
|
|
||||||
|
project.tags << new_tags
|
||||||
|
m.tags << new_tags
|
||||||
|
end
|
||||||
|
|
||||||
|
save
|
||||||
|
end
|
||||||
|
|
||||||
|
# Get projects where user is either owner or user in the same organization
|
||||||
|
# as this experiment
|
||||||
|
def projects_with_role_above_user(current_user)
|
||||||
|
organization = project.organization
|
||||||
|
projects = organization.projects.where(archived: false)
|
||||||
|
|
||||||
|
current_user.user_projects
|
||||||
|
.where(project: projects)
|
||||||
|
.where('role < 2')
|
||||||
|
.map(&:project)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Projects to which this experiment can be moved (inside the same
|
||||||
|
# organization and not archived), all users assigned on experiment.project has
|
||||||
|
# to be assigned on such project
|
||||||
|
def moveable_projects(current_user)
|
||||||
|
projects = projects_with_role_above_user(current_user)
|
||||||
|
|
||||||
|
projects = projects.each_with_object([]) do |p, arr|
|
||||||
|
arr << p if (project.users - p.users).empty?
|
||||||
|
arr
|
||||||
|
end
|
||||||
|
projects - [project]
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
# Archive all modules. Receives an array of module integer IDs.
|
# Archive all modules. Receives an array of module integer IDs.
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,7 @@
|
||||||
<h4 class="modal-title" id="move-experiment-modal-label"><%= t("experiments.move.modal_title", experiment: @experiment.name ) %></h5>
|
<h4 class="modal-title" id="move-experiment-modal-label"><%= t("experiments.move.modal_title", experiment: @experiment.name ) %></h5>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<%= f.select :project_id, options_for_select(@projects.collect { |p| [ p.name, p.id ] },
|
<%= f.select :project_id, options_for_select(@projects.collect { |p| [ p.name, p.id ] }),
|
||||||
@project.id ),
|
|
||||||
{}, {class: "form-control selectpicker", "data-role" => "clear"} %>
|
{}, {class: "form-control selectpicker", "data-role" => "clear"} %>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue