Add AJAX tag search box to collections.index page.
authorTom Clegg <tom@curoverse.com>
Mon, 13 Jan 2014 08:56:26 +0000 (00:56 -0800)
committerTom Clegg <tom@curoverse.com>
Mon, 13 Jan 2014 08:56:26 +0000 (00:56 -0800)
refs #1499

apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/views/collections/_index_tbody.html.erb [new file with mode: 0644]
apps/workbench/app/views/collections/index.html.erb
apps/workbench/app/views/collections/index.js.erb [new file with mode: 0644]

index 548d4f7dc419b3c0de422f6acbdcc255a23eefc7..f0e7765be5b11989e447f2d98273e2966391d78d 100644 (file)
@@ -7,7 +7,12 @@ class CollectionsController < ApplicationController
   end
 
   def index
-    @collections = Collection.limit(100)
+    if params[:search].andand.length > 0
+      tags = Link.where(link_class: 'tag', any: ['contains', params[:search]])
+      @collections = Collection.where(uuid: tags.collect(&:head_uuid))
+    else
+      @collections = Collection.limit(100)
+    end
     @links = Link.limit(1000).
       where(head_uuid: @collections.collect(&:uuid))
     @collection_info = {}
diff --git a/apps/workbench/app/views/collections/_index_tbody.html.erb b/apps/workbench/app/views/collections/_index_tbody.html.erb
new file mode 100644 (file)
index 0000000..f8fbcdc
--- /dev/null
@@ -0,0 +1,27 @@
+<% @collections.each do |c| %>
+
+<tr class="collection">
+  <td>
+    <%= link_to_if_arvados_object c.uuid %>
+  </td><td>
+    <% c.files.each do |file| %>
+      <%= file[0] == '.' ? file[1] : "#{file[0]}/#{file[1]}" %>
+    <% end %>
+  </td><td>
+    <%= raw(distance_of_time_in_words(c.created_at, Time.now).sub('about ','~').sub(' ','&nbsp;')) if c.created_at %>
+  </td><td>
+    <% if @collection_info[c.uuid] %>
+      <%= @collection_info[c.uuid][:tags].uniq.join ', ' %>
+    <% end %>
+  </td><td>
+    <% if @collection_info[c.uuid][:wanted_by_me] %>
+      <span class="label label-info">2&times;</span>
+    <% elsif @collection_info[c.uuid][:wanted] %>
+      <span class="label">2&times;</span>
+    <% else %>
+      <span class="label">cache</span>
+    <% end %>
+  </td>
+</tr>
+
+<% end %>
index 6fb506d1e8d92eae1da81cef400e11104b8877fb..11cacc7b8c783b519df9b3997c47b70a9febf587 100644 (file)
@@ -1,6 +1,15 @@
 <%#= render :partial => 'nav' %>
 
-<table class="topalign table table-bordered table-condensed table-fixedlayout table-smallcontent">
+<div class="pull-right">
+  <%= form_tag collections_path, method: 'get', remote: true do %>
+  <div class="input-append">
+    <%= text_field_tag :search, params[:search] %>
+    <%= submit_tag "Search", name: nil, class: 'btn btn-info' %>
+  </div>  
+  <% end %>
+</div>
+
+<table id="collections-index" class="topalign table table-bordered table-condensed table-fixedlayout table-smallcontent">
   <colgroup>
     <col width="10%" />
     <col width="50%" />
     </tr>
   </thead>
   <tbody>
-
-    <% @collections.each do |c| %>
-
-    <tr class="collection">
-      <td>
-        <%= link_to_if_arvados_object c.uuid %>
-      </td><td>
-        <% c.files.each do |file| %>
-          <%= file[0] == '.' ? file[1] : "#{file[0]}/#{file[1]}" %>
-        <% end %>
-      </td><td>
-       <%= raw(distance_of_time_in_words(c.created_at, Time.now).sub('about ','~').sub(' ','&nbsp;')) if c.created_at %>
-      </td><td>
-        <% if @collection_info[c.uuid] %>
-          <%= @collection_info[c.uuid][:tags].uniq.join ', ' %>
-        <% end %>
-      </td><td>
-        <% if @collection_info[c.uuid][:wanted_by_me] %>
-        <span class="label label-info">2&times;</span>
-        <% elsif @collection_info[c.uuid][:wanted] %>
-        <span class="label">2&times;</span>
-        <% else %>
-        <span class="label">cache</span>
-        <% end %>
-      </td>
-    </tr>
-
-    <% end %>
-
+    <%= render partial: 'index_tbody' %>
   </tbody>
 </table>
+
+<% content_for :js do %>
+$(document).on('click', 'form[data-remote] input[type=submit]', function() {
+  $('table#collections-index tbody').fadeTo(200, 0.3);
+  return true;
+});
+<% end %>
diff --git a/apps/workbench/app/views/collections/index.js.erb b/apps/workbench/app/views/collections/index.js.erb
new file mode 100644 (file)
index 0000000..cbe1096
--- /dev/null
@@ -0,0 +1,2 @@
+$('table#collections-index tbody').html("<%= escape_javascript(render partial: 'index_tbody') %>");
+$('table#collections-index tbody').fadeTo(200, 1.0);