comable_backend 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/comable/admin/application.coffee +4 -0
  3. data/app/assets/stylesheets/comable/admin/_common.scss +23 -0
  4. data/app/assets/stylesheets/comable/admin/_flow.scss +149 -0
  5. data/app/assets/stylesheets/comable/admin/application.scss +1 -0
  6. data/app/assets/stylesheets/comable/admin/overrides/bootstrap.scss +1 -0
  7. data/app/controllers/comable/admin/application_controller.rb +24 -4
  8. data/app/controllers/comable/admin/dashboard_controller.rb +4 -4
  9. data/app/controllers/comable/admin/orders_controller.rb +82 -1
  10. data/app/controllers/comable/admin/payment_methods_controller.rb +1 -0
  11. data/app/controllers/comable/admin/products_controller.rb +16 -0
  12. data/app/controllers/comable/admin/stocks_controller.rb +16 -0
  13. data/app/controllers/comable/admin/trackers_controller.rb +58 -0
  14. data/app/controllers/comable/admin/{customers_controller.rb → users_controller.rb} +8 -8
  15. data/app/helpers/comable/admin/orders_helper.rb +30 -0
  16. data/app/views/comable/admin/categories/index.slim +2 -2
  17. data/app/views/comable/admin/dashboard/show.slim +9 -10
  18. data/app/views/comable/admin/orders/_payment_state.slim +40 -0
  19. data/app/views/comable/admin/orders/_shipment_state.slim +44 -0
  20. data/app/views/comable/admin/orders/edit.slim +112 -0
  21. data/app/views/comable/admin/orders/index.slim +22 -6
  22. data/app/views/comable/admin/orders/show.slim +141 -110
  23. data/app/views/comable/admin/payment_methods/_form.slim +6 -2
  24. data/app/views/comable/admin/products/_form.slim +9 -9
  25. data/app/views/comable/admin/products/index.slim +16 -0
  26. data/app/views/comable/admin/shared/_header.slim +3 -3
  27. data/app/views/comable/admin/shared/_sidebar.slim +5 -3
  28. data/app/views/comable/admin/shared/export.xlsx.axlsx +17 -0
  29. data/app/views/comable/admin/shipment_methods/_form.slim +2 -2
  30. data/app/views/comable/admin/stocks/_form.slim +2 -2
  31. data/app/views/comable/admin/stocks/index.slim +16 -0
  32. data/app/views/comable/admin/store/_form.slim +2 -2
  33. data/app/views/comable/admin/trackers/_form.slim +109 -0
  34. data/app/views/comable/admin/trackers/edit.slim +27 -0
  35. data/app/views/comable/admin/trackers/index.slim +37 -0
  36. data/app/views/comable/admin/trackers/new.slim +16 -0
  37. data/app/views/comable/admin/{customers → users}/edit.slim +10 -10
  38. data/app/views/comable/admin/{customers → users}/index.slim +20 -20
  39. data/app/views/comable/admin/users/show.slim +88 -0
  40. data/app/views/layouts/comable/admin/application.slim +1 -1
  41. data/config/routes.rb +31 -4
  42. metadata +19 -8
  43. data/app/views/comable/admin/customers/show.slim +0 -88
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0d5ce48da7e6b0b8a887a746cad4a75e4c31916
4
- data.tar.gz: b22f25a4c7cbcdb0182651740c1736fcbb8aae04
3
+ metadata.gz: aa2786c8556acb44601370d90dedc34405b75fc4
4
+ data.tar.gz: 302afe2c02974bdba2d04c700165ca215a813cfa
5
5
  SHA512:
