From de9db9a2031126e9c3ff3d8330512a35c07768b0 Mon Sep 17 00:00:00 2001 From: Jessica Tatham Date: Mon, 21 Jul 2014 17:51:21 -0400 Subject: [PATCH 1/3] Created a search bar to search for events based on title. Want to implement search for venue --- app/assets/stylesheets/layout.scss | 11 ++++++++++- app/controllers/site_controller.rb | 5 +++++ app/views/site/_navbar.html.haml | 3 +-- config/routes.rb | 2 +- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 704676ba..62da7536 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -81,8 +81,17 @@ } #navbar-search { - float: right; + position: absolute; + right: 13%; + top: 15px; + color: $navbar-link-color; + background-color: white; padding: 0px 20px; + z-index: 2; + width: 15%; + height: 30px; + border-radius: 3px; + display: block; } #login_links a { diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index fe6888cd..e55f9dd5 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -21,4 +21,9 @@ def opensearch format.xml { render :content_type => 'application/opensearchdescription+xml' } end end + + def search + event = Event.find_by_title(params[:search]) + redirect_to '/events/'+event.id.to_s + end end diff --git a/app/views/site/_navbar.html.haml b/app/views/site/_navbar.html.haml index 866926aa..3dd37d5f 100644 --- a/app/views/site/_navbar.html.haml +++ b/app/views/site/_navbar.html.haml @@ -20,6 +20,5 @@ %li{:class => link_class[:venues]}= link_to t('.menu.venues'), venues_path %li= link_to t('.menu.new_event'), new_event_path -#navbar-search = form_tag search_events_path, :method => :get do - = text_field_tag 'query', @query, :placeholder => t('.search.placeholder') + = text_field_tag :search, nil, id: "navbar-search", :placeholder => "Search for an event" diff --git a/config/routes.rb b/config/routes.rb index 6f961678..23019399 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -15,7 +15,7 @@ resources :events do collection do post :squash_many_duplicates - get :search + get :search, to: 'site#search', as: 'search' get :duplicates get :widget, :action => 'index', :widget => true get 'widget/builder', :action => 'widget_builder' From 637aea0eaa6e8fa50b7029f27e26f160b50ba638 Mon Sep 17 00:00:00 2001 From: Jessica Tatham Date: Mon, 21 Jul 2014 21:27:40 -0400 Subject: [PATCH 2/3] Working search bar for event titles and venue titles --- app/controllers/site_controller.rb | 9 ++++++++- app/views/site/_navbar.html.haml | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index e55f9dd5..744b0ebe 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -24,6 +24,13 @@ def opensearch def search event = Event.find_by_title(params[:search]) - redirect_to '/events/'+event.id.to_s + venue = Venue.find_by_title(params[:search]) + if event != nil + redirect_to '/events/'+event.id.to_s + elsif venue != nil + redirect_to '/venues/'+venue.id.to_s + else + redirect_to '/' + end end end diff --git a/app/views/site/_navbar.html.haml b/app/views/site/_navbar.html.haml index 3dd37d5f..1af2f6ee 100644 --- a/app/views/site/_navbar.html.haml +++ b/app/views/site/_navbar.html.haml @@ -21,4 +21,4 @@ %li= link_to t('.menu.new_event'), new_event_path = form_tag search_events_path, :method => :get do - = text_field_tag :search, nil, id: "navbar-search", :placeholder => "Search for an event" + = text_field_tag :search, nil, id: "navbar-search", :placeholder => "Search" From 1a631c22c81ef7bdc6828e11b4e02abb52287879 Mon Sep 17 00:00:00 2001 From: Jessica Tatham Date: Mon, 21 Jul 2014 22:10:31 -0400 Subject: [PATCH 3/3] Can now search for a portion of the venue or event title and return results --- app/controllers/site_controller.rb | 13 +++++++------ app/models/event.rb | 6 ++++++ app/models/venue.rb | 6 ++++++ 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/controllers/site_controller.rb b/app/controllers/site_controller.rb index 744b0ebe..7a175e0a 100644 --- a/app/controllers/site_controller.rb +++ b/app/controllers/site_controller.rb @@ -23,14 +23,15 @@ def opensearch end def search - event = Event.find_by_title(params[:search]) - venue = Venue.find_by_title(params[:search]) - if event != nil - redirect_to '/events/'+event.id.to_s - elsif venue != nil - redirect_to '/venues/'+venue.id.to_s + event = Event.find_event(params[:search]) + venue = Venue.find_venue(params[:search]) + if event != [] + redirect_to '/events/'+event.first.id.to_s + elsif venue != [] + redirect_to '/venues/'+venue.first.id.to_s else redirect_to '/' end end + end diff --git a/app/models/event.rb b/app/models/event.rb index 7d5e4b31..9915cd8f 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -196,6 +196,12 @@ def self.time_for(value) end end + def self.find_event(search) + if search + Event.find(:all, :conditions => ['title LIKE ?', "%#{search}%"]) + end + end + #---[ Queries ]--------------------------------------------------------- # Returns groups of records for the site overview screen in the following format: diff --git a/app/models/venue.rb b/app/models/venue.rb index 73e9752b..95a0a761 100644 --- a/app/models/venue.rb +++ b/app/models/venue.rb @@ -153,6 +153,12 @@ def self.find_duplicates_by_type(type='na') end end + def self.find_venue(search) + if search + Venue.find(:all, :conditions => ['title LIKE ?', "%#{search}%"]) + end + end + #===[ Address helpers ]================================================= # Does this venue have any address information?