Skip to content

Commit

Permalink
final changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hawesg committed Jun 5, 2011
1 parent 1bfd169 commit afa1f1b
Show file tree
Hide file tree
Showing 16 changed files with 186 additions and 23 deletions.
1 change: 1 addition & 0 deletions app/controllers/view_controller.rb
Expand Up @@ -5,6 +5,7 @@ def index
del = params[:deliver] || [true, false]
walk = params[:walk] || [true, false]
cat = params[:cat_id] || Category.all.collect(&:id)
@pagination = params[:paginate]
if params[:cat_id]
@results = Restaurant.limit(params[:limit] || 50 ).random.find_all_by_deliver_and_walk_and_category_id(del, walk, cat)
else
Expand Down
3 changes: 2 additions & 1 deletion app/models/restaurant.rb
@@ -1,7 +1,8 @@
class Restaurant < ActiveRecord::Base
belongs_to :category
validates_presence_of :name
scope :random, :order => "Rand()"
#scope :random, :order => "Rand()"
scope :random, :order => "Random()"
def self.list_options
Category.all.map{|s| {"id" => s.id, "name" => s.name} }
end
Expand Down
6 changes: 6 additions & 0 deletions app/views/layouts/application.html.erb
Expand Up @@ -9,6 +9,7 @@
<link href="http://fonts.googleapis.com/css?family=Nobile:regular,bold" rel="stylesheet" type="text/css" >
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.js' %>
<%= javascript_include_tag 'rails_jquery.js' %>
<%= javascript_include_tag 'page.js' %>
<%= javascript_include_tag 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.js' %>
<%= javascript_include_tag 'jquery-ui-timepicker-addon.js' %>
<%= javascript_include_tag 'application.js' %>
Expand Down Expand Up @@ -62,13 +63,18 @@
<br />
<%= label_tag 'limit', "How Many Results Do You Want?" %>
<%= number_field_tag 'limit', '30', :in => 1...50 %>
<%= label_tag 'paginate', 'Pagination?' %>
<%= check_box_tag 'paginate', 't' %><br />
<%= submit_tag "Submit", :class => "form_submit" %>
<% end %>
</div>
<% end %>
<div id="footer">
<p>Garrett Hawes | CS 80 | Santa Monica College | 2011</p>
<div class="footer_links">
<a href="https://github.com/hawesg/Restaurant-Finder/tree/new" id="git">
Git Hub
</a>
<a href="http://validator.w3.org/check?uri=referer" id="validHtml">
Valid Html
</a>
Expand Down
6 changes: 6 additions & 0 deletions app/views/layouts/rails
@@ -0,0 +1,6 @@
#!/usr/bin/env ruby
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.

APP_PATH = File.expand_path('../../config/application', __FILE__)
require File.expand_path('../../config/boot', __FILE__)
require 'rails/commands'
15 changes: 0 additions & 15 deletions app/views/view/_list_results.html.erb

This file was deleted.

15 changes: 15 additions & 0 deletions app/views/view/_paginate.html.erb
@@ -0,0 +1,15 @@
<p>
<a class="action" href="#" rel="first">first</a> |
<a class="action" href="#" rel="prev">prev</a>

(<span id="count2"></span> / <span id="total2"></span>)
<a class="action" href="#" rel="next">next</a> |
<a class="action" href="#" rel="last">last</a> | show :
<select name="perpage">
<option value="1">1 per page</option>
<option value="2">2 per page</option>
<option value="5">5 per page</option>
</select>
</p>
<%= javascript_include_tag 'paginate.js' %>

4 changes: 2 additions & 2 deletions app/views/view/_results.html.erb
@@ -1,4 +1,4 @@
<p><%= raw results.name %><br />
<li><strong><%= raw results.name %></strong><br />
<% if results.phone %>
<%= results.phone %>
<%= image_tag("http://www.shallowgallery.com/images/contacts2.png", :class => "contacts") %><br />
Expand All @@ -9,5 +9,5 @@
<% if results.menu %>
<a href="<%= results.menu %>"> menu </a>
<% end %>
</p>
</li>