6
- metadata.gz: 3da03ea18f27b7badb7c125d694f2ee471573f8a527edcb799618b88e3339ea65ef540f143dfccb452acae19a13476317ca2c563bcc80416aac0db0be12676f8
7
- data.tar.gz: 24b68b045eb0abcc5ce41fafccb7d7cdfbeea15a7b9031e9812762e4e3410fe98f5403fe93a793739293863578f707939453eb499ae576df2b03d3f120a92d64
6
+ metadata.gz: 8b09ac7adc713fc6433722946eb45c60a6d9f6bd9eeca82cf7d93442c4f1200fa95bc519694157ca5ca37f2ef65e41df387499d6387339f5feced120b2679d79
7
+ data.tar.gz: f820fa64c10074668e0bd4c2b68fd34257bd373dc24b5052bfae1b6597d29c7b0552d3e2d324130fed9617eeb336e8c914eac1e3ada30c864a8ae5630612123b
@@ -92,6 +92,10 @@ $( ->
92
92
  $(window).on('resize', resize_comable_affix)
93
93
 
94
94
  $('[data-toggle="tooltip"]').tooltip()
95
+
96
+ $(document).on('change', '.btn-file :file', ->
97
+ $(this).closest('form').submit()
98
+ )
95
99
  )
96
100
  # Place all the behaviors and hooks related to the matching controller here.
97
101
  # All this logic will automatically be available in application.js.
@@ -290,3 +290,26 @@ footer {
290
290
  color: #000;
291
291
  }
292
292
  }
