Prettify the video section of the application
authorIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 01:15:40 +0000 (17:15 -0800)
committerIra W. Snyder <devel@irasnyder.com>
Sun, 25 Nov 2007 01:15:40 +0000 (17:15 -0800)
Signed-off-by: Ira W. Snyder <devel@irasnyder.com>
app/controllers/video_controller.rb
app/helpers/application_helper.rb
app/views/layouts/admin.rhtml
app/views/video/index.rhtml [new file with mode: 0644]
app/views/video/list.rhtml
app/views/video/search.rhtml [moved from app/views/video/searchbyname.rhtml with 57% similarity]
app/views/video/searchresults.rhtml

index ee34e5c..2451704 100644 (file)
@@ -1,11 +1,11 @@
 class VideoController < ApplicationController
+  layout "admin"
 
   # Make sure that a user logs in before doing any action here
   before_filter :authorize, :except => :login
 
   def index
-    list
-    render :action => 'list'
+    render :action => 'index'
   end
 
   # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
@@ -53,12 +53,13 @@ class VideoController < ApplicationController
     redirect_to :action => 'list'
   end
 
-  def searchbyname
-    render :action => 'searchbyname'
-  end
-
-  def searchresults
-    query = params[:q]
-    @videos = Video.find(:all, :conditions => ["title like ?", query[0]+"%"])
+  def search
+    if request.post?
+      @query = params[:q]
+      @videos = Video.find(:all, :conditions => ["title like ?", @query[0]+"%"])
+      render :action => 'searchresults'
+    else
+      render :action => 'search'
+    end
   end
 end
index 22a7940..4071221 100644 (file)
@@ -1,3 +1,9 @@
 # Methods added to this helper will be available to all templates in the application.
 module ApplicationHelper
+
+  # Convert true and false to "Yes" and "No"
+  def tf_to_yesno(value)
+    return value ? "Yes" : "No"
+  end
+
 end
index 429a923..bb59815 100644 (file)
@@ -16,9 +16,9 @@
       <p><%= link_to "Make A Purchase", :controller => 'purchase', :action => 'begin' %></p>
       <p><%= link_to "Return Items", :controller => 'coitem', :action => 'return' %></p>
       <br/>
-      <p><%= link_to "Video Maintenence", :controller => 'video', :action => 'list' %></p>
+      <p><%= link_to "Video Maintenence", :controller => 'video', :action => 'index' %></p>
       <p><%= link_to "Game Maintenence", :controller => 'game', :action => 'list' %></p>
-      <p><%= link_to "Checked Out Items", :controller => 'coitem', :acion => 'list' %></p>
+      <p><%= link_to "Checked Out Items", :controller => 'coitem', :action => 'list' %></p>
       <p><%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %></p>
       <br/>
       <p><%= link_to "Logout", :controller => 'login', :action => 'logout' %></p>
diff --git a/app/views/video/index.rhtml b/app/views/video/index.rhtml
new file mode 100644 (file)
index 0000000..142c363
--- /dev/null
@@ -0,0 +1,7 @@
+<h1>Video Maintenence</h1>
+
+<h3>Actions</h3>
+<ul>
+  <li><%= link_to 'List All Videos', :action => 'list' %></li>
+  <li><%= link_to 'Search for a Video', :action => 'search' %></li>
+</ul>
index afe84ed..113ee97 100644 (file)
@@ -1,10 +1,10 @@
 <h1>Listing videos</h1>
 
-<table>
+<table border="1">
   <tr>
     <th>Video ID</th>
-    <th>Checked Out</th>
     <th>Title</th>
+    <th>Checked Out</th>
     <th>New Release</th>
     <th>Genre</th>
     <th>Director</th>
 <% for video in @videos %>
   <tr>
     <td><%=h video.id %></td>
-    <td><%=h video.checkedout? %></td>
     <td><%=h video.title %></td>
-    <td><%=h video.newrelease %></td>
+    <td><%=h tf_to_yesno(video.checkedout?) %></td>
+    <td><%=h tf_to_yesno(video.newrelease) %></td>
     <td><%=h video.genre %></td>
     <td><%=h video.director %></td>
     <td><%=h video.media_name %></td>
-    <td><%= link_to 'Show', :action => 'show', :id => video %></td>
+    <td><%= link_to 'View', :action => 'show', :id => video %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => video %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :method => :post %></td>
+    <td><%= link_to 'Remove', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :method => :post %></td>
   </tr>
 <% end %>
 </table>
similarity index 57%
rename from app/views/video/searchbyname.rhtml
rename to app/views/video/search.rhtml
index 01e85d7..830eb6e 100644 (file)
@@ -1,7 +1,7 @@
 <h1>Search for a Video by Name</h1>
 
-<%= start_form_tag :action => 'searchresults'%>
-<%= text_field 'q', nil  %>
+<%= start_form_tag :action => 'search%>
+<%= text_field 'q', nil %>
   <%= submit_tag 'Search' %></form>
 <%= end_form_tag %>
 
index daefca0..eae7d23 100644 (file)
@@ -1,27 +1,31 @@
-<h1>Search Results</h1>
+<h1>Search Results for '<%= @query[0].to_s %>'</h1>
 
 <% if @videos.empty? %>
 <p>Sorry, there were no results</p>
 <% else %>
-<table>
+<table border=1>
   <tr>
-  <th>Video ID</th>
-  <th>Checked Out</th>
-  <% for column in Video.content_columns %>
-    <th><%= column.human_name %></th>
-  <% end %>
+    <th>Video ID</th>
+    <th>Title</th>
+    <th>Checked Out</th>
+    <th>New Release</th>
+    <th>Genre</th>
+    <th>Director</th>
+    <th>Media</th>
   </tr>
 
 <% for video in @videos %>
   <tr>
-  <td><%=h video.id %></td>
-  <td><%=h video.checkedout? %></td>
-  <% for column in Video.content_columns %>
-    <td><%=h video.send(column.name) %></td>
-  <% end %>
-    <td><%= link_to 'Show', :action => 'show', :id => video %></td>
+    <td><%=h video.id %></td>
+    <td><%=h video.title %></td>
+    <td><%=h tf_to_yesno(video.checkedout?) %></td>
+    <td><%=h tf_to_yesno(video.newrelease) %></td>
+    <td><%=h video.genre %></td>
+    <td><%=h video.director %></td>
+    <td><%=h video.media_name %></td>
+    <td><%= link_to 'View', :action => 'show', :id => video %></td>
     <td><%= link_to 'Edit', :action => 'edit', :id => video %></td>
-    <td><%= link_to 'Destroy', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :post => true %></td>
+    <td><%= link_to 'Remove', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :post => true %></td>
   </tr>
 <% end %>
 </table>