comable-frontend 0.7.0.beta1 → 0.7.0.beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bd8d3056a1d712053111167dc1077011461824ac
4
- data.tar.gz: 533909155a352a26e60ec64901310c293d8b72d3
3
+ metadata.gz: 870c952f33ce77fec8cdafb0871f58345024231e
4
+ data.tar.gz: 511e035e802ae57a27106f3d8477f4eb172723be
5
5
  SHA512:
6
- metadata.gz: c866da507485e1170c6f21354a07e07bcc6f79e3c110d2da26a130814dcee10629f0f95e37c6c94c08eb266e92d6cbac7969e501ee4b3bbb50a1c634ebdb8317
7
- data.tar.gz: 6def5925e8c1e1ba5a8817296f9d4061e66c1075fd9cc6792ee007d1b1ea6c95e3f984f831a505b8e00a9f707e3b57612c3cf0fa79931ca64e03e3c3573b3d9c
6
+ metadata.gz: 1a058efa161f9a0bedb9d9c829e95285ab6ed4931d75dff22784b1a45446bb9f59304937d66829cfb2c619d219d4cdebb5697d3de3b7011bc2dc7dc7ddeee751
7
+ data.tar.gz: a1175f75f112243e600e0200de8b54a1d9e49163e12fd2dfcfd0ddc243b538faa67934acb772b966af4489f46a1dc41e5e0950ecfc80a360ef5849ff37d15138
data/Rakefile CHANGED
@@ -4,6 +4,7 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
+ require 'rspec/core/rake_task'
7
8
  require 'rdoc/task'
8
9
 
9
10
  RDoc::Task.new(:rdoc) do |rdoc|
@@ -69,9 +70,9 @@ if File.exist?('comable.gemspec')
69
70
  end
70
71
  end
71
72
 
72
- task default: ['app:spec:all', 'rubocop', 'brakeman:all']
73
+ task default: ['app:spec:all', 'jasmine', 'rubocop', 'brakeman:all']
73
74
  else
74
- task default: ['app:spec', 'rubocop', 'brakeman']
75
+ task default: ['app:spec', 'jasmine', 'rubocop', 'brakeman']
75
76
  end
76
77
 
77
78
  Bundler::GemHelper.install_tasks
@@ -79,6 +80,10 @@ Bundler::GemHelper.install_tasks
79
80
  # from https://github.com/rspec/rspec-rails/issues/936
80
81
  task 'test:prepare'
81
82
 
83
+ task :jasmine do
84
+ sh 'bundle exec rake app:spec:javascript RAILS_ENV=test'
85
+ end
86
+
82
87
  task :rubocop do
83
88
  sh 'rubocop'
84
89
  end
@@ -2,4 +2,7 @@
2
2
  #= require jquery_ujs
3
3
  #= require jquery-ui
4
4
  #= require bootstrap-sprockets