293
+
294
+ // for File Inputs
295
+ // refs: http://www.abeautifulsite.net/whipping-file-inputs-into-shape-with-bootstrap-3/
296
+ .btn-file {
297
+ position: relative;
298
+ overflow: hidden;
299
+ cursor: pointer;
300
+ }
301
+
302
+ .btn-file input[type=file] {
303
+ @include opacity(0);
304
+ position: absolute;
305
+ top: 0;
306
+ right: 0;
307
+ min-width: 100%;
308
+ min-height: 100%;
309
+ font-size: 100px;
310
+ text-align: right;
311
+ outline: none;
312
+ background: white;
313
+ cursor: inherit;
314
+ display: block;
315
+ }
@@ -0,0 +1,149 @@
1
+ // Variables
2
+ $comable-flow-border: #eee;
3
+ $comable-badge-size: 50px;
4
+ $comable-badge-default-color: $gray;
5
+ $comable-badge-default-bg: #fff;
6
+ $comable-badge-default-border: $btn-default-border;
7
+ $comable-badge-disable-color: #fff;
8
+ $comable-badge-disable-bg: #ddd;
9
+ $comable-badge-disable-border: $btn-default-border;
10
+ $comable-badge-primary-color: $btn-primary-color;
11
+ $comable-badge-primary-bg: $btn-primary-bg;
12
+ $comable-badge-primary-border: $btn-primary-border;
13
+ $comable-badge-success-color: $btn-success-color;
14
+ $comable-badge-success-bg: $btn-success-bg;
15
+ $comable-badge-success-border: $btn-success-border;
16
+ $comable-badge-warning-color: $btn-warning-color;
17
+ $comable-badge-warning-bg: $btn-warning-bg;
18
+ $comable-badge-warning-border: $btn-warning-border;
19
+ $comable-badge-danger-color: $btn-danger-color;
20
+ $comable-badge-danger-bg: $btn-danger-bg;
21
+ $comable-badge-danger-border: $btn-danger-border;
22
+
23
+ // Mixins
24
+ @mixin comable-badge($color, $background-color, $border-color) {
25
+ color: $color;
26
+ background-color: $background-color;
27
+ border-color: $border-color;
28
+
29
+ &:hover, &:focus {
30
+ color: $color;
31
+ }
32
+
33
+ @at-root a#{&}:hover, a#{&}:focus {
34
+ background-color: darken($background-color, 10%);
35
+ border-color: darken($border-color, 10%);
36
+ }
37
+ }
38
+
39
+ // Rules
40
+ .comable-flow {
41
+ list-style: none;
42
+ margin-bottom: 20px;
43
+ padding: 20px 0;
44
+ position: relative;
45
+
46
+ &:before {
47
+ content: ' ';
48
+ margin-top: -1.5px;
49
+ height: 3px;
50
+ background-color: $comable-flow-border;
51
+ position: absolute;
52
+ top: 50%;
53
+ left: 0;
54
+ right: 0;
55
+ }
56
+
57
+ li {
58
+ @include inline-block;
59
+ margin-right: $comable-badge-size + 50px;
60
+ position: relative;
61
+ }
62
+ }
63
+
64
+ .comable-badge {
65
+ @include border-radius(50%);
66
+ margin-top: -($comable-badge-size / 2);
67
+ height: $comable-badge-size;
68
+ width: $comable-badge-size;
69
+ line-height: $comable-badge-size;
70
+ font-size: 1.4em;
71
+ text-align: center;
72
+ position: absolute;
73
+ left: 16px;
74
+ top: 50%;
75
+ z-index: 100;
76
+ border: 1px solid transparent;
77
+
78
+ &[disabled] {
79
+ @include opacity(0.65);
80
+ @include box-shadow(none);
81
+ cursor: not-allowed;
82
+ pointer-events: none;
83
+ }
84
+ }
85
+
86
+ .comable-badge-default {
87
+ @include comable-badge(
88
+ $color: $comable-badge-default-color,
89
+ $background-color: $comable-badge-default-bg,
90
+ $border-color: $comable-badge-default-border
91
+ );
92
+ }
93
+
94
+ .comable-badge-disable {
95
+ @include comable-badge(
96
+ $color: $comable-badge-disable-color,
97
+ $background-color: $comable-badge-disable-bg,
98
+ $border-color: $comable-badge-default-border
99
+ );
100
+ }
101
+
102
+ .comable-badge-primary {
103
+ @include comable-badge(
104
+ $color: $comable-badge-primary-color,
105
+ $background-color: $comable-badge-primary-bg,
106
+ $border-color: $comable-badge-primary-border
107
+ );
108
+ }
109
+
110
+ .comable-badge-success {
111
+ @include comable-badge(
112
+ $color: $comable-badge-success-color,
113
+ $background-color: $comable-badge-success-bg,
114
+ $border-color: $comable-badge-success-border
115
+ );
116
+ }
117
+
118
+ .comable-badge-danger {
119
+ @include comable-badge(
120
+ $color: $comable-badge-danger-color,
121
+ $background-color: $comable-badge-danger-bg,
122
+ $border-color: $comable-badge-danger-border
123
+ );
124
+ }
125
+
126
+ .comable-badge-warning {
127
+ @include comable-badge(
128
+ $color: $comable-badge-warning-color,
129
+ $background-color: $comable-badge-warning-bg,
130
+ $border-color: $comable-badge-warning-border
131
+ );
132
+ }
133
+
134
+ .comable-flow-label {
135
+ display: table;
136
+ height: $comable-badge-size + 5px;
137
+ margin: 0 0 0 auto;
138
+ text-align: right;
139
+ }
140
+
141
+ .comable-flow-label-container {
142
+ display: table-cell;
143
+ vertical-align: middle;
144
+
145
+ *:last-child {
146
+ margin-bottom: 0;
147
+ padding-bottom: 0;
148
+ }
149
+ }
@@ -13,6 +13,7 @@
13
13
  @import 'comable/admin/mixins';
14
14
  @import 'comable/admin/overrides';
15
15
  @import 'comable/admin/common';
16
+ @import 'comable/admin/flow';
16
17
  @import 'comable/admin/errors';
17
18
  @import 'comable/admin/dashboard';
18
19
  @import 'comable/admin/orders';
@@ -52,6 +52,7 @@ label {
52
52
  }
53
53
 
54
54
  select,
55
+ textarea,
55
56
  input[type="password"],
56
57
  input[type="email"],
