2020-12-08 23:07:26 +08:00
|
|
|
# frozen_string_literal: true
|
2016-02-12 23:52:43 +08:00
|
|
|
|
2020-12-08 23:07:26 +08:00
|
|
|
module ProjectsHelper
|
2021-01-12 17:51:17 +08:00
|
|
|
def projects_view_mode
|
2021-01-19 18:28:59 +08:00
|
|
|
return 'archived' if current_folder&.archived?
|
|
|
|
|
2021-01-12 17:51:17 +08:00
|
|
|
params[:view_mode] == 'archived' ? 'archived' : 'active'
|
|
|
|
end
|
|
|
|
|
|
|
|
def projects_view_mode_archived?
|
2021-01-19 18:28:59 +08:00
|
|
|
projects_view_mode == 'archived'
|
2021-01-12 17:51:17 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def user_project_role_to_s(user_project)
|
2020-12-08 23:07:26 +08:00
|
|
|
t('user_projects.enums.role.' + user_project.role)
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
|
2021-01-04 23:44:31 +08:00
|
|
|
def user_names_with_roles(user_projects)
|
2021-01-06 01:31:33 +08:00
|
|
|
user_projects.map { |up| user_name_with_role(up) }.join('
').html_safe
|
2021-01-04 23:44:31 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_name_with_role(user_project)
|
2021-01-06 16:14:43 +08:00
|
|
|
"#{sanitize_input(user_project.user.name)} - #{I18n.t("user_projects.enums.role.#{user_project.role}")}"
|
2021-01-04 23:44:31 +08:00
|
|
|
end
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def construct_module_connections(my_module)
|
2020-12-08 23:07:26 +08:00
|
|
|
conns = []
|
2016-02-12 23:52:43 +08:00
|
|
|
my_module.outputs.each do |output|
|
|
|
|
conns.push(output.to.id)
|
|
|
|
end
|
|
|
|
conns.to_s[1..-2]
|
|
|
|
end
|
2020-12-08 23:07:26 +08:00
|
|
|
|
2021-01-12 17:51:17 +08:00
|
|
|
def sidebar_folders_tree(team, user, sort, folders_only: false)
|
2021-01-21 18:24:25 +08:00
|
|
|
sort ||= team.current_view_state(user).state.dig('projects', 'active', 'sort')
|
2021-01-12 17:51:17 +08:00
|
|
|
if projects_view_mode_archived?
|
|
|
|
records = ProjectFolder.archived.inner_folders(team)
|
|
|
|
records += team.projects.archived.visible_to(user, team) unless folders_only
|
|
|
|
else
|
|
|
|
records = ProjectFolder.active.inner_folders(team)
|
|
|
|
records += team.projects.active.visible_to(user, team) unless folders_only
|
2021-01-21 18:24:25 +08:00
|
|
|
sort = 'new' if %w(archived_old archived_new).include?(sort)
|
2021-01-12 17:51:17 +08:00
|
|
|
end
|
2021-01-07 20:16:05 +08:00
|
|
|
records = case sort
|
2020-12-08 23:07:26 +08:00
|
|
|
when 'new'
|
|
|
|
records.sort_by(&:created_at).reverse!
|
|
|
|
when 'old'
|
|
|
|
records.sort_by(&:created_at)
|
|
|
|
when 'atoz'
|
|
|
|
records.sort_by { |c| c.name.downcase }
|
|
|
|
when 'ztoa'
|
|
|
|
records.sort_by { |c| c.name.downcase }.reverse!
|
2020-12-31 23:00:26 +08:00
|
|
|
when 'archived_old'
|
2020-12-18 18:22:04 +08:00
|
|
|
records.sort_by(&:archived_on)
|
2020-12-31 23:00:26 +08:00
|
|
|
when 'archived_new'
|
2020-12-18 18:22:04 +08:00
|
|
|
records.sort_by(&:archived_on).reverse!
|
2020-12-08 23:07:26 +08:00
|
|
|
end
|
|
|
|
folders_recursive_builder(nil, records)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def folders_recursive_builder(folder, records)
|
|
|
|
children = records.select do |i|
|
|
|
|
(defined?(i.parent_folder_id) && i.parent_folder_id == folder&.id) ||
|
|
|
|
(defined?(i.project_folder_id) && i.project_folder_id == folder&.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
children.map do |i|
|
|
|
|
if i.class == Project
|
|
|
|
{ project: i }
|
|
|
|
else
|
|
|
|
{
|
|
|
|
folder: i,
|
|
|
|
children: folders_recursive_builder(i, records)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|