Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a search bar in the nav #90

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion app/assets/stylesheets/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ def opensearch
format.xml { render :content_type => 'application/opensearchdescription+xml' }
end
end

def search
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
6 changes: 6 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 6 additions & 0 deletions app/models/venue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
3 changes: 1 addition & 2 deletions app/views/site/_navbar.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down