57
58
  input[type="text"] {
@@ -9,7 +9,19 @@ module Comable
9
9
  layout 'comable/admin/application'
10
10
 
11
11
  def current_ability
12
- Comable::Ability.new(current_customer)
12
+ Comable::Ability.new(current_comable_user)
13
+ end
14
+
15
+ def respond_to_export_with(records)
16
+ respond_to do |format|
17
+ format.csv do
18
+ render csv: records, filename: filename
19
+ end
20
+
21
+ format.xlsx do
22
+ render xlsx: 'export', filename: filename, locals: { records: records }, template: 'comable/admin/shared/export', layout: false
23
+ end
24
+ end
13
25
  end
14
26
 
15
27
  private
@@ -17,22 +29,30 @@ module Comable
17
29
  rescue_from CanCan::AccessDenied, with: :unauthorized
18
30
 
19
31
  def unauthorized
20
- if current_customer.signed_in?
32
+ if current_comable_user.signed_in?
21
33
  flash[:alert] = Comable.t('admin.access_denied')
22
34
  redirect_to after_access_denied_path
23
35
  else
24
36
  store_location
25
- redirect_to comable.new_admin_customer_session_path
37
+ redirect_to comable.new_admin_user_session_path
26
38
  end
27
39
  end
28
40
 
29
41
  def after_access_denied_path
30
- if current_customer.customer?
42
+ if current_comable_user.user?
31
43
  comable.root_path
32
44
  else
33
45
  comable.admin_root_path
34
46
  end
35
47
  end
48
+
49
+ def filename
50
+ "#{timestamp}_#{controller_name}"
51
+ end
52
+
53
+ def timestamp
54
+ Time.now.strftime('%Y%m%d%H%M%S')
55
+ end
36
56
  end
37
57
  end
38
58
  end
@@ -10,10 +10,10 @@ module Comable
10
10
  authorize! :read, @this_month_orders
11
11
 
12
12
  # TODO: Comment out after adding timestamp columns
13
- # @this_month_customers = Comable::Customer.with_role(:customer).this_month
14
- # @this_week_customers = Comable::Customer.with_role(:customer).this_week
15
- # @last_week_customers = Comable::Customer.with_role(:customer).last_week
16
- # authorize! :read, @this_week_customers
13
+ # @this_month_users = Comable::User.with_role(:user).this_month
14
+ # @this_week_users = Comable::User.with_role(:user).this_week
15
+ # @last_week_users = Comable::User.with_role(:user).last_week
16
+ # authorize! :read, @this_week_users
17
17
  end
18
18
  end
19
19
  end
@@ -3,15 +3,96 @@ require_dependency 'comable/admin/application_controller'
3
3
  module Comable
4
4
  module Admin
5
5
  class OrdersController < Comable::Admin::ApplicationController
6
+ include Comable::PermittedAttributes
7
+
6
8
  load_and_authorize_resource class: Comable::Order.name, except: :index
7
9
 
8
10
  def index
9
11
  @q = Comable::Order.complete.ransack(params[:q])
10
- @orders = @q.result.page(params[:page]).per(15).order('completed_at DESC').accessible_by(current_ability)
12
+ @orders = @q.result.page(params[:page]).per(15).recent.accessible_by(current_ability)
11
13
  end
12
14
 
13
15
  def show
14
16
  end
17
+
18
+ def edit
19
+ end
20
+
21
+ def update
22
+ if @order.update_attributes(order_params)
23
+ redirect_to comable.admin_order_path(@order), notice: Comable.t('successful')
24
+ else
25
+ flash.now[:alert] = Comable.t('failure')
26
+ render :edit
27
+ end
28
+ end
29
+
30
+ def export
31
+ q = Comable::Order.complete.ransack(params[:q])
32
+ orders = q.result.recent.accessible_by(current_ability)
33
+ order_items = Comable::OrderItem.joins(:order).merge(orders)
34
+
35
+ respond_to_export_with order_items
36
+ end
37
+
38
+ def cancel
39
+ @order.cancel!
40
+ redirect_to :back, notice: Comable.t('successful')
41
+ rescue ActiveRecord::RecordInvalid => e
42
+ redirect_to :back, alert: e.message
43
+ end
44
+
45
+ def resume
46
+ @order.resume!
47
+ redirect_to :back, notice: Comable.t('successful')
48
+ rescue ActiveRecord::RecordInvalid => e
49
+ redirect_to :back, alert: e.message
50
+ end
51
+
52
+ def cancel_payment
53
+ @order.payment.cancel!
54
+ redirect_to :back, notice: Comable.t('successful')
55
+ rescue ActiveRecord::RecordInvalid => e
56
+ redirect_to :back, alert: e.message
57
+ end
58
+
59
+ def resume_payment
60
+ @order.payment.resume!
61
+ redirect_to :back, notice: Comable.t('successful')
62
+ rescue ActiveRecord::RecordInvalid => e
63
+ redirect_to :back, alert: e.message
64
+ end
65
+
66
+ def ship
67
+ @order.shipment.ship!
68
+ redirect_to :back, notice: Comable.t('successful')
69
+ rescue ActiveRecord::RecordInvalid => e
70
+ redirect_to :back, alert: e.message
71
+ end
72
+
73
+ def cancel_shipment
74
+ @order.shipment.cancel!
75
+ redirect_to :back, notice: Comable.t('successful')
76
+ rescue ActiveRecord::RecordInvalid => e
77
+ redirect_to :back, alert: e.message
78
+ end
79
+
80
+ def resume_shipment
81
+ @order.shipment.resume!
82
+ redirect_to :back, notice: Comable.t('successful')
83
+ rescue ActiveRecord::RecordInvalid => e
84
+ redirect_to :back, alert: e.message
85
+ end
86
+
87
+ private
88
+
89
+ def order_params
90
+ params.require(:order).permit(
91
+ :email,
92
+ bill_address_attributes: permitted_address_attributes,
93
+ ship_address_attributes: permitted_address_attributes
94
+ )
95
+ end
15
96
  end
16
97
  end
17
98
  end
@@ -49,6 +49,7 @@ module Comable
49
49
  :name,
50
50
  :payment_provider_type,
51
51
  :payment_provider_kind,
52
+ :fee,
52
53
  :enable_price_from,
53
54
  :enable_price_to
54
55
  )
