comable_backend 0.3.3 → 0.3.4

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: 3e94beb188851f0e46828bfd1646cae7bb4e05f6
4
- data.tar.gz: a2d0d7d82a72830d474ad05002d6b2a4ee534929
3
+ metadata.gz: e0d5ce48da7e6b0b8a887a746cad4a75e4c31916
4
+ data.tar.gz: b22f25a4c7cbcdb0182651740c1736fcbb8aae04
5
5
  SHA512:
6
- metadata.gz: a5be16acf1bca4ee13335261547b9b6ca8c3272f1061b5014f8969d24979882bed37b5dfd2f63844a01c61839d172cae6c5fc261b45ea1b81857636270815fc6
7
- data.tar.gz: 4c6436f0ff47e42d5eb9ae467aef140a7e88166f0777a2c43e379b772c60c902dc61e252fd88ee3a76afa5e30cc13fbb1ee62f3d75fc24836f05a4348cd680b5
6
+ metadata.gz: 3da03ea18f27b7badb7c125d694f2ee471573f8a527edcb799618b88e3339ea65ef540f143dfccb452acae19a13476317ca2c563bcc80416aac0db0be12676f8
7
+ data.tar.gz: 24b68b045eb0abcc5ce41fafccb7d7cdfbeea15a7b9031e9812762e4e3410fe98f5403fe93a793739293863578f707939453eb499ae576df2b03d3f120a92d64
@@ -93,3 +93,26 @@ $( ->
93
93
 
94
94
  $('[data-toggle="tooltip"]').tooltip()
95
95
  )
96
+ # Place all the behaviors and hooks related to the matching controller here.
97
+ # All this logic will automatically be available in application.js.
98
+ # You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
99
+ class @Search
100
+ constructor: (@templates = {}) ->
101
+
102
+ remove_fields: (button) ->
103
+ $(button).closest('.fields').remove()
104
+
105
+ add_fields: (button, type, content) ->
106
+ new_id = new Date().getTime()
107
+ regexp = new RegExp('new_' + type, 'g')
108
+ $(button).before(content.replace(regexp, new_id))
109
+
110
+ nest_fields: (button, type) ->
111
+ new_id = new Date().getTime()
112
+ id_regexp = new RegExp('new_' + type, 'g')
113
+ template = @templates[type]
114
+ object_name = $(button).closest('.fields').attr('data-object-name')
115
+ sanitized_object_name = object_name.replace(/\]\[|[^-a-zA-Z0-9:.]/g, '_').replace(/_$/, '')
116
+ template = template.replace(/new_object_name\[/g, object_name + "[")
117
+ template = template.replace(/new_object_name_/, sanitized_object_name + '_')
118
+ $(button).before(template.replace(id_regexp, new_id))
@@ -262,3 +262,31 @@ footer {
262
262
  padding-top: 89px + 20px;
263
263
  }
264
264
  }
265
+
266
+
267
+ #comable-advanced-search {
268
+ margin-top: 10px;
269
+
270
+ fieldset > fieldset {
271
+ margin-bottom: 10px;
272
+ }
273
+
274
+ button.comable-remove-button {
275
+ @include appearance(none);
276
+ padding: 0;
277
+ cursor: pointer;
278
+ background: transparent;
279
+ border: 0;
280
+ height: $input-height-base;
281
+ outline: none;
282
+ }
283
+
284
+ .comable-remove-button {
285
+ @include text-shadow(0 1px 0 #fff);
286
+ @include opacity(0.2);
287
+ font-size: 16px;
288
+ font-weight: bold;
289
+ line-height: 1;
290
+ color: #000;
291
+ }
292
+ }
@@ -1,4 +1,3 @@
1
1
  @import 'comable/admin/overrides/bootstrap';
2
2
  @import 'comable/admin/overrides/jstree';
3
3
  @import 'comable/admin/overrides/tagit';
4
- @import 'comable/admin/overrides/pace';
@@ -39,6 +39,3 @@ $navbar-default-toggle-hover-bg: $navbar-default-link-hover-bg;
39
39
 
40
40
  // $panel-default-heading-bg: $comable-sidebar-bg;
41
41
  // $panel-default-border: $comable-sidebar-border;
42
-
43
- // pace
44
- $comable-pace: #fff;
@@ -7,8 +7,7 @@
7
7
  @import 'font-awesome';
8
8
  @import 'jquery-ui';