5
- #= require_tree
5
+ #= require comable/frontend/dispatcher
6
+ #= require comable/frontend/module
7
+ #= require_tree .
8
+ #= require_self
@@ -0,0 +1,19 @@
1
+ $(->
2
+ new Dispatcher
3
+ )
4
+
5
+ class Dispatcher
6
+ constructor: ->
7
+ @initialize_page_scripts()
8
+
9
+ initialize_page_scripts: ->
10
+ page = $('body').attr('data-page')
11
+ return false unless page
12
+
13
+ path = page.split(':')
14
+ contoller_name = path[0]
15
+ action_name = path[1]
16
+
17
+ switch page
18
+ when 'products:show'
19
+ new VariantSelector
@@ -0,0 +1,28 @@
1
+ @Comable = {}
2
+
3
+ # TODO: Move to comable-core
4
+ # Based on https://arcturo.github.io/library/coffeescript/03_classes.html
5
+ class Comable.Module
6
+ moduleKeywords = ['extended', 'included']
7
+
8
+ @extend: (obj) ->
9
+ for key, value of obj when key not in moduleKeywords
10
+ @[key] = value
11
+ obj.extended?.apply(@)
12
+ this
13
+
14
+ @include: (obj) ->
15
+ for key, value of obj when key not in moduleKeywords
16
+ # Assign properties to the prototype
17
+ @::[key] = value
18
+ obj.included?.apply(@)
19
+ this
20
+
21
+ Comable.helpers =
22
+ numberWithDelimiter: (number, delimiter = ',') ->
23
+ numbers = number.toString().split('.')
24
+ integers = numbers[0]
25
+ decimals = if numbers.length > 1 then '.' + numbers[1] else ''
26
+ pattern = /(\d+)(\d{3})/
27
+ integers = integers.replace(pattern, '$1' + delimiter + '$2') while pattern.test(integers)
28
+ integers + decimals
@@ -0,0 +1,90 @@
1
+ class @VariantSelector
2
+ class: VariantSelector
3
+
4
+ @setProduct: (productJson) ->
5
+ @variants = productJson.variants
6
+
7
+ constructor: ->
8
+ @setSelectors()
9
+ @selectVariant()
10
+ @$optionSelector.on('change', => @selectVariant())
11
+
12
+ setSelectors: ->
13
+ @$optionSelector = $('[name="option_values[]"]')
14
+ @$variantSelector = $('[name="variant_id"]')
15
+
16
+ selectVariant: ->
17
+ return unless @class.variants
18
+ options = @getSelectedOptions()
19
+ variant = @getVariant(options)
20
+ @resetVariantSelector(variant && variant.id)
21
+ new ProductPage(variant)
22
+
23
+ getVariant: (optionValues) ->
24
+ matchedVariant = null
25
+ $.each(@class.variants, (_, variant) =>
26
+ matched = true
27
+ $.each(variant.options, (index, option) =>
28
+ return matched = false if option != optionValues[index]
29
+ )
30
+ matchedVariant = variant if matched
31
+ return !matched
32
+ )
33
+ matchedVariant
34
+
35
+ getSelectedOptions: ->
36
+ @$optionSelector.find(':selected').map( ->
37
+ $(this).text()
38
+ )
39
+
40
+ resetVariantSelector: (id = null) ->
41
+ @$variantSelector.find(':selected').each(
42
+ -> $(this).prop('selected', false)
43
+ )
44
+ @$variantSelector.find('[value="' + id + '"]').prop('selected', true) if id
45
+
46
+ class @ProductPage extends Comable.Module
47
+ @include Comable.helpers
48
+
49
+ # TODO: Get translations from Rails
50
+ translations: {
51
+ add_to_cart: 'カートに入れる'
52
+ sold_out: '品切れ'
53
+ currency_format: '%{number}円'
54
+ }
55
+
56
+ constructor: (variant) ->
57
+ @variant = variant
58
+ @setSelectors()
59
+ @changeProductInfomations()
60
+
61
+ setSelectors: ->
62
+ @$productPrice = $('#comable-product .price')
63
+ @$cartForm = $('#comable-product form')
64
+ @$cartFormSubmit = @$cartForm.find('input[type="submit"]')
65
+
66
+ changeProductInfomations: ->
67
+ @changeProductPrice()
68
+ @changeCartForm()
69
+
70
+ changeProductPrice: ->
71
+ return unless @variant
72
+ currency = @numberToCurrency(@variant.price)
73
+ @$productPrice.text(currency)
74
+
75
+ changeCartForm: ->
76
+ return @disableCartFormSubmit() unless @variant
77
+ return @disableCartFormSubmit() if @variant.quantity <= 0
78
+ @enableCartFormSubmit()
79
+
80
+ enableCartFormSubmit: ->
81
+ @$cartFormSubmit.prop('disabled', false)
82
+ @$cartFormSubmit.val(@translations.add_to_cart)
83
+
84
+ disableCartFormSubmit: ->
85
+ @$cartFormSubmit.prop('disabled', true)
86
+ @$cartFormSubmit.val(@translations.sold_out)
87
+
88
+ numberToCurrency: (number) ->
89
+ numberLabel = @numberWithDelimiter(number)
90
+ @translations.currency_format.replace(/%{number}/, numberLabel)
@@ -0,0 +1,3 @@
1
+ .property {
2
+ margin-top: 10px;
3
+ }
@@ -2,6 +2,7 @@ module Comable
2
2
  class CartsController < Comable::ApplicationController
3
3
  before_filter :set_cart_item, only: [:add, :update, :destroy]
4
4
  before_filter :ensure_found_cart_item, only: [:add, :update, :destroy]
5
+ after_filter :reset_shipments, only: [:add, :update, :destroy], if: -> { current_order.shipments.any? }
5
6
 
