2872: Add infinite scroll to chooser modal.
[arvados.git] / apps / workbench / app / controllers / application_controller.rb
index 4aa79fb3fcfa1ca9ae7938b566089f63d99677ae..09419216b503be3c8c0ca6b64618ae515c903c00 100644 (file)
@@ -88,6 +88,20 @@ class ApplicationController < ActionController::Base
     @objects = @objects.filter(@filters).limit(@limit).offset(@offset)
   end
 
+  helper_method :next_page_offset
+  def next_page_offset
+    if @objects.respond_to?(:result_offset) and
+        @objects.respond_to?(:result_limit) and
+        @objects.respond_to?(:items_available)
+      next_offset = @objects.result_offset + @objects.result_limit
+      if next_offset < @objects.items_available
+        next_offset
+      else
+        nil
+      end
+    end
+  end
+
   def index
     find_objects_for_index if !@objects
     respond_to do |f|
@@ -115,8 +129,25 @@ class ApplicationController < ActionController::Base
   end
 
   def choose
-    find_objects_for_index
-    render partial: 'choose', locals: {multiple: params[:multiple]}
+    params[:limit] ||= 20
+    find_objects_for_index if !@objects
+    respond_to do |f|
+      if params[:partial]
+        f.json {
+          render json: {
+            content: render_to_string(partial: "choose_rows.html",
+                                      formats: [:html],
+                                      locals: {
+                                        multiple: params[:multiple]
+                                      }),
+            next_page_href: @next_page_href
+          }
+        }
+      end
+      f.js {
+        render partial: 'choose', locals: {multiple: params[:multiple]}
+      }
+    end
   end
 
   def render_content
@@ -130,7 +161,7 @@ class ApplicationController < ActionController::Base
   end
 
   def update
-    @updates ||= params[@object.class.to_s.underscore.singularize.to_sym]
+    @updates ||= params[@object.resource_param_name.to_sym]
     @updates.keys.each do |attr|
       if @object.send(attr).is_a? Hash
         if @updates[attr].is_a? String
@@ -198,7 +229,7 @@ class ApplicationController < ActionController::Base
   end
 
   def show_pane_list
-    %w(Attributes Metadata Advanced)
+    %w(Attributes Advanced)
   end
 
   protected
@@ -438,4 +469,30 @@ class ApplicationController < ActionController::Base
       @notification_count = ''
     end
   end
+
+  helper_method :my_folders
+  def my_folders
+    return @my_folders if @my_folders
+    @my_folders = []
+    root_of = {}
+    Group.filter([['group_class','=','folder']]).each do |g|
+      root_of[g.uuid] = g.owner_uuid
+      @my_folders << g
+    end
+    done = false
+    while not done
+      done = true
+      root_of = root_of.each_with_object({}) do |(child, parent), h|
+        if root_of[parent]
+          h[child] = root_of[parent]
+          done = false
+        else
+          h[child] = parent
+        end
+      end
+    end
+    @my_folders = @my_folders.select do |g|
+      root_of[g.uuid] == current_user.uuid
+    end
+  end
 end