3821: Rename collection file path
authorradhika <radhika@curoverse.com>
Fri, 24 Mar 2017 20:58:20 +0000 (16:58 -0400)
committerradhika <radhika@curoverse.com>
Fri, 24 Mar 2017 20:58:20 +0000 (16:58 -0400)
apps/workbench/app/controllers/collections_controller.rb
apps/workbench/app/helpers/application_helper.rb
apps/workbench/app/models/collection.rb
apps/workbench/app/views/collections/_show_files.html.erb

index c3777962d09d0b52589d2db6e104a1420b899cf7..701b590bcbb8a49c152a8c04e2455aa207724486 100644 (file)
@@ -321,6 +321,36 @@ class CollectionsController < ApplicationController
     end
   end
 
+  def update
+    updated_attr = params[:collection].each.select {|a| a[0].andand.start_with? 'rename-file-path:'}
+
+    if updated_attr.size > 0
+      # Is it file rename?
+      file_path = updated_attr[0][0].split('rename-file-path:')[-1]
+
+      new_file_path = updated_attr[0][1]
+      if new_file_path.start_with?('./')
+        # looks good
+      elsif new_file_path.start_with?('/')
+        new_file_path = '.' + new_file_path
+      else
+        new_file_path = './' + new_file_path
+      end
+
+      arv_coll = Arv::Collection.new(@object.manifest_text)
+      arv_coll.rename "./"+file_path, new_file_path
+
+      if @object.update_attributes manifest_text: arv_coll.manifest_text
+        show
+      else
+        self.render_error status: 422
+      end
+    else
+      # Non a file rename; use default
+      super
+    end
+  end
+
   protected
 
   def find_usable_token(token_list)
index 21879a57a7d90aa77ba0f90e6a325f9ae9d5f00c..0dc16fbb44561c183b338e5b0272f9380565acc6 100644 (file)
@@ -274,10 +274,10 @@ module ApplicationHelper
       "data-placement" => "bottom",
       "data-type" => input_type,
       "data-title" => "Edit #{attr.to_s.gsub '_', ' '}",
-      "data-name" => attr,
+      "data-name" => htmloptions['selection_path'] || attr,
       "data-object-uuid" => object.uuid,
       "data-toggle" => "manual",
-      "data-value" => attrvalue,
+      "data-value" => htmloptions['data-value'] || attrvalue,
       "id" => span_id,
       :class => "editable #{is_textile?( object, attr ) ? 'editable-textile' : ''}"
     }.merge(htmloptions).merge(ajax_options)
index 13f5357faadba842e57bbc24b1bdc883509ed7f6..746833320240680ffb824af96fc9e0e70c0e8182 100644 (file)
@@ -1,6 +1,8 @@
 require "arvados/keep"
 
 class Collection < ArvadosBase
+  attr_accessor :filename
+
   MD5_EMPTY = 'd41d8cd98f00b204e9800998ecf8427e'
 
   def default_name
@@ -71,7 +73,7 @@ class Collection < ArvadosBase
   end
 
   def editable_attributes
-    %w(name description manifest_text)
+    %w(name description manifest_text filename)
   end
 
   def provenance
index f7a94fc5eca0abf547d0f52eb68826e2b8b07d77..fc1ca58d2a9a00cc55912a72bc75ac4209ae39ca 100644 (file)
                   <i class="fa fa-fw fa-trash-o"></i>
                 <% end %>
             <% end %>
-
         <% if CollectionsHelper::is_image(filename) %>
-            <i class="fa fa-fw fa-bar-chart-o"></i> <%= filename %></div>
+            <i class="fa fa-fw fa-bar-chart-o"></i>
+              <% if @object.editable? %>
+                <%= render_editable_attribute @object, 'filename', filename, {'data-value' => file_path, 'data-toggle' => 'manual', 'selection_path' => 'rename-file-path:'+file_path} %>
+              <% else %>
+                <%= filename %>
+              <% end %>
+            </div>
           <div class="collection_files_inline">
             <%= link_to(image_tag("#{url_for object}/#{file_path}"),
                         link_params.merge(disposition: 'inline'),
           </div>
          </div>
         <% else %>
-            <i class="fa fa-fw fa-file" href="<%=object.uuid%>/<%=file_path%>" ></i> <%= filename %></div>
+              <% if @object.editable? %>
+                <i class="fa fa-fw fa-file"></i><%= render_editable_attribute @object, 'filename', filename, {'data-value' => file_path, 'data-toggle' => 'manual', 'selection_path' => 'rename-file-path:'+file_path} %>
+              <% else %>
+                <i class="fa fa-fw fa-file" href="<%=object.uuid%>/<%=file_path%>" ></i> <%= filename %>
+              <% end %>
+            </div>
          </div>
         <% end %>
         </li>