+ helper_method :projects_shared_with_me
+ def projects_shared_with_me
+ my_project_uuids = my_projects.collect &:uuid
+ all_projects.reject { |x| x.uuid.in? my_project_uuids }
+ end
+
+ helper_method :recent_jobs_and_pipelines
+ def recent_jobs_and_pipelines
+ (Job.limit(10) |
+ PipelineInstance.limit(10)).
+ sort_by do |x|
+ x.finished_at || x.started_at || x.created_at rescue x.created_at
+ end
+ end
+
+ helper_method :my_project_tree
+ def my_project_tree
+ build_project_trees
+ @my_project_tree
+ end
+
+ helper_method :shared_project_tree
+ def shared_project_tree
+ build_project_trees
+ @shared_project_tree
+ end
+
+ def build_project_trees
+ return if @my_project_tree and @shared_project_tree
+ parent_of = {current_user.uuid => 'me'}
+ all_projects.each do |ob|
+ parent_of[ob.uuid] = ob.owner_uuid
+ end
+ children_of = {false => [], 'me' => [current_user]}
+ all_projects.each do |ob|
+ if ob.owner_uuid != current_user.uuid and
+ not parent_of.has_key? ob.owner_uuid
+ parent_of[ob.uuid] = false
+ end
+ children_of[parent_of[ob.uuid]] ||= []
+ children_of[parent_of[ob.uuid]] << ob
+ end
+ buildtree = lambda do |children_of, root_uuid=false|
+ tree = {}
+ children_of[root_uuid].andand.each do |ob|
+ tree[ob] = buildtree.call(children_of, ob.uuid)
+ end
+ tree
+ end
+ sorted_paths = lambda do |tree, depth=0|
+ paths = []
+ tree.keys.sort_by { |ob|
+ ob.is_a?(String) ? ob : ob.friendly_link_name
+ }.each do |ob|
+ paths << {object: ob, depth: depth}
+ paths += sorted_paths.call tree[ob], depth+1
+ end
+ paths
+ end
+ @my_project_tree =
+ sorted_paths.call buildtree.call(children_of, 'me')
+ @shared_project_tree =
+ sorted_paths.call({'Shared with me' =>
+ buildtree.call(children_of, false)})
+ end
+
+ helper_method :get_object
+ def get_object uuid
+ if @get_object.nil? and @objects
+ @get_object = @objects.each_with_object({}) do |object, h|
+ h[object.uuid] = object
+ end
+ end
+ @get_object ||= {}
+ @get_object[uuid]
+ end
+
+ helper_method :project_breadcrumbs
+ def project_breadcrumbs
+ crumbs = []
+ current = @name_link || @object
+ while current
+ if current.is_a?(Group) and current.group_class.in?(['project','folder'])
+ crumbs.prepend current
+ end
+ if current.is_a? Link
+ current = Group.find?(current.tail_uuid)
+ else
+ current = Group.find?(current.owner_uuid)
+ end
+ end
+ crumbs
+ end
+
+ helper_method :current_project_uuid
+ def current_project_uuid
+ if @object.is_a? Group and @object.group_class.in?(['project','folder'])
+ @object.uuid
+ elsif @name_link.andand.tail_uuid
+ @name_link.tail_uuid
+ elsif @object and resource_class_for_uuid(@object.owner_uuid) == Group
+ @object.owner_uuid
+ else
+ nil
+ end
+ end
+