2012-03-06 15:53:04 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
|
|
|
class SearchController < ApplicationController
|
2012-03-31 00:37:54 +01:00
|
|
|
before_filter :authenticate_user! unless APP_CONFIG['anonymous_access']
|
2012-03-06 15:53:04 +00:00
|
|
|
# load_and_authorize_resource
|
|
|
|
|
|
|
|
def index
|
|
|
|
params[:type] ||= 'all'
|
2012-03-31 01:43:55 +01:00
|
|
|
params[:type] = 'projects' unless current_user
|
2012-03-06 15:53:04 +00:00
|
|
|
case params[:type]
|
|
|
|
when 'all'
|
|
|
|
find_collection('projects')
|
|
|
|
find_collection('users')
|
|
|
|
find_collection('groups')
|
|
|
|
find_collection('platforms')
|
|
|
|
when 'projects', 'users', 'groups', 'platforms'
|
|
|
|
find_collection(params[:type])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def find_collection(type)
|
|
|
|
var = :"@#{type}"
|
2012-03-28 00:58:03 +01:00
|
|
|
instance_variable_set var, type.classify.constantize.opened.search(params[:query]).search_order.paginate(:page => params[:page]) unless instance_variable_defined?(var)
|
2012-03-06 15:53:04 +00:00
|
|
|
end
|
|
|
|
end
|