Commit 0a4283b5 authored by Marin Jankovski's avatar Marin Jankovski

Extract sorting into a method.

parent eda2c0c6
...@@ -130,14 +130,13 @@ class ProjectsController < ApplicationController ...@@ -130,14 +130,13 @@ class ProjectsController < ApplicationController
else else
[] []
end end
team_members = @project.team.members.sort_by(&:username).map { |user| { username: user.username, name: user.name } } team_members = sorted(@project.team.members)
participants = team_members + participating participants = team_members + participating
#participating = @project.issues.map { |issue| issue.participants.sort_by(&:username).map { |user| { username: user.username, name: user.name } } }.flatten
@suggestions = { @suggestions = {
emojis: Emoji.names.map { |e| { name: e, path: view_context.image_url("emoji/#{e}.png") } }, emojis: Emoji.names.map { |e| { name: e, path: view_context.image_url("emoji/#{e}.png") } },
issues: @project.issues.select([:iid, :title, :description]), issues: @project.issues.select([:iid, :title, :description]),
mergerequests: @project.merge_requests.select([:iid, :title, :description]), mergerequests: @project.merge_requests.select([:iid, :title, :description]),
members: participants.uniq members: participants
} }
respond_to do |format| respond_to do |format|
...@@ -174,14 +173,19 @@ class ProjectsController < ApplicationController ...@@ -174,14 +173,19 @@ class ProjectsController < ApplicationController
end end
def participants_in(type, id) def participants_in(type, id)
note = case type users = case type
when "Issue", "MergeRequest" when "Issue", "MergeRequest"
type.constantize.find_by_iid(id) type.constantize.find_by_iid(id).participants
when "Commits" when "Commit"
type.constantize.find(id) author_ids = Note.for_commit_id(id).pluck(:author_id).uniq
User.where(id: author_ids)
else else
[] []
end end
note.participants.sort_by(&:username).map { |user| { username: user.username, name: user.name } } sorted(users)
end
def sorted(users)
users.uniq.sort_by(&:username).map { |user| { username: user.username, name: user.name } }
end end
end end
...@@ -169,7 +169,6 @@ class User < ActiveRecord::Base ...@@ -169,7 +169,6 @@ class User < ActiveRecord::Base
scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all } scope :not_in_project, ->(project) { project.users.present? ? where("id not in (:ids)", ids: project.users.map(&:id) ) : all }
scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)') } scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM users_projects)') }
scope :ldap, -> { where(provider: 'ldap') } scope :ldap, -> { where(provider: 'ldap') }
scope :participating, ->(notes){ where(id: notes.inc_author.map(&:author_id))}
scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active } scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment