[ARVADOS] created: fc10c21d75b15e36c4f861fdd17bf985ca83d888

Git user git at public.curoverse.com
Tue May 30 18:42:34 EDT 2017


        at  fc10c21d75b15e36c4f861fdd17bf985ca83d888 (commit)


commit fc10c21d75b15e36c4f861fdd17bf985ca83d888
Author: radhika <radhika at curoverse.com>
Date:   Tue May 30 18:35:06 2017 -0400

    9587: trash page

diff --git a/apps/workbench/app/controllers/trash_items_controller.rb b/apps/workbench/app/controllers/trash_items_controller.rb
new file mode 100644
index 0000000..17d3340
--- /dev/null
+++ b/apps/workbench/app/controllers/trash_items_controller.rb
@@ -0,0 +1,94 @@
+class TrashItemsController < ApplicationController
+  def model_class
+    Collection
+  end
+
+  def find_objects_for_index
+    # If it's not the index rows partial display, just return
+    # The /index request will again be invoked to display the
+    # partial at which time, we will be using the objects found.
+    return if !params[:partial]
+
+    trashed_items
+
+    if @objects.any?
+      @next_page_filters = next_page_filters('<=')
+      @next_page_href = url_for(partial: :trash_rows,
+                                filters: @next_page_filters.to_json)
+      preload_links_for_objects(@objects.to_a)
+    else
+      @next_page_href = nil
+    end
+  end
+
+  def next_page_href with_params={}
+    @next_page_href
+  end
+
+  def trashed_items
+    # API server index doesn't return manifest_text by default, but our
+    # callers want it unless otherwise specified.
+    @select ||= Collection.columns.map(&:name)
+    limit = if params[:limit] then params[:limit].to_i else 100 end
+    offset = if params[:offset] then params[:offset].to_i else 0 end
+
+    base_search = Collection.select(@select).include_trash(true).where(is_trashed: true)
+    base_search = base_search.filter(params[:filters]) if params[:filters]
+
+    if params[:search].andand.length.andand > 0
+      tags = Link.where(any: ['contains', params[:search]])
+      @objects = (base_search.limit(limit).offset(offset).where(uuid: tags.collect(&:head_uuid)) |
+                      base_search.where(any: ['contains', params[:search]])).
+        uniq { |c| c.uuid }
+    else
+      @objects = base_search.limit(limit).offset(offset)
+    end
+
+    @links = Link.where(head_uuid: @objects.collect(&:uuid))
+    @collection_info = {}
+    @objects.each do |c|
+      @collection_info[c.uuid] = {
+        tag_links: [],
+        wanted: false,
+        wanted_by_me: false,
+        provenance: [],
+        links: []
+      }
+    end
+    @links.each do |link|
+      @collection_info[link.head_uuid] ||= {}
+      info = @collection_info[link.head_uuid]
+      case link.link_class
+      when 'tag'
+        info[:tag_links] << link
+      when 'resources'
+        info[:wanted] = true
+        info[:wanted_by_me] ||= link.tail_uuid == current_user.uuid
+      when 'provenance'
+        info[:provenance] << link.name
+      end
+      info[:links] << link
+    end
+    @request_url = request.url
+  end
+
+  def untrash_item
+    params[:item_uuids] = [params[:item_uuid]]
+    untrash_items
+    render template: 'untrash_items'
+  end
+
+  def untrash_items
+    @untrashed_uuids = []
+
+    updates = {trash_at: nil}
+    #updates[:trash_at] = nil
+
+    params[:item_uuids].collect { |uuid| ArvadosBase.find uuid }.each do |item|
+      item.update_attributes updates
+      @untrashed_uuids << item.uuid
+    end
+
+    render_template :untrashed_items
+  end
+end
diff --git a/apps/workbench/app/models/arvados_base.rb b/apps/workbench/app/models/arvados_base.rb
index 5d6a4c9..f06193c 100644
--- a/apps/workbench/app/models/arvados_base.rb
+++ b/apps/workbench/app/models/arvados_base.rb
@@ -152,6 +152,10 @@ class ArvadosBase < ActiveRecord::Base
     ArvadosResourceList.new(self).distinct(*args)
   end
 
+  def self.include_trash(*args)
+    ArvadosResourceList.new(self).include_trash(*args)
+  end
+
   def self.eager(*args)
     ArvadosResourceList.new(self).eager(*args)
   end
diff --git a/apps/workbench/app/models/arvados_resource_list.rb b/apps/workbench/app/models/arvados_resource_list.rb
index 35dcde3..8ae48d8 100644
--- a/apps/workbench/app/models/arvados_resource_list.rb
+++ b/apps/workbench/app/models/arvados_resource_list.rb
@@ -21,6 +21,11 @@ class ArvadosResourceList
     self
   end
 
+  def include_trash(option=nil)
+    @include_trash = option
+    self
+  end
+
   def limit(max_results)
     if not max_results.nil? and not max_results.is_a? Integer
       raise ArgumentError("argument to limit() must be an Integer or nil")
@@ -192,6 +197,7 @@ class ArvadosResourceList
     api_params[:order] = @orderby_spec if @orderby_spec
     api_params[:filters] = @filters if @filters
     api_params[:distinct] = @distinct if @distinct
+    api_params[:include_trash] = @include_trash if @include_trash
     if @fetch_multiple_pages
       # Default limit to (effectively) api server's MAX_LIMIT
       api_params[:limit] = 2**(0.size*8 - 1) - 1
diff --git a/apps/workbench/app/views/application/_breadcrumbs.html.erb b/apps/workbench/app/views/application/_breadcrumbs.html.erb
index 3ef2aec..489dbf3 100644
--- a/apps/workbench/app/views/application/_breadcrumbs.html.erb
+++ b/apps/workbench/app/views/application/_breadcrumbs.html.erb
@@ -66,4 +66,11 @@
             <% end %>
           <% end %>
         </ul>
+        <ul class="nav navbar-nav navbar-right">
+          <li>
+            <a href="/trash">
+              <i class="fa fa-lg fa-fw fa-trash-o"></i>
+            </a>
+          </li>
+        </ul>
       </nav>
diff --git a/apps/workbench/app/views/trash_items/_show_trash_items.html.erb b/apps/workbench/app/views/trash_items/_show_trash_items.html.erb
new file mode 100644
index 0000000..f069527
--- /dev/null
+++ b/apps/workbench/app/views/trash_items/_show_trash_items.html.erb
@@ -0,0 +1,29 @@
+<%= form_tag({}, {id: "trash_items"}) do |f| %>
+  <table id="trash-index" class="topalign table table-condensed table-fixedlayout">
+    <colgroup>
+      <col width="5%" />
+      <col width="15%" />
+      <col width="10%" />
+      <col width="10%" />
+      <col width="30%" />
+      <col width="25%" />
+      <col width="5%" />
+    </colgroup>
+
+    <thead>
+      <tr class="contain-align-left">
+        <th></th>
+        <th>Name</th>
+        <th>Created at</th>
+        <th>Trashed at</th>
+        <th>Contents</th>
+        <th>Tags</th>
+        <th></th>
+      </tr>
+    </thead>
+
+    <tbody data-infinite-scroller="#recent-trash-items" id="recent-trash-items"
+      data-infinite-content-href="<%= url_for partial: :trash_rows %>" >
+    </tbody>
+  </table>
+<% end %>
diff --git a/apps/workbench/app/views/trash_items/_show_trash_rows.html.erb b/apps/workbench/app/views/trash_items/_show_trash_rows.html.erb
new file mode 100644
index 0000000..73b89dd
--- /dev/null
+++ b/apps/workbench/app/views/trash_items/_show_trash_rows.html.erb
@@ -0,0 +1,39 @@
+<% @objects.sort_by { |obj| obj.created_at }.reverse.each do |obj| %>
+    <tr data-object-uuid="<%= obj.uuid %>" data-kind="<%= obj.kind %>" >
+      <td>
+        <%= check_box_tag 'uuids[]', obj.uuid, false, :class => 'persistent-selection' %>
+      </td>
+      <td>
+        <%= link_to_if_arvados_object obj, friendly_name: true %>
+      <td>
+        <%= obj.created_at.to_s if obj.created_at %>
+      <td>
+        <%= obj.trash_at.to_s if obj.trash_at %>
+      </td>
+      <td>
+        <% i = 0 %>
+        <% while i < 3 and i < obj.files.length %>
+          <% file = obj.files[i] %>
+          <% file_path = "#{file[0]}/#{file[1]}" %>
+          <%= link_to file[1], {controller: 'collections', action: 'show_file', uuid: obj.uuid, file: file_path, size: file[2], disposition: 'inline'}, {title: 'View in browser'} %><br />
+          <% i += 1 %>
+        <% end %>
+        <% if i < obj.files.length %>
+          ⋮
+        <% end %>
+      </td>
+      <td>
+        <span class="tag-container">
+        <% if @collection_info[obj.uuid] %>
+          <% @collection_info[obj.uuid][:tag_links].each do |tag_link| %>
+            <span class="label label-info" data-tag-link-uuid="<%= tag_link.uuid %>"><%= tag_link.name %>
+            </span> 
+          <% end %>
+        <% end %>
+        </span>
+      </td>
+      <td>
+        <%= render partial: 'untrash_item', locals: {object:obj} %>
+      </td>
+    </tr>
+<% end %>
diff --git a/apps/workbench/app/views/trash_items/_untrash_item.html.erb b/apps/workbench/app/views/trash_items/_untrash_item.html.erb
new file mode 100644
index 0000000..7fd7af7
--- /dev/null
+++ b/apps/workbench/app/views/trash_items/_untrash_item.html.erb
@@ -0,0 +1,5 @@
+<% if object.editable? %>
+  <%= link_to({action: 'untrash_item', id: object.uuid}, remote: true, data: {confirm: "Un-trash #{object.class_for_display.downcase} '#{object.friendly_link_name}'?"}) do %>
+    <i class="fa fa-fw fa-recycle"></i>
+  <% end %>
+<% end %>
diff --git a/apps/workbench/app/views/trash_items/index.html.erb b/apps/workbench/app/views/trash_items/index.html.erb
new file mode 100644
index 0000000..673ffdc
--- /dev/null
+++ b/apps/workbench/app/views/trash_items/index.html.erb
@@ -0,0 +1,26 @@
+<% content_for :tab_line_buttons do %>
+  <div class="input-group">
+    <div class="col-md-6 pull-left">
+      <div class="btn-group btn-group-sm">
+        <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Selection... <span class="caret"></span></button>
+        <ul class="dropdown-menu" role="menu">
+          <li><%= link_to "Un-trash selected items", '#',
+                  method: :post,
+                  'data-href' => untrash_items_trash_items_path,
+                  'data-selection-param-name' => 'selection[]',
+                  'data-selection-action' => 'untrash-items',
+                  'data-toggle' => 'dropdown'
+            %></li>
+        </ul>
+      </div>
+    </div>
+    <div class="col-md-6 pull-right">
+      <input type="text" class="form-control filterable-control recent-trash-items"
+           placeholder="Search trash"
+           data-filterable-target="#recent-trash-items"
+           value="<%= params[:search] %>" />
+    </div>
+  </div>
+<% end %>
+
+<%= render partial: 'show_trash_items' %>
diff --git a/apps/workbench/app/views/trash_items/untrashed_items.js.erb b/apps/workbench/app/views/trash_items/untrashed_items.js.erb
new file mode 100644
index 0000000..6d79aca
--- /dev/null
+++ b/apps/workbench/app/views/trash_items/untrashed_items.js.erb
@@ -0,0 +1,6 @@
+$(document).trigger('count-change');
+<% @untrashed_uuids.each do |uuid| %>
+	$('[data-object-uuid=<%= uuid %>]').hide('slow', function() {
+	    $(this).remove();
+	});
+<% end %>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 0eef73f..8ac726c 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -108,6 +108,12 @@ ArvadosWorkbench::Application.routes.draw do
 
   resources :workflows
 
+  get "trash" => 'trash_items#index', :as => :trash
+  resources :trash_items do
+    post 'untrash_item', on: :member
+    post 'untrash_items', on: :collection
+  end
+
   post 'actions' => 'actions#post'
   get 'actions' => 'actions#show'
   get 'websockets' => 'websocket#index'
diff --git a/services/api/app/controllers/arvados/v1/collections_controller.rb b/services/api/app/controllers/arvados/v1/collections_controller.rb
index 939ca21..8ba7925 100644
--- a/services/api/app/controllers/arvados/v1/collections_controller.rb
+++ b/services/api/app/controllers/arvados/v1/collections_controller.rb
@@ -13,7 +13,7 @@ class Arvados::V1::CollectionsController < ApplicationController
 
   def find_objects_for_index
     if params[:include_trash] || ['destroy', 'trash'].include?(action_name)
-      @objects = Collection.unscoped.readable_by(*@read_users)
+      @objects = Collection.readable_by(*@read_users).unscoped
     end
     super
   end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list