6
7
  def add
7
8
  if current_comable_user.add_cart_item(@cart_item, cart_item_options)
@@ -47,24 +48,23 @@ module Comable
47
48
  end
48
49
 
49
50
  def find_cart_item
50
- cart_item = Comable::Stock.where(id: params[:stock_id]).first
51
- cart_item ||= find_variant
52
- cart_item ||= Comable::Product.where(id: params[:product_id]).first
51
+ cart_item = Comable::Stock.find_by(id: params[:stock_id])
52
+ cart_item ||= Comable::Variant.find_by(id: params[:variant_id])
53
+ cart_item ||= Comable::Product.find_by(id: params[:product_id])
53
54
  return unless cart_item
54
55
  return if cart_item.is_a?(Comable::Product) && cart_item.sku?
55
56
  cart_item
56
57
  end
57
58
 
58
- def find_variant
59
- Comable::Variant.joins(:option_values).where(
60
- Comable::OptionValue.table_name => { id: params[:option_values] }
61
- ).first
62
- end
63
-
64
59
  def cart_item_options
65
60
  options = {}
66
61
  options.update(quantity: params[:quantity].to_i) if params[:quantity]
67
62
  options
68
63
  end
64
+
65
+ def reset_shipments
66
+ current_order.reset_shipments
67
+ current_order.update!(state: 'cart')
68
+ end
69
69
  end
70
70
  end
@@ -55,7 +55,7 @@ module Comable
55
55
  end
56
56
 
57
57
  def ensure_saleable_stocks
58
- return if current_order.stocked_items.empty?
58
+ return if current_order.unstocked_items.empty?
59
59
  flash[:alert] = Comable.t('errors.messages.out_of_stocks')
60
60
  redirect_to comable.cart_path
61
61
  end
@@ -7,7 +7,8 @@ module Comable
7
7
  end
8
8
 
9
9
  def show
10
- @product = preview? ? Comable::Product.find(params[:id]) : Comable::Product.published.find(params[:id])
10
+ products = Comable::Product.includes(:variants)
11
+ @product = preview? ? products.find(params[:id]) : products.published.find(params[:id])
11
12
  end
12
13
 
13
14
  private
@@ -10,7 +10,7 @@ module Comable
10
10
 
11
11
  def order_params_for_shipment
12
12
  params.fetch(:order, {}).permit(
13
- shipment_attributes: [:shipment_method_id]
13
+ shipments_attributes: [:id, :shipment_method_id]
14
14
  )
15
15
  end
16
16
  end
@@ -22,12 +22,14 @@
22
22
  = @order.class.human_attribute_name(:payment_method)
23
23
  = @order.payment.name
24
24
 
25
- - if @order.shipment
25
+ - if @order.shipments.any?
26
26
  .row
27
27
  .col-sm-12.comable-shipment
28
28
  h2
29
29
  = @order.class.human_attribute_name(:shipment_method)
30
- = @order.shipment.name
30
+ - @order.shipments.each.with_index(1) do |shipment, index|
31
+ p
32
+ | ##{index} #{shipment.name}
31
33
 
32
34
  .row
33
35
  .col-sm-12.comable-order_items
@@ -4,12 +4,35 @@
4
4
  = @order.class.human_state_name(:shipment)
5
5
 
6
6
  = form_for @order, as: :order, url: update_order_path, method: :put do |f|
