Skip to content

Commit

Permalink
Setup basic search action.
Browse files Browse the repository at this point in the history
  • Loading branch information
nchapman committed Feb 21, 2010
1 parent 18be7ea commit fb26da6
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 60 deletions.
6 changes: 5 additions & 1 deletion .gitignore
@@ -1,6 +1,10 @@
log/*.log
tmp/**/*
*.pid
doc/api
doc/app
db/*.sqlite3
.DS_Store
.DS_Store
config/*.sphinx.conf
db/sphinx
*.esproj
6 changes: 5 additions & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -5,7 +5,7 @@ class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection for details
filter_parameter_logging :password, :password_confirmation
helper_method :current_user_session, :current_user
helper_method :current_user_session, :current_user, :logged_in?

private
def current_user_session
Expand All @@ -18,6 +18,10 @@ def current_user
@current_user = current_user_session && current_user_session.record
end

def logged_in?
return current_user != nil
end

def require_user
unless current_user
store_location
Expand Down
40 changes: 27 additions & 13 deletions app/controllers/notes_controller.rb
@@ -1,5 +1,5 @@
class NotesController < ApplicationController
before_filter :require_user
before_filter :require_user, :except => :show

# GET /notes
# GET /notes.xml
Expand All @@ -8,18 +8,22 @@ def index

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @notes }
#format.xml { render :xml => @notes }
end
end

# GET /notes/1
# GET /notes/1.xml
def show
@note = current_user.notes.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @note }
@note = Note.find(params[:id])

if @note.public? || (current_user && @note.user_id == current_user.id)
respond_to do |format|
format.html # show.html.erb
#format.xml { render :xml => @note }
end
else
require_user
end
end

Expand All @@ -32,7 +36,7 @@ def new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @note }
#format.xml { render :xml => @note }
end
end

Expand All @@ -52,10 +56,10 @@ def create
if @note.save
flash[:notice] = 'Note was successfully saved.'
format.html { redirect_to(@note) }
format.xml { render :xml => @note, :status => :created, :location => @note }
#format.xml { render :xml => @note, :status => :created, :location => @note }
else
format.html { render :action => "new" }
format.xml { render :xml => @note.errors, :status => :unprocessable_entity }
#format.xml { render :xml => @note.errors, :status => :unprocessable_entity }
end
end
end
Expand All @@ -69,10 +73,10 @@ def update
if @note.update_attributes(params[:note])
flash[:notice] = 'Note was successfully saved.'
format.html { redirect_to(@note) }
format.xml { head :ok }
#format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @note.errors, :status => :unprocessable_entity }
#format.xml { render :xml => @note.errors, :status => :unprocessable_entity }
end
end
end
Expand All @@ -85,7 +89,17 @@ def destroy

respond_to do |format|
format.html { redirect_to(notes_url) }
format.xml { head :ok }
#format.xml { head :ok }
end
end

def search
@query = params[:query]
@notes = Note.search(@query)

respond_to do |format|
format.html
#format.xml { render :xml => @notes }
end
end
end
5 changes: 3 additions & 2 deletions app/views/layouts/application.html.erb
Expand Up @@ -16,8 +16,9 @@
<header>
<h1><a href="/">jsttxt</a></h1>
<nav class="user">
<%= link_to "new", new_note_path %> |
<a href="/account/edit">settings</a>
<% if current_user %>
<%= link_to "new", new_note_path %> | <a href="/account/edit">settings</a>
<% end %>
</nav>
</header>
<section id="main" class="yui-cssbase">
Expand Down
63 changes: 41 additions & 22 deletions app/views/notes/index.html.erb
@@ -1,26 +1,45 @@
<% if @notes.size > 0 %>
<div class="note_list">
<% current_date = nil %>
<% @notes.each do |note| %>
<% if current_date != note.created_at.strftime("%B %d, %Y") %>
<% current_date = note.created_at.strftime("%B %d, %Y") %>
<h2 class="date"><%= current_date %></h2>
<% end %>
<div class="note">
<h3><%= link_to h(note.title), note %></h3>
<% if note.tag_list.size > 0 %>
<div class="tags">
<% note.tag_list.each do |tag| %>
<span><%= tag %></span>
<style>
.column.first {
width: 75%;
}

.column.last {
width: 25%;
}
</style>

<div class="two_columns">
<section class="column first">
<% if @notes.size > 0 %>
<div class="note_list">
<% current_date = nil %>
<% @notes.each do |note| %>
<% if current_date != note.created_at.strftime("%B %d, %Y") %>
<% current_date = note.created_at.strftime("%B %d, %Y") %>
<h2 class="date"><%= current_date %></h2>
<% end %>
<div class="note">
<h3><%= link_to h(note.title), note %></h3>
<% if false and note.tag_list.size > 0 %>
<div class="tags">
<% note.tag_list.each do |tag| %>
<span><%= tag %></span>
<% end %>
</div>
<% end %>
<div class="summary">
<%= smash(note.body_html) %><span class="ellipsis">&hellip;</span>
</div>
</div>
<% end %>
<div class="summary">
<%= smash(note.body_html) %><span class="ellipsis">&hellip;</span>
</div>
</div>
<% end %>
</div>
<% else %>
<p>You don't have any notes yet. <%= link_to "Create a note", new_note_path %> to get started!</p>
<% end %>
<% else %>
<p>You don't have any notes yet. <%= link_to "Create a note", new_note_path %> to get started!</p>
<% end %>
</section>
<section class="column last">
<form action="/notes/search/">
<input type="text" name="query" value="<%= @query %>" />
</form>
</section>
</div>
33 changes: 33 additions & 0 deletions app/views/notes/search.html.erb
@@ -0,0 +1,33 @@
<style>
.column.first {
width: 75%;
}

.column.last {
width: 25%;
}
</style>

<div class="two_columns">
<section class="column first">
<% if @notes.size > 0 %>
<div class="note_list">
<% @notes.each do |note| %>
<div class="note">
<h3><%= link_to note.excerpts.title, note %></h3>
<div class="excerpt">
<%= note.excerpts.body %>
</div>
</div>
<% end %>
</div>
<% else %>
<p>No results.</p>
<% end %>
</section>
<section class="column last">
<form action="/notes/search/">
<input type="text" name="query" value="<%= @query %>" />
</form>
</section>
</div>
16 changes: 9 additions & 7 deletions app/views/notes/show.html.erb
@@ -1,6 +1,6 @@
<div class="note">
<h2 class="title"><%=h @note.title %></h2>
<% if @note.tag_list.size > 0 %>
<% if logged_in? && @note.tag_list.size > 0 %>
<div class="tags">
<% @note.tag_list.each do |tag| %>
<span><%= tag %></span>
Expand All @@ -12,9 +12,11 @@
</div>
</div>

<script>
jsttxt.applyTextFilters();
</script>

<%= link_to 'Edit', edit_note_path(@note) %> |
<%= link_to 'Back', notes_path %>
<% if logged_in? %>
<script>
jsttxt.applyTextFilters();
</script>

<%= link_to 'Edit', edit_note_path(@note) %> |
<%= link_to 'Back', notes_path %>
<% end %>
2 changes: 1 addition & 1 deletion config/routes.rb
@@ -1,5 +1,5 @@
ActionController::Routing::Routes.draw do |map|
map.resources :notes
map.resources :notes, :collection => {:search => :get}

map.resource :account, :controller => "users"
map.resources :users
Expand Down
28 changes: 15 additions & 13 deletions public/stylesheets/screen.css
@@ -1,16 +1,14 @@
@import url(http://yui.yahooapis.com/combo?3.0.0/build/cssreset/reset-min.css&3.0.0/build/cssfonts/fonts-min.css&3.0.0/build/cssbase/base-context-min.css);
@import url(/stylesheets/albi.css);

article, aside, dialog, figure, footer, header, hgroup, menu, nav, section { display: block; }

body, input {
body {
color: #333;
font-family: "museo-sans-1","museo-sans-2", Helvetica, Arial, sans-serif;
font-size: 108%;
font-size: 16px;
font-weight: 300;
}

body {
line-height: 160%;
line-height: 1.6em;
}

a {
Expand All @@ -27,8 +25,12 @@ h1, h2, h3, h4, h5, h6, h7, h8 {
font-family: "museo-slab-1","museo-slab-2", Georgia, serif;
}

.match {
background: yellow;
}

.note h2.title {
font-size: 146.5% !important;
font-size: 150% !important;
font-weight: 900 !important;
margin-bottom: 0 !important;
}
Expand Down Expand Up @@ -75,7 +77,7 @@ p.notice {
border-radius: .5em;
color: #333;
display: none;
font-size: 85%;
font-size: 81%;
line-height: 1em;
padding: .5em .8em;
text-transform: lowercase;
Expand All @@ -92,7 +94,7 @@ p.notice {
.note_list h2.date {
border-bottom: 1px solid #eee;
color: #555;
font-size: 68% !important;
font-size: 69% !important;
font-weight: normal;
letter-spacing: .09em;
line-height: 140%;
Expand All @@ -101,7 +103,7 @@ p.notice {
}

.note_list .note h3 {
font-size: 123.1%;
font-size: 125%;
font-weight: normal;
line-height: 1em;
margin: 0;
Expand All @@ -110,16 +112,16 @@ p.notice {
.tags span {
background: #D7E2F6;
border: 1px solid #AAC1EC;
border-radius: 8px;
font-size: 11px;
-webkit-border-radius: 8px;
font-size: 69%;
font-weight: 500;
color: #111;
padding: .1em .7em;
}

.note_list .note .summary {
color: #aaa;
font-size: 85%;
font-size: 88%;
overflow: hidden;
position: relative;
white-space: nowrap;
Expand Down

0 comments on commit fb26da6

Please sign in to comment.