Skip to content

Commit

Permalink
Merge pull request #421 from scouttyg/search-tweaks
Browse files Browse the repository at this point in the history
Made search a little easier for Kandan
  • Loading branch information
scouttyg committed Jan 13, 2015
2 parents 619a493 + 6bc37b8 commit 75ca9d8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
6 changes: 6 additions & 0 deletions app/assets/stylesheets/chat_area/_activity.sass
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
.activities
@extend %content-block
.no-results
padding: 10px 0
h2
text-align: center
margin-top: 20px
margin-bottom: 20px

.activity
background: #FFF
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/main_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def search
minimum_query_length = 3

if params[:query] and params[:query].length >= minimum_query_length
@activities = Activity.includes(:user).where("content LIKE ?", "%#{params[:query]}%").limit(params[:limit] || 100).all
@activities = Activity.includes(:user).where("LOWER(content) LIKE ?", "%#{params[:query]}%").limit(params[:limit] || 100).all
end

respond_to do |format|
Expand Down
2 changes: 1 addition & 1 deletion app/views/main/_nav.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<nav class="nav">
<form class="search" method="get" action="/search">
<input type="text" class="query" name="query"/>
<input type="text" class="query" name="query" value="<%= params[:query].presence || "" %>" />
<input type="submit" class="submit" value="Search">
</form>
<ul id="channel_nav"></ul>
Expand Down
19 changes: 14 additions & 5 deletions app/views/main/search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@
Kandan.Plugins.initAll()
activities = <%= json_escape(@activities.as_json(:include => { user: { :only => [:email, :first_name, :last_name, :username, :avatar_url, :gravatar_hash, :is_admin]} }).to_json.html_safe) %>;

$.each(activities, function(index, activityAttributes) {
activity = new Kandan.Models.Activity(activityAttributes);
activityView = new Kandan.Views.ShowActivity({activity: activity});
$(".activities").append(activityView.render().el);
})
if(activities.length){
$.each(activities, function(index, activityAttributes) {
activity = new Kandan.Models.Activity(activityAttributes);
activityView = new Kandan.Views.ShowActivity({activity: activity});
$(".activities").append(activityView.render().el);
})
}else{
$(".activities").append("<div class='no-results'><h2>No search results for '<%= params[:query] %>'</h2></div>");
}

})
<%- end %>

<div class="activities"></div>

<% content_for :end do %>
<%= render "nav" %>
<% end %>

0 comments on commit 75ca9d8

Please sign in to comment.