This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Tons of changes

  • Loading branch information...
Burke Libbey
Burke Libbey committed Aug 27, 2008
1 parent b79064e commit f6c81814eea0850b0d7e937d525cb728f07dff31
Showing with 33,259 additions and 136 deletions.
  1. +50 −43 app/controllers/books_controller.rb
  2. +35 −4 app/models/book.rb
  3. +20 −0 app/models/notifier.rb
  4. +10 −6 app/views/books/_book.html.haml
  5. +1 −1 app/views/books/edit.html.haml
  6. +4 −3 app/views/books/list.html.haml
  7. +31 −30 app/views/books/new.html.haml
  8. +3 −3 app/views/books/search.html.haml
  9. +28 −27 app/views/books/show.html.haml
  10. +33 −0 app/views/layouts/#application.html.haml#
  11. +20 −5 app/views/layouts/application.html.haml
  12. +18 −0 app/views/notifier/book_confirmation.html.erb
  13. +18 −0 app/views/notifier/message.html.erb
  14. +1 −1 app/views/shared/_sidebar.html.haml
  15. +1 −12 config/database.yml
  16. +2 −0 config/environment.rb
  17. +65 −0 config/production.sphinx.conf
  18. 0 config/daily.cron → crontasks/daily/sphinx_index
  19. +3 −1 db/migrate/20080803015923_create_books.rb
  20. +3 −0 db/schema.rb
  21. BIN db/sphinx/development/book_core.spa
  22. BIN db/sphinx/development/book_core.spd
  23. BIN db/sphinx/development/book_core.sph
  24. BIN db/sphinx/development/book_core.spi
  25. BIN db/sphinx/development/book_core.spp
  26. BIN db/sphinx/development/book_delta.spa
  27. BIN db/sphinx/development/book_delta.spd
  28. BIN db/sphinx/development/book_delta.sph
  29. BIN db/sphinx/development/book_delta.spi
  30. BIN db/sphinx/development/book_delta.spp
  31. 0 db/sphinx/production/book_core.spa
  32. +1 −0 db/sphinx/production/book_core.spd
  33. BIN db/sphinx/production/book_core.sph
  34. +1 −0 db/sphinx/production/book_core.spi
  35. 0 db/sphinx/production/book_core.spl
  36. 0 db/sphinx/production/book_core.spm
  37. +1 −0 db/sphinx/production/book_core.spp
  38. BIN db/sphinx/production/book_delta.spa
  39. BIN db/sphinx/production/book_delta.spd
  40. BIN db/sphinx/production/book_delta.sph
  41. BIN db/sphinx/production/book_delta.spi
  42. 0 db/sphinx/production/book_delta.spl
  43. 0 db/sphinx/production/book_delta.spm
  44. BIN db/sphinx/production/book_delta.spp
  45. +29,710 −0 log/development.log
  46. +2,694 −0 log/production.log
  47. +159 −0 log/searchd.log
  48. +64 −0 log/searchd.query.log
  49. BIN public/images/head-back.png
  50. BIN public/images/logo.png
  51. BIN public/images/nocover.png
  52. BIN public/images/search-back.png
  53. +32 −0 public/javascripts/jquery.js
  54. +3 −0 public/javascripts/site.js
  55. +239 −0 public/stylesheets/style.css
  56. +9 −0 test/unit/notifier_test.rb
