Commit 70904e91 by Vy Quoc Vu

Admin update

parent 13bbc9a4
# 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://coffeescript.org/
# 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://coffeescript.org/
# 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://coffeescript.org/
# 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://coffeescript.org/
# 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://coffeescript.org/
# 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://coffeescript.org/
# 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://coffeescript.org/
// Place all the styles related to the admin/application controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the admin/categories controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the admin/posts controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the admin/products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the admin/sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the admins/products controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
// Place all the styles related to the sessions controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class Admins::ConfirmationsController < Devise::ConfirmationsController
# GET /resource/confirmation/new
# def new
# super
# end
# POST /resource/confirmation
# def create
# super
# end
# GET /resource/confirmation?confirmation_token=abcdef
# def show
# super
# end
# protected
# The path used after resending confirmation instructions.
# def after_resending_confirmation_instructions_path_for(resource_name)
# super(resource_name)
# end
# The path used after confirmation.
# def after_confirmation_path_for(resource_name, resource)
# super(resource_name, resource)
# end
end
class Admins::OmniauthCallbacksController < Devise::OmniauthCallbacksController
# You should configure your model like this:
# devise :omniauthable, omniauth_providers: [:twitter]
# You should also create an action method in this controller like this:
# def twitter
# end
# More info at:
# https://github.com/plataformatec/devise#omniauth
# GET|POST /resource/auth/twitter
# def passthru
# super
# end
# GET|POST /users/auth/twitter/callback
# def failure
# super
# end
# protected
# The path used when OmniAuth fails
# def after_omniauth_failure_path_for(scope)
# super(scope)
# end
end
class Admins::PasswordsController < Devise::PasswordsController
# GET /resource/password/new
# def new
# super
# end
# POST /resource/password
# def create
# super
# end
# GET /resource/password/edit?reset_password_token=abcdef
# def edit
# super
# end
# PUT /resource/password
# def update
# super
# end
# protected
# def after_resetting_password_path_for(resource)
# super(resource)
# end
# The path used after sending reset password instructions
# def after_sending_reset_password_instructions_path_for(resource_name)
# super(resource_name)
# end
end
class Admins::ProductsController < ApplicationController
def new
@product = Product.new
end
def create
if admin_signed_in?
if product_params[:price].to_i >= 0 && product_params[:category_id].to_i > 0 && !product_params[:image].nil?
product = Product.find_or_create_by(name: product_params[:name]) do |product|
product.image = product_params[:image]
product.category_id = product_params[:category_id]
product.price = product_params[:price]
product.description = product_params[:description]
end
flash[:success] = "Success!"
redirect_to "/products/#{product.id}"
else
flash[:danger] = "Wrong params!"
redirect_to :action => :new
end
end
end
def edit
if admin_signed_in?
if product_params[:price].to_i >= 0 && product_params[:category_id].to_i > 0 && !product_params[:image].nil?
product = Product.find(params[:id])
byebug
product.name = product_params[:name]
product.image = product_params[:image]
product.category_id = product_params[:category_id]
product.price = product_params[:price]
product.description = product_params[:description]
product.save
byebug
flash[:success] = "Success!"
redirect_to "/products/#{product.id}"
else
flash[:danger] = "Wrong params!"
redirect_to :action => :new
end
end
end
def destroy
if admin_signed_in?
@product = Product.find(params[:id])
@product.destroy
flash[:success] = "Deleted!"
redirect_to :back
end
end
def show
if
@product = Product.find(params[:id])
else
flash[:danger] = "Only Admin"
end
end
private
def product_params
params.require(:product).permit(:name, :price, :description,
:image, :category_id, :id)
end
end
\ No newline at end of file
class Admins::RegistrationsController < Devise::RegistrationsController
# before_filter :configure_sign_up_params, only: [:create]
# before_filter :configure_account_update_params, only: [:update]
# GET /resource/sign_up
# def new
# super
# end
# POST /resource
# def create
# super
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_up_params
# devise_parameter_sanitizer.for(:sign_up) << :attribute
# end
# If you have extra params to permit, append them to the sanitizer.
# def configure_account_update_params
# devise_parameter_sanitizer.for(:account_update) << :attribute
# end
# The path used after sign up.
# def after_sign_up_path_for(resource)
# super(resource)
# end
# The path used after sign up for inactive accounts.
# def after_inactive_sign_up_path_for(resource)
# super(resource)
# end
end
class Admins::SessionsController < Devise::SessionsController
# before_filter :configure_sign_in_params, only: [:create]
# GET /resource/sign_in
# def new
# super
# end
# POST /resource/sign_in
# def create
# super
# end
# DELETE /resource/sign_out
# def destroy
# super
# end
# protected
# If you have extra params to permit, append them to the sanitizer.
# def configure_sign_in_params
# devise_parameter_sanitizer.for(:sign_in) << :attribute
# end
end
class Admins::UnlocksController < Devise::UnlocksController
# GET /resource/unlock/new
# def new
# super
# end
# POST /resource/unlock
# def create
# super
# end
# GET /resource/unlock?unlock_token=abcdef
# def show
# super
# end
# protected
# The path used after sending unlock password instructions
# def after_sending_unlock_instructions_path_for(resource)
# super(resource)
# end
# The path used after unlocking the resource
# def after_unlock_path_for(resource)
# super(resource)
# end
end
...@@ -7,6 +7,8 @@ class ApplicationController < ActionController::Base ...@@ -7,6 +7,8 @@ class ApplicationController < ActionController::Base
include ApplicationHelper include ApplicationHelper
include CartsHelper include CartsHelper
include CategoriesHelper include CategoriesHelper
include SessionsHelper
def configure_permitted_parameters def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :username devise_parameter_sanitizer.for(:sign_up) << :username
......
...@@ -10,4 +10,8 @@ class ProductsController < ApplicationController ...@@ -10,4 +10,8 @@ class ProductsController < ApplicationController
@product = Product.find(params[:id]) @product = Product.find(params[:id])
end end
def add
end
end end
class Admin::AdminsController < ApplicationController class SessionsController < ApplicationController
end end
class Admin::UsersController < ApplicationController module Admin::ApplicationHelper
end end
module Admin::CategoriesHelper
end
module Admin::PostsHelper
end
module Admin::ProductsHelper
end
module Admin::SessionsHelper
end
module Admins::ProductsHelper
end
module SessionsHelper
def log_in(user)
session[:user_id] = user.id
end
def current_user_s
@current_user_s ||= User.find_by(id: session[:user_id])
end
def logged_in?
!current_user_s.nil?
end
def log_out
session.delete(:user_id)
@current_user = nil
end
end
class ModelMailer < ApplicationMailer
# Subject can be set in your I18n file at config/locales/en.yml
# with the following lookup:
#
# en.model_mailer.new_record_notification.subject
#
def new_record_notification(record)
@record = record
mail to: "recipient@MYDOMAIN.com", subject: "Success! You did it."
end
end
<h2>Resend confirmation instructions</h2>
<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div>
<div class="actions">
<%= f.submit "Resend confirmation instructions" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<p>Welcome <%= @email %>!</p>
<p>You can confirm your account email through the link below:</p>
<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password. You can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
<p>Hello <%= @resource.email %>!</p>
<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
<p>Click the link below to unlock your account:</p>
<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
<h2>Change your password</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<%= f.hidden_field :reset_password_token %>
<div class="field">
<%= f.label :password, "New password" %><br />
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autofocus: true, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation, "Confirm new password" %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Change my password" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<h2>Forgot your password?</h2>
<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Send me reset password instructions" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<% if admin_signed_in? %>
<h1>Add Products</h1>
<div class="row">
<div class="col-md-3" style=" padding-top: 50px;">
<% if admin_signed_in? %>
<h1>Admin</h1>
<%= render 'layouts/admin' %>
<% end %>
</div>
<div class="col-md-9" style=" padding-top: 50px;">
<%= form_for(@product, url: {action: "create"}) do |f| %>
<%= f.label :name %>
<%= f.text_field :name, value: "", class: 'form-control'%>
<%= f.label :price %>
<%= f.number_field :price, value: "", class: 'form-control' %>
<%= f.label :category_id %>
<%= f.number_field :category_id, value: "", class: 'form-control' %>
<%= f.label :description %>
<%= f.text_area :description, class: 'form-control' %>
<%= f.label :image %>
<%= f.text_field :image, class: 'form-control' %>
</br>
<%= f.submit "Submit" , class: "btn btn-primary" %>
<% end %>
</div>
</div>
<% else %>
<h1>Only Admin</h1>
<% end %>
\ No newline at end of file
<% if admin_signed_in? %>
<div class="col-md-3" style=" padding-top: 50px;">
<% if admin_signed_in? %>
<h1>Admin</h1>
<%= render 'layouts/admin' %>
<% end %>
</div>
<div class="col-md-9" style=" padding-top: 50px;">
<div class="center jumbotron">
<%= image_tag(@product.image)%>
<h3><%= (@product.price/100.to_f).to_s + "$" %></h3>
<%= form_for(@product, url: {action: "edit"}) do |f| %>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control'%>
<%= f.label :price %>
<%= f.number_field :price, class: 'form-control' %>
<%= f.label :category_id %>
<%= f.number_field :category_id, class: 'form-control' %>
<%= f.label :description %>
<%= f.text_area :description, class: 'form-control' %>
<%= f.label :image %>
<%= f.text_field :image, class: 'form-control' %>
</br>
<%= f.submit "Submit" , class: "btn btn-primary" %>
<% end %>
</div>
</div>
<% else %>
<h1>Only Admin</h1>
<% end %>
\ No newline at end of file
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>
<div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>
<% end %>
<div class="field">
<%= f.label :password %> <i>(leave blank if you don't want to change it)</i><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i><br />
<%= f.password_field :current_password, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Update" %>
</div>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" }, method: :delete %></p>
<%= link_to "Back", :back %>
<h2>Sign up Admin</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %>
<% if @minimum_password_length %>
<em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<div class="field">
<%= f.label :password_confirmation %><br />
<%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>
<div class="actions">
<%= f.submit "Sign up" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<h2>Log in Admin</h2>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="field">
<%= f.label :password %><br />
<%= f.password_field :password, autocomplete: "off" %>
</div>
<% if devise_mapping.rememberable? -%>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end -%>
<div class="actions">
<%= f.submit "Log in" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<%- if controller_name != 'sessions' %>
<%= link_to "Log in", new_session_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.registerable? && controller_name != 'registrations' %>
<%= link_to "Sign up", new_registration_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>
<%= link_to "Forgot your password?", new_password_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>
<%= link_to "Didn't receive confirmation instructions?", new_confirmation_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>
<%= link_to "Didn't receive unlock instructions?", new_unlock_path(resource_name) %><br />
<% end -%>
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in with #{provider.to_s.titleize}", omniauth_authorize_path(resource_name, provider) %><br />
<% end -%>
<% end -%>
<h2>Resend unlock instructions</h2>
<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>
<%= devise_error_messages! %>
<div class="field">
<%= f.label :email %><br />
<%= f.email_field :email, autofocus: true %>
</div>
<div class="actions">
<%= f.submit "Resend unlock instructions" %>
</div>
<% end %>
<%= render "admins/shared/links" %>
<h1>Your Cart</h1> <h1>Your Cart</h1>
<div class="col-md-3" style=" padding-top: 50px;">
<div class="col-md-12"> <% if admin_signed_in? %>
<form class="navbar-left" style="padding-left: 0px" > <h1>Admin</h1>
<%= link_to "Empty Cart" ,'/cart_product/clear' %> <%= render 'layouts/admin' %>
</form> <% else %>
<form class=" navbar-right" > <%= render 'layouts/cart' %>
<%= link_to "Back " ,root_path %> <%= render 'categories/view' %>
</form> <% end %>
</div>
<div>
<ul>
<% total = 0 %>
<% if !@cart_product.nil? %>
<% @cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% total = total + product.price * quantity.to_i %>
<div class="col-md-4">
<%= image_tag(product.image, size: "170x210")%>
<h5><%= truncate(product.name, length: 22) %></h5>
<%= number_to_currency(product.price/100.to_f) %>
</br>
<form action="/cart_product/update" style="padding-left : 0px ; resize: vertical;" >
<input type="number" name="new_quantity" min="1" max="100" value= <%= quantity %> >
</br>
<input type="submit" value="Update" style="font-size: 1em;" />
<input type="hidden" name="id" value="<%= product.id %>"/>
</form>
<form action="/cart_product/remove" style="padding-left : 0px" >
<input type="submit" value="Remove" style="font-size: 1em;" />
<input type="hidden" name="id" value="<%= product.id %>"/>
</form>
</div>
<% end %>
<% end -%>
<% else %>
<h2>Empty</h2>
<% end -%>
</ul>
</div> </div>
<div class="col-md-9" style=" padding-top: 50px;">
<div class="col-md-12">
<form class="navbar-left" style="padding-left: 0px" >
<%= link_to "Empty Cart" ,'/cart_product/clear' %>
</form>
<form class=" navbar-right" >
<%= link_to "Back " ,root_path %>
</form>
</div>
<div>
<ul>
<% total = 0 %>
<% if !@cart_product.nil? %>
<% @cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% total = total + product.price * quantity.to_i %>
<div class="col-md-4">
<%= image_tag(product.image, size: "170x210")%>
<h5><%= truncate(product.name, length: 22) %></h5>
<%= number_to_currency(product.price/100.to_f) %>
</br>
<form action="/cart_product/update" style="padding-left : 0px ; resize: vertical;" >
<input type="number" name="new_quantity" min="1" max="100" value= <%= quantity %> >
</br>
<input type="submit" value="Update" style="font-size: 1em;" />
<input type="hidden" name="id" value="<%= product.id %>"/>
</form>
<form action="/cart_product/remove" style="padding-left : 0px" >
<input type="submit" value="Remove" style="font-size: 1em;" />
<input type="hidden" name="id" value="<%= product.id %>"/>
</form>
</div>
<% end %>
<% end -%>
<% else %>
<h2>Empty</h2>
<% end -%>
</ul>
</div>
<div class="footer col-md-12"> <div class="footer col-md-12">
</br> </br>
</br> </br>
<h2> Total price: <%=(total/100.to_f).to_s + "$" %></h2> <h2> Total price: <%=(total/100.to_f).to_s + "$" %></h2>
</br> </br>
<%= link_to "Checkout", "/cart", class: "btn btn-lg btn-danger"%> <%= link_to "Checkout", "/cart", class: "btn btn-lg btn-danger"%>
</footer> </div>
\ No newline at end of file </div>
\ No newline at end of file
<% if !session[:cart].nil? && !session[:cart].empty? %> <% if !session[:cart].nil? && !session[:cart].empty? %>
<h1>Cart info</h1> <div class="col-md-3" style=" padding-top: 50px;">
<ul> <% if admin_signed_in? %>
<% @total = 0 %> <h1>Admin</h1>
<% cart_product.each do |id, quantity| %> <%= render 'layouts/admin' %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% @total = @total + product.price * quantity %>
<li>
<%= link_to product.name, "/products/#{product.id}" %>
</br>
<p>Quantity: <%= quantity %></p>
</li>
<% end -%>
<% end -%>
<br>
<h2> <%= number_to_currency(@total/100.to_f, :unit => '$')%> </h2>
</ul>
<div class="row">
<div class="col-md-10 ">
<% if user_signed_in? %>
<% mail = @current_user.email %>
<% name = "" %>
<% address = "" %>
<% else %> <% else %>
<% mail = "" %> <%= render 'layouts/cart' %>
<% name = "" %>
<% address = "" %>
<% end %>
<%= form_for(:session, url: create_cart_path) do |f| %>
<%= f.label :mail %>
<%= f.email_field :mail, value: mail, class: 'form-control'%>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :address %>
<%= f.text_field :address, class: 'form-control' %>
</br>
<%= f.submit "Submit" , class: "btn btn-primary" %>
<% end %> <% end %>
</div> </div>
<div class="col-md-9" style=" padding-top: 50px;">
<h1>Cart info</h1>
<ul>
<% @total = 0 %>
<% cart_product.each do |id, quantity| %>
<% product = Product.find_by_id(id) %>
<% if !product.nil? %>
<% @total = @total + product.price * quantity %>
<li>
<%= link_to product.name, "/products/#{product.id}" %>
</br>
<p>Quantity: <%= quantity %></p>
</li>
<% end -%>
<% end -%>
<br>
<h2> <%= number_to_currency(@total/100.to_f, :unit => '$')%> </h2>
</ul>
<div class="row">
<div class="col-md-10 ">
<% if user_signed_in? %>
<% mail = @current_user.email %>
<% name = "" %>
<% address = "" %>
<% else %>
<% mail = "" %>
<% name = "" %>
<% address = "" %>
<% end %>
<%= form_for(:session, url: create_cart_path) do |f| %>
<%= f.label :mail %>
<%= f.email_field :mail, value: mail, class: 'form-control'%>
<%= f.label :name %>
<%= f.text_field :name, class: 'form-control' %>
<%= f.label :address %>
<%= f.text_field :address, class: 'form-control' %>
</br>
<%= f.submit "Submit" , class: "btn btn-primary" %>
<% end %>
</div>
</div>
</div> </div>
<%else%> <%else%>
<h1>Your Cart is Empty</h1> <h1>Your Cart is Empty</h1>
......
<h1>show cart</h1> <h1>show cart</h1>
<ul> <div class="col-md-3" style=" padding-top: 50px;">
<% if !@show_cart.nil? %> <% if admin_signed_in? %>
<% @show_cart.each do |cart| %> <h1>Admin</h1>
<h4> <%= render 'layouts/admin' %>
<%= cart.id.to_s + " | "%> <% else %>
<%= cart.mail.to_s + " | " %> <%= render 'layouts/cart' %>
<%= cart.name.to_s + " | " %> <% end %>
<%= cart.total_price.to_s + " | " %> </div>
<%= cart.address+ " | " %> <div class="col-md-9" style=" padding-top: 50px;">
<%= cart.status.to_s %> <ul>
</h4> <% if !@show_cart.nil? %>
<% @show_cart.each do |cart| %>
<h4>
<%= cart.id.to_s + " | "%>
<%= cart.mail.to_s + " | " %>
<%= cart.name.to_s + " | " %>
<%= cart.total_price.to_s + " | " %>
<%= cart.address+ " | " %>
<%= cart.status.to_s %>
</h4>
<% end -%>
<% else -%>
<h2> Your cart Empty </h2>
<% end -%> <% end -%>
<% else -%> </ul>
<h2> Your cart Empty </h2> </div>
<% end -%>
</ul>
</ul> </ul>
<div class="dropdown" style="padding-top: 10px;" > <div class="dropdown" style="padding-top: 10px;" >
<button class="btn btn-info dropdown-toggle" type="button" data-toggle="dropdown" style="font-size: 1.5em; width: 250px;">Category <button class="btn btn-info dropdown-toggle" type="button" data-toggle="dropdown" style="font-size: 1.5em; width: 230px;">Category
<span class="caret"></span></button> <span class="caret"></span></button>
<ul class="dropdown-menu nav nav-pills nav-stacked" > <ul class="dropdown-menu nav nav-pills nav-stacked" >
<li class="list-group-item"> <li class="list-group-item">
......
<div class="col-md-3" style=" padding-top: 50px;">
<% @products.each do |product| %> <% if admin_signed_in? %>
<div class="col-md-4"> <h1>Admin</h1>
<div class="center jumbotron" style="padding-left : 40px;"> <%= render 'layouts/admin' %>
<%= image_tag(product.image, size: "170x210")%> <% else %>
<h5><%= truncate(product.name, length: 22) %></h5> <%= render 'layouts/cart' %>
<%= (product.price/100.to_f).to_s + "$" %> <%= render 'categories/view' %>
</br> <% end %>
<%= link_to "Info", "/products/#{product.id}", class: "btn btn-lg btn-info" %> </div>
<%= link_to "Buy", "/products/#{product.id}", class: "btn btn-lg btn-danger" %> <div class="col-md-9" style=" padding-top: 50px;">
<% @products.each do |product| %>
<div class="col-md-4">
<div class="center jumbotron" style="padding-left : 40px;">
<%= image_tag(product.image, size: "170x210")%>
<h5><%= truncate(product.name, length: 22) %></h5>
<%= (product.price/100.to_f).to_s + "$" %>
</br>
<%= link_to "Info", "/products/#{product.id}", class: "btn btn-lg btn-info" %>
<%= link_to "Buy", "/products/#{product.id}", class: "btn btn-lg btn-danger" %>
</div>
</div> </div>
</div> <% end -%>
<% end -%> </div>
\ No newline at end of file \ No newline at end of file
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
<div class="field"> <div class="field">
<%= f.label :email %><br /> <%= f.label :email %><br />
<%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %> <%= f.email_field :email, autofocus: true, value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %>
</div> </div>
<div class="actions"> <div class="actions">
<%= f.submit "Resend confirmation instructions" %> <%= f.submit "Resend confirmation instructions" %>
</div> </div>
<% end %> <% end %>
<%= render "devise/shared/links" %> <%= render "devise/shared/links" %>
<h2>Sign up in devise</h2> <h2>Sign up Devise</h2>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %> <%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %> <%= devise_error_messages! %>
......
<h3>Home</h3>
<h3>Categories</h3>
<h3>Products</h3>
<h3>Cart</h3>
\ No newline at end of file
<table>
<tr>
<th><%= render 'cart_products/new' %></th>
</tr>
</table>
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<div class="container-fluid"> <div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display --> <!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header"> <div class="navbar-header">
<a class="navbar-brand" href= "/index" >Venshop</a> <a class="navbar-brand" href= "/index" > Venshop </a>
</div> </div>
<!-- Collect the nav links, forms, and other content for toggling --> <!-- Collect the nav links, forms, and other content for toggling -->
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<button type="submit" class="btn btn-success">Submit</button> <button type="submit" class="btn btn-success">Submit</button>
</form> </form>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<% if user_signed_in? %> <% if user_signed_in? || admin_signed_in? %>
<li> <li>
<span class="glyphicon glyphicon-log-out"> <span class="glyphicon glyphicon-log-out">
<%= link_to "Log out", destroy_user_session_path, method: "delete" %> <%= link_to "Log out", destroy_user_session_path, method: "delete" %>
......
<!DOCTYPE html>
<html>
<head>
<title>Venshop</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<div class="container">
<%= render 'layouts/header' %>
<div class="row">
<div class="col-md-3" style=" padding-top: 50px;">
<table>
<tr>
<th><%= render 'cart_products/new' %></th>
</tr>
<tr>
</tr>
</table>
</div>
<div class="col-md-9" style=" padding-top: 50px;">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %>
</div>
</div>
</div>
<%= render 'layouts/footer' %>
</body>
</html>
...@@ -10,23 +10,7 @@ ...@@ -10,23 +10,7 @@
<body> <body>
<div class="container"> <div class="container">
<%= render 'layouts/header' %> <%= render 'layouts/header' %>
<div class="row">
<div class="col-md-3" style=" padding-top: 50px;">
<table>
<tr>
<th><%= render 'cart_products/new' %></th>
</tr>
<tr>
</tr>
</table>
</div>
<div class="col-md-9" style=" padding-top: 50px;">
<% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<%= yield %> <%= yield %>
</div>
</div>
</div> </div>
<%= render 'layouts/footer' %> <%= render 'layouts/footer' %>
</body> </body>
......
<h1>ModelMailer#new_record_notification</h1>
<p>
<%= @greeting %>, find me in app/views/model_mailer/new_record_notification.html.erb
</p>
ModelMailer#new_record_notification
<%= @greeting %>, find me in app/views/model_mailer/new_record_notification.text.erb
<%= will_paginate %>
<div class="row">
<% @products.each do |product| %>
<div class="col-md-4" style="padding-top : 20px">
<div>
<%= image_tag(product.image, size: "180x230")%>
<%= simple_format(truncate(product.name, length:21)) %>
</div>
<div>
<% price = (product.price/100.to_f) %>
<input type="number" name="quantity" min="1" max="100" value=<%= price %> >
</br>
<%= link_to "Edit", "/admins/products/#{product.id}", class: "btn btn-lg btn-primary" %>
<%= link_to "delete", "/admins/destroy/#{product.id}", class: "btn btn-lg btn-danger" %>
</form>
</div>
</div>
<% end %>
</div>
<%= will_paginate %>
\ No newline at end of file
<%= will_paginate %> <%= will_paginate %>
<div class="row"> <div class="row">
<% @products.each do |product| %> <% @products.each do |product| %>
<div class="col-md-4" style="padding-top : 20px"> <div class="col-md-4" style="padding-top : 20px">
<div> <div>
<%= image_tag(product.image, size: "180x230")%> <%= image_tag(product.image, size: "180x230")%>
<%= simple_format(truncate(product.name, length:21)) %> <%= simple_format(truncate(product.name, length:21)) %>
<%= (product.price/100.to_f).to_s + "$" %> <%= (product.price/100.to_f).to_s + "$" %>
</div>
<div>
</div> </div>
</div> <div>
<% end %> <form action="/cart_products" style="padding-left : 0px" >
</div> <input type="number" name="quantity" value= "1" min="1" max="100">
</br>
<input type="submit" value="Add" class = "btn btn-lg btn-success" />
<%= link_to "Detail", "/products/#{product.id}", class: "btn btn-lg btn-info" %>
<input type="hidden" name="id" value="<%= product.id %>"/>
</form>
</div>
</div>
<% end %>
</div>
<%= will_paginate %> <%= will_paginate %>
\ No newline at end of file
<%= will_paginate %>
<div class="row"> <div class="row">
<% @products.each do |product| %> <div class="col-md-3" style=" padding-top: 50px;">
<div class="col-md-4" style="padding-top : 20px"> <% if admin_signed_in? %>
<div> <%= render 'layouts/admin' %>
<%= image_tag(product.image, size: "180x230")%> <% else %>
<%= simple_format(truncate(product.name, length:21)) %> <%= render 'layouts/cart' %>
<%= (product.price/100.to_f).to_s + "$" %> <%= render 'categories/view' %>
</div>
<div>
<form action="/cart_products" style="padding-left : 0px" >
<input type="number" name="quantity" value= "1" min="1" max="100" value="1">
</br>
<input type="submit" value="Add" class = "btn btn-lg btn-success" />
<%= link_to "Detail", "/products/#{product.id}", class: "btn btn-lg btn-info" %>
<input type="hidden" name="id" value="<%= product.id %>"/>
</form>
</div>
</div>
<% end %> <% end %>
</div> </div>
<%= will_paginate %> <div class="col-md-9" style=" padding-top: 50px;">
\ No newline at end of file <% flash.each do |message_type, message| %>
<div class="alert alert-<%= message_type %>"><%= message %></div>
<% end %>
<% if admin_signed_in? %>
<%= render 'products/admin_products' %>
<% else %>
<%= render 'products/custom_products' %>
<% end %>
</div>
</div>
\ No newline at end of file
<div> <div class="col-md-3" style=" padding-top: 50px;">
<% if admin_signed_in? %>
<h1>Admin</h1>
<% else %>
<%= render 'layouts/cart' %>
<%= render 'categories/view' %>
<% end %>
</div>
<div class="col-md-9" style=" padding-top: 50px;">
<div class="center jumbotron" style="padding-left: 35px;"> <div class="center jumbotron" style="padding-left: 35px;">
<%= image_tag(@product.image)%> <%= image_tag(@product.image)%>
<h3><%= simple_format(@product.name) %></h3> <h3><%= simple_format(@product.name) %></h3>
...@@ -8,10 +16,10 @@ ...@@ -8,10 +16,10 @@
</br> </br>
<form action="/cart_products" style="padding-left: 0px" > <form action="/cart_products" style="padding-left: 0px" >
<input type="number" name="quantity" value= "1" min="1" max="100" value="1"> <input type="number" name="quantity" value= "1" min="1" max="100" value="1">
</br> </br>
<input type="submit" value="Add" class = "btn btn-lg btn-success" /> <input type="submit" value="Add" class = "btn btn-lg btn-success" />
<input type="hidden" name="id" value="<%= @product.id %>"/> <input type="hidden" name="id" value="<%= @product.id %>"/>
</form> </form>
</div> </div>
</div> </div>
\ No newline at end of file
<h1>Sessions#new</h1>
<p>Find me in app/views/sessions/new.html.erb</p>
<h2>Log in</h2> <h2>Log in user</h2>
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
<div class="field"> <div class="field">
......
Rails.application.routes.draw do Rails.application.routes.draw do
#devise_for :admins get 'sessions/new'
devise_for :users, controllers: { sessions: "users/sessions" } devise_for :users, controllers: { sessions: "users/sessions" }
devise_for :admins, controllers: { sessions: "admins/sessions" } devise_for :admins, controllers: { sessions: "admins/sessions" }
namespace :admins do
resources :products
end
get 'index' => 'products#index' get 'index' => 'products#index'
get 'login' => 'sessions#new' get 'login' => 'sessions#new'
get '/admins/destroy/:id' => 'admins/products#destroy', as: 'destroy_product'
patch "/admins/products/:id/edit"=>'admins/products#edit'
get 'category/:id' => 'category#show' get 'category/:id' => 'category#show'
get 'products/:id' => 'products#show' get 'products/:id' => 'products#show'
......
...@@ -4,6 +4,8 @@ class DeviseCreateUsers < ActiveRecord::Migration ...@@ -4,6 +4,8 @@ class DeviseCreateUsers < ActiveRecord::Migration
## Database authenticatable ## Database authenticatable
t.string :email, null: false, default: "" t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: "" t.string :encrypted_password, null: false, default: ""
t.string :name
t.string :address
## Recoverable ## Recoverable
t.string :reset_password_token t.string :reset_password_token
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150728075925) do ActiveRecord::Schema.define(version: 20150730041232) do
create_table "admins", force: :cascade do |t| create_table "admins", force: :cascade do |t|
t.string "email", limit: 255, default: "", null: false t.string "email", limit: 255, default: "", null: false
......
...@@ -4,4 +4,4 @@ ...@@ -4,4 +4,4 @@
# Examples: # Examples:
# #
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first) # Mayor.create(name: 'Emanuel', city: cities.first)
\ No newline at end of file
require 'test_helper'
class Admin::ApplicationControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class Admin::CategoriesControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class Admin::PostsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class Admin::ProductsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class Admin::SessionsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class Admins::ProductsControllerTest < ActionController::TestCase
# test "the truth" do
# assert true
# end
end
require 'test_helper'
class SessionsControllerTest < ActionController::TestCase
test "should get new" do
get :new
assert_response :success
end
end
require 'test_helper'
class ModelMailerTest < ActionMailer::TestCase
test "new_record_notification" do
mail = ModelMailer.new_record_notification
assert_equal "New record notification", mail.subject
assert_equal ["to@example.org"], mail.to
assert_equal ["from@example.com"], mail.from
assert_match "Hi", mail.body.encoded
end
end
# Preview all emails at http://localhost:3000/rails/mailers/model_mailer
class ModelMailerPreview < ActionMailer::Preview
# Preview this email at http://localhost:3000/rails/mailers/model_mailer/new_record_notification
def new_record_notification
ModelMailer.new_record_notification
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment