2011-03-10 11:35:46 +00:00
|
|
|
module ProjectsHelper
|
2012-09-24 19:04:53 +01:00
|
|
|
def options_for_filters(all_projects, groups, owners)
|
2014-01-21 04:51:49 +00:00
|
|
|
projects_count_by_groups = all_projects.where(owner_id: groups, owner_type: 'Group').
|
2012-09-25 10:50:28 +01:00
|
|
|
group(:owner_id).count
|
2014-01-21 04:51:49 +00:00
|
|
|
projects_count_by_owners = all_projects.where(owner_id: owners, owner_type: 'User').
|
2012-09-25 10:50:28 +01:00
|
|
|
group(:owner_id).count
|
2012-09-24 19:04:53 +01:00
|
|
|
(groups + owners).map do |o|
|
|
|
|
class_name = o.class.name
|
|
|
|
{
|
2014-01-21 04:51:49 +00:00
|
|
|
id: "#{class_name.downcase}-#{o.id}",
|
|
|
|
color: '0054a6',
|
|
|
|
selected: false,
|
|
|
|
check_box_name: class_name.downcase.pluralize,
|
|
|
|
check_box_value: o.id,
|
|
|
|
name: content_tag(:div, content_tag(:span, o.uname, class: class_name.downcase)),
|
|
|
|
uname: o.uname, # only for sorting
|
|
|
|
count: o.is_a?(User) ? projects_count_by_owners[o.id] : projects_count_by_groups[o.id]
|
2012-09-24 19:04:53 +01:00
|
|
|
}
|
2012-09-24 19:36:02 +01:00
|
|
|
end.sort_by{ |f| f[:uname] }
|
2012-09-24 19:04:53 +01:00
|
|
|
end
|
|
|
|
|
2014-02-18 19:16:23 +00:00
|
|
|
def available_project_to_repositories(project)
|
|
|
|
project.project_to_repositories.includes(repository: :platform).select do |p_to_r|
|
|
|
|
p_to_r.repository.publish_without_qa ? true : can?(:local_admin_manage, p_to_r.repository.platform)
|
|
|
|
end.sort_by do |p_to_r|
|
|
|
|
"#{p_to_r.repository.platform.name}/#{p_to_r.repository.name}"
|
|
|
|
end.map do |p_to_r|
|
|
|
|
{
|
|
|
|
repository_name: "#{p_to_r.repository.platform.name}/#{p_to_r.repository.name}",
|
|
|
|
repository_path: platform_repository_path(p_to_r.repository.platform, p_to_r.repository),
|
|
|
|
auto_publish: p_to_r.auto_publish?,
|
|
|
|
enabled: p_to_r.enabled?,
|
|
|
|
repository_id: p_to_r.repository_id
|
|
|
|
}
|
|
|
|
end.to_a.to_json
|
|
|
|
end
|
|
|
|
|
2013-11-15 14:46:09 +00:00
|
|
|
def repositories_grouped_by_platform
|
|
|
|
groups = {}
|
|
|
|
Platform.accessible_by(current_ability, :related).order(:name).each do |platform|
|
|
|
|
next unless can?(:local_admin_manage, platform)
|
|
|
|
groups[platform.name] = Repository.custom_sort(platform.repositories).map{ |r| [r.name, r.id] }
|
|
|
|
end
|
|
|
|
groups
|
|
|
|
end
|
|
|
|
|
2011-11-22 18:58:23 +00:00
|
|
|
def git_repo_url(name)
|
|
|
|
if current_user
|
2012-03-31 17:36:32 +01:00
|
|
|
"#{request.protocol}#{current_user.uname}@#{request.host_with_port}/#{name}.git"
|
2011-11-10 09:04:24 +00:00
|
|
|
else
|
2012-03-31 17:36:32 +01:00
|
|
|
"#{request.protocol}#{request.host_with_port}/#{name}.git"
|
2011-11-10 09:04:24 +00:00
|
|
|
end
|
2011-10-26 21:57:51 +01:00
|
|
|
end
|
2012-02-29 14:45:04 +00:00
|
|
|
|
2013-03-07 08:06:34 +00:00
|
|
|
def git_ssh_repo_url(name)
|
|
|
|
"git@#{request.host}:#{name}.git"
|
|
|
|
end
|
|
|
|
|
2012-02-29 14:45:04 +00:00
|
|
|
def options_for_collaborators_roles_select
|
|
|
|
options_for_select(
|
|
|
|
Relation::ROLES.collect { |role|
|
|
|
|
[t("layout.collaborators.role_names.#{ role }"), role]
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2012-03-07 21:34:49 +00:00
|
|
|
|
|
|
|
def visibility_icon(visibility)
|
|
|
|
visibility == 'open' ? 'unlock.png' : 'lock.png'
|
|
|
|
end
|
2012-03-29 17:27:33 +01:00
|
|
|
|
|
|
|
def participant_class(alone_member, project)
|
|
|
|
c = alone_member ? 'user' : 'group'
|
|
|
|
c = 'user_owner' if project.owner == current_user
|
|
|
|
c = 'group_owner' if project.owner.in? current_user.groups
|
|
|
|
return c
|
|
|
|
end
|
|
|
|
|
|
|
|
def alone_member?(project)
|
2012-04-26 02:38:33 +01:00
|
|
|
Relation.by_target(project).by_actor(current_user).size > 0
|
2012-03-29 17:27:33 +01:00
|
|
|
end
|
2012-04-09 18:11:39 +01:00
|
|
|
|
|
|
|
def participant_path(participant)
|
|
|
|
participant.kind_of?(User) ? user_path(participant) : group_path(participant)
|
|
|
|
end
|
2011-03-10 11:35:46 +00:00
|
|
|
end
|