diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb index ce54361..eb13d5d 100644 --- a/app/controllers/box_organizer_controller.rb +++ b/app/controllers/box_organizer_controller.rb @@ -83,9 +83,13 @@ class BoxOrganizerController < ApplicationController def search_autocomplete if request.xhr? and params[:query] search = params[:query] - articles = @profile.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20) - path_list = articles.map { |content| "/{profile}/"+content.path } - + path_list = if boxes_holder.is_a?(Environment) && boxes_holder.enabled?('use_portal_community') && boxes_holder.portal_community + boxes_holder.portal_community.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{portal}/"+content.path } + elsif boxes_holder.is_a?(Profile) + boxes_holder.articles.find(:all, :conditions=>"name ILIKE '%#{search}%' or path ILIKE '%#{search}%'", :limit=>20).map { |content| "/{profile}/"+content.path } + else + [] + end render :json => path_list.to_json else redirect_to "/" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 5905840..cfd3c28 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -1890,7 +1890,7 @@ a.button.disabled, input.disabled { margin-bottom: 5px; padding: 10px 1px 10px 10px; cursor: pointer; - width: 90%; + width: 97%; } .link-list-row:hover { background: #ddd url(/images/drag-and-drop.png) no-repeat; diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb index bbc159e..31d0b8e 100644 --- a/test/functional/environment_design_controller_test.rb +++ b/test/functional/environment_design_controller_test.rb @@ -379,4 +379,38 @@ class EnvironmentDesignControllerTest < ActionController::TestCase end end + should 'return a list of paths from portal related to the words used in the query search' do + env = Environment.default + login_as(create_admin_user(env)) + community = fast_create(Community, :environment_id => env) + env.portal_community = community + env.enable('use_portal_community') + env.save + @controller.stubs(:boxes_holder).returns(env) + article1 = fast_create(Article, :profile_id => community.id, :name => "Some thing") + article2 = fast_create(Article, :profile_id => community.id, :name => "Some article") + article3 = fast_create(Article, :profile_id => community.id, :name => "Not an article") + + xhr :get, :search_autocomplete, :query => 'Some' + + json_response = ActiveSupport::JSON.decode(@response.body) + + assert_response :success + assert_equal json_response.include?("/{portal}/"+article1.path), true + assert_equal json_response.include?("/{portal}/"+article2.path), true + assert_equal json_response.include?("/{portal}/"+article3.path), false + end + + should 'return empty if portal not configured' do + env = Environment.default + login_as(create_admin_user(env)) + + xhr :get, :search_autocomplete, :query => 'Some' + + json_response = ActiveSupport::JSON.decode(@response.body) + + assert_response :success + assert_equal json_response, [] + end + end -- libgit2 0.21.2