scinote-web/app/helpers/projects_helper.rb

63 lines
1.7 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2016-02-12 23:52:43 +08:00
module ProjectsHelper
def projects_view_mode(project: nil)
return (project.archived? ? 'archived' : 'active') if project
return 'archived' if current_folder&.archived?
params[:view_mode] == 'archived' ? 'archived' : 'active'
end
def projects_view_mode_archived?
projects_view_mode == 'archived'
end
def user_names_with_roles(user_assignments)
names_with_roles = user_assignments.map { |up| user_name_with_role(up) }.join('
')
sanitize_input(names_with_roles)
2016-02-12 23:52:43 +08:00
end
def user_name_with_role(user_assignment)
"#{escape_input(user_assignment.user.name)} - #{escape_input(user_assignment.user_role.name)}"
end
2016-02-12 23:52:43 +08:00
def construct_module_connections(my_module)
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
2023-12-01 07:01:08 +08:00
def folders_tree(team, user)
2021-01-21 18:24:25 +08:00
sort ||= team.current_view_state(user).state.dig('projects', 'active', 'sort')
if projects_view_mode_archived?
2023-12-01 07:01:08 +08:00
records = ProjectFolder.archived.inner_folders(team).order(:name).select(:id, :name, :parent_folder_id)
else
2023-12-01 07:01:08 +08:00
records = ProjectFolder.active.inner_folders(team).order(:name).select(:id, :name, :parent_folder_id)
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