mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-27 18:21:50 +08:00
Fixed unassigned user methods, order by name [SCI-6104] (#3589)
This commit is contained in:
parent
362658021e
commit
462f8ffc47
5 changed files with 24 additions and 20 deletions
|
@ -33,7 +33,7 @@ class UserMyModulesController < ApplicationController
|
|||
|
||||
def index_edit
|
||||
@user_my_modules = @my_module.user_my_modules
|
||||
@unassigned_users = @my_module.unassigned_users
|
||||
@undesignated_users = @my_module.undesignated_users.order(full_name: :asc)
|
||||
@new_um = UserMyModule.new(my_module: @my_module)
|
||||
|
||||
respond_to do |format|
|
||||
|
|
|
@ -191,15 +191,15 @@ class MyModule < ApplicationRecord
|
|||
report_elements.where(repository_id: ids).update(repository: repository)
|
||||
end
|
||||
|
||||
def unassigned_users
|
||||
User.find_by_sql(
|
||||
"SELECT DISTINCT users.id, users.full_name FROM users " +
|
||||
"INNER JOIN user_projects ON users.id = user_projects.user_id " +
|
||||
"INNER JOIN experiments ON experiments.project_id = user_projects.project_id " +
|
||||
"WHERE experiments.id = #{experiment_id.to_s}" +
|
||||
" AND users.id NOT IN " +
|
||||
"(SELECT DISTINCT user_id FROM user_my_modules WHERE user_my_modules.my_module_id = #{id.to_s})"
|
||||
)
|
||||
def undesignated_users
|
||||
User.joins(:user_assignments)
|
||||
.joins(
|
||||
"LEFT OUTER JOIN user_my_modules ON user_my_modules.user_id = users.id "\
|
||||
"AND user_my_modules.my_module_id = #{id}"
|
||||
)
|
||||
.where(user_assignments: { assignable: self })
|
||||
.where(user_my_modules: { id: nil })
|
||||
.distinct
|
||||
end
|
||||
|
||||
def unassigned_tags
|
||||
|
|
|
@ -196,16 +196,20 @@ class Project < ApplicationRecord
|
|||
end
|
||||
|
||||
def unassigned_users
|
||||
User
|
||||
.joins('INNER JOIN user_teams ON users.id = user_teams.user_id')
|
||||
.where('user_teams.team_id = ?', team)
|
||||
.where.not(confirmed_at: nil)
|
||||
.where('users.id NOT IN (?)',
|
||||
UserProject.where(project: self).select(:user_id).distinct)
|
||||
User.joins(:user_teams)
|
||||
.joins(
|
||||
"LEFT OUTER JOIN user_assignments ON user_assignments.user_id = users.id "\
|
||||
"AND user_assignments.assignable_id = #{id} "\
|
||||
"AND user_assignments.assignable_type = 'Project'"
|
||||
)
|
||||
.where(user_teams: { team_id: team_id })
|
||||
.where(user_assignments: { id: nil })
|
||||
.where.not(confirmed_at: nil)
|
||||
.distinct
|
||||
end
|
||||
|
||||
def user_role(user)
|
||||
user_assignments.find_by_user_id(user)&.user_role.name
|
||||
user_assignments.includes(:user_role).references(:user_role).find_by(user: user)&.user_role&.name
|
||||
end
|
||||
|
||||
def sorted_experiments(user, sort_by = :new, archived = false)
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<%= image_tag avatar_path(user, :icon_small) %>
|
||||
</span>
|
||||
<% end %>
|
||||
<% if can_manage_my_module_users?(@my_module) && @my_module.unassigned_users.any? %>
|
||||
<% if can_manage_my_module_users?(@my_module) && @my_module.undesignated_users.any? %>
|
||||
<span class="global-avatar-container assign-new-user">
|
||||
<i class="fas fa-plus"></i>
|
||||
</span>
|
||||
|
|
|
@ -34,13 +34,13 @@
|
|||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if can_manage_my_module_users?(@my_module) && @unassigned_users.count > 0 %>
|
||||
<% if can_manage_my_module_users?(@my_module) && @undesignated_users.any? %>
|
||||
<li>
|
||||
<hr>
|
||||
<div class="row">
|
||||
<%= bootstrap_form_for [@my_module, @new_um], remote: true, format: :json, html: { class: 'add-user-form' } do |f| %>
|
||||
<div class="col-xs-4">
|
||||
<%= collection_select(:user_my_module, :user_id, @unassigned_users, :id, :full_name, {}, { class: 'selectpicker' }) %>
|
||||
<%= collection_select(:user_my_module, :user_id, @undesignated_users, :id, :full_name, {}, { class: 'selectpicker' }) %>
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<%= f.button class: 'btn btn-primary' do %>
|
||||
|
|
Loading…
Reference in a new issue