7
- - shipment = @order.shipment || @order.build_shipment
8
- = f.fields_for :shipment, shipment do |ff|
9
- ul
10
- - Comable::ShipmentMethod.activated.each.with_index do |shipment_method, index|
11
- li
12
- - checked_flag = shipment.shipment_method ? (shipment.shipment_method == shipment_method) : index.zero?
13
- = ff.radio_button :shipment_method_id, shipment_method.id, checked: checked_flag
14
- = ff.label :shipment_method_id, shipment_method.name, value: shipment_method.id
7
+ - @order.shipments.build if @order.shipments.empty?
8
+ = f.fields_for :shipments, @order.shipments do |ff|
9
+ .panel.panel-default
10
+ .panel-heading
11
+ | 発送 ##{ff.index.next}
12
+ ul.list-group
13
+ - Comable::ShipmentMethod.activated.each.with_index do |shipment_method, index|
14
+ li.list-group-item
15
+ - checked_flag = ff.object.shipment_method ? (ff.object.shipment_method == shipment_method) : index.zero?
16
+ = ff.radio_button :shipment_method_id, shipment_method.id, checked: checked_flag
17
+ | &nbsp;
18
+ = ff.label :shipment_method_id, shipment_method.name, value: shipment_method.id
19
+ table
20
+ thead
21
+ tr
22
+ th
23
+ = Comable.t('products')
24
+ th
25
+ = Comable.t('price')
26
+ th
27
+ = Comable.t('quantity')
28
+ tbody
29
+ - ff.object.shipment_items.group_by(&:stock).each_pair do |stock, shipment_items|
30
+ tr
31
+ td
32
+ = stock.name
33
+ td
34
+ = number_to_currency stock.price
35
+ td
36
+ = number_with_delimiter shipment_items.size
37
+
15
38
  = f.submit Comable.t('next_step')
@@ -30,6 +30,13 @@
30
30
  = @product.caption
31
31
  .price
32
32
  = number_to_currency @product.price
33
+ - if @product.properties.any?(&:present?)
34
+ .property
35
+ table.table.table-bordered
36
+ - @product.properties.each do |property|
37
+ tr
38
+ td= property['property_key']
39
+ td= property['property_value']
33
40
 
34
41
  = form_tag comable.add_cart_path do
35
42
  - if @product.sku?
@@ -39,6 +46,11 @@
39
46
  = option_type.name
40
47
  = select_tag "option_values[]", options_for_select(option_values.map { |o| [o.name, o.id] }), id: "option_values_#{index}"
41
48
 
49
+ #variant-selector.hidden
50
+ = select_tag 'variant_id', options_for_select(@product.variants.map { |v| [v.name, v.id] }), include_blank: true
51
+ javascript:
52
+ VariantSelector.setProduct(#{@product.to_json.html_safe});
53
+
42
54
  - if @product.stocked?
43
55
  .add_cart.form-inline.form-group
44
56
  = hidden_field_tag :product_id, @product.id
@@ -52,7 +52,7 @@
52
52
  = form_tag comable.add_cart_path do
53
53
  - if order_item.stock.stocked?
54
54
  .add_cart.form-inline.form-group
55
- = hidden_field_tag :stock_id, order_item.stock_id
55
+ = hidden_field_tag :variant_id, order_item.variant_id
56
56
  = hidden_field_tag :quantity, order_item.quantity
57
57
  = submit_tag Comable.t('reorder'), class: 'btn btn-default'
58
58
 
@@ -18,7 +18,7 @@ html
18
18
  });
19
19
 
20
20
  - mini_header_flag = controller_name == 'orders' || devise_controller?
21
- body class="#{'comable-checkout-layout' if mini_header_flag}"
21
+ body class="#{'comable-checkout-layout' if mini_header_flag}" data-page="#{page_name}"
22
22
  = render 'comable/shared/tracker'
23
23
 
24
24
  - if mini_header_flag
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comable-frontend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.beta1
4
+ version: 0.7.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - YOSHIDA Hiroki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-25 00:00:00.000000000 Z
11
+ date: 2015-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: comable-core
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.0.beta1
19
+ version: 0.7.0.beta2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.0.beta1
26
+ version: 0.7.0.beta2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -258,6 +258,9 @@ files:
258
258
  - app/assets/images/comable/frontend/home-one.jpg
259
259
  - app/assets/images/comable/frontend/home-top.jpg
260
260
  - app/assets/javascripts/comable/frontend/application.coffee
261
+ - app/assets/javascripts/comable/frontend/dispatcher.coffee
262
+ - app/assets/javascripts/comable/frontend/module.coffee
263
+ - app/assets/javascripts/comable/frontend/products.coffee
261
264
  - app/assets/stylesheets/comable/frontend/application.scss
262
265
  - app/assets/stylesheets/comable/frontend/products.scss
263
266
  - app/assets/stylesheets/comable/products.scss
@@ -324,7 +327,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
324
327
  version: 1.3.1
325
328
  requirements: []
326
329
  rubyforge_project:
327
- rubygems_version: 2.2.2
330
+ rubygems_version: 2.4.5
328
331
  signing_key:
329
332
  specification_version: 4
330
333
  summary: Provide frontend functions for Comable.