Commit 65a31567 by Tran Hoang Viet

Merge remote-tracking branch 'origin/vietth_feat_order_management' into deploy_mina

Conflicts:
	Gemfile
	Gemfile.lock
	app/views/layouts/_header.html.haml
	db/schema.rb
parents 867b0162 1236556d
......@@ -96,7 +96,6 @@ gem 'cartman', '~> 2.1.2'
gem 'font-awesome-rails', '~> 4.3.0.0'
gem 'rolify', '~> 4.0.0'
gem 'meta-tags', '~> 2.0.0'
gem 'mina', '~> 0.3.4'
gem 'mina-unicorn', :require => false
\ No newline at end of file
gem 'rolify', '~> 4.0.0'
\ No newline at end of file
......@@ -155,12 +155,10 @@ GEM
nokogiri (>= 1.5.9)
mail (2.6.3)
mime-types (>= 1.16, < 3)
meta-tags (2.0.0)
actionpack (>= 3.0.0)
method_source (0.8.2)
mime-types (2.6.1)
mina (0.3.7)
open4 (~> 1.3.4)
rake
mina-unicorn (0.3.0)
mini_magick (3.8.1)
subexec (~> 0.2.1)
mini_portile (0.6.2)
......@@ -173,7 +171,6 @@ GEM
net-ssh (2.9.2)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
open4 (1.3.4)
orm_adapter (0.5.0)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
......@@ -349,8 +346,7 @@ DEPENDENCIES
jquery-rails
kaminari (~> 0.16.3)
letter_opener (~> 1.4.1)
mina (~> 0.3.4)
mina-unicorn
meta-tags (~> 2.0.0)
mini_magick (~> 3.8.1)
mysql2
pry-rails (~> 0.3.4)
......
......@@ -17,4 +17,5 @@
*= require layout
*= require product
*= require cart
*= require order
*/
......@@ -38,7 +38,7 @@ label.error{
-moz-box-shadow: 0px 1px 5px 0px rgba(0,0,0,0.72);
box-shadow: 0px 1px 5px 0px rgba(0,0,0,0.72);
background-color: #F3F3F3;
.share-scocial{
.share-social{
display: block;
}
}
......@@ -61,7 +61,7 @@ label.error{
}
}
.share-scocial{
.share-social{
display: none;
text-align: center;
margin-left: -15px;
......
#order-detail{
.value{
padding-top: 7px;
}
}
#orders-list{
.status{
&.done{
color: #ccc;
}
&.original{
color: #00812A;
}
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@
font-size: 16px;
}
.share-scocial{
.share-social{
display: block !important;
}
}
\ No newline at end of file
class ApplicationController < ActionController::Base
include MetaManagement
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
layout Proc.new { |controller| controller.devise_controller? ? 'devise' : 'application' }
......@@ -19,4 +21,5 @@ class ApplicationController < ActionController::Base
def record_not_found
redirect_to(root_path, alert: "Resource not found")
end
end
\ No newline at end of file
class CategoriesController < ApplicationController
before_action :set_category, only: [:show]
before_action :set_meta, only: [:show]
before_action :add_breadcrumb_home
def show
......@@ -8,14 +7,18 @@ class CategoriesController < ApplicationController
add_breadcrumb(@category.decorate.title)
end
def meta_attributes
return if @category.blank?
@meta_attributes ||= {
title: @category.decorate.title,
description: @category.decorate.title
}
end
private
def set_category
@category = Category.find(params[:id])
end
def set_meta
Meta.title = @category.decorate.title
Meta.name = @category.decorate.title
end
end
\ No newline at end of file
module MetaManagement extend ActiveSupport::Concern
included do
def render(options = nil, extra_options = {}, &block)
set_metas
super
end
def meta_attributes_default
{
image: ActionController::Base.helpers.asset_url('logo.png'),
title: 'Venshop Zigexn VeNtura',
description: 'Venshop',
keywords: 'Ventura, Zigexn, venshop',
type: 'shop'
}
end
def set_metas
attributes = meta_attributes_default
if self.respond_to?(:meta_attributes) && meta_attributes.present?
attributes = attributes.merge(meta_attributes)
end
set_meta_tags(
title: attributes[:title],
description: attributes[:description],
keywords: attributes[:keywords],
separator: "&mdash;".html_safe,
og: {
title: attributes[:title],
type: attributes[:type],
url: Settings.base_url,
image: attributes[:image],
description: attributes[:description]
},
twitter: {
title: attributes[:title],
description: attributes[:description],
card: attributes[:type],
image: {
_: attributes[:image],
width: 100,
height: 100
}
}
)
end
end
end
\ No newline at end of file
class OrdersController < ApplicationController
before_action :authenticate_user!
before_action :set_order, only: [:show, :update]
def index
end
......@@ -19,11 +20,32 @@ class OrdersController < ApplicationController
end
end
def management
@orders = current_user.admin? ? Order.all : current_user.orders
@orders = @orders.includes(:user).order(created_at: :desc).page(params[:page])
end
def show
end
def update
if order_service.update(@order, order_params)[:status].present?
redirect_to management_orders_path, notice: 'Update order successful!'
else
render :show
end
end
private
def cart_params
params.require(:cart).permit(items: [:id, :quantity])
end
def order_params
params.require(:order).permit(:status)
end
def order_service
@order_service ||= OrderService.new(current_user, params)
end
......@@ -32,4 +54,8 @@ class OrdersController < ApplicationController
@cart_service ||= CartService.new(current_user, params)
end
def set_order
@order = Order.find(params[:id])
end
end
\ No newline at end of file
......@@ -3,7 +3,6 @@ class ProductsController < ApplicationController
before_action :set_categories, only: [:new, :create]
before_action :add_breadcrumb_home
before_action :authenticate_user!, only: [:new, :create, :add_cart]
before_action :set_meta, only: [:show]
def new
@product = Product.new
......@@ -39,6 +38,16 @@ class ProductsController < ApplicationController
add_breadcrumb('Search result')
end
def meta_attributes
return if @product.blank?
@meta_attributes ||= {
title: @product.title,
image: @product.image_lg_url,
description: "#{@product.title} - #{@product.price}"
}
end
private
def set_product
@product = Product.find(params[:id])
......@@ -56,13 +65,4 @@ class ProductsController < ApplicationController
@cart_service ||= CartService.new(current_user, params)
end
def set_meta
Meta.title = @product.title
Meta.name = @product.title
Meta.image = @product.image_md_url
Meta.image_lg = @product.image_lg_url
Meta.description = "#{@product.title} - #{@product.price}"
Meta.author = @product.user.email
end
end
\ No newline at end of file
class OrderDecorator < Draper::Decorator
delegate_all
def status
object.original? ? 'New' : object.status.titleize
end
end
\ No newline at end of file
module ScocialHelper
module SocialHelper
def facebook_share_url(url)
"https://www.facebook.com/sharer/sharer.php?u=#{url || request.original_url}"
end
......
......@@ -3,4 +3,6 @@ class Order < ActiveRecord::Base
has_many :order_items, dependent: :destroy
accepts_nested_attributes_for :order_items
enum status: %i(original preparing shipping done cancel_refund)
end
......@@ -19,6 +19,10 @@ class OrderService < BaseService
end
end
def update(order, params)
{status: order.update(params)}
end
private
def send_checkout_email(order)
OrderMailer.send_checkout(current_user.email, order).deliver_later
......
......@@ -12,9 +12,11 @@
%ul.nav.navbar-nav.navbar-right
- if user_signed_in?
%li
= link_to 'Orders', management_orders_path
%li
= link_to 'New product', new_product_path
%li
= link_to 'Change profile', edit_user_registration_path
= link_to 'Profile', edit_user_registration_path
%li
= link_to 'Logout', destroy_user_session_path, method: :delete
......
%title= Meta.title || 'Venshop Zigexn VeNtura'
%meta{content: Meta.description, name: "description"}
/ Schema.org markup for Google+
%meta{content: Meta.name, itemprop: "name"}
%meta{content: Meta.description, itemprop: "description"}
%meta{content: Meta.image, itemprop: "image"}
/ Twitter Card data
%meta{content: Meta.image_lg, name: "twitter:card"}
%meta{content: Meta.title, name: "twitter:title"}
%meta{content: Meta.description, name: "twitter:description"}
%meta{content: Meta.author, name: "twitter:creator"}
/ Twitter summary card with large image must be at least 280x150px
%meta{content: Meta.image_lg, name: "twitter:image:src"}
/ Open Graph data
%meta{content: Meta.title, property: "og:title"}
%meta{content: "article", property: "og:type"}
%meta{content: Settings.base_url, property: "og:url"}
%meta{content: Meta.image, property: "og:image"}
%meta{content: Meta.description, property: "og:description"}
%meta{content: Meta.title, property: "og:site_name"}
%meta{content: ENV['FB_APP_ID'], property: "fb:admins"}
\ No newline at end of file
......@@ -4,7 +4,7 @@
= javascript_include_tag 'application'
= csrf_meta_tags
= render 'layouts/meta'
= display_meta_tags
%body
%nav.navbar.navbar-inverse.navbar-fixed-top
......@@ -31,7 +31,7 @@
= render 'layouts/cart'
.row
.col-md-12
= render 'layouts/share_scocial'
= render 'layouts/share_social'
.col-md-10
= yield
......
%h3.title Checkout
- if cart_valid?
#checkout-cart
#checkout-cart.table-responsive
= form_for Order.new do |f|
%table.table
%thead
......
%h3.title Orders management
.module
#orders-list
.order-item.table-responsive
%table.table
%thead
%tr
%td.text-right #
%td Order number
/ %td Ordered by
%td Created at
%td Status
%tbody
- @orders.each_with_index do |order_item, index|
%tr
%td.number.text-right
= index + 1
%td.order-number
= link_to order_item.created_at.to_i, order_path(order_item)
/ %td.created-by
/ = order_item.user.email
%td.created-at
= I18n.l(order_item.created_at)
%td.status{class: order_item.status}
= order_item.decorate.status
%tfooter
%tr
%td{colspan: 10}
= paginate @orders
%h3.title Order detail
#order-detail.module
= form_for @order, html: {class: 'form-horizontal'} do |f|
.form-group
%label.col-md-2.col-sm-3.col-xs-3.control-label Order number
.col-md-4.col-sm-9.col-xs-9.value
= f.object.created_at.to_i
.form-group
%label.col-md-2.col-sm-3.col-xs-3.control-label Created by
.col-md-4.col-sm-9.col-xs-9.value
= f.object.user.email
.form-group
%label.col-md-2.col-sm-3.col-xs-3.control-label Created at
.col-md-4.col-sm-9.col-xs-9.value
= I18n.l(f.object.created_at)
.form-group
%label.col-md-2.col-sm-3.col-xs-3.control-label Total price
.col-md-4.col-sm-9.col-xs-9.value
= f.object.total
.form-group
%label.col-md-2.col-sm-3.col-xs-3.control-label Status
.col-md-2.col-sm-9.col-xs-9.value
- if current_user.admin?
= f.select :status, Order.statuses.keys.map { |status| [status.titleize, status] }, {}, class: 'form-control'
- else
= f.object.status.titleize
- if current_user.admin?
.form-group
%label.col-md-2.col-sm-3.col-xs-3.control-label
.col-md-2.col-sm-4.col-xs-9
= f.submit 'Save', class: 'btn btn-primary'
.list-order-items.table-responsive
%table.table
%thead
%tr
%td.text-right #
%td Title
%td Price
%td Quantity
%tbody
- @order.order_items.each_with_index do |order_item, index|
%tr
%td.number.text-right
= index + 1
%td.title
= link_to order_item.product.title, product_path(order_item.id)
%td.price
= order_item.product.price
%td.quantity
= order_item.quantity
.product-addto-cart.input-group
- max_quantity = product.stock - current_user.cart.find(product).try(:quantity).to_i
- max_quantity = product.stock
- max_quantity -= current_user.cart.find(product).try(:quantity).to_i if user_signed_in?
= form_tag add_cart_product_path(product), method: :get, class: 'form-quantity' do
= text_field_tag :quantity, 1, class: 'form-control quantity'
= hidden_field_tag :stock, max_quantity, class: 'max-quantity'
......
.product-item.col-md-3.text-center
.product-item.col-md-3.col-sm-6.text-center
.product-title
= link_to product.decorate.short_title, product
.product-price
......@@ -14,7 +14,7 @@
.clearfix
.share-scocial
.share-social
= link_to facebook_share_url(product_url(product)), class: 'facebook', target: '_blank' do
= image_tag 'facebook.png'
= link_to twitter_share_url(product_url(product)), class: 'twitter', target: '_blank' do
......
set :domain, '192.168.1.204'
set :deploy_to, '/web/training/vietth2/'
set :domain, 'alicuche.koding.io'
set :rails_env, 'production'
set :deploy_to, '/home/alicuche/Web/venshop'
set :app_path, "#{deploy_to}/#{current_path}"
set :repository, 'git@gitlab.zigexn.vn:vietth/VietTH-VenShop.git'
set :branch, 'master'
set :branch, 'deploy_mina'
set :user, 'ventura'
set :forward_agent, true
set :port, '22'
set :unicorn_pid, "#{deploy_to}/current/tmp/pids/unicorn.pid"
set :shared_paths, ['config/database.yml', 'log', 'config/secrets.yml', 'config/application.yml']
set :shared_paths, ['config/database.yml', 'log', 'config/application.yml']
set :keep_releases, 5
require 'mina/bundler'
require 'mina/rails'
......@@ -34,24 +36,37 @@ task :deploy => :environment do
end
end
# namespace :unicorn do
# desc "Start the application"
# task :start do
# queue 'echo "-----> Puma start"'
# config_file = "#{app_path}/config/unicorn/#{stage}.rb"
# queue "cd #{app_path} && RAILS_ENV=#{stage} bundle exec unicorn -c #{config_file} -D", :pty => false
# end
# desc "Stop the application"
# task :stop do
# queue 'echo "-----> Unicorn stop"'
# queue "cd #{app_path} && kill -9 `cat #{app_path}/tmp/pids/unicorn.pid`"
# end
# desc "Restart the application"
# task :restart do
# queue 'echo "-----> Restart unicorn"'
# invoke :'unicorn:stop'
# invoke :'unicorn:start'
# end
# end
\ No newline at end of file
namespace :unicorn do
set :unicorn_pid, "#{app_path}/tmp/pids/unicorn.pid"
set :start_unicorn, %{
cd #{app_path}
bundle exec unicorn -c #{app_path}/config/unicorn/#{rails_env}.rb -E #{rails_env} -D
}
# Start task
# ------------------------------------------------------------------------------
desc "Start unicorn"
task :start => :environment do
queue 'echo "-----> Start Unicorn"'
queue! start_unicorn
end
# Stop task
# ------------------------------------------------------------------------------
desc "Stop unicorn"
task :stop do
queue 'echo "-----> Stop Unicorn"'
queue! %{
test -s "#{unicorn_pid}" && kill -QUIT `cat "#{unicorn_pid}"` && echo "Stop Ok" && exit 0
echo >&2 "Not running"
}
end
# Restart task
# ------------------------------------------------------------------------------
desc "Restart unicorn using 'upgrade'"
task :restart => :environment do
invoke 'unicorn:stop'
invoke 'unicorn:start'
end
end
\ No newline at end of file
......@@ -14,5 +14,9 @@ Rails.application.routes.draw do
resources :categories
resources :orders
resources :orders do
collection do
get :management
end
end
end
\ No newline at end of file
class UpdateRoleUsers < SeedMigration::Migration
def up
User.all.map(&:default_role)
end
end
class AddStatusToOrders < ActiveRecord::Migration
def change
add_column :orders, :status, :integer, default: 0
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150716012713) do
ActiveRecord::Schema.define(version: 20150716032049) do
create_table "categories", force: :cascade do |t|
t.datetime "created_at", null: false
......@@ -39,6 +39,7 @@ ActiveRecord::Schema.define(version: 20150716012713) do
t.datetime "updated_at", null: false
t.integer "user_id", limit: 4, null: false
t.decimal "total", precision: 10, default: 0
t.integer "status", limit: 4, default: 0
end
add_index "orders", ["user_id"], name: "index_orders_on_user_id", using: :btree
......
......@@ -13,4 +13,4 @@
ActiveRecord::Base.transaction do
end
SeedMigration::Migrator.bootstrap(20150708092434)
SeedMigration::Migrator.bootstrap(20150716025400)
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