[ARVADOS] created: 20334fa95bb7d554c09225c02fae3d4e83c6c6c5

git at public.curoverse.com git at public.curoverse.com
Thu Apr 24 17:53:31 EDT 2014


        at  20334fa95bb7d554c09225c02fae3d4e83c6c6c5 (commit)


commit 20334fa95bb7d554c09225c02fae3d4e83c6c6c5
Author: Tom Clegg <tom at curoverse.com>
Date:   Thu Apr 24 17:52:56 2014 -0400

    Add persistent/cache switch to collections index page.

diff --git a/apps/workbench/app/assets/javascripts/application.js b/apps/workbench/app/assets/javascripts/application.js
index 6afc8c3..189063b 100644
--- a/apps/workbench/app/assets/javascripts/application.js
+++ b/apps/workbench/app/assets/javascripts/application.js
@@ -19,6 +19,7 @@
 //= require bootstrap/popover
 //= require bootstrap/collapse
 //= require bootstrap/modal
+//= require bootstrap/button
 //= require bootstrap3-editable/bootstrap-editable
 //= require_tree .
 
@@ -105,6 +106,12 @@ jQuery(function($){
             return false;
         });
 
+    $(document).
+        on('ajax:complete ready', function() {
+            // See http://getbootstrap.com/javascript/#buttons
+            $('.btn').button();
+        });
+
     HeaderRowFixer = function(selector) {
         this.duplicateTheadTr = function() {
             $(selector).each(function() {
diff --git a/apps/workbench/app/assets/javascripts/collections.js b/apps/workbench/app/assets/javascripts/collections.js
new file mode 100644
index 0000000..806ee6d
--- /dev/null
+++ b/apps/workbench/app/assets/javascripts/collections.js
@@ -0,0 +1,53 @@
+jQuery(function($){
+    $(document).on('change', '.toggle-persist input[name=wants]', function() {
+        var toggle_group = $(this).parents('[data-remote-href]').first();
+        if (toggle_group.attr('data-persistent-state') == $(this).val()) {
+            // When the user clicks the already-selected choice, or
+            // the fail() handler below reverts state to the existing
+            // state, don't start an AJAX request.
+            return;
+        }
+        $.ajax(toggle_group.attr('data-remote-href'),
+               {dataType: 'json',
+                type: 'POST',
+                data: {
+                    value: $(this).val()
+                },
+                context: {
+                    toggle_group: toggle_group,
+                    input: this
+                }
+               }).
+            done(function(data, status, jqxhr) {
+                var context = this;
+                $(document).trigger('ajax:complete');
+                // Remove "danger" status in case a previous action failed
+                $('label.btn-danger', context.toggle_group).
+                    addClass('btn-info').
+                    removeClass('btn-danger');
+                // Update last-saved-state
+                context.toggle_group.
+                    attr('data-persistent-state', $(context.input).val());
+            }).
+            fail(function(jqxhr, status, error) {
+                var context = this;
+                $(document).trigger('ajax:complete');
+                // Add a visual indication that something failed
+                $('label.btn', context.toggle_group).
+                    addClass('btn-danger').
+                    removeClass('btn-info');
+                // Select the button reflecting the last-saved-state
+                $('label.btn input[value=' +
+                  context.toggle_group.attr('data-persistent-state') +
+                  ']', context.toggle_group).
+                    button('toggle');
+                if (jqxhr.responseJSON && jqxhr.responseJSON.errors) {
+                    window.alert("Request failed: " +
+                                 jqxhr.responseJSON.errors.join("; "));
+                } else {
+                    window.alert("Request failed.");
+                }
+            });
+        $(document).trigger('ajax:send');
+    });
+});
diff --git a/apps/workbench/app/assets/javascripts/collections.js.coffee b/apps/workbench/app/assets/javascripts/collections.js.coffee
deleted file mode 100644
index 7615679..0000000
--- a/apps/workbench/app/assets/javascripts/collections.js.coffee
+++ /dev/null
@@ -1,3 +0,0 @@
-# Place all the behaviors and hooks related to the matching controller here.
-# All this logic will automatically be available in application.js.
-# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
diff --git a/apps/workbench/app/controllers/collections_controller.rb b/apps/workbench/app/controllers/collections_controller.rb
index a5ac215..bed09d3 100644
--- a/apps/workbench/app/controllers/collections_controller.rb
+++ b/apps/workbench/app/controllers/collections_controller.rb
@@ -6,6 +6,36 @@ class CollectionsController < ApplicationController
     %w(Files Attributes Metadata Provenance_graph Used_by JSON API)
   end
 
+  def set_persistent
+    case params[:value]
+    when 'persistent', 'cache'
+      persist_links = Link.filter([['owner_uuid', '=', current_user.uuid],
+                                   ['link_class', '=', 'resources'],
+                                   ['name', '=', 'wants'],
+                                   ['tail_uuid', '=', current_user.uuid],
+                                   ['head_uuid', '=', @object.uuid]])
+      logger.debug persist_links.inspect
+    else
+      return unprocessable "Invalid value #{value.inspect}"
+    end
+    if params[:value] == 'persistent'
+      if not persist_links.any?
+        Link.create(link_class: 'resources',
+                    name: 'wants',
+                    tail_uuid: current_user.uuid,
+                    head_uuid: @object.uuid)
+      end
+    else
+      persist_links.each do |link|
+        link.destroy || raise
+      end
+    end
+
+    respond_to do |f|
+      f.json { render json: @object }
+    end
+  end
+
   def index
     if params[:search].andand.length.andand > 0
       tags = Link.where(any: ['contains', params[:search]])
@@ -68,7 +98,6 @@ class CollectionsController < ApplicationController
     self.response_body = FileStreamer.new opts
   end
 
-
   def show
     return super if !@object
     @provenance = []
diff --git a/apps/workbench/app/views/collections/_index_tbody.html.erb b/apps/workbench/app/views/collections/_index_tbody.html.erb
index 7574537..b2b5b23 100644
--- a/apps/workbench/app/views/collections/_index_tbody.html.erb
+++ b/apps/workbench/app/views/collections/_index_tbody.html.erb
@@ -23,18 +23,19 @@
       ⋮
     <% end %>
   </td>
-  <td><%= link_to_if_arvados_object c.owner_uuid, friendly_name: true %></td>
   <td>
     <%= raw(distance_of_time_in_words(c.created_at, Time.now).sub('about ','~').sub(' ',' ')) if c.created_at %>
   </td>
   <td>
-    <% if @collection_info[c.uuid][:wanted_by_me] %>
-      <span class="label label-info">2×</span>
-    <% elsif @collection_info[c.uuid][:wanted] %>
-      <span class="label">2×</span>
-    <% else %>
-      <span class="label">cache</span>
-    <% end %>
+    <% current_state = @collection_info[c.uuid][:wanted_by_me] ? 'persistent' : 'cache' %>
+    <div class="btn-group btn-group-xs toggle-persist fill" data-toggle="buttons" data-remote-href="<%= set_persistent_collection_path(id: c.uuid) %>" data-persistent-state="<%= current_state %>">
+      <label class="btn btn-info <%= 'active' if current_state=='persistent' %>">
+        <input type="radio" name="wants" value="persistent">Persistent
+      </label>
+      <label class="btn btn-info <%= 'active' if current_state=='cache' %>">
+        <input type="radio" name="wants" value="cache">Cache
+      </label>
+    </div>
   </td>
   <td class="add-tag-button">
     <a class="btn btn-xs btn-info add-tag-button pull-right" data-remote-href="<%= url_for(controller: 'links', action: 'create') %>" data-remote-method="post"><i class="glyphicon glyphicon-plus"></i> Add</a>
diff --git a/apps/workbench/app/views/collections/_show_recent.html.erb b/apps/workbench/app/views/collections/_show_recent.html.erb
index e0a12ff..a4ab51c 100644
--- a/apps/workbench/app/views/collections/_show_recent.html.erb
+++ b/apps/workbench/app/views/collections/_show_recent.html.erb
@@ -23,10 +23,9 @@
   <colgroup>
     <col width="4%" />
     <col width="10%" />
-    <col width="36%" />
+    <col width="34%" />
     <col width="15%" />
-    <col width="8%" />
-    <col width="8%" />
+    <col width="18%" />
     <col width="23%" />
   </colgroup>
   <thead>
@@ -34,7 +33,6 @@
       <th></th>
       <th>uuid</th>
       <th>contents</th>
-      <th>owner</th>
       <th>age</th>
       <th>storage</th>
       <th>tags</th>
diff --git a/apps/workbench/config/routes.rb b/apps/workbench/config/routes.rb
index 8c89238..cc175eb 100644
--- a/apps/workbench/config/routes.rb
+++ b/apps/workbench/config/routes.rb
@@ -39,7 +39,9 @@ ArvadosWorkbench::Application.routes.draw do
   end
   resources :links
   match '/collections/graph' => 'collections#graph'
-  resources :collections
+  resources :collections do
+    post 'set_persistent', on: :member
+  end
   get '/collections/:uuid/*file' => 'collections#show_file', :format => false
 
   post 'actions' => 'actions#post'
diff --git a/services/api/app/controllers/application_controller.rb b/services/api/app/controllers/application_controller.rb
index fcc7618..4e7b73b 100644
--- a/services/api/app/controllers/application_controller.rb
+++ b/services/api/app/controllers/application_controller.rb
@@ -202,6 +202,9 @@ class ApplicationController < ActionController::Base
               value[0] == 'contains' then
             ilikes = []
             model_class.searchable_columns('ilike').each do |column|
+              # Including owner_uuid in an "any column" search will
+              # probably just return a lot of false positives.
+              next if column == 'owner_uuid'
               ilikes << "#{table_name}.#{column} ilike ?"
               conditions << "%#{value[1]}%"
             end
diff --git a/services/api/app/models/arvados_model.rb b/services/api/app/models/arvados_model.rb
index 25d7317..e42194b 100644
--- a/services/api/app/models/arvados_model.rb
+++ b/services/api/app/models/arvados_model.rb
@@ -47,9 +47,7 @@ class ArvadosModel < ActiveRecord::Base
   def self.searchable_columns operator
     textonly_operator = !operator.match(/[<=>]/)
     self.columns.collect do |col|
-      if col.name == 'owner_uuid'
-        nil
-      elsif [:string, :text].index(col.type)
+      if [:string, :text].index(col.type)
         col.name
       elsif !textonly_operator and [:datetime, :integer].index(col.type)
         col.name

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list