@@ -47,6 +47,22 @@ module Comable
47
47
  end
48
48
  end
49
49
 
50
+ def export
51
+ q = Comable::Product.ransack(params[:q])
52
+ products = q.result.accessible_by(current_ability)
53
+
54
+ respond_to_export_with products
55
+ end
56
+
57
+ def import
58
+ ActiveRecord::Base.transaction do
59
+ Comable::Product.import_from(params[:file])
60
+ end
61
+ redirect_to comable.admin_products_path, notice: Comable.t('successful')
62
+ rescue Comable::Importable::Exception => e
63
+ redirect_to comable.admin_products_path, alert: e.message
64
+ end
65
+
50
66
  private
51
67
 
52
68
  def product_params
@@ -50,6 +50,22 @@ module Comable
50
50
  end
51
51
  end
52
52
 
53
+ def export
54
+ q = @stocks.ransack(params[:q])
55
+ stocks = q.result.includes(:product).accessible_by(current_ability)
56
+
57
+ respond_to_export_with stocks
58
+ end
59
+
60
+ def import
61
+ ActiveRecord::Base.transaction do
62
+ Comable::Stock.import_from(params[:file])
63
+ end
64
+ redirect_to comable.admin_stocks_path, notice: Comable.t('successful')
65
+ rescue Comable::Importable::Exception => e
66
+ redirect_to comable.admin_stocks_path, alert: e.message
67
+ end
68
+
53
69
  private
54
70
 
55
71
  def stock_params