Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Make search cover Entity, Photo and Post, and display results visually
Browse files Browse the repository at this point in the history
  • Loading branch information
dcabo committed Aug 25, 2013
1 parent 5eb0de1 commit fbb996a
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 55 deletions.
11 changes: 11 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
module ApplicationHelper
def partial_name(thing)
case thing.class.to_s
when 'Post'
return '/shared/show_post'
when 'Entity'
return thing.person? ? '/shared/show_person' : '/shared/show_organization'
when 'Photo'
return '/shared/show_photo'
end
nil # Shouldn't happen
end
end
3 changes: 3 additions & 0 deletions app/models/photo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ class Photo < ActiveRecord::Base
has_many :entity_photo_associations, dependent: :delete_all
has_many :related_entities, through: :entity_photo_associations, source: :entity

include PgSearch
multisearchable :against => [:footer]

mount_uploader :file, PhotoUploader

acts_as_taggable
Expand Down
3 changes: 3 additions & 0 deletions app/models/post.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
class Post < ActiveRecord::Base
belongs_to :author, foreign_key: :author_id, class_name: User

include PgSearch
multisearchable :against => [:title, :content]

acts_as_url :title, url_attribute: :slug, only_when_blank: true
def to_param
slug
Expand Down
19 changes: 0 additions & 19 deletions app/views/organizations/_show_organization.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/organizations/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div id="wall" class="row-fluid">

<% @organizations.each do |organization| %>
<%= render 'show_organization', :entity => organization %>
<%= render '/shared/show_organization', :item => organization %>
<% end %>

</div>
Expand Down
16 changes: 0 additions & 16 deletions app/views/people/_show_person.html.erb

This file was deleted.

2 changes: 1 addition & 1 deletion app/views/people/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div id="wall" class="row-fluid">

<% @people.each do |person| %>
<%= render 'show_person', :entity => person %>
<%= render '/shared/show_person', :item => person %>
<% end %>

</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/photos/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<div id="wall" class="row-fluid">

<% @photos.each do |photo| %>
<%= render 'shared/show_photo', :photo => photo %>
<%= render 'shared/show_photo', :item => photo %>
<% end %>

</div>
Expand Down
28 changes: 16 additions & 12 deletions app/views/search/search.html.erb
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<!--start: Wrapper-->
<div id="wrapper" class="full">
<!-- start: Page Title -->
<div id="page-title">

<!--start: Row -->
<div class="row-fluid">
<h2>Resultados para '<%= @query %>'</h2>

<div class="span8 separate">
<h3>Resultados para '<%= @query %>'</h3>
</div>
<!-- end: Page Title -->

<ul>
<!--start: Wrapper-->
<div id="wrapper">

<!-- start: Portfolio -->
<div id="wall" class="row-fluid">

<% @results.each do |result| %>
<li><%= result.searchable.name %></li>
<%= render partial_name(result.searchable), :item => result.searchable %>
<% end %>
</ul>

<%= paginate @results %>
</div>

</div>
<!-- end: Portfolio -->

<%= paginate @results %>

</div>
<!-- end: Wrapper -->
19 changes: 19 additions & 0 deletions app/views/shared/_show_organization.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="span3 item">
<div class="picture">
<%= link_to image_tag(item.avatar.url ? item.avatar.url : 'avatar.png'),
organization_path(item), class: 'image' %>
<div class="description">
<p>
<%= link_to item.name, organization_path(item) %>
<% if !item.short_name.nil? && !item.short_name.blank? %>
(<%= link_to item.short_name, organization_path(item) %>)
<% end %>
</p>
<p>
<%= item.description %>
</p>

<%= render 'shared/show_admin_links', :item => item %>
</div>
</div>
</div>
16 changes: 16 additions & 0 deletions app/views/shared/_show_person.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="span3 item">
<div class="picture">
<%= link_to image_tag(item.avatar.url ? item.avatar.url : 'avatar.png'),
person_path(item), class: 'image' %>
<div class="description">
<p>
<%= link_to item.short_or_long_name, person_path(item) %>
</p>
<p>
<%= item.description %>
</p>

<%= render 'shared/show_admin_links', :item => item %>
</div>
</div>
</div>
10 changes: 5 additions & 5 deletions app/views/shared/_show_photo.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div class="<%= photo.extra_wide? ? 'span6': 'span3' %> item">
<div class="<%= item.extra_wide? ? 'span6': 'span3' %> item">
<div class="picture">
<%= link_to image_tag(photo.file.url(photo.extra_wide ? :full : :small)), photo, class: 'image' %>
<%= link_to image_tag(item.file.url(item.extra_wide ? :full : :small)), item, class: 'image' %>
<div class="description">
<p>
<%= link_to photo.footer, photo %>
<%= link_to item.footer, item %>
</p>
<p>
&copy; <%= link_to photo.copyright, photo.source %>
&copy; <%= link_to item.copyright, item.source %>
</p>

<%= render 'shared/show_admin_links', :item => photo %>
<%= render 'shared/show_admin_links', :item => item %>
</div>
</div>
</div>
10 changes: 10 additions & 0 deletions app/views/shared/_show_post.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div class="span3 item">
<div class="picture">
<div class="description">
<p>
<%= link_to item.title, post_path(item) %>
</p>
<%= render 'shared/show_admin_links', :item => item %>
</div>
</div>
</div>

0 comments on commit fbb996a

Please sign in to comment.