Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Recoverying some stuff...

  • Loading branch information...
commit 85f49daf0eceb6d19f07e019a868f33b0981b865 1 parent 721a6c0
@florida authored
Showing with 343 additions and 125 deletions.
  1. BIN  app/assets/images/logo.png
  2. +3 −0  app/assets/javascripts/store.js.coffee
  3. +0 −17 app/assets/stylesheets/application.css
  4. +110 −0 app/assets/stylesheets/application.css.scss
  5. +3 −0  app/assets/stylesheets/store.css.scss
  6. +0 −19 app/controllers/sessions_controller.rb
  7. +33 −0 app/controllers/store_controller.rb
  8. +0 −15 app/controllers/users_controller.rb
  9. +0 −2  app/helpers/sessions_helper.rb
  10. +13 −0 app/helpers/store_helper.rb
  11. +37 −0 app/models/cart.rb
  12. +10 −0 app/models/lineitem.rb
  13. +7 −1 app/models/order.rb
  14. +13 −1 app/models/product.rb
  15. +37 −17 app/views/layouts/application.html.erb
  16. +0 −18 app/views/sessions/new.html.erb
  17. +11 −0 app/views/store/_items_in_cart.html.erb
  18. +15 −0 app/views/store/_product.html.erb
  19. +1 −0  app/views/store/_product_in_cart.html.erb
  20. +3 −0  app/views/store/index.html.erb
  21. +17 −0 app/views/store/shoppingcart.html.erb
  22. +5 −0 app/views/store/show.html.erb
  23. +0 −29 app/views/users/new.html.erb
  24. +12 −6 config/routes.rb
  25. +9 −0 test/functional/store_controller_test.rb
  26. +4 −0 test/unit/helpers/store_helper_test.rb
View
BIN  app/assets/images/logo.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
3  app/assets/javascripts/store.js.coffee
@@ -0,0 +1,3 @@
+# Place all the behaviors and hooks related to the matching controller here.
+# All this logic will automatically be available in application.js.
+# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
View
17 app/assets/stylesheets/application.css
@@ -1,17 +0,0 @@
-/*
- * This is a manifest file that'll be compiled into application.css, which will include all the files
- * listed below.
- *
- * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
- * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
- *
- * You're free to add application-wide styles to this file and they'll appear at the top of the
- * compiled file, but it's generally better to create a new file per style scope.
- *
- *= require_self
- *= require_tree .
- */
-
- body{
- background-image: url(bg.png);
- }
View
110 app/assets/stylesheets/application.css.scss
@@ -0,0 +1,110 @@
+/*
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
+ * listed below.
+ *
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
+ *
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
+ * compiled file, but it's generally better to create a new file per style scope.
+ *
+ *= require_self
+ *= require_tree .
+ */
+
+ $footer_link_background: #d5d5d5;
+ $footer_background_color: #202020;
+ $footer_link_shadow: rgba(0,0,0,0.2);
+ @mixin footer_links{
+ box-shadow: 1px 1px 0px $footer_link_shadow, 2px 2px 0px $footer_link_shadow, 3px 3px 0px $footer_link_shadow, 4px 4px 0px $footer_link_shadow, 5px 5px 0px $footer_link_shadow, 6px 6px 0px $footer_link_shadow;
+ background-color: $footer_link_background;
+ padding: 20px;
+ height: 70px;
+ width: 70px;
+ border-radius: 70px;
+ }
+ * {
+ margin: 0;
+ padding: 0;
+ box-sizing: border-box;
+ }
+
+ body{
+ background-image: url('bg.png');
+ width: 80%;
+ margin: 0 auto;
+ font-family: "Arial Narrow", sans-serif;
+ }
+
+header.main {
+ background: rgba(0,0,0,0.6);
+ clear: both;
+}
+
+#logo > img {
+ width: 80px;
+ height: 80px;
+ float: left;
+}
+
+nav.main {
+ padding: 20px;
+ ul {
+ list-style-type: none;
+ padding-bottom: 10px;
+ border-bottom: 7px double #FFF;
+ margin-left: 70px;
+ padding-left: 10px;
+ li {
+ display: inline;
+ padding: 30px 10px 10px 10px;
+ a{
+ color: #FFF;
+ text-decoration: none;
+ font-size: 25px;
+ letter-spacing: 1px;
+ background: none;
+ }
+ &:hover{
+ background: rgba(0,0,0,0.2);
+ }
+ }
+ }
+}
+section#footer_amplifier {
+ background-image: url('footer_amplifier.png');
+ background-size:100%;
+ background-repeat: no-repeat;
+ height: 64px;
+}
+
+footer {
+ font-color: #fff;
+ section#footer_container{
+ background-color: $footer_background_color;
+ padding: 0 20px 0 20px;
+ }
+ ul{
+ list-style-type: none;
+ background-image: url('footer_background.png');
+ padding: 10px;
+ margin: 0 auto;
+ border-radius: 20px 20px 0 0;
+ height: 150px;
+ display: block;
+ text-align:center;
+ li{
+ @include footer_links;
+ display: inline-block;
+ font-color: #fff;
+ margin: 20px 5% 0px 5%;
+ a{
+ text-decoration: none;
+ vertical-align: center;
+ }
+ }
+ }
+}
+
+
+
View
3  app/assets/stylesheets/store.css.scss
@@ -0,0 +1,3 @@
+// Place all the styles related to the store controller here.
+// They will automatically be included in application.css.
+// You can use Sass (SCSS) here: http://sass-lang.com/
View
19 app/controllers/sessions_controller.rb
@@ -1,19 +0,0 @@
-class SessionsController < ApplicationController
- def new
- end
-
- def create
- user = login(params[:email], params[:password], params[:remember_me])
- if user
- redirect_back_or_to root_url, :notice => "Logged in!"
- end
- flash.now.alert = "Email or Password was invalid"
- render :new
- end
-
- def destroy
- logout
- redirect_to root_url, :notice => "Logged Out!"
- end
-
-end
View
33 app/controllers/store_controller.rb
@@ -0,0 +1,33 @@
+class StoreController < ApplicationController
+ def index
+ @products = Product.available_items
+ end
+
+ def add_to_cart
+ product = Product.find(params[:id])
+ @cart = get_cart
+ @cart.add_line_item(product)
+
+ redirect_to store_path
+ end
+
+ def show_cart
+ @cart = get_cart
+ @items = @cart.items
+ render 'shoppingcart'
+ end
+
+ def empty_cart
+ @cart = get_cart
+ @cart.empty_cart_contents!
+ flash[:notice] = ' Your cart is now empty'
+ redirect_to store_path
+ end
+
+private
+
+ def get_cart
+ session[:cart] ||= Cart.new
+ end
+
+end
View
15 app/controllers/users_controller.rb
@@ -1,15 +0,0 @@
-class UsersController < ApplicationController
- def new
- @user = User.new
- end
-
- def create
- @user = User.new(params[:user])
- if @user.save
- redirect_to root_url, :notice => "Signed Up"
-
- else
- render :new
- end
- end
-end
View
2  app/helpers/sessions_helper.rb
@@ -1,2 +0,0 @@
-module SessionsHelper
-end
View
13 app/helpers/store_helper.rb
@@ -0,0 +1,13 @@
+module StoreHelper
+ def span_label label
+ content_tag(:span, :class => 'label') do
+ label
+ end
+ end
+
+ def span_value value
+ content_tag(:span, :class => 'value') do
+ "#{value}"
+ end
+ end
+end
View
37 app/models/cart.rb
@@ -0,0 +1,37 @@
+class Cart
+ #Model not persisted in the database
+ #Cart will have items, cart will have a total price
+ # and tax
+
+ #feature to add... adding line items with quantity
+
+ attr_reader :items, :total_price, :taxes
+ def initialize
+ @items = []
+ @total_price = 0.0
+ @taxes = 0.0
+ end
+
+
+
+ def add_line_item(product)
+ #finds if item is already in the cart
+ item = @items.find {|i| i.product_id == product.id}
+
+ if item
+ item.quantity += 1
+ else
+ item = Lineitem.add_product(product)
+ @items << item
+
+ end
+ @total_price += product.price
+ end
+
+
+ def empty_cart_contents!
+ @items = []
+ @total_price = 0.0
+ @taxes = 0.0
+ end
+end
View
10 app/models/lineitem.rb
@@ -2,4 +2,14 @@ class Lineitem < ActiveRecord::Base
attr_accessible :order_id, :product_id, :quantity, :unit_price
belongs_to :product
belongs_to :order
+
+ # # # # next feature, receiving quantity...
+
+ def self.add_product(product)
+ item = self.new
+ item.quantity = 1
+ item.product = product
+ #record the price during the sale
+ item.unit_price = product.price
+ end
end
View
8 app/models/order.rb
@@ -1,4 +1,10 @@
class Order < ActiveRecord::Base
- attr_accessible :address, :email, :first_name, :last_name
+ ORDER_STATUS = ["Shipped", "Pending", "Order Requested"]
+ attr_accessible :address, :email, :first_name, :last_name, :status
has_many :lineitems
+ validates :address, :presence => true
+ validates :email, :presence => true, :format => { :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i }
+ validates :first_name, :presence => true
+ validates :last_name, :presence => true
+ validates_inclusion_of :status, :in => ORDER_STATUS
end
View
14 app/models/product.rb
@@ -1,4 +1,16 @@
class Product < ActiveRecord::Base
- attr_accessible :description, :name, :price, :stock_no
+ attr_accessible :description, :name, :price, :stock_no, :image_url, :available
has_many :lineitems
+ validates :description, :presence => true
+ validates :name, :presence => true
+ validates :price, :numericality => { :greater_than_or_equal_to => 0 }, :presence => true
+ validates :stock_no, :numericality => { :only_integer => true, :greater_than_or_equal_to => 0 }
+ validates :image_url, :presence => true, :format => { :with => %r{\.(gif|jpe?g|png)$}i }
+
+
+ def self.available_items
+ find(:all,
+ :conditions => { :available => true} )
+ end
+
end
View
54 app/views/layouts/application.html.erb
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html>
+<html lang="en-US">
<head>
<title>Elmorfstore</title>
<%= stylesheet_link_tag "application", :media => "all" %>
@@ -7,24 +7,44 @@
<%= csrf_meta_tags %>
</head>
<body>
+ <header class="main">
+ <section id="logo">
+ <img src="/assets/logo.png" alt="Logo" />
+ </section>
+ <nav class="main">
+ <ul>
+ <li><%= link_to 'Home', root_path %></li>
+ <li><%= link_to 'Orders', admin_orders_path %></li>
+ <li><%= link_to 'Products', admin_products_path %></li>
+ <li><%= link_to 'Shopping Cart', shoppingcart_path %></li>
+ </ul>
+ </nav>
+ </header>
-<header>
- <ul>
- <li><%= link_to 'Orders', admin_orders_path %></li>
- <li><%= link_to 'Products', admin_products_path %></li>
- <li></li>
- </ul>
-
-
-</header>
+ <section id="content">
+ <% if flash[:notice] %>
+ <section class="notice"><%= flash[:notice] %></section>
+ <% end %>
+ <% if flash[:error] %>
+ <section class="error"><%= flash[:error] %></section>
+ <% end %>
+ <%= yield %>
+ </section>
+ <section id="footer_amplifier"></section>
+ <footer>
+ <section id="footer_container">
+ <ul>
+ <li><%= link_to 'Link', '#'%></li>
+ <li><%= link_to 'Link', '#'%></li>
+ <li><%= link_to 'Link', '#'%></li>
+ <li><%= link_to 'Link', '#'%></li>
+ <li><%= link_to 'Link', '#'%></li>
+ </ul>
+ </section>
+
+ </footer>
-
-<section id="container">
- <% flash.each do |name,msg| %>
- <%= content_tag :section, msg, :id => "flash_#{name}" %>
- <% end %>
- <%= yield %>
-</section>
</body>
+
</html>
View
18 app/views/sessions/new.html.erb
@@ -1,18 +0,0 @@
-<%= form_tag sessions_path do %>
- <section class="field">
- <% label_tag :email %>
- <% text_field_tag :email, params [:email] %>
-
- </section>
- <section class="field">
- <%= label_tag :password %>
- <%= password_field_tag :password %>
- </section>
- <section class="field">
- <%= check_box_tag :remember_me, 1, params[:remember_me]%>
- <%= label_tag :remember_me %>
- </section>
- <section class="actions">
- <%= submit_tag "Log in" %>
- </section>
-<% end %>
View
11 app/views/store/_items_in_cart.html.erb
@@ -0,0 +1,11 @@
+<section class="items_in_cart">
+ <section class="item_in_cart">
+ <%= image_tag item.product.image_url, :class=> "item_image" if item.product.image_url.present? %>
+ <%= span_label 'Product Name:' %>
+ <%= span_value item.product.name %>
+ <%= span_label 'Quantity:' %>
+ <%= span_value item.quantity %>
+ <%= span_label 'Price: ' %>
+ <%= span_value item.unit_price %>
+ </section>
+</section>
View
15 app/views/store/_product.html.erb
@@ -0,0 +1,15 @@
+<section class="product">
+ <header><%= product.name %></header>
+ <section class="product_image">
+ <%= image_tag product.image_url, :width => '20%' if product.image_url.present? %>
+ </section>
+ <section class="product_info">
+ <span class="label">Price</span>
+ <span class="value"><%= product.price %></span>
+ </section>
+ <footer>
+ <%= link_to 'Buy Now', add_to_cart_path(product) %>
+ <% span_label 'Product Name: ' %>
+
+ </footer>
+</section>
View
1  app/views/store/_product_in_cart.html.erb
@@ -0,0 +1 @@
+<section class="">
View
3  app/views/store/index.html.erb
@@ -0,0 +1,3 @@
+
+
+<%= render :partial => 'product', :collection => @products, :as => 'product' %>
View
17 app/views/store/shoppingcart.html.erb
@@ -0,0 +1,17 @@
+<h1>Display Cart Check</h1>
+ <nav>
+ <ul>
+ <li><%= link_to 'Continue shopping', store_path %></li>
+ <li><%= link_to 'Empty cart', store_path, :method => :delete %></li>
+ <li><%= link_to 'Checkout', '#' %></li>
+ </ul>
+</nav>
+
+
+
+<p>
+ Cart contains <%= @items.size %> items.
+ Total: <%= @cart.total_price %>
+</p>
+
+<%= render :partial => 'items_in_cart', :collection => @items, :as => 'item' %>
View
5 app/views/store/show.html.erb
@@ -0,0 +1,5 @@
+<section class="product_show">
+ <section class="product_image">
+ <%= image_tag %>
+ </section>
+</section>
View
29 app/views/users/new.html.erb
@@ -1,29 +0,0 @@
-<%= form_for @user do |f| %>
- <% if @user.errors.any? %>
- <section class="error_messages">
- <h2>Form is invalid </h2>
- <ul>
- <% for message in @user.errors.full_messages %>
- <li><%= message %></li>
- <% end %>
- </ul>
- </section>
- <% end %>
-
- <section class="field">
- <%= f.label :email %>
- <%= f.text_field :email%>
- </section>
- <section class="field">
- <%= f.label :password %>
- <%= f.password_field :password %>
- </section>
- <section class="field">
- <%= f.label :password_confirmation %>
- <%= f.password_field :password_confirmation %>
- </section>
-
- <section class="actions">
- <%= f.submit %>
- </section>
-<% end %>
View
18 config/routes.rb
@@ -1,11 +1,17 @@
Elmorfstore::Application.routes.draw do
- # root :to => "store#index"
-
- namespace :admin do
- resources :orders, :products
- end
-
+ match 'store' => 'store#index', :as => 'store', :via => :get
+ match 'shoppingcart' => 'store#show_cart', :as => 'shoppingcart', :via => :get
+ match 'add_to_cart/:id' => 'store#add_to_cart', :as => 'add_to_cart'
+ match 'store' => 'store#empty_cart', :via => :delete
+# get "store/index"
+
+root :to => 'store#index'
+
+namespace :admin do
resources :orders, :products
+end
+
+resources :orders, :products
# The priority is based upon order of creation:
# first created -> highest priority.
View
9 test/functional/store_controller_test.rb
@@ -0,0 +1,9 @@
+require 'test_helper'
+
+class StoreControllerTest < ActionController::TestCase
+ test "should get index" do
+ get :index
+ assert_response :success
+ end
+
+end
View
4 test/unit/helpers/store_helper_test.rb
@@ -0,0 +1,4 @@
+require 'test_helper'
+
+class StoreHelperTest < ActionView::TestCase
+end
Please sign in to comment.
Something went wrong with that request. Please try again.