@@ -5,31 +5,31 @@ class BooksController < ApplicationController
def search
end
- def index
- search
- render :template => 'books/search'
- end
-
# GET /books/list
# GET /books/list.xml
def list
if params[:query]
@searched = true
- @books = Book.search(params[:query])
+ @books = Book.active.search(params[:query])
else
- @books = Book.paginate :page => params[:page]
+ @books = Book.active_reverse.paginate :page => params[:page]
end
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @books }
end
end
+
+ def index
+ redirect_to :action => 'list'
+ end
+
# GET /books/1
# GET /books/1.xml
def show
- @book = Book.find(params[:id])
+ @book = Book.active.find(params[:id])
respond_to do |format|
format.html # show.html.erb
@@ -49,54 +49,61 @@ def new
end
end
- # GET /books/1/edit
- def edit
- @book = Book.find(params[:id])
- end
-
# POST /books
- # POST /books.xml
def create
@book = Book.new(params[:book])
-
- respond_to do |format|
- if @book.save
- flash[:notice] = 'Book was successfully created.'
- format.html { redirect_to(@book) }
- format.xml { render :xml => @book, :status => :created, :location => @book }
- else
- format.html { render :action => "new" }
- format.xml { render :xml => @book.errors, :status => :unprocessable_entity }
- end
+ @book.salt = rand.to_s[2..15]
+
+ if @book.save
+ Notifier.deliver_book_confirmation(@book)
+ flash[:notice] = 'Book was successfully created. Check your email for the confirmation code.'
+ redirect_to '/books/list'
+ else
+ render :action => "new"
end
end
- # PUT /books/1
- # PUT /books/1.xml
- def update
+
+ def confirm
@book = Book.find(params[:id])
+ key = params[:k]
- respond_to do |format|
- if @book.update_attributes(params[:book])
- flash[:notice] = 'Book was successfully updated.'
- format.html { redirect_to(@book) }
- format.xml { head :ok }
- else
- format.html { render :action => "edit" }
- format.xml { render :xml => @book.errors, :status => :unprocessable_entity }
- end
+ if key == @book.confirmation_code
+ @book.update_attributes!({:confirmed => true})
+ flash[:notice] = "Your book has been confirmed!"
+ redirect_to @book
+ else
+ flash[:errors] = "You supplied an invalid confirmation code. Maybe you copied and pasted wrong?"
+ redirect_to '/books/list'
end
end
- # DELETE /books/1
- # DELETE /books/1.xml
- def destroy
+ def remove
@book = Book.find(params[:id])
- @book.destroy
+ key = params[:k]
- respond_to do |format|
- format.html { redirect_to(books_url) }
- format.xml { head :ok }
+ if key == @book.removal_code
+ @book.update_attributes!({:disabled => true})
+ flash[:notice] = "Your book has been removed!"
+ redirect_to '/books/list'
+ else
+ flash[:errors] = "You supplied an invalid removal code. Maybe you copied and pasted wrong?"
+ redirect_to '/books/list'
end
end
+
+
+ def contact
+
+ @book = Book.find(params[:id])
+ if params[:buyer] !~ /^um[a-z0-9]{2,8}/
+ flash[:errors] = "You must specify a valid UMNetID."
+ redirect_to @book
+ else
+ Notifier.deliver_message(@book,params[:message],params[:buyer])
+ flash[:notice] = 'Message was sent to seller. Now you play the waiting game.'
+ redirect_to '/books/list'
+ end
+ end
+
end
View
@@ -1,4 +1,3 @@
-require 'net/http'
class Book < ActiveRecord::Base
cattr_reader :per_page
@@ -10,7 +9,9 @@ class Book < ActiveRecord::Base
indexes author, :sortable => true
indexes isbn
end
-
+
+ validates_presence_of :title, :author
+
# Make sure the seller is present and is a valid umnetid.
validates_presence_of :seller
validates_format_of :seller,
@@ -19,10 +20,16 @@ class Book < ActiveRecord::Base
validates_presence_of :price
validates_numericality_of :price
-
+
validates_format_of :isbn,
:with => /^[0-9]-?[0-9]{3}-?[0-9]{5}-?[0-9]$/,
:message => "must be a valid ISBN-10"
+
+ def validate
+ if price <= 0
+ errors.add(:price, "must be positive.")
+ end
+ end
def isbn=(_isbn)
write_attribute(:isbn, format_isbn(_isbn))
@@ -43,6 +50,22 @@ def after_save
end
end
+ def confirmation_link
+ "http://text.umes.mb.ca/books/confirm/#{id}?k=#{confirmation_code}"
+ end
+
+ def removal_link
+ "http://text.umes.mb.ca/books/remove/#{id}?k=#{removal_code}"
+ end
+
+ def confirmation_code
+ Digest::SHA1.hexdigest("#{title}#{isbn}#{seller}#{salt}")
+ end
+
+ def removal_code
+ Digest::SHA1.hexdigest("#{title}disable#{isbn}#{seller}#{salt}")
+ end
+
def thumbnail_url
"/images/cover-sm/#{isbn}.jpg"
end
@@ -65,5 +88,13 @@ def format_isbn(_isbn)
return _isbn
end
end
-
+
+ named_scope :active_reverse,
+ :conditions => { :confirmed => true, :disabled => nil },
+ :order => 'ID DESC'
+
+ named_scope :active,
+ :conditions => { :confirmed => true, :disabled => nil }
+
+
end
View
@@ -0,0 +1,20 @@
+class Notifier < ActionMailer::Base
+
+ def book_confirmation( book )
+ recipients "#{book.seller}@cc.umanitoba.ca"
+ from "noreply@umes.mb.ca"
+ subject "Confirm your listing on text.umes.mb.ca"
+
+ body :book => book
+ end
+
+ def message( book, message, buyer )
+ recipients "#{book.seller}@cc.umanitoba.ca"
+ from "noreply@umes.mb.ca"
+ subject "UMES Textbook Exchange: Mail for #{book.title}"
+
+ body :book => book, :message => message, :buyer => buyer
+
+ end
+
+end
@@ -1,7 +1,11 @@
%tr
- %td= link_to h(book.title), book
- %td=h book.author
- %td=h book.seller
- %td= number_to_currency book.price
- %td=h book.isbn
- %td= image_tag book.thumbnail_url
+ %td.a
+ %span.title= link_to h(book.title), book
+ %span.isbn== (#{h book.isbn})
+ %br/
+ %span.author=h book.author
+ %td.b
+ %span.price= number_to_currency book.price
+ %br/
+ %span.seller=h book.seller
+ %td.c= image_tag book.thumbnail_url
@@ -1,5 +1,5 @@
%h1 Editing book
-
+%hr/
- form_for(@book) do |f|
= f.error_messages
@@ -1,6 +1,7 @@
-%h1 Listing books
+%h1= params[:query] ? "Search Results for &ldquo;#{h(params[:query])}&rdquo;" : "Available Books"
+%hr/
-%table
- = render :partial => @books
+%table{:style=>'width:100%'}
+ = render :partial => @books rescue nil
= will_paginate @books
@@ -1,33 +1,34 @@
-%h1 New book
-
+%h1 Sell a Book
+%hr/
- form_for(@book) do |f|
= f.error_messages
- %p
- = f.label :title
- %br/
- = f.text_field :title
- %p
- = f.label :author
- %br/
- = f.text_field :author
- %p
- = f.label :seller
- %br/
- = f.text_field :seller
- %p
- = f.label :price
- %br/
- = f.text_field :price
- %p
- = f.label :comments
- %br/
- = f.text_area :comments
- %p
- = f.label :isbn
- %br/
- = f.text_field :isbn
- %p
- = f.submit "Create"
-
-= link_to 'Back', books_path
+ .yui-g
+ .yui-u.first
+ %p
+ = f.label :title, "Title"
+ %br/
+ = f.text_field :title, :class => 'fancy'
+ %p
+ = f.label :author, "Author"
+ %br/
+ = f.text_field :author, :class => 'fancy'
+ %p
+ = f.label :seller, "Your UMNetID (eg. umsample42)"
+ %br/
+ = f.text_field :seller, :class => 'fancy'
+ %p
+ = f.label :price, "Price"
+ %br/
+ = f.text_field :price, :class => 'fancy'
+ %p
+ = f.label :isbn, "ISBN-10"
+ %br/
+ = f.text_field :isbn, :class => 'fancy'
+ %p.center
+ = f.submit "Create"
+ .yui-u
+ %p
+ = f.label :comments, "Comments"
+ %br/
+ = f.text_area :comments, :class => 'fancy'
@@ -1,7 +1,7 @@
%h1 Search Books
-
+%hr/
- form_tag :action => 'list' do |f|
- %p
+ %p.search
= text_field_tag :query
%p
- = submit_tag "Search"
+ = submit_tag "Search!"
Oops, something went wrong.

0 comments on commit f6c8181

Please sign in to comment.