[ARVADOS] created: 259d991afb684e95a47ac77f1435b07800e83fbb
Git user
git at public.curoverse.com
Wed Jun 28 17:49:18 EDT 2017
at 259d991afb684e95a47ac77f1435b07800e83fbb (commit)
commit 259d991afb684e95a47ac77f1435b07800e83fbb
Author: radhika <radhika at curoverse.com>
Date: Wed Jun 28 17:46:29 2017 -0400
11870: add infinite scrolling and "add new repository" button to repositories index page
Arvados-DCO-1.1-Signed-off-by: Radhika Chippada <radhika at curoverse.com>
diff --git a/apps/workbench/app/controllers/repositories_controller.rb b/apps/workbench/app/controllers/repositories_controller.rb
index c5b3501..78ac055 100644
--- a/apps/workbench/app/controllers/repositories_controller.rb
+++ b/apps/workbench/app/controllers/repositories_controller.rb
@@ -2,7 +2,7 @@ class RepositoriesController < ApplicationController
before_filter :set_share_links, if: -> { defined? @object }
def index_pane_list
- %w(recent help)
+ %w(repositories help)
end
def show_pane_list
@@ -32,4 +32,72 @@ class RepositoriesController < ApplicationController
def show_commit
@commit = params[:commit]
end
+
+ def all_repos
+ limit = if params[:limit] then params[:limit].to_i else 100 end
+ offset = if params[:offset] then params[:offset].to_i else 0 end
+ @filters = params[:filters] || []
+
+ if @filters.any?
+ owner_filter = @filters.select do |attr, op, val|
+ (attr == 'owner_uuid')
+ end
+ end
+
+ if !owner_filter.andand.any?
+ filters = @filters + [["owner_uuid", "=", current_user.uuid]]
+ my_repos = Repository.all.order("name ASC").limit(limit).offset(offset).filter(filters).results
+ else # done fetching all owned repositories
+ my_repos = []
+ end
+
+ if !owner_filter.andand.any? # if this is next page request, the first page was still fetching "own" repos
+ @filters = @filters.reject do |attr, op, val|
+ (attr == 'owner_uuid') or
+ (attr == 'name') or
+ (attr == 'uuid')
+ end
+ end
+
+ filters = @filters + [["owner_uuid", "!=", current_user.uuid]]
+ other_repos = Repository.all.order("name ASC").limit(limit).offset(offset).filter(filters).results
+
+ @objects = (my_repos + other_repos).first(limit)
+ end
+
+ def find_objects_for_index
+ return if !params[:partial]
+
+ all_repos
+
+ if @objects.any?
+ @next_page_filters = next_page_filters('>=')
+ @next_page_href = url_for(partial: :repositories_rows,
+ filters: @next_page_filters.to_json)
+ else
+ @next_page_href = nil
+ end
+ end
+
+ def next_page_href with_params={}
+ @next_page_href
+ end
+
+ def next_page_filters nextpage_operator
+ next_page_filters = @filters.reject do |attr, op, val|
+ (attr == 'owner_uuid') or
+ (attr == 'name' and op == nextpage_operator) or
+ (attr == 'uuid' and op == 'not in')
+ end
+
+ if @objects.any?
+ last_obj = @objects.last
+ next_page_filters += [['name', nextpage_operator, last_obj.name]]
+ next_page_filters += [['uuid', 'not in', [last_obj.uuid]]]
+ # if not-owned, it means we are done with owned repos and fetching other repos
+ next_page_filters += [['owner_uuid', '!=', last_obj.uuid]] if last_obj.owner_uuid != current_user.uuid
+ end
+
+ next_page_filters
+ end
end
diff --git a/apps/workbench/app/views/users/_add_repository_modal.html.erb b/apps/workbench/app/views/repositories/_add_repository_modal.html.erb
similarity index 100%
rename from apps/workbench/app/views/users/_add_repository_modal.html.erb
rename to apps/workbench/app/views/repositories/_add_repository_modal.html.erb
diff --git a/apps/workbench/app/views/repositories/_show_repositories.html.erb b/apps/workbench/app/views/repositories/_show_repositories.html.erb
new file mode 100644
index 0000000..d522293
--- /dev/null
+++ b/apps/workbench/app/views/repositories/_show_repositories.html.erb
@@ -0,0 +1,32 @@
+<%= render partial: "add_repository_modal" %>
+
+<div class="container" style="width: 100%">
+ <div class="pull-right">
+ <%= link_to raw('<i class="fa fa-plus"></i> Add new repository'), "#",
+ {class: 'btn btn-xs btn-primary', 'data-toggle' => "modal",
+ 'data-target' => '#add-repository-modal'} %>
+ </div>
+
+ <div>
+ <table class="table table-condensed table-fixedlayout repositories-table">
+ <colgroup>
+ <col style="width: 5%" />
+ <col style="width: 30%" />
+ <col style="width: 60%" />
+ <col style="width: 5%" />
+ </colgroup>
+ <thead>
+ <tr>
+ <th></th>
+ <th> Name </th>
+ <th> URL </th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody data-infinite-scroller="#repositories-rows" id="repositories-rows"
+ data-infinite-content-href="<%= url_for partial: :repositories_rows %>" >
+ </tbody>
+ </table>
+ </div>
+</div>
diff --git a/apps/workbench/app/views/repositories/_show_repositories_rows.html.erb b/apps/workbench/app/views/repositories/_show_repositories_rows.html.erb
new file mode 100644
index 0000000..3b322ad
--- /dev/null
+++ b/apps/workbench/app/views/repositories/_show_repositories_rows.html.erb
@@ -0,0 +1,19 @@
+<% @objects.each do |repo| %>
+ <tr data-object-uuid="<%= repo.uuid %>">
+ <td>
+ <%= render :partial => "show_object_button", :locals => {object: repo, size: 'xs' } %>
+ </td>
+ <td style="word-break:break-all;">
+ <%= repo[:name] %>
+ </td>
+ <td style="word-break:break-all;">
+ <code><%= repo.http_fetch_url %></code><br/>
+ <code><%= repo.editable? ? repo.push_url : repo.fetch_url %></code>
+ </td>
+ <td>
+ <% if repo.editable? %>
+ <%= render partial: 'delete_object_button', locals: {object: repo} %>
+ <% end %>
+ </td>
+ </tr>
+<% end %>
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list