9
9
  @import 'morris';
10
- // TODO: https://github.com/yovu/pace-rails/issues/5
11
- // @import 'pace/pace-theme-minimal';
10
+ @import 'pace/white/pace-theme-minimal';
12
11
  @import 'gritter';
13
12
 
14
13
  @import 'comable/admin/mixins';
@@ -81,3 +81,7 @@ legend {
81
81
  table > tbody > tr > td > ul {
82
82
  margin-bottom: 0;
83
83
  }
84
+
85
+ .btn-link {
86
+ outline: none !important;
87
+ }
@@ -7,7 +7,7 @@ module Comable
7
7
 
8
8
  def index
9
9
  @q = Comable::Product.ransack(params[:q])
10
- @products = @q.result.includes(:stocks, :images).page(params[:page]).accessible_by(current_ability)
10
+ @products = @q.result(distinct: true).includes(:stocks, :images).page(params[:page]).accessible_by(current_ability)
11
11
  end
12
12
 
13
13
  def show
@@ -13,10 +13,41 @@ module Comable
13
13
  def link_to_add_fields(name, f, association, options = {})
14
14
  new_object = f.object.class.reflect_on_association(association).klass.new
15
15
  fields = f.fields_for(association, new_object, child_index: "new_#{association}") do |builder|
16
- render("#{association.to_s.singularize}_fields", ff: builder)
16
+ render("comable/admin/shared/#{association.to_s.singularize}_fields", ff: builder)
17
17
  end
18
18
  link_to(name, 'javascript:void(0)', options.merge(onclick: "add_fields(this, '#{association}', '#{escape_javascript(fields)}')"))
19
19
  end
20
+
21
+ def setup_search_form
22
+ render('comable/admin/shared/setup_search_form')
23
+ end
24
+
25
+ def button_to_remove_fields(name, options = {})
26
+ content_tag(:button, name, options.merge(class: "ransack remove_fields #{options[:class]}"))
27
+ end
28
+
29
+ def button_to_add_fields(name, f, type, options = {})
30
+ new_fields = build_fields(f, type)
31
+ content_tag(:button, name, options.merge(class: "ransack add_fields #{options[:class]}", 'data-field-type' => type, 'data-content' => "#{new_fields}"))
32
+ end
33
+
34
+ def build_fields(f, type)
35
+ new_object = f.object.send("build_#{type}")
36
+
37
+ f.send("#{type}_fields", new_object, child_index: "new_#{type}") do |builder|
38
+ render("comable/admin/shared/#{type}_fields", f: builder)
39
+ end
40
+ end
41
+
42
+ def enable_advanced_search?
43
+ grouping_params = params[:q][:g]
44
+ conditions_params = grouping_params.values.first[:c]
45
+ value_params = conditions_params.values.first[:v]
46
+
47
+ value_params.values.first[:value].present?
48
+ rescue NoMethodError
49
+ false
50
+ end
20
51
  end
21
52
  end
22
53
  end
@@ -13,8 +13,7 @@
13
13
  h1.page-header
14
14
  = Comable.t('admin.nav.customer')
15
15
  small<
16
- = @customers.total_count
17
- = Comable.t('admin.results')
16
+ | #{@customers.total_count} #{Comable.t('admin.results')}
18
17
 
19
18
  .comable-page-body
20
19
  .comable-search
@@ -25,12 +24,16 @@
25
24
  i.fa.fa-search
26
25
  span.caret<
27
26
  ul.dropdown-menu role="menu"
27
+ li
28
+ = link_to Comable.t('admin.advanced_search'), 'javascript:void(0)', 'data-toggle' => 'collapse', 'data-target' => '#comable-advanced-search'
28
29
  li
29
30
  = link_to Comable.t('admin.clear_search_conditions'), comable.admin_customers_path
30
31
  = f.text_field :email_cont, class: 'form-control'
31
32
  span.input-group-btn
32
33
  = f.submit Comable.t('admin.search'), class: 'btn btn-default'
33
34
 
35
+ = render 'comable/admin/shared/advanced_search', f: f
36
+
34
37
  section
35
38
  - if @customers.empty?
36
39
  = Comable.t('admin.not_found')
@@ -62,8 +65,7 @@
62
65
  span> = customer.bill_address.city
63
66
  span> = customer.bill_address.detail
64
67
  td
65
- = customer.orders.count
66
- = Comable.t('admin.times')
68
+ | #{customer.orders.count} #{Comable.t('admin.times')}
67
69
 
68
70
  .text-center
69
71
  = paginate @customers, theme: :comable_backend
@@ -13,8 +13,7 @@
13
13
  h1.page-header
14
14
  = Comable.t('admin.nav.order')
15
15
  small<
16
- = @orders.total_count
17
- = Comable.t('admin.results')
16
+ | #{@orders.total_count} #{Comable.t('admin.results')}
18
17
 
19
18
  .comable-page-body
20
19
  .comable-search
@@ -25,6 +24,8 @@
25
24
  i.fa.fa-search
26
25
  span.caret<
27
26
  ul.dropdown-menu role="menu"
27
+ li
28
+ = link_to Comable.t('admin.advanced_search'), 'javascript:void(0)', 'data-toggle' => 'collapse', 'data-target' => '#comable-advanced-search'
28
29
  li
29
30
  = link_to Comable.t('admin.clear_search_conditions'), comable.admin_orders_path
30
31
  = f.text_field :code_cont, class: 'form-control'
@@ -34,6 +35,8 @@
34
35
  = f.label :customer_id
35
36
  = f.text_field :customer_id_eq
36
37
 
38
+ = render 'comable/admin/shared/advanced_search', f: f
39
+
37
40
  section
38
41
  - if @orders.empty?
39
42
  = Comable.t('admin.not_found')
@@ -7,8 +7,7 @@
7
7
  h1.page-header
8
8
  = Comable.t('admin.nav.payment_method')
9
9
  small<
10
- = @payment_methods.total_count
11
- = Comable.t('admin.results')
10
+ | #{@payment_methods.total_count} #{Comable.t('admin.results')}
12
11
 
13
12
  .comable-page-body
14
13
  - if @payment_methods.empty?
@@ -147,7 +147,7 @@
147
147
  .row
148
148
  - sub_images.each.with_index(1) do |image, index|
149
149
  = f.fields_for :images, image do |ff|
150
- = render 'image_fields', ff: ff, index: index
150
+ = render 'comable/admin/shared/image_fields', ff: ff, index: index
151
151
 
152
152
  .col-sm-6
153
153
  = link_to_add_fields Comable.t('admin.add_sub_image'), f, :images
@@ -16,8 +16,7 @@
16
16
  h1.page-header
17
17
  = Comable.t('admin.nav.product')
18
18
  small<
19
- = @products.total_count
20
- = Comable.t('admin.results')
19
+ | #{@products.total_count} #{Comable.t('admin.results')}
21
20
 
22
21
  .comable-page-body
23
22
  .comable-search
@@ -28,12 +27,16 @@
28
27
  i.fa.fa-search
29
28
  span.caret<
30
29
  ul.dropdown-menu role="menu"
30
+ li
31
+ = link_to Comable.t('admin.advanced_search'), 'javascript:void(0)', 'data-toggle' => 'collapse', 'data-target' => '#comable-advanced-search'
31
32
  li
32
33
  = link_to Comable.t('admin.clear_search_conditions'), comable.admin_products_path
33
- = f.text_field :code_or_name_cont, class: 'form-control'
34
+ = f.text_field :code_or_name_cont_any_splitted, class: 'form-control'
34
35
  span.input-group-btn
35
36
  = f.submit Comable.t('admin.search'), class: 'btn btn-default'
36
37
 
38
+ = render 'comable/admin/shared/advanced_search', f: f
39
+
37
40
  section
38
41
  - if @products.empty?
39
42
  = Comable.t('admin.not_found')
@@ -48,7 +51,7 @@
48
51
  th
49
52
  = sort_link [:comable, @q], :price
50
53
  th
51
- = sort_link [:comable, @q], :stocks_quantity
54
+ = Comable.t('admin.stocks')
52
55
  tbody
53
56
  - @products.each do |product|
54
57
  - quantity = product.stocks.to_a.sum(&:quantity)
@@ -63,8 +66,14 @@
63
66
  td
64
67
  = number_to_currency product.price
65
68
  td
66
- strong class="#{(quantity <= 0) ? 'text-danger' : (quantity <= 10) ? 'text-warning' : 'text-success'}"
67
- = number_with_delimiter product.stocks.to_a.sum(&:quantity)
69
+ ul.list-unstyled
70
+ - product.stocks.each do |stock|
71
+ li
72
+ strong class="#{(quantity <= 0) ? 'text-danger' : (quantity <= 10) ? 'text-warning' : 'text-success'}"
73
+ = number_with_delimiter stock.quantity
74
+ - if stock.sku?
75
+ span<
76
+ | (#{stock.sku_name})
68
77
 
69
78
  .text-center
70
79
  = paginate @products, theme: :comable_backend
@@ -0,0 +1,8 @@
1
+ fieldset
2
+ .collapse#comable-advanced-search class="#{'in' if enable_advanced_search? }"
3
+ .well
4
+ = setup_search_form
5
+ = f.grouping_fields do |g|
6
+ = render 'comable/admin/shared/grouping_fields', f: g
7
+ - unless enable_advanced_search?
8
+ = build_fields f, :grouping
@@ -0,0 +1,15 @@
1
+ = content_tag :fieldset, { class: 'fields condition', 'data-object-name' => f.object_name } do
2
+ .row
3
+ .col-sm-2
4
+ = f.attribute_fields do |a|
5
+ - klass = f.object.context.object
6
+ - options = {}
7
+ - options = klass.ransack_options[:attribute_select] if klass.respond_to? :ransack_options
8
+ = content_tag(:span, a.attribute_select(options), { class: 'fields', 'data-object-name' => a.object_name }, false)
9
+ .col-sm-2
10
+ = f.predicate_select only: %i(gteq lteq eq_any_splitted cont_any_splitted), compounds: false
11
+ .col-sm-7
12
+ = f.value_fields do |v|
13
+ = render 'comable/admin/shared/value_fields', f: v
14
+ .col-sm-1.text-center
15
+ = button_to_remove_fields Comable.t('admin.remove_search_condition'), class: 'comable-remove-button'
@@ -0,0 +1,8 @@
1
+ = content_tag :fieldset, { class: 'fields', 'data-object-name' => f.object_name } do
2
+ = f.condition_fields do |c|
3
+ = render 'comable/admin/shared/condition_fields', f: c
4
+
5
+ - if f.object.conditions.empty?
6
+ = build_fields f, :condition
7
+
8
+ = button_to_add_fields Comable.t('admin.add_search_condition'), f, :condition, class: 'btn btn-link'
@@ -0,0 +1,14 @@
1
+ coffee:
2
+ jQuery(document).ready(->
3
+ search = new Search()
4
+
5
+ $(document).on('click', '.ransack.add_fields', ->
6
+ search.add_fields(this, $(this).data('fieldType'), $(this).data('content'))
7
+ false
8
+ );
9
+
10
+ $(document).on('click', '.ransack.remove_fields', ->
11
+ search.remove_fields(this);
12
+ return false;
13
+ )
14
+ )
@@ -0,0 +1 @@
1
+ = content_tag(:span, f.text_field(:value), { class: 'fields value', 'data-object-name' => f.object_name }, false)
@@ -7,8 +7,7 @@
7
7
  h1.page-header
8
8
  = Comable.t('admin.nav.shipment_method')
9
9
  small<
10
- = @shipment_methods.total_count
11
- = Comable.t('admin.results')
10
+ | #{@shipment_methods.total_count} #{Comable.t('admin.results')}
12
11
 
13
12
  .comable-page-body
14
13
  - if @shipment_methods.empty?
@@ -13,8 +13,7 @@
13
13
  h1.page-header
14
14
  = Comable.t('admin.nav.stock')
15
15
  small<
16
- = @stocks.total_count
17
- = Comable.t('admin.results')
16
+ | #{@stocks.total_count} #{Comable.t('admin.results')}
18
17
 
19
18
  .comable-page-body
20
19
  .comable-search
@@ -25,12 +24,16 @@
25
24
  i.fa.fa-search
26
25
  span.caret<
27
26
  ul.dropdown-menu role="menu"
27
+ li
28
+ = link_to Comable.t('admin.advanced_search'), 'javascript:void(0)', 'data-toggle' => 'collapse', 'data-target' => '#comable-advanced-search'
28
29
  li
29
30
  = link_to Comable.t('admin.clear_search_conditions'), comable.admin_stocks_path
30
31
  = f.text_field :code_cont, class: 'form-control'
31
32
  span.input-group-btn
32
33
  = f.submit Comable.t('admin.search'), class: 'btn btn-default'
33
34
 
35
+ = render 'comable/admin/shared/advanced_search', f: f
36
+
34
37
  section
35
38
  - if @stocks.empty?
36
39
  = Comable.t('admin.not_found')
@@ -30,6 +30,31 @@ module Comable
30
30
  g.test_framework :rspec, fixture: true
31
31
  g.fixture_replacement :factory_girl, dir: 'spec/factories'
32
32
  end
33
+
34
+ initializer 'comable.ransack.configure' do
35
+ Ransack.configure do |config|
36
+ config.add_predicate(
37
+ 'eq_any_splitted',
38
+ arel_predicate: 'eq_any',
39
+ formatter: proc { |v| v.split(' ') },
40
+ validator: proc { |v| v.present? },
41
+ compounds: false,
42
+ type: :string
43
+ )
44
+
45
+ config.add_predicate(
46
+ 'cont_any_splitted',
47
+ arel_predicate: 'matches_any',
48
+ formatter: proc { |v| v.split(' ').map { |s| "%#{s}%" } },
49
+ validator: proc { |v| v.present? },
50
+ compounds: false,
51
+ type: :string
52
+ )
53
+ end
54
+ end
55
+
56
+ # Add support Rails 4.1.x, 4.2.x for gritter
57
+ config.assets.precompile += %w( error.png gritter-close.png gritter.png ie-spacer.gif notice.png progress.gif success.png warning.png ) if Rails::VERSION::MAJOR == 4
33
58
  end
34
59
  end
35
60
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: comable_backend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
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-03-03 00:00:00.000000000 Z
11
+ date: 2015-04-07 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.3.3
19
+ version: 0.3.4
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.3.3
26
+ version: 0.3.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -258,14 +258,14 @@ dependencies:
258
258
  requirements:
259
259
  - - "~>"
260
260
  - !ruby/object:Gem::Version
261
- version: 0.1.1
261
+ version: 0.1.3
262
262
  type: :runtime
263
263
  prerelease: false
264
264
  version_requirements: !ruby/object:Gem::Requirement
265
265
  requirements:
266
266
  - - "~>"
267
267
  - !ruby/object:Gem::Version
268
- version: 0.1.1
268
+ version: 0.1.3
269
269
  - !ruby/object:Gem::Dependency
270
270
  name: gritter
271
271
  requirement: !ruby/object:Gem::Requirement
@@ -303,7 +303,6 @@ files:
303
303
  - app/assets/stylesheets/comable/admin/application.scss
304
304
  - app/assets/stylesheets/comable/admin/overrides/bootstrap.scss
305
305
  - app/assets/stylesheets/comable/admin/overrides/jstree.scss
306
- - app/assets/stylesheets/comable/admin/overrides/pace.scss
307
306
  - app/assets/stylesheets/comable/admin/overrides/tagit.scss
308
307
  - app/controllers/comable/admin/application_controller.rb
309
308
  - app/controllers/comable/admin/categories_controller.rb
@@ -334,14 +333,19 @@ files:
334
333
  - app/views/comable/admin/payment_methods/index.slim
335
334
  - app/views/comable/admin/payment_methods/new.slim
336
335
  - app/views/comable/admin/products/_form.slim
337
- - app/views/comable/admin/products/_image_fields.slim
338
336
  - app/views/comable/admin/products/edit.slim
339
337
  - app/views/comable/admin/products/index.slim
340
338
  - app/views/comable/admin/products/new.slim
339
+ - app/views/comable/admin/shared/_advanced_search.slim
340
+ - app/views/comable/admin/shared/_condition_fields.slim
341
341
  - app/views/comable/admin/shared/_footer.slim
342
+ - app/views/comable/admin/shared/_grouping_fields.slim
342
343
  - app/views/comable/admin/shared/_header.slim
344
+ - app/views/comable/admin/shared/_image_fields.slim
343
345
  - app/views/comable/admin/shared/_notifier.slim
346
+ - app/views/comable/admin/shared/_setup_search_form.slim
344
347
  - app/views/comable/admin/shared/_sidebar.slim
348
+ - app/views/comable/admin/shared/_value_fields.slim
345
349
  - app/views/comable/admin/shipment_methods/_form.slim
346
350
  - app/views/comable/admin/shipment_methods/edit.slim
347
351
  - app/views/comable/admin/shipment_methods/index.slim
@@ -1,4 +0,0 @@
1
- .pace .pace-progress {
2
- @include transition-property(none);
3
- background-color: $comable-pace !important;
4
- }