1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 class RepositoriesController < ApplicationController
6 before_action :set_share_links, if: -> { defined? @object }
14 panes = super | %w(Sharing)
15 panes.insert(panes.length-1, panes.delete_at(panes.index('Advanced'))) if panes.index('Advanced')
20 panes.delete('Attributes') if !current_user.is_admin
25 @commit = params[:commit]
26 @path = params[:path] || ''
27 @subtree = @object.ls_subtree @commit, @path.chomp('/')
31 @commit = params[:commit]
33 @blobdata = @object.cat_file @commit, @path
37 @commit = params[:commit]
41 limit = params[:limit].andand.to_i || 100
42 offset = params[:offset].andand.to_i || 0
43 @filters = params[:filters] || []
46 owner_filter = @filters.select do |attr, op, val|
47 (attr == 'owner_uuid')
51 if !owner_filter.andand.any?
52 filters = @filters + [["owner_uuid", "=", current_user.uuid]]
53 my_repos = Repository.all.order("name ASC").limit(limit).offset(offset).filter(filters).results
54 else # done fetching all owned repositories
58 if !owner_filter.andand.any? # if this is next page request, the first page was still fetching "own" repos
59 @filters = @filters.reject do |attr, op, val|
60 (attr == 'owner_uuid') or
66 filters = @filters + [["owner_uuid", "!=", current_user.uuid]]
67 other_repos = Repository.all.order("name ASC").limit(limit).offset(offset).filter(filters).results
69 @objects = (my_repos + other_repos).first(limit)
72 def find_objects_for_index
73 return if !params[:partial]
78 @next_page_filters = next_page_filters('>=')
79 @next_page_href = url_for(partial: :repositories_rows,
80 filters: @next_page_filters.to_json)
86 def next_page_href with_params={}
90 def next_page_filters nextpage_operator
91 next_page_filters = @filters.reject do |attr, op, val|
92 (attr == 'owner_uuid') or
93 (attr == 'name' and op == nextpage_operator) or
94 (attr == 'uuid' and op == 'not in')
98 last_obj = @objects.last
99 next_page_filters += [['name', nextpage_operator, last_obj.name]]
100 next_page_filters += [['uuid', 'not in', [last_obj.uuid]]]
101 # if not-owned, it means we are done with owned repos and fetching other repos
102 next_page_filters += [['owner_uuid', '!=', last_obj.uuid]] if last_obj.owner_uuid != current_user.uuid