From f5428b31e180b85713a3d2358a2dade29a19aeb9 Mon Sep 17 00:00:00 2001 From: "Ira W. Snyder" Date: Sat, 24 Nov 2007 17:15:40 -0800 Subject: [PATCH] Prettify the video section of the application Signed-off-by: Ira W. Snyder --- app/controllers/video_controller.rb | 19 +++++------ app/helpers/application_helper.rb | 6 ++++ app/views/layouts/admin.rhtml | 4 +-- app/views/video/index.rhtml | 7 ++++ app/views/video/list.rhtml | 12 +++---- .../{searchbyname.rhtml => search.rhtml} | 4 +-- app/views/video/searchresults.rhtml | 32 +++++++++++-------- 7 files changed, 51 insertions(+), 33 deletions(-) create mode 100644 app/views/video/index.rhtml rename app/views/video/{searchbyname.rhtml => search.rhtml} (57%) diff --git a/app/controllers/video_controller.rb b/app/controllers/video_controller.rb index ee34e5c..2451704 100644 --- a/app/controllers/video_controller.rb +++ b/app/controllers/video_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 22a7940..4071221 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/views/layouts/admin.rhtml b/app/views/layouts/admin.rhtml index 429a923..bb59815 100644 --- a/app/views/layouts/admin.rhtml +++ b/app/views/layouts/admin.rhtml @@ -16,9 +16,9 @@

<%= link_to "Make A Purchase", :controller => 'purchase', :action => 'begin' %>

<%= link_to "Return Items", :controller => 'coitem', :action => 'return' %>


-

<%= link_to "Video Maintenence", :controller => 'video', :action => 'list' %>

+

<%= link_to "Video Maintenence", :controller => 'video', :action => 'index' %>

<%= link_to "Game Maintenence", :controller => 'game', :action => 'list' %>

-

<%= link_to "Checked Out Items", :controller => 'coitem', :acion => 'list' %>

+

<%= link_to "Checked Out Items", :controller => 'coitem', :action => 'list' %>

<%= link_to "Customer Maintenence", :controller => 'customer', :action => 'list' %>


<%= link_to "Logout", :controller => 'login', :action => 'logout' %>

diff --git a/app/views/video/index.rhtml b/app/views/video/index.rhtml new file mode 100644 index 0000000..142c363 --- /dev/null +++ b/app/views/video/index.rhtml @@ -0,0 +1,7 @@ +

Video Maintenence

+ +

Actions

+ diff --git a/app/views/video/list.rhtml b/app/views/video/list.rhtml index afe84ed..113ee97 100644 --- a/app/views/video/list.rhtml +++ b/app/views/video/list.rhtml @@ -1,10 +1,10 @@

Listing videos

- +
- + @@ -14,15 +14,15 @@ <% for video in @videos %> - - + + - + - + <% end %>
Video IDChecked Out TitleChecked Out New Release Genre Director
<%=h video.id %><%=h video.checkedout? %> <%=h video.title %><%=h video.newrelease %><%=h tf_to_yesno(video.checkedout?) %><%=h tf_to_yesno(video.newrelease) %> <%=h video.genre %> <%=h video.director %> <%=h video.media_name %><%= link_to 'Show', :action => 'show', :id => video %><%= link_to 'View', :action => 'show', :id => video %> <%= link_to 'Edit', :action => 'edit', :id => video %><%= link_to 'Destroy', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :method => :post %><%= link_to 'Remove', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :method => :post %>
diff --git a/app/views/video/searchbyname.rhtml b/app/views/video/search.rhtml similarity index 57% rename from app/views/video/searchbyname.rhtml rename to app/views/video/search.rhtml index 01e85d7..830eb6e 100644 --- a/app/views/video/searchbyname.rhtml +++ b/app/views/video/search.rhtml @@ -1,7 +1,7 @@

Search for a Video by Name

-<%= start_form_tag :action => 'searchresults'%> -<%= text_field 'q', nil %> +<%= start_form_tag :action => 'search' %> +<%= text_field 'q', nil %> <%= submit_tag 'Search' %> <%= end_form_tag %> diff --git a/app/views/video/searchresults.rhtml b/app/views/video/searchresults.rhtml index daefca0..eae7d23 100644 --- a/app/views/video/searchresults.rhtml +++ b/app/views/video/searchresults.rhtml @@ -1,27 +1,31 @@ -

Search Results

+

Search Results for '<%= @query[0].to_s %>'

<% if @videos.empty? %>

Sorry, there were no results

<% else %> - +
- - - <% for column in Video.content_columns %> - - <% end %> + + + + + + + <% for video in @videos %> - - - <% for column in Video.content_columns %> - - <% end %> - + + + + + + + + - + <% end %>
Video IDChecked Out<%= column.human_name %>Video IDTitleChecked OutNew ReleaseGenreDirectorMedia
<%=h video.id %><%=h video.checkedout? %><%=h video.send(column.name) %><%= link_to 'Show', :action => 'show', :id => video %><%=h video.id %><%=h video.title %><%=h tf_to_yesno(video.checkedout?) %><%=h tf_to_yesno(video.newrelease) %><%=h video.genre %><%=h video.director %><%=h video.media_name %><%= link_to 'View', :action => 'show', :id => video %> <%= link_to 'Edit', :action => 'edit', :id => video %><%= link_to 'Destroy', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :post => true %><%= link_to 'Remove', { :action => 'destroy', :id => video }, :confirm => 'Are you sure?', :post => true %>
-- 2.25.1