Commit 4872138e by Truong Ba Dieu

Refactor syntax ruby

parent 85209882
......@@ -69,7 +69,7 @@ gem 'kaminari', '0.16.3'
# cron job
gem 'whenever', :require => false
gem 'sidekiq' # background job. run server bundle exec sidekiq
# upload source
gem 'capistrano', '~> 3.1.0'
......@@ -95,6 +95,8 @@ group :development, :test do
gem 'rspec-mocks'
gem 'rspec-rails', '~> 3.0.1'
gem 'rspec-support'
gem "pry" # debug
gem "pry" # debug . put in file debug require 'pry' , binding.pry
gem "quiet_assets"
gem 'rubocop', require: false # check syntax code. rubocop [file]
end
\ No newline at end of file
......@@ -66,6 +66,9 @@ GEM
arbre (1.0.3)
activesupport (>= 3.0.0)
arel (6.0.2)
ast (2.0.0)
astrolabe (1.3.1)
parser (~> 2.2)
autoprefixer-rails (5.2.1)
execjs
json
......@@ -103,6 +106,8 @@ GEM
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
celluloid (0.16.0)
timers (~> 4.0.0)
childprocess (0.5.6)
ffi (~> 1.0, >= 1.0.11)
chronic (0.10.2)
......@@ -116,6 +121,7 @@ GEM
coffee-script-source (1.9.1.1)
colorize (0.7.7)
columnize (0.9.0)
connection_pool (2.2.0)
daemons (1.2.3)
database_cleaner (1.4.1)
debug_inspector (0.0.2)
......@@ -165,6 +171,7 @@ GEM
has_scope (0.6.0)
actionpack (>= 3.2, < 5)
activesupport (>= 3.2, < 5)
hitimes (1.2.2)
i18n (0.7.0)
inherited_resources (1.6.0)
actionpack (>= 3.2, < 5)
......@@ -209,8 +216,11 @@ GEM
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
orm_adapter (0.5.0)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
polyamorous (1.2.0)
activerecord (>= 3.0)
powerpack (0.1.1)
pry (0.10.1)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
......@@ -246,6 +256,7 @@ GEM
activesupport (= 4.2.1)
rake (>= 0.8.7)
thor (>= 0.18.1, < 2.0)
rainbow (2.0.0)
rake (10.4.2)
ransack (1.6.6)
actionpack (>= 3.0)
......@@ -254,6 +265,9 @@ GEM
i18n
polyamorous (~> 1.2)
rdoc (4.2.0)
redis (3.2.1)
redis-namespace (1.5.2)
redis (~> 3.0, >= 3.0.4)
request_store (1.1.0)
responders (2.1.0)
railties (>= 4.2.0, < 5)
......@@ -280,8 +294,15 @@ GEM
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.4)
rubocop (0.32.1)
astrolabe (~> 1.3)
parser (>= 2.2.2.5, < 3.0)
powerpack (~> 0.1)
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-growl (4.1)
uuid (~> 2.3, >= 2.3.5)
ruby-progressbar (1.7.5)
rubyzip (1.1.7)
sass (3.4.16)
sass-rails (5.0.3)
......@@ -300,6 +321,12 @@ GEM
websocket (~> 1.0)
shoulda-matchers (2.8.0)
activesupport (>= 3.0.0)
sidekiq (3.4.2)
celluloid (~> 0.16.0)
connection_pool (~> 2.2, >= 2.2.0)
json (~> 1.0)
redis (~> 3.2, >= 3.2.1)
redis-namespace (~> 1.5, >= 1.5.2)
slim (3.0.6)
temple (~> 0.7.3)
tilt (>= 1.3.3, < 2.1)
......@@ -325,6 +352,8 @@ GEM
thread_safe (0.3.5)
tilt (1.4.1)
timeliness (0.3.7)
timers (4.0.1)
hitimes
turbolinks (2.5.3)
coffee-rails
turnip (1.3.1)
......@@ -399,11 +428,13 @@ DEPENDENCIES
rspec-mocks
rspec-rails (~> 3.0.1)
rspec-support
rubocop
ruby-growl
sass-rails (~> 5.0)
sdoc (~> 0.4.0)
selenium-webdriver
shoulda-matchers
sidekiq
slim
spring
thin
......
ActiveAdmin.register_page "Dashboard" do
ActiveAdmin.register_page 'Dashboard' do
menu priority: 1, label: proc{ I18n.t("active_admin.dashboard") }
menu priority: 1, label: proc{ I18n.t('active_admin.dashboard') }
content title: proc{ I18n.t("active_admin.dashboard") } do
div class: "blank_slate_container", id: "dashboard_default_message" do
span class: "blank_slate" do
span I18n.t("active_admin.dashboard_welcome.welcome")
small I18n.t("active_admin.dashboard_welcome.call_to_action")
content title: proc{ I18n.t('active_admin.dashboard') } do
div class: 'blank_slate_container', id: 'dashboard_default_message' do
span class: 'blank_slate' do
span I18n.t('active_admin.dashboard_welcome.welcome')
small I18n.t('active_admin.dashboard_welcome.call_to_action')
end
end
......@@ -14,7 +14,7 @@ ActiveAdmin.register_page "Dashboard" do
#
# columns do
# column do
# panel "Recent Posts" do
# panel 'Recent Posts' do
# ul do
# Post.recent(5).map do |post|
# li link_to(post.title, admin_post_path(post))
......@@ -24,8 +24,8 @@ ActiveAdmin.register_page "Dashboard" do
# end
# column do
# panel "Info" do
# para "Welcome to ActiveAdmin."
# panel 'Info' do
# para 'Welcome to ActiveAdmin.'
# end
# end
# end
......
......@@ -7,7 +7,6 @@ ActiveAdmin.register Order do
filter :state, as: :select, collection: proc{ Order.states.map{ |k,v| [k, v] } }
filter :created_at
form do |f|
f.inputs do
f.input :pid, input_html: { disabled: true }
......
......@@ -12,7 +12,7 @@ class ApplicationController < ActionController::Base
# rescue for gem pundit
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
add_breadcrumb "Home", :root_path
add_breadcrumb 'Home', :root_path
def get_categories
@categories = Category.featured
......@@ -21,18 +21,19 @@ class ApplicationController < ActionController::Base
def authenticate_admin_user!
authenticate_user!
unless current_user.has_role?(:admin)
redirect_to root_path, error: "This area is restricted to administrators only."
redirect_to root_path, error: 'This area is restricted to administrators only.'
end
end
private
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up).push(:name)
devise_parameter_sanitizer.for(:account_update).push(:name)
end
def user_not_authorized
flash[:notice] = "You are not authorized to perform this action."
flash[:notice] = 'You are not authorized to perform this action.'
redirect_to(request.referrer || root_path)
end
......
......@@ -7,4 +7,4 @@ class CategoriesController < ApplicationController
add_breadcrumb @category.name
end
end
\ No newline at end of file
end
......@@ -8,18 +8,19 @@ class HomeController < ApplicationController
end
def search
add_breadcrumb "Search"
add_breadcrumb 'Search'
@solr_products = Product.solr_search(params)
@products = Product.where(id: @solr_products.map{ |h| h["id"] })
@products = Product.where(id: @solr_products.map{ |h| h['id'] })
end
def cart
add_breadcrumb "Cart"
render layout: "cart"
add_breadcrumb 'Cart'
render layout: 'cart'
end
private
def get_recommend
@recommend_products = Product.recommend
end
end
\ No newline at end of file
end
......@@ -2,7 +2,7 @@ class OrdersController < ApplicationController
before_action :authenticate_user!
before_action :set_order, only: [:show]
before_action -> { authorize(@order) }, only: [:show]
layout "cart"
layout 'cart'
def index
@orders = current_user.orders.order(completed_at: :desc).paginate(page: params[:page])
......@@ -29,6 +29,7 @@ class OrdersController < ApplicationController
private
def set_order
@order = Order.find(params[:id])
end
......
......@@ -2,16 +2,16 @@ class ProductsController < ApplicationController
include ApplicationHelper
before_action :get_categories
before_action :authenticate_user!, :only => [:new, :create]
after_action :verify_authorized, :only => [:new, :create]
before_action :authenticate_user!, only: [:new, :create]
after_action :verify_authorized, only: [:new, :create]
def show
@product = Product.find(params[:id])
add_breadcrumb @product.category.try(:name), category_path(@product.category.try(:id))
add_breadcrumb @product.title
add_breadcrumb(@product.category.try(:name), category_path(@product.category.try(:id)))
add_breadcrumb(@product.title)
fetch_social_info(@product.title, @product.title, @product.image.thumb("158x158#").url)
render layout: "share_social"
fetch_social_info(@product.title, @product.title, @product.image.thumb('158x158#').url)
render layout: 'share_social'
end
def new
......@@ -24,16 +24,17 @@ class ProductsController < ApplicationController
@product = Product.new(new_product_params)
if @product.save
redirect_to category_path(@product.category), notice: "Product create successfully"
redirect_to category_path(@product.category), notice: 'Product create successfully'
else
render 'new'
end
end
private
def new_product_params
params[:product][:release_date] = Datetime.rstrptime(params[:product][:release_date], "%m/%d/%Y %H:%M %p")
params[:product][:public_date] = Datetime.rstrptime(params[:product][:public_date], "%m/%d/%Y %H:%M %p")
params[:product][:release_date] = DateTime.rstrptime(params[:product][:release_date], '%m/%d/%Y %H:%M %p')
params[:product][:public_date] = DateTime.rstrptime(params[:product][:public_date], '%m/%d/%Y %H:%M %p')
params.require(:product).permit(:stock, :pid, :title, :author, :publisher, :studio, :price, :currency, :category_id, :image, :release_date, :public_date, :recommend)
end
end
\ No newline at end of file
end
ActiveRecord::Base.class_eval do
def to_hash(fields)
begin
hash = {}
fields.each do |f|
hash[f.to_sym] = send(f.to_sym)
end
hash
def to_hash(fields = nil)
hash = {}
fields.each do |field|
hash[field.to_sym] = send(field.to_sym)
end
hash
rescue
{}
end
end
end
\ No newline at end of file
end
DateTime.instance_eval do
def rstrftime(datetime = nil, type="%B %d, %Y", rescue_datetime=nil)
begin
datetime.strftime(type)
def rstrftime(datetime = nil, type = '%B %d, %Y', rescue_datetime = nil)
datetime.strftime(type)
rescue # try to strftime rescue_datetime when error
rescue_datetime.strftime(type) if rescue_datetime.is_a?(DateTime) || rescue_datetime.is_a?(Time)
end
if rescue_datetime.is_a?(DateTime) || rescue_datetime.is_a?(Time)
rescue_datetime.strftime(type)
end
end
def rstrptime(str = nil, type="%Y-%m-%d", rescue_time=DateTime.now)
begin
str.strptime(type)
def rstrptime(str = nil, type = '%Y-%m-%d', rescue_time = DateTime.now)
str.strptime(type)
rescue
rescue_time
end
end
end
\ No newline at end of file
end
......@@ -3,7 +3,7 @@ class OrderDecorator < Draper::Decorator
def pid_link
if object.cart?
h.content_tag( :i, "Order not checkout" )
h.content_tag( :i, 'Order not checkout' )
else
h.content_tag( :a, object.pid, href: order_path(object.id) )
end
......@@ -16,4 +16,4 @@ class OrderDecorator < Draper::Decorator
object.state
end
end
end
\ No newline at end of file
end
......@@ -10,4 +10,3 @@ class ProductDecorator < Draper::Decorator
link_to object.title, product_path(object.id)
end
end
......@@ -4,4 +4,4 @@ class UserDecorator < Draper::Decorator
def edit_profile_link
h.content_tag(:a, object.name || object.email, href: edit_user_registration_path)
end
end
\ No newline at end of file
end
module ApplicationHelper
include ActionView::Helpers::TextHelper
def currency_number(price=0, currency="usd")
def currency_number(price = 0, currency = 'usd')
"#{currency}#{price}"
end
......
module OrderHelper
def current_order
if current_user.present?
current_user.orders.where(state: Order.states[:cart]).first_or_create
else
nil
end
return nil if current_user.blank?
current_user.orders.where(state: Order.states[:cart]).first_or_create
end
end
class UserMailer < ActionMailer::Base
default from: ENV["default_send_mail"]
default from: ENV['default_send_mail']
add_template_helper(ApplicationHelper)
def success_checkout(current_order)
@user = current_order.user
@order = current_order
mail to: @user.email, subject: "Venshop! Checkout successfully"
mail to: @user.email, subject: 'Venshop! Checkout successfully'
end
end
......@@ -11,6 +11,7 @@ module Solr extend ActiveSupport::Concern
end
private
def update_solr
if solr_fields_change?
self.class.rsolr.add fetch_solr_attr
......@@ -28,38 +29,38 @@ module Solr extend ActiveSupport::Concern
end
def solr_fields_change?
changed.any? {|field| solr_fields.include? field }
changed.any? { |field| solr_fields.include? field }
end
end
module ClassMethods
def solr_search(params={})
def solr_search(params = {})
params[:page] ||= 1
keyword = refine_keyword(params[:keyword])
res = rsolr.paginate params[:page], ENV["default_perpage"], 'select', :params => {:q => "*#{keyword}*"}
res = rsolr.paginate params[:page], ENV['default_perpage'], 'select', :params => { q: "*#{keyword}*" }
fetch_result(res)
end
def rsolr
@rsolr ||= RSolr.connect :url => ENV["solr_url"]
@rsolr ||= RSolr.connect :url => ENV['solr_url']
end
private
# refine some special chars can not accept from solr
def refine_keyword(keyword="")
def refine_keyword(keyword = '')
%w(+ - && || ! ( ) { } [ ] ^ " ~ * ? : \\).each do |s|
keyword = keyword.gsub(s, " ")
keyword = keyword.gsub(s, ' ')
end
keyword
end
def fetch_result(response)
begin
response["response"]["docs"]
response['response']['docs']
rescue
[]
end
end
end
end
\ No newline at end of file
......@@ -6,7 +6,7 @@ module UserRole extend ActiveSupport::Concern
before_save :default_role
def default_role
self.add_role(:user) if self.roles.blank?
add_role(:user) if roles.blank?
end
end
......
......@@ -8,14 +8,13 @@ class LineItem < ActiveRecord::Base
after_save :trigger_recalculate
before_destroy :trigger_calculate_order
private
def trigger_recalculate
if quantity_changed?
order.recalculate
change_square = quantity - quantity_was
product.substract_stock(change_square)
end
return unless quantity_changed?
order.recalculate
change_square = quantity - quantity_was
product.substract_stock(change_square)
end
# validate quantity line_item with product stock
......@@ -23,7 +22,7 @@ class LineItem < ActiveRecord::Base
return false if quantity.blank? || product_id.blank?
change_square = quantity - quantity_was
if change_square > product.try(:stock)
self.errors.add(:quantity, "Product #{product.try(:title)} is not enough in stock")
errors.add(:quantity, "Product #{product.try(:title)} is not enough in stock")
return false
end
end
......
......@@ -8,18 +8,18 @@ class Order < ActiveRecord::Base
def recalculate
count = line_items.sum(:quantity)
self.update_attributes(
update_attributes(
item_count: count,
item_total: self.reload.line_items.inject(0) {|sum, item| sum + item.quantity*item.price }
item_total: self.reload.line_items.inject(0) { |sum, item| sum + item.quantity * item.price }
)
end
def checkout
pid = generate_token
self.update_attributes(state: Order.states[:checkout], pid: pid, completed_at: DateTime.now)
update_attributes(state: Order.states[:checkout], pid: generate_token, completed_at: DateTime.now)
end
private
def generate_token
loop do
random_token = SecureRandom.urlsafe_base64(nil, false)
......
......@@ -8,12 +8,12 @@ class Product < ActiveRecord::Base
# default 'public/images/product_default.jpg'
end
self.per_page = ENV["default_perpage"]
self.per_page = ENV['default_perpage']
validates :pid, :title, :price, :image, :category_id, :stock, :release_date, :public_date, presence: true
validates :pid, uniqueness: true
validates :price, numericality: true
validates_datetime :public_date, :on_or_after => :release_date
validates_datetime :public_date, on_or_after: :release_date
scope :recommend, -> { where(recommend: true) }
......@@ -22,7 +22,7 @@ class Product < ActiveRecord::Base
end
def substract_stock(change)
self.update_attributes(stock: stock - change)
update_attributes(stock: stock - change)
end
def solr_fields
......
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true
has_and_belongs_to_many :users, join_table: :users_roles
belongs_to :resource, polymorphic: true
validates :resource_type,
:inclusion => { :in => Rolify.resource_types },
:allow_nil => true
inclusion: { :in => Rolify.resource_types },
allow_nil: true
scopify
end
......@@ -12,22 +12,22 @@ class CartService
line_item = order.line_items.where(product_id: product.id, price: product.price).first_or_create
line_item.quantity += params[:quantity].to_i
if line_item.save
ResultMessage.new({ type: :notice, content: "Add to cart successfully"})
ResultMessage.new({ type: :notice, content: 'Add to cart successfully'})
else
ResultMessage.new({ type: :error, content: "Something went wrong"})
ResultMessage.new({ type: :error, content: 'Something went wrong'})
end
else
ResultMessage.new({ type: :error, content: "Product is not enough in stock"})
ResultMessage.new({ type: :error, content: 'Product is not enough in stock'})
end
end
def checkout
if order.line_items.blank?
ResultMessage.new({ type: :error, content: "Your cart is empty"})
ResultMessage.new({ type: :error, content: 'Your cart is empty'})
else
if order.checkout
UserMailer.success_checkout(order).deliver
ResultMessage.new({ type: :notice, content: "Checkout successfully"})
ResultMessage.new({ type: :notice, content: 'Checkout successfully'})
else
ResultMessage.new({ type: :error, content: "Checkout fail. #{order.errors.full_messages.join(', ')}"})
end
......@@ -36,7 +36,7 @@ class CartService
def update_cart(params)
if order.update_attributes(params)
ResultMessage.new({ type: :notice, content: "Update cart successfully"})
ResultMessage.new({ type: :notice, content: 'Update cart successfully'})
else
ResultMessage.new({ type: :error, content: "Update cart fail. #{order.errors.full_messages.join(', ')}"})
end
......
......@@ -12,7 +12,7 @@ class CronjobService
aws_object = vaccum.item_lookup(item_id: object.pid)
aws_object = vaccum.to_attr(aws_object)
if aws_object.present?
attributes = aws_object.select{|key, value| fields.include?(key.to_s) }
attributes = aws_object.select{ |key, value| fields.include?(key.to_s) }
object.update_attributes(attributes)
end
end
......
class VacuumAwsService
def initialize(options={})
@request = Vacuum.new(options.fetch(:country_code, "GB"))
@request = Vacuum.new(options.fetch(:country_code, 'GB'))
@request.configure(
aws_access_key_id: ENV['aws_access_key_id'],
aws_secret_access_key: ENV['aws_secret_access_key'],
......@@ -15,14 +15,12 @@ class VacuumAwsService
# search item by pid
def item_lookup(options={})
begin
response = request.item_lookup(
query: default_query_options.merge('ItemId' => options[:item_id])
)
parse_item(response)
response = request.item_lookup(
query: default_query_options.merge('ItemId' => options[:item_id])
)
parse_item(response)
rescue
nil
end
end
# search items
......@@ -32,46 +30,41 @@ class VacuumAwsService
end
def parse_items(response)
begin
response.to_h["ItemSearchResponse"]["Items"]["Item"]
response.to_h['ItemSearchResponse']['Items']['Item']
rescue
false
end
end
def parse_item(response)
begin
response.to_h["ItemLookupResponse"]["Items"]["Item"]
response.to_h['ItemLookupResponse']['Items']['Item']
rescue
nil
end
end
def to_attr(item)
# only get product have pid, title, price
if validate(item)
unless validate?(item)
{
pid: item["ASIN"],
title: item["ItemAttributes"]["Title"],
author: item["ItemAttributes"]["Author"],
publisher: item["ItemAttributes"]["Publisher"],
studio: item["ItemAttributes"]["Studio"],
price: item["ItemAttributes"]["ListPrice"]["FormattedPrice"][1..-1].to_f,
currency: item["ItemAttributes"]["ListPrice"]["FormattedPrice"].to_s.first,
release_date: ::DateTime.rstrptime(item["ItemAttributes"]["ReleaseDate"], "%Y-%m-%d"),
public_date: ::DateTime.rstrptime(item["ItemAttributes"]["PublicationDate"], "%Y-%m-%d"),
image_url: item["LargeImage"]["URL"]
pid: item['ASIN'],
title: item['ItemAttributes']['Title'],
author: item['ItemAttributes']['Author'],
publisher: item['ItemAttributes']['Publisher'],
studio: item['ItemAttributes']['Studio'],
price: item['ItemAttributes']['ListPrice']['FormattedPrice'][1..-1].to_f,
currency: item['ItemAttributes']['ListPrice']['FormattedPrice'].to_s.first,
release_date: ::DateTime.rstrptime(item['ItemAttributes']['ReleaseDate'], '%Y-%m-%d'),
public_date: ::DateTime.rstrptime(item['ItemAttributes']['PublicationDate'], '%Y-%m-%d'),
image_url: item['LargeImage']['URL']
}
end
end
private
def validate(item)
item.present? && item["ASIN"].present? &&
item["ItemAttributes"]["Title"].present? &&
item["ItemAttributes"]["ListPrice"].present? &&
item["LargeImage"].present?
def validate?(item)
item.present? && item['ASIN'].present? &&
item['ItemAttributes']['Title'].present? &&
item['ItemAttributes']['ListPrice'].present? &&
item['LargeImage'].present?
end
end
#categories
- if @products.present?
.products
= render partial: "products/item", collection: @products, as: :product
= render partial: 'products/item', collection: @products, as: :product
.text-center
= will_paginate @products
\ No newline at end of file
......@@ -2,9 +2,9 @@
- if current_order.line_items.blank?
.text-center
'You cart is empty.
= link_to "Continue shopping", root_path
= link_to 'Continue shopping', root_path
- else
= form_for current_order, html:{ class: "form-horizontal" } do |f|
= form_for current_order, html:{ class: 'form-horizontal' } do |f|
#error_explanation
- current_order.line_items.each do |i|
- if i.errors.any?
......@@ -29,7 +29,7 @@
td= i.index+1
td= i.object.product.title
td
= i.number_field :quantity, class: "form-control item-quantity", min: 1
= i.number_field :quantity, class: 'form-control item-quantity', min: 1
span= "(available: #{i.object.product.stock})"
td
span.item-price= i.object.price
......@@ -46,13 +46,13 @@
span.total-cart= current_order.item_total
span= current_order.line_items.first.try(:product).try(:currency)
td
= f.submit "Update Cart", class: "btn btn-primary"
= f.submit 'Update Cart', class: 'btn btn-primary'
tr
td(colspan=5)
td
.text-center
= link_to "Checkout", checkout_orders_path, class: "btn btn-success btn-lg"
= link_to 'Checkout', checkout_orders_path, class: 'btn btn-success btn-lg'
br
i
'(You must update change before checkout cart)
\ No newline at end of file
- if @recommend_products.present?
h3 Recommend Products
.row.recommends
= render partial: "products/recommend_item", collection: @recommend_products, as: :product
= render partial: 'products/recommend_item', collection: @recommend_products, as: :product
hr
- if @products.present?
.products
h3 Products
= render partial: "products/item", collection: @products, as: :product
= render partial: 'products/item', collection: @products, as: :product
.text-center
= will_paginate @products
\ No newline at end of file
h4= "Search with keyword '#{params[:keyword]}'"
- if @products.present?
.products
= render partial: "products/item", collection: @products, as: :product
= render partial: 'products/item', collection: @products, as: :product
.text-center
= will_paginate @solr_products
\ No newline at end of file
nav.navbar.navbar-inverse
.container
.navbar-header
button.navbar-toggle[type="button" data-toggle="collapse" data-target=".navbar-collapse"]
button.navbar-toggle[type='button' data-toggle='collapse' data-target='.navbar-collapse']
span.sr-only
| Toggle navigation
span.icon-bar
......@@ -9,7 +9,7 @@ nav.navbar.navbar-inverse
span.icon-bar
h1.logo
a(href="#{root_path}" class='navbar-brand')
= image_tag "logo.png"
= image_tag 'logo.png'
'Venshop
.collapse.navbar-collapse
ul.nav.navbar-nav
......@@ -22,9 +22,9 @@ nav.navbar.navbar-inverse
li
= current_user.decorate.edit_profile_link
li
= link_to "Logout", destroy_user_session_path, method: 'delete'
= link_to 'Logout', destroy_user_session_path, method: 'delete'
- else
li
= link_to "Login", new_user_session_path
= link_to 'Login', new_user_session_path
li
= link_to "Sign up", new_user_registration_path
\ No newline at end of file
= link_to 'Sign up', new_user_registration_path
\ No newline at end of file
- if policy(:product).new?
li= link_to "New product", new_product_path
li= link_to 'New product', new_product_path
- if current_user.present?
li= link_to "My orders", orders_path
li= link_to 'My orders', orders_path
doctype html
html
head
meta[name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"]
meta[name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no']
title
= @title || "Venshop"
= @title || 'Venshop'
= favicon_link_tag 'favicon.ico'
= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png'
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags
body
#wrap
......
doctype html
html
head
meta[name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"]
meta[name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no']
title
= @title || "Venshop"
= @title || 'Venshop'
= favicon_link_tag 'favicon.ico'
= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png'
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags
body
#wrap
......
doctype html
html
head
meta[name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"]
meta[name='viewport' content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no']
title
= @title || "Venshop"
= @title || 'Venshop'
= favicon_link_tag 'favicon.ico'
= favicon_link_tag 'apple-touch-icon.png', rel: 'apple-touch-icon', type: 'image/png'
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true
= javascript_include_tag 'application', 'data-turbolinks-track' => true
= csrf_meta_tags
body
#wrap
......
.product-form
= form_for @product, html:{class: "form-horizontal"} do |f|
= form_for @product, html:{ class: 'form-horizontal' } do |f|
- if @product.errors.any?
#error_explanation
h3= "#{pluralize(@product.errors.count, "error")} prohibited this product from being saved:"
h3= "#{pluralize(@product.errors.count, 'error')} prohibited this product from being saved:"
ul
- @product.errors.full_messages.each do |msg|
li= msg
= f.hidden_field :currency, value: '£'
.form-group
= f.label :pid, class:"control-label col-sm-3"
= f.label :pid, class:'control-label col-sm-3'
.col-sm-9
= f.text_field :pid, class: "form-control"
= f.text_field :pid, class: 'form-control'
.form-group
= f.label :title, class:"control-label col-sm-3"
= f.label :title, class:'control-label col-sm-3'
.col-sm-9
= f.text_field :title, class: "form-control"
= f.text_field :title, class: 'form-control'
.form-group
= f.label :stock, class:"control-label col-sm-3"
= f.label :stock, class:'control-label col-sm-3'
.col-sm-9
= f.number_field :stock, class: "form-control"
= f.number_field :stock, class: 'form-control'
.form-group
= f.label :author, class:"control-label col-sm-3"
= f.label :author, class:'control-label col-sm-3'
.col-sm-9
= f.text_field :author, class: "form-control"
= f.text_field :author, class: 'form-control'
.form-group
= f.label :publisher, class:"control-label col-sm-3"
= f.label :publisher, class:'control-label col-sm-3'
.col-sm-9
= f.text_field :publisher, class: "form-control"
= f.text_field :publisher, class: 'form-control'
.form-group
= f.label :studio, class:"control-label col-sm-3"
= f.label :studio, class:'control-label col-sm-3'
.col-sm-9
= f.text_field :studio, class: "form-control"
= f.text_field :studio, class: 'form-control'
.form-group
= f.label :price, class:"control-label col-sm-3"
= f.label :price, class:'control-label col-sm-3'
.col-sm-9
= f.number_field :price, class: "form-control"
= f.number_field :price, class: 'form-control'
.form-group
= f.label :category_id, class:"control-label col-sm-3"
= f.label :category_id, class:'control-label col-sm-3'
.col-sm-9
= f.select :category_id, options_for_select(categories_options, @product.category_id), {}, class: "form-control"
= f.select :category_id, options_for_select(categories_options, @product.category_id), {}, class: 'form-control'
.form-group
= f.label "Image", class:"control-label col-sm-3", for: "product_image"
= f.label 'Image', class:'control-label col-sm-3', for: 'product_image'
.col-sm-9
- if !@product.new_record? && @product.image.present?
= image_tag @product.image.thumb('200x200#')
= f.file_field :image
.form-group
= f.label :release_date, class:"control-label col-sm-3"
= f.label :release_date, class:'control-label col-sm-3'
.col-sm-9
.input-group.date.datetimepicker
input(type='text' class="form-control" name="product[release_date]")
input(type='text' class='form-control' name='product[release_date]')
span.input-group-addon
span.glyphicon.glyphicon-calendar
.form-group
= f.label :public_date, class:"control-label col-sm-3"
= f.label :public_date, class:'control-label col-sm-3'
.col-sm-9
.input-group.date.datetimepicker
input(type='text' class="form-control" name="product[public_date]")
input(type='text' class='form-control' name='product[public_date]')
span.input-group-addon
span.glyphicon.glyphicon-calendar
.form-group
= f.label :recommend, class:"control-label col-sm-3"
= f.label :recommend, class:'control-label col-sm-3'
.col-sm-9
.checkbox
= f.check_box :recommend, class:'mar-l-0'
.form-group
.col-sm-offset-3.col-sm-9
= f.submit "Save", class: "btn btn-primary"
= f.submit 'Save', class: 'btn btn-primary'
h1 New Product
= render "form"
\ No newline at end of file
= render 'form'
\ No newline at end of file
script(type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-55af38b64560cb34" async="async")
script(type='text/javascript' src='//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-55af38b64560cb34' async='async')
#product
h4= @product.title
= image_tag @product.image.thumb("110x86#").url
= image_tag @product.image.thumb('110x86#').url
.content
p= "Item ID: #{@product.pid}"
p= "Price #{currency_number(@product.price, @product.currency)}"
......@@ -12,10 +12,10 @@ script(type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pub
p= "Publisher: #{@product.publisher}"
p= "Studio: #{@product.studio}"
p= "Stock: #{@product.stock}"
= form_tag add_to_cart_orders_path, class: "form-inline" do |f|
= form_tag add_to_cart_orders_path, class: 'form-inline' do |f|
.form-group
= number_field_tag :quantity, 1, class: "form-control"
= number_field_tag :quantity, 1, class: 'form-control'
= hidden_field_tag :product_id, @product.id
= submit_tag "Add to cart", class: "btn btn-primary xs-mar-top-10"
= submit_tag 'Add to cart', class: 'btn btn-primary xs-mar-top-10'
.mar-top-20
.addthis_native_toolbox
\ No newline at end of file
- flash.each do |name, msg|
- if msg.is_a?(String)
.alert(class="alert-#{name == 'notice' ? 'success' : 'danger'}")
button.close(data-dismiss="alert" aria-hidden="true")&times;
button.close(data-dismiss='alert' aria-hidden='true')&times;
= content_tag :div, msg, :id => "flash_#{name}"
#search-bar
= form_tag search_path, class: "form-horizontal", method: "GET" do |f|
= form_tag search_path, class: 'form-horizontal', method: 'GET' do |f|
.row
.col-sm-10.col-xs-8
= text_field_tag :keyword, params[:keyword], placeholder: "Keyword", class: "form-control"
= text_field_tag :keyword, params[:keyword], placeholder: 'Keyword', class: 'form-control'
.col-sm-2.col-xs-4
= submit_tag "Search", class: "btn btn-primary"
= submit_tag 'Search', class: 'btn btn-primary'
......@@ -7,5 +7,5 @@ h2
br
= f.email_field :email, autofocus: true
.actions
= f.submit "Resend confirmation instructions"
= render "users/shared/links"
= f.submit 'Resend confirmation instructions'
= render 'users/shared/links'
......@@ -4,13 +4,13 @@ h2
= devise_error_messages!
= f.hidden_field :reset_password_token
.field
= f.label :password, "New password"
= f.label :password, 'New password'
br
= f.password_field :password, autofocus: true, autocomplete: "off"
= f.password_field :password, autofocus: true, autocomplete: 'off'
.field
= f.label :password_confirmation, "Confirm new password"
= f.label :password_confirmation, 'Confirm new password'
br
= f.password_field :password_confirmation, autocomplete: "off"
= f.password_field :password_confirmation, autocomplete: 'off'
.actions
= f.submit "Change my password"
= render "users/shared/links"
= f.submit 'Change my password'
= render 'users/shared/links'
......@@ -7,5 +7,5 @@ h2
br
= f.email_field :email, autofocus: true
.actions
= f.submit "Send me reset password instructions"
= render "users/shared/links"
= f.submit 'Send me reset password instructions'
= render 'users/shared/links'
.form-devise
h2
| Edit
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class:"form-horizontal" }) do |f|
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class:'form-horizontal' }) do |f|
.col-sm-offset-3.col-sm-9
= devise_error_messages!
.form-group
= f.label :name, class: "control-label col-sm-3"
= f.label :name, class: 'control-label col-sm-3'
.col-sm-9
= f.text_field :name, autofocus: true, class: "form-control"
= f.text_field :name, autofocus: true, class: 'form-control'
.form-group
= f.label :email, class: "control-label col-sm-3"
= f.label :email, class: 'control-label col-sm-3'
.col-sm-9
= f.email_field :email, class: "form-control"
= f.email_field :email, class: 'form-control'
- if devise_mapping.confirmable? && resource.pending_reconfirmation?
div
| Currently waiting confirmation for:
= resource.unconfirmed_email
.form-group
= f.label :password, class: "control-label col-sm-3"
= f.label :password, class: 'control-label col-sm-3'
.col-sm-9
= f.password_field :password, autocomplete: "off", class: "form-control"
= f.password_field :password, autocomplete: 'off', class: 'form-control'
i
| (leave blank if you don't want to change it)
.form-group
= f.label :password_confirmation, class: "control-label col-sm-3"
= f.label :password_confirmation, class: 'control-label col-sm-3'
.col-sm-9
= f.password_field :password_confirmation, autocomplete: "off", class: "form-control"
= f.password_field :password_confirmation, autocomplete: 'off', class: 'form-control'
.form-group
= f.label :current_password, class: "control-label col-sm-3"
= f.label :current_password, class: 'control-label col-sm-3'
.col-sm-9
= f.password_field :current_password, autocomplete: "off", class: "form-control"
= f.password_field :current_password, autocomplete: 'off', class: 'form-control'
i
| (we need your current password to confirm your changes)
.form-group
.col-sm-offset-3.col-sm-9
= f.submit "Update", class: "btn btn-primary"
= f.submit 'Update', class: 'btn btn-primary'
.form-devise
h2
| Sign up
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class:"form-horizontal" }) do |f|
= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class:'form-horizontal' }) do |f|
.col-sm-offset-3.col-sm-9
= devise_error_messages!
.form-group
= f.label :name, class: "control-label col-sm-3"
= f.label :name, class: 'control-label col-sm-3'
.col-sm-9
= f.text_field :name, autofocus: true, class: "form-control"
= f.text_field :name, autofocus: true, class: 'form-control'
.form-group
= f.label :email, class: "control-label col-sm-3"
= f.label :email, class: 'control-label col-sm-3'
.col-sm-9
= f.email_field :email, class: "form-control"
= f.email_field :email, class: 'form-control'
.form-group
= f.label :password, class: "control-label col-sm-3"
= f.label :password, class: 'control-label col-sm-3'
.col-sm-9
= f.password_field :password, autocomplete: "off", class: "form-control"
= f.password_field :password, autocomplete: 'off', class: 'form-control'
- if @validatable
em
| (
......@@ -31,7 +31,7 @@
.form-group
.col-sm-offset-3.col-sm-9
= f.submit "Sign up", class: "btn btn-primary"
= f.submit 'Sign up', class: 'btn btn-primary'
.clearfix
br
= render "users/shared/links"
= render 'users/shared/links'
.form-devise
h2
| Log in
= form_for(resource, as: resource_name, url: session_path(resource_name), html: { class:"form-horizontal" }) do |f|
= form_for(resource, as: resource_name, url: session_path(resource_name), html: { class:'form-horizontal' }) do |f|
.form-group
= f.label :email, class: "control-label col-sm-3"
= f.label :email, class: 'control-label col-sm-3'
.col-sm-9
= f.email_field :email, autofocus: true, class: "form-control"
= f.email_field :email, autofocus: true, class: 'form-control'
.form-group
= f.label :password, class: "control-label col-sm-3"
= f.label :password, class: 'control-label col-sm-3'
.col-sm-9
= f.password_field :password, autocomplete: "off", class: "form-control"
= f.password_field :password, autocomplete: 'off', class: 'form-control'
- if devise_mapping.rememberable?
.form-group
.col-sm-offset-3.col-sm-9
......@@ -20,7 +20,7 @@
.form-group
.col-sm-offset-3.col-sm-9
= f.submit "Log in", class: "btn btn-primary"
= f.submit 'Log in', class: 'btn btn-primary'
.clearfix
br
= render "users/shared/links"
= render 'users/shared/links'
- if controller_name != 'sessions'
= link_to "Log in", new_session_path(resource_name)
= link_to 'Log in', new_session_path(resource_name)
br
- if devise_mapping.registerable? && controller_name != 'registrations'
= link_to "Sign up", new_registration_path(resource_name)
= link_to 'Sign up', new_registration_path(resource_name)
br
-#- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations'
-# = link_to "Forgot your password?", new_password_path(resource_name)
......
......@@ -7,5 +7,5 @@ h2
br
= f.email_field :email, autofocus: true
.actions
= f.submit "Resend unlock instructions"
= render "users/shared/links"
= f.submit 'Resend unlock instructions'
= render 'users/shared/links'
class HardWorker
include Sidekiq::Worker
def perform
puts "It 's work"
end
end
\ No newline at end of file
......@@ -24,7 +24,7 @@ module VenShop
# Do not swallow errors in after_commit/after_rollback callbacks.
config.active_record.raise_in_transactional_callbacks = true
config.autoload_paths += %W(#{config.root}/app/services #{config.root}/lib)
config.autoload_paths += %W(#{config.root}/app/services #{config.root}/app/workers #{config.root}/lib)
config.to_prepare do
Dir.glob(File.join(File.dirname(__FILE__), "../app/core_extensions/*_extension.rb")) do |c|
# Rails.configuration.cache_classes ? require(c) : load(c)
......
aws_access_key_id: "AKIAIAJR65JO6EIPQWTA"
aws_secret_access_key: "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"
associate_tag: "microv"
aws_access_key_id: 'AKIAIAJR65JO6EIPQWTA'
aws_secret_access_key: '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'
associate_tag: 'microv'
solr_url: "http://tomcat:tomcat@localhost:8080/solr/venshop"
solr_url: 'http://tomcat:tomcat@localhost:8080/solr/venshop'
default_perpage: 5
default_send_mail: "no-reply@venshop.com"
default_send_mail: 'no-reply@venshop.com'
......@@ -4,7 +4,7 @@ lock '3.1.0'
require "whenever/capistrano"
set :application, 'dieutb_venshop'
set :branch, "dev"
set :branch, "feature-refactor"
set :repo_url, 'git@gitlab.zigexn.vn:dieutb/VenShop.git'
set :whenever_command, "bundle exec whenever"
......
......@@ -6,7 +6,7 @@
# Example:
#
set :output, 'log/cron.log'
set :environment, "production"
set :environment, 'production'
every 1.hours do
runner "CronjobService.new({klass: Product}).update(%w(price))"
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :role do
end
end
require 'rails_helper'
RSpec.describe Role, :type => :model do
pending "add some examples to (or delete) #{__FILE__}"
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