From 82124b32223f7cc9237cf7f9e3b247a99e893f93 Mon Sep 17 00:00:00 2001 From: Robin Ward <robin.ward@gmail.com> Date: Thu, 2 Apr 2015 14:51:49 -0400 Subject: [PATCH] UX: Login to decide when to show you near the top of the directory Don't show yourself there if you are close to the top already. --- app/controllers/directory_items_controller.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/controllers/directory_items_controller.rb b/app/controllers/directory_items_controller.rb index 35ed1ffc1..8499f1a4b 100644 --- a/app/controllers/directory_items_controller.rb +++ b/app/controllers/directory_items_controller.rb @@ -43,9 +43,16 @@ class DirectoryItemsController < ApplicationController more_params[:page] = page + 1 # Put yourself at the top of the first page - if result.present? && current_user.present? && page == 0 && result[0].user_id != current_user.id - your_item = DirectoryItem.where(period_type: period_type, user_id: current_user.id).first - result.insert(0, your_item) if your_item + if result.present? && current_user.present? && page == 0 + + position = result.index {|r| r.user_id == current_user.id } + + # Don't show the record unless you're not in the top positions already + if (position || 10) >= 10 + your_item = DirectoryItem.where(period_type: period_type, user_id: current_user.id).first + result.insert(0, your_item) if your_item + end + end render_json_dump(directory_items: serialize_data(result, DirectoryItemSerializer),