Permalink
Browse files

Search feature more or less works

  • Loading branch information...
1 parent 42eadcf commit 1e69f3b664ca430e4b2c1502c645d67ae43d9387 @ddemaree committed Mar 30, 2009
@@ -59,6 +59,19 @@ def current_timer
@current_timer ||= current_account.timers.current
end
helper_method :current_timer
+
+ def event_params
+ params[:tagged] ||= (params[:tag] || params[:tags])
+ @event_params ||= Event::Params.new(params)
+ end
+ helper_method :event_params
+
+ def current_project
+ @current_project = current_account.trackables.find_by_id(event_params[:project]) ||
+ current_account.trackables.find_by_nickname(event_params[:project]) ||
+ current_account.trackables.find_by_name(event_params[:project])
+ end
+ helper_method :current_project
protected
@@ -4,21 +4,16 @@ class EventsController < ApplicationController
rescue_from ActiveRecord::RecordInvalid, :with => :respond_on_invalid_event
def index
- session[:events_view] = {
- :controller => 'events',
- :page => params[:page],
- :per_page => params[:per_page],
- :tags => params[:tags],
- :trackable_id => params[:trackable_id],
- :starred => !!params[:starred]
- }
-
- scoped_events = current_account.events.filtered({
- :trackable => params[:trackable_id],
- :tag => params[:tags],
- :starred => !!params[:starred]
- })
+ # session[:events_view] = {
+ # :controller => 'events',
+ # :page => params[:page],
+ # :per_page => params[:per_page],
+ # :tags => params[:tags],
+ # :trackable_id => params[:trackable_id],
+ # :starred => !!params[:starred]
+ # }
+ scoped_events = current_account.events.filtered(event_params)
@events = scoped_events.paginate(:all, :per_page => (params[:per_page] || 20), :page => params[:page])
respond_to do |format|
@@ -2,9 +2,8 @@ module EventsHelper
def index_description
returning("") do |output|
- if params[:trackable_id]
- @current_project = Trackable.find(params[:trackable_id])
- output << "#{link_to(@current_project, @current_project)} &mdash; "
+ if current_project
+ output << "#{link_to(current_project, current_project)} &mdash; "
end
output << "Events"
@@ -6,12 +6,17 @@ def self.included(base)
base.send(:extend, ClassMethods)
base.class_eval do
- named_scope :filtered, lambda { |options| Event.options_for_filter(options) }
+ named_scope :filtered, lambda { |options| Event.filter(options) }
end
end
module ClassMethods
+ def filter(options)
+ options = options.is_a?(Event::Params) ? options : Event::Params.new(options)
+ options.to_finder_options
+ end
+
def keywords_to_options(string)
Event::Params.from_string(string)
end
Oops, something went wrong.

0 comments on commit 1e69f3b

Please sign in to comment.