Commit 89e7a441 by Tran Hoang Viet

VietTH: Implement AWS S3 for products image management

parent eebd25df
...@@ -97,4 +97,6 @@ gem 'cartman', '~> 2.1.2' ...@@ -97,4 +97,6 @@ gem 'cartman', '~> 2.1.2'
gem 'font-awesome-rails', '~> 4.3.0.0' gem 'font-awesome-rails', '~> 4.3.0.0'
gem 'meta-tags', '~> 2.0.0' gem 'meta-tags', '~> 2.0.0'
\ No newline at end of file
gem 'fog', '~> 1.32.0'
\ No newline at end of file
GEM GEM
remote: http://rubygems.org/ remote: http://rubygems.org/
specs: specs:
CFPropertyList (2.3.1)
actionmailer (4.2.3) actionmailer (4.2.3)
actionpack (= 4.2.3) actionpack (= 4.2.3)
actionview (= 4.2.3) actionview (= 4.2.3)
...@@ -114,10 +115,107 @@ GEM ...@@ -114,10 +115,107 @@ GEM
i18n (~> 0.5) i18n (~> 0.5)
figaro (1.1.1) figaro (1.1.1)
thor (~> 0.14) thor (~> 0.14)
fission (0.5.0)
CFPropertyList (~> 2.2)
fog (1.32.0)
fog-atmos
fog-aws (>= 0.6.0)
fog-brightbox (~> 0.4)
fog-core (~> 1.32)
fog-ecloud (= 0.1.1)
fog-google (>= 0.0.2)
fog-json
fog-local
fog-powerdns (>= 0.1.1)
fog-profitbricks
fog-radosgw (>= 0.0.2)
fog-riakcs
fog-sakuracloud (>= 0.0.4)
fog-serverlove
fog-softlayer
fog-storm_on_demand
fog-terremark
fog-vmfusion
fog-voxel
fog-xml (~> 0.1.1)
ipaddress (~> 0.5)
nokogiri (~> 1.5, >= 1.5.11)
fog-atmos (0.1.0)
fog-core
fog-xml
fog-aws (0.7.3)
fog-core (~> 1.27)
fog-json (~> 1.0)
fog-xml (~> 0.1)
ipaddress (~> 0.8)
fog-brightbox (0.8.0)
fog-core (~> 1.22)
fog-json
inflecto (~> 0.0.2)
fog-core (1.32.0)
builder
excon (~> 0.45)
formatador (~> 0.2)
mime-types
net-scp (~> 1.1)
net-ssh (>= 2.1.3)
fog-ecloud (0.1.1)
fog-core
fog-xml
fog-google (0.0.7)
fog-core
fog-json
fog-xml
fog-json (1.0.2)
fog-core (~> 1.0)
multi_json (~> 1.10)
fog-local (0.2.1)
fog-core (~> 1.27)
fog-powerdns (0.1.1)
fog-core (~> 1.27)
fog-json (~> 1.0)
fog-xml (~> 0.1)
fog-profitbricks (0.0.3)
fog-core
fog-xml
nokogiri
fog-radosgw (0.0.4)
fog-core (>= 1.21.0)
fog-json
fog-xml (>= 0.0.1)
fog-riakcs (0.1.0)
fog-core
fog-json
fog-xml
fog-sakuracloud (1.0.1)
fog-core
fog-json
fog-serverlove (0.1.2)
fog-core
fog-json
fog-softlayer (0.4.7)
fog-core
fog-json
fog-storm_on_demand (0.1.1)
fog-core
fog-json
fog-terremark (0.1.0)
fog-core
fog-xml
fog-vmfusion (0.1.0)
fission
fog-core
fog-voxel (0.1.0)
fog-core
fog-xml
fog-xml (0.1.2)
fog-core
nokogiri (~> 1.5, >= 1.5.11)
font-awesome-rails (4.3.0.0) font-awesome-rails (4.3.0.0)
railties (>= 3.2, < 5.0) railties (>= 3.2, < 5.0)
font-awesome-sass (4.3.2.1) font-awesome-sass (4.3.2.1)
sass (~> 3.2) sass (~> 3.2)
formatador (0.2.5)
globalid (0.3.5) globalid (0.3.5)
activesupport (>= 4.1.0) activesupport (>= 4.1.0)
haml (4.0.6) haml (4.0.6)
...@@ -135,6 +233,8 @@ GEM ...@@ -135,6 +233,8 @@ GEM
nokogiri (~> 1.6.0) nokogiri (~> 1.6.0)
ruby_parser (~> 3.5) ruby_parser (~> 3.5)
i18n (0.7.0) i18n (0.7.0)
inflecto (0.0.2)
ipaddress (0.8.0)
jbuilder (2.3.1) jbuilder (2.3.1)
activesupport (>= 3.0.0, < 5) activesupport (>= 3.0.0, < 5)
multi_json (~> 1.2) multi_json (~> 1.2)
...@@ -344,6 +444,7 @@ DEPENDENCIES ...@@ -344,6 +444,7 @@ DEPENDENCIES
factory_girl_rails (~> 4.5.0) factory_girl_rails (~> 4.5.0)
faker (~> 1.4.3) faker (~> 1.4.3)
figaro (~> 1.1.1) figaro (~> 1.1.1)
fog (~> 1.32.0)
font-awesome-rails (~> 4.3.0.0) font-awesome-rails (~> 4.3.0.0)
font-awesome-sass font-awesome-sass
haml-rails (~> 0.9) haml-rails (~> 0.9)
......
...@@ -17,6 +17,13 @@ ...@@ -17,6 +17,13 @@
#total-price{ #total-price{
color: blue; color: blue;
} }
.image{
width: 100%;
text-align: center;
img{
height: 40px;
}
}
} }
} }
.input-group.spinner{ .input-group.spinner{
......
...@@ -151,7 +151,11 @@ footer{ ...@@ -151,7 +151,11 @@ footer{
.item{ .item{
float: left; float: left;
width: 100%; width: 100%;
padding: 5px 0; padding: 10px 0;
cursor: pointer;
&.even{
background-color: #EDEDED;
}
} }
} }
.total{ .total{
...@@ -174,4 +178,13 @@ footer{ ...@@ -174,4 +178,13 @@ footer{
.breadcrumb{ .breadcrumb{
margin-bottom: 0; margin-bottom: 0;
}
.sidebar{
.counter{
float: right;
}
.title{
margin-bottom: 0;
}
} }
\ No newline at end of file
...@@ -17,7 +17,8 @@ class CartService < BaseService ...@@ -17,7 +17,8 @@ class CartService < BaseService
cost: (product.price || 0) * quantity, cost: (product.price || 0) * quantity,
quantity: quantity, quantity: quantity,
type: Product, type: Product,
stock: product.stock stock: product.stock,
image: product.decorate.image_sm_url
) )
{status: true} {status: true}
else else
......
...@@ -8,8 +8,11 @@ class ImageUploader < CarrierWave::Uploader::Base ...@@ -8,8 +8,11 @@ class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader: # Choose what kind of storage to use for this uploader:
storage :file if Rails.env.production?
# storage :fog storage :fog
else
storage :file
end
# Override the directory where uploaded files will be stored. # Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted: # This is a sensible default for uploaders that are meant to be mounted:
......
%li %li
= link_to "#{category.decorate.title} (#{category.decorate.products_count})", category = link_to category do
\ No newline at end of file = category.decorate.title
%span.counter
= category.decorate.products_count
\ No newline at end of file
- if cart_valid? - if cart_valid?
#cart-info #cart-info
%h3.title Cart info %h3.title Cart info
.col-md-9 Title / .col-md-6 Title
.col-md-3.text-right Quantity / .col-md-6.text-right Quantity
.list-cart-item .list-cart-item
- current_user.cart.items.each do |item| - current_user.cart.items.each_with_index do |item, index|
.item .item{class: "#{index.even? ? 'even' : 'odd'}"}
.col-md-9 .col-md-9
= link_to item.name.truncate(25, separator: ' '), product_path(item.id) = link_to item.name.truncate(25, separator: ' '), product_path(item.id)
.col-md-3.text-right .col-md-3.text-right
......
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
- if user_signed_in? - if user_signed_in?
%li %li
= link_to 'Orders', management_orders_path = link_to 'Orders', management_orders_path
/ %li
/ = link_to 'My products', products_path(current_user)
%li %li
= link_to 'New product', new_product_path = link_to 'New product', new_product_path
%li %li
......
...@@ -3,10 +3,11 @@ ...@@ -3,10 +3,11 @@
- if cart_valid? - if cart_valid?
#checkout-cart.table-responsive #checkout-cart.table-responsive
= form_for Order.new do |f| = form_for Order.new do |f|
%table.table %table.table.table-hover
%thead %thead
%tr %tr
%td.text-right # %td.text-right #
%td.text-center Image
%td Title %td Title
%td Price %td Price
%td Stock %td Stock
...@@ -16,6 +17,9 @@ ...@@ -16,6 +17,9 @@
%tr %tr
%td.number.text-right %td.number.text-right
= index + 1 = index + 1
%td
.image
= image_tag order_item.image
%td.title %td.title
= link_to order_item.name, product_path(order_item.id) = link_to order_item.name, product_path(order_item.id)
= hidden_field_tag "cart[items][#{index}][id]", order_item.id = hidden_field_tag "cart[items][#{index}][id]", order_item.id
...@@ -34,12 +38,12 @@ ...@@ -34,12 +38,12 @@
%tfoot %tfoot
%tr %tr
%td#total-price-title.text-right{colspan: 2} Total: %td#total-price-title.text-right{colspan: 3} Total:
%td#total-price{colspan: 3} %td#total-price{colspan: 4}
= format_price(current_user.cart.total) = format_price(current_user.cart.total)
%tr %tr
%td.no-border.text-right{colspan: 5} %td.no-border.text-right{colspan: 6}
= f.submit 'Checkout', class: 'btn btn-primary' = f.submit 'Checkout', class: 'btn btn-primary'
:javascript :javascript
......
%h3.title My products
.module
#my-products.products-list-detail
= render @products
\ No newline at end of file
...@@ -3,6 +3,9 @@ AWS_ACCESS: AKIAJ77C4CTZOP7TUVWQ ...@@ -3,6 +3,9 @@ AWS_ACCESS: AKIAJ77C4CTZOP7TUVWQ
AWS_SECRET: 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 AWS_SECRET: cYJYb/MLGV0M6oi1+DjlliL1cfxmh78tKXnT6ZmX
AWS_TAG: zigexn6400-22 AWS_TAG: zigexn6400-22
S3_KEY: AKIAIQP5WZFK3IWF3PCA
S3_SECRET: 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
FB_APP_ID: 1629224294024346 FB_APP_ID: 1629224294024346
SOLR_URL: http://localhost:8080/solr/venshop SOLR_URL: http://localhost:8080/solr/venshop
\ No newline at end of file
CarrierWave.configure do |config|
# config.fog_provider = 'fog/aws' # required
config.fog_credentials = {
provider: 'AWS', # required
aws_access_key_id: ENV['S3_KEY'], # required
aws_secret_access_key: ENV['S3_SECRET'], # required
region: 'ap-southeast-1', # optional, defaults to 'us-east-1'
# host: 's3.example.com', # optional, defaults to nil
# endpoint: 'https://s3.example.com:8080' # optional, defaults to nil
}
config.fog_directory = 'venshop' # required
config.fog_public = false # optional, defaults to true
config.fog_attributes = { 'Cache-Control' => "max-age=#{365.day.to_i}" } # optional, defaults to {}
end
\ No newline at end of file
...@@ -2,6 +2,10 @@ Rails.application.routes.draw do ...@@ -2,6 +2,10 @@ Rails.application.routes.draw do
devise_for :users devise_for :users
root 'home#index' root 'home#index'
resources :users do
resources :products, only: [:index]
end
resources :products do resources :products do
member do member do
get :add_cart get :add_cart
......
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