3531: Fix name-editing behavior: preserve name_links when merging results.
authorTom Clegg <tom@curoverse.com>
Sun, 10 Aug 2014 19:57:42 +0000 (15:57 -0400)
committerTom Clegg <tom@curoverse.com>
Sun, 10 Aug 2014 19:57:42 +0000 (15:57 -0400)
apps/workbench/app/controllers/projects_controller.rb

index 3e7bfcc71dea4f5c5094ba7181eb38e1f9370d6f..44348616dcd2a4fb4634d66683ccbae7a02b0b42 100644 (file)
@@ -139,13 +139,18 @@ class ProjectsController < ApplicationController
       # retrieving the next page. Ideally the API would do this for
       # us, but it doesn't (yet).
       @objects = []
+      @name_link_for = {}
       kind_filters.each do |attr,op,val|
         (val.is_a?(Array) ? val : [val]).each do |type|
-          @objects += @object.contents(order: @order,
-                                       limit: @limit,
-                                       include_linked: true,
-                                       filters: (@filters - kind_filters + [['uuid', 'is_a', type]]),
-                                       offset: @offset)
+          objects = @object.contents(order: @order,
+                                     limit: @limit,
+                                     include_linked: true,
+                                     filters: (@filters - kind_filters + [['uuid', 'is_a', type]]),
+                                     offset: @offset)
+          objects.each do |object|
+            @name_link_for[object.andand.uuid] = objects.links_for(object, 'name').first
+          end
+          @objects += objects
         end
       end
       @objects = @objects.to_a.sort_by(&:created_at).reverse[0..@limit-1]
@@ -223,6 +228,8 @@ class ProjectsController < ApplicationController
         name_links.each do |name_link|
           objects_and_names << [object, name_link]
         end
+      elsif @name_link_for.andand[object.uuid]
+        objects_and_names << [object, @name_link_for[object.uuid]]
       elsif object.respond_to? :name
         objects_and_names << [object, object]
       else