Merge branch 'master' into 2060-edit-tags-in-workbench
authorTom Clegg <tom@curoverse.com>
Tue, 25 Feb 2014 17:21:54 +0000 (09:21 -0800)
committerTom Clegg <tom@curoverse.com>
Tue, 25 Feb 2014 17:21:54 +0000 (09:21 -0800)
apps/workbench/app/assets/javascripts/application.js
apps/workbench/app/assets/stylesheets/application.css.scss
apps/workbench/app/controllers/application_controller.rb
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/views/collections/_index_tbody.html.erb
apps/workbench/app/views/collections/_show_recent.html.erb

index 92842825f1fc609f032f7736788eeea1c7652c8a..770a904947ba02e1ab9a9a2b292209ccc1dc4854 100644 (file)
@@ -47,6 +47,61 @@ jQuery(function($){
         }).
         on('ajax:complete', function(e, status) {
             $('.loading').fadeOut('fast', 0);
+        }).
+        on('click', '.removable-tag a', function(e) {
+            var tag_span = $(this).parents('[data-tag-link-uuid]').eq(0)
+            tag_span.fadeTo('fast', 0.2);
+            $.ajax('/links/' + tag_span.attr('data-tag-link-uuid'),
+                   {dataType: 'json',
+                    type: 'POST',
+                    data: { '_method': 'DELETE' },
+                    context: tag_span}).
+                done(function(data, status, jqxhr) {
+                    this.remove();
+                }).
+                fail(function(jqxhr, status, error) {
+                    this.addClass('label-danger').fadeTo('fast', '1');
+                });
+            return false;
+        }).
+        on('click', 'a.add-tag-button', function(e) {
+            var jqxhr;
+            var new_tag_uuid = 'new-tag-' + Math.random();
+            var tag_head_uuid = $(this).parents('tr').attr('data-object-uuid');
+            var new_tag = window.prompt("Add tag for collection "+
+                                    tag_head_uuid,
+                                    "");
+            if (new_tag == null)
+                return false;
+            var new_tag_span =
+                $('<span class="label label-info removable-tag"></span>').
+                attr('data-tag-link-uuid', new_tag_uuid).
+                text(new_tag).
+                css('opacity', '0.2').
+                append('&nbsp;<a title="Delete tag"><i class="glyphicon glyphicon-trash"></i></a>&nbsp;');
+            $(this).
+                parent().
+                find('>span').
+                append(new_tag_span).
+                append(' ');
+            $.ajax($(this).attr('data-remote-href'),
+                           {dataType: 'json',
+                            type: $(this).attr('data-remote-method'),
+                            data: {
+                                'link[head_kind]': 'arvados#collection',
+                                'link[head_uuid]': tag_head_uuid,
+                                'link[link_class]': 'tag',
+                                'link[name]': new_tag
+                            },
+                            context: new_tag_span}).
+                done(function(data, status, jqxhr) {
+                    this.attr('data-tag-link-uuid', data.uuid).
+                        fadeTo('fast', '1');
+                }).
+                fail(function(jqxhr, status, error) {
+                    this.addClass('label-danger').fadeTo('fast', '1');
+                });
+            return false;
         });
 
     HeaderRowFixer = function(selector) {
index 5ada51a936a33d7e6fc3e622a443e63bc90ddd0c..7d241addf8f89739fe668f63813b3b0ce519b1f9 100644 (file)
@@ -126,6 +126,24 @@ ul.arvados-nav li ul li {
     display:inline-block;
 }
 
+td.add-tag-button {
+    white-space: normal;
+}
+td.add-tag-button .add-tag-button {
+    margin-right: 4px;
+    opacity: 0.2;
+}
+td.add-tag-button .add-tag-button:hover {
+    opacity: 1;
+}
+.label.removable-tag {
+    margin-top: .2em;
+}
+.label.removable-tag a {
+    color: #fff;
+    cursor: pointer;
+}
+
 li.notification {
     padding: 10px;
 }
index 02ebc8b3a198090c83fe98e5c3f99f18c0993c9d..e94428e92dca51ad00e415f38dac8ff69c35c4ef 100644 (file)
@@ -107,9 +107,10 @@ class ApplicationController < ActionController::Base
   end
 
   def create
-    @object ||= model_class.new params[model_class.to_s.singularize.to_sym]
+    @object ||= model_class.new params[model_class.to_s.underscore.singularize]
     @object.save!
     respond_to do |f|
+      f.json { render json: @object }
       f.html {
         redirect_to(params[:return_to] || @object)
       }
@@ -120,6 +121,7 @@ class ApplicationController < ActionController::Base
   def destroy
     if @object.destroy
       respond_to do |f|
+        f.json { render json: @object }
         f.html {
           redirect_to(params[:return_to] || :back)
         }
index f8895da5d38c8dd7ca8fcc8da70252f5ecdfebb3..b6997b97595d59c1f3f905995628e34da381e224 100644 (file)
@@ -19,7 +19,7 @@ class CollectionsController < ApplicationController
     @collection_info = {}
     @collections.each do |c|
       @collection_info[c.uuid] = {
-        tags: [],
+        tag_links: [],
         wanted: false,
         wanted_by_me: false,
         provenance: [],
@@ -31,7 +31,7 @@ class CollectionsController < ApplicationController
       info = @collection_info[link.head_uuid]
       case link.link_class
       when 'tag'
-        info[:tags] << link.name
+        info[:tag_links] << link
       when 'resources'
         info[:wanted] = true
         info[:wanted_by_me] ||= link.tail_uuid == current_user.uuid
index 9252886bb2094cf05ee6819ce9dbab290471d16b..258b00b01c6bdee89f9cdd0ec9711fb079651c52 100644 (file)
@@ -1,6 +1,6 @@
 <% @collections.each do |c| %>
 
-<tr class="collection">
+<tr class="collection" data-object-uuid="<%= c.uuid %>">
   <td>
     <%= link_to_if_arvados_object c.uuid %>
   </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>
       <span class="label">cache</span>
     <% end %>
   </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>&nbsp;Add</a>
+    <span>
+    <% if @collection_info[c.uuid] %>
+      <% @collection_info[c.uuid][:tag_links].each do |tag_link| %>
+        <span class="label label-info removable-tag" data-tag-link-uuid="<%= tag_link.uuid %>"><%= tag_link.name %>
+          <% if tag_link.owner_uuid == current_user.uuid %>
+          &nbsp;<a title="Delete tag"><i class="glyphicon glyphicon-trash"></i></a>
+          <% end %>
+        </span>
+      <% end %>
+    <% end %>
+    </span>
+  </td>
 </tr>
 
 <% end %>
index 125f413a9d1f1b6de1f69ea227de4301790cf00e..3cedb57e85c8a854efabad7bde2dc294a7d75746 100644 (file)
   <colgroup>
     <col width="10%" />
     <col width="36%" />
-    <col width="22%" />
+    <col width="15%" />
     <col width="8%" />
-    <col width="16%" />
     <col width="8%" />
+    <col width="23%" />
   </colgroup>
   <thead>
     <tr class="contain-align-left">
@@ -30,8 +30,8 @@
       <th>contents</th>
       <th>owner</th>
       <th>age</th>
-      <th>tags</th>
       <th>storage</th>
+      <th>tags</th>
     </tr>
   </thead>
   <tbody>