2 changes: 1 addition & 1 deletion app/views/view/home.html.erb
@@ -1,2 +1,2 @@
<h4> Welcome to Restaurant Finder ...... </h4>
<p>Both me and my roommate eat out a lot and are usually very indecisive about where to eat this is meant to help with that problem by outputting a list in random order of the restaurants that meet certain criteria. Originally my plan was to write an algorithm that wighted choices based on things like when we last ate there, our tendency to select one restaurant over anther, etc... But i underestimated the amount of time working with a language in which i had no real experience in. To manage restaurant or categories visit their respective admin sections. For ease in data entry there is the ability to enter restaurants by MenuPages&trade; url. The categories to the left are dynamically generated from the database. Feel free to add, remove, change any data you need to. I did not write any functional test for rails as i am not there yet learning wise. Please use the css validation link below as i have used some css 3 and you need to pass css3 to the validator via url.</p>
<p>My roommate and I eat out a lot and are fairly indecisive about where to eat. This program is designed to help with that problem by outputting a list, in random order, of the restaurants that meet certain criteria. Originally, my plan was to write an algorithm that weighted choices based on criteria like when we last ate there, our tendency to select one restaurant over another, and similar factors. Having said that, I underestimated the amount of time required when working with a new language. To manage restaurant choices or categories visit their respective admin sections. For ease with respect to data entry, I have allowed for the opportunity of entering restaurants by MenuPages&trade; URL. The categories to the left are dynamically generated from the database. Feel free to add, remove, or change any data that you need to. I did not write any functional test for rails, as I am not at that point in terms of my learning curve. Please use the css validation link below as I have used some css 3 and you need to pass css3 to the validator via URL.</p>
7 changes: 6 additions & 1 deletion app/views/view/index.html.erb
@@ -1 +1,6 @@
<%= render :partial => "results", :collection => @results %>
<% if @pagination %>
<%= render :partial => "paginate" %>
<% end %>
<ul id="wrapper2" class="wrapper">
<%= render :partial => "results", :collection => @results %>
</ul>
2 changes: 1 addition & 1 deletion config/locales/en.yml
Expand Up @@ -5,4 +5,4 @@ en:
hello: "Hello world"
time:
formats:
default: "%a, %d %b %Y %H:%M:%S"
default: "%a, %d %b %Y %H:%M:%S"
Binary file added public/images/github.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,6 +1,6 @@
jQuery(function($){
if (typeof($.datepicker) === 'object') {
$.datepicker.regional['en'] = {"showMonthAfterYear":false,"nextText":"Next","changeMonth":true,"prevText":"Previous","closeText":"Close","monthNamesShort":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"firstDay":0,"weekHeader":"Wk","isRTL":false,"changeYear":true,"dayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"dateFormat":"yy-mm-dd","dayNamesMin":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"dayNamesShort":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"currentText":"Today","monthNames":["January","February","March","April","May","June","July","August","September","October","November","December"]};
$.datepicker.regional['en'] = {"nextText":"Next","changeMonth":true,"showMonthAfterYear":false,"prevText":"Previous","closeText":"Close","monthNamesShort":["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],"firstDay":0,"weekHeader":"Wk","changeYear":true,"isRTL":false,"dayNames":["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],"dateFormat":"yy-mm-dd","dayNamesMin":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"dayNamesShort":["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],"currentText":"Today","monthNames":["January","February","March","April","May","June","July","August","September","October","November","December"]};
$.datepicker.setDefaults($.datepicker.regional['en']);
}
if (typeof($.timepicker) === 'object') {
Expand Down
3 changes: 2 additions & 1 deletion public/javascripts/application.js
Expand Up @@ -9,4 +9,5 @@ jQuery(function($) {
$("#tool-form").bind("ajax:loading", toggleLoading).bind("ajax:complete", toggleLoading).bind("ajax:success", function(data, status, xhr) {
$("#main").html(status);
});
});
});

114 changes: 114 additions & 0 deletions public/javascripts/page.js
@@ -0,0 +1,114 @@
// JQuery event-driven pagination plugin
// Written by Mark Perkins, mark@allmarkedup.com
// License: http://unlicense.org/ (i.e. do what you want with it!)

;(function($) {

var defaults = {
perPage : 5, // number of items per page
startPage : 1, // page to begin on - NOT zero indexed
atEnd : 'stop' // loop / stop
};

$.fn.evtpaginate = function( options )
{
return this.each(function(){

var opts = $.extend(true, {}, defaults, options); // set options
var wrap = opts.wrapper = $(this);

wrap.bind( 'show.evtpaginate', function( e, pageNum ){ show( opts, pageNum-1 ); });
wrap.bind( 'next.evtpaginate', function(){ next( opts ); });
wrap.bind( 'prev.evtpaginate', function(){ prev( opts ); });
wrap.bind( 'first.evtpaginate', function(){ show( opts, 0 ); });
wrap.bind( 'last.evtpaginate', function(){ show( opts, opts.totalPages-1 ); });
wrap.bind( 'refresh.evtpaginate', function( e, newopts ){ refresh( opts, newopts ); });

setUp( opts );
});
};

function setUp( opts )
{
opts.perPage = parseInt(opts.perPage);
opts.items = opts.wrapper.children();
opts.totalItems = opts.items.size();
opts.totalPages = Math.ceil( opts.totalItems / opts.perPage );
opts.currentPage = parseInt(opts.startPage) - 1;
opts.first = isFirstPage( opts, opts.currentPage );
opts.last = isLastPage( opts, opts.currentPage );
opts.pages = [];

if ( opts.currentPage > opts.totalPages-1 ) opts.currentPage = opts.totalPages-1;

opts.items.hide();

for ( var i = 0; i < opts.totalPages; i++ )
{
var startItem = i*opts.perPage;
opts.pages[i] = opts.items.slice( startItem, (startItem + opts.perPage) );
}

show( opts, opts.currentPage );

opts.wrapper.trigger( 'initialized.evtpaginate', [opts.currentPage+1, opts.totalPages] );
}

function refresh( opts, newopts )
{
if ( newopts !== undefined ) $.extend(true, opts, newopts); // update options
opts.startPage = parseInt(opts.currentPage)+1;
setUp( opts );
}

function next( opts )
{
switch( opts.atEnd )
{
case 'loop': show( opts, (opts.last ? 0 : opts.currentPage + 1) ); break;
default: show( opts, (opts.last ? opts.totalPages - 1 : opts.currentPage + 1) ); break; // stop when getting to last page
}
}

function prev( opts )
{
switch( opts.atEnd )
{
case 'loop': show( opts, (opts.first ? opts.totalPages - 1 : opts.currentPage - 1) ); break;
default: show( opts, (opts.first ? 0 : opts.currentPage - 1) ); break; // stop when getting to first page
}
}

function show( opts, pageNum )
{
if ( pageNum > opts.totalPages-1 ) pageNum = opts.totalPages-1;

if ( ! opts.pages[opts.currentPage].is(':animated') )
{
opts.wrapper.trigger( 'started.evtpaginate', opts.currentPage+1 );

$.fn.evtpaginate.swapPages( opts, pageNum, function(){

opts.currentPage = pageNum;
opts.first = isFirstPage( opts, opts.currentPage ) ? true : false;
opts.last = isLastPage( opts, opts.currentPage ) ? true : false;

opts.wrapper.trigger( 'finished.evtpaginate', [opts.currentPage+1, opts.first, opts.last] );

});
}
}

// public, can override this if neccessary
$.fn.evtpaginate.swapPages = function( opts, pageNum, onFinish )
{
opts.pages[opts.currentPage].hide();
opts.pages[pageNum].show();
onFinish();
};

// utility functions
function isFirstPage( opts, internalPageNum ) { return ( internalPageNum === 0 ); }
function isLastPage( opts, internalPageNum ) { return ( internalPageNum === opts.totalPages-1 ); }

})(jQuery);
19 changes: 19 additions & 0 deletions public/javascripts/paginate.js
@@ -0,0 +1,19 @@
$(function(){
var wrap2 = $('#wrapper2');
$('.action').click(function(){
var action = $(this).attr('rel'); // get the appropriate action from the rel attribute
wrap2.trigger(action+'.evtpaginate');
return false;
});
$('select[name=perpage]').change(function(){
wrap2.trigger('refresh.evtpaginate', { perPage : $(this).val() } );
return false;
});
// listen out for events triggered by the plugin to update the counter
wrap2.bind( 'initialized.evtpaginate', function(e, startnum, totalnum ){
$('#count2').text(startnum);
$('#total2').text(totalnum);
});
wrap2.bind( 'finished.evtpaginate', function(e, num, isFirst, isLast ){ $('#count2').text(num); } );
wrap2.evtpaginate({perPage:4, atEnd:'loop'}); // call the plugin!
});
10 changes: 10 additions & 0 deletions public/stylesheets/main.css
Expand Up @@ -69,6 +69,9 @@ ul#navlist
list-style-type: none;
border: 1px black solid;
}
#wrapper2{
list-style-type: none;
}

#navlist a { padding-right: 3px; padding-left: 3px; /*padding: 3px 10px;*/}

Expand Down Expand Up @@ -141,6 +144,13 @@ ul#navlist
text-indent: -9999px;
width: 37px;
}
#git{
background-image: url(http://www.shallowgallery.com/images/github.png);
height: 25px;
display: inline-block;
text-indent: -9999px;
width: 25px;
}
#footer p{
display: inline-block;
}

0 comments on commit afa1f1b

Please sign in to comment.