comable_backend 0.3.4 → 0.4.0

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.
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
@@ -0,0 +1,58 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class TrackersController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::Tracker.name
7
+
8
+ def index
9
+ @trackers = @trackers.page(params[:page])
10
+ end
11
+
12
+ def show
13
+ render :edit
14
+ end
15
+
16
+ def new
17
+ end
18
+
19
+ def create
20
+ if @tracker.save
21
+ redirect_to comable.admin_tracker_path(@tracker), notice: Comable.t('successful')
22
+ else
23
+ flash.now[:alert] = Comable.t('failure')
24
+ render :new
25
+ end
26
+ end
27
+
28
+ def edit
29
+ end
30
+
31
+ def update
32
+ if @tracker.update_attributes(tracker_params)
33
+ redirect_to comable.admin_tracker_path(@tracker), notice: Comable.t('successful')
34
+ else
35
+ flash.now[:alert] = Comable.t('failure')
36
+ render :edit
37
+ end
38
+ end
39
+
40
+ def destroy
41
+ @tracker.destroy
42
+ redirect_to comable.admin_trackers_path, notice: Comable.t('successful')
43
+ end
44
+
45
+ private
46
+
47
+ def tracker_params
48
+ params.require(:tracker).permit(
49
+ :activate_flag,
50
+ :name,
51
+ :tracker_id,
52
+ :code,
53
+ :place
54
+ )
55
+ end
56
+ end
57
+ end
58
+ end
@@ -2,14 +2,14 @@ require_dependency 'comable/admin/application_controller'
2
2
 
3
3
  module Comable
4
4
  module Admin
5
- class CustomersController < Comable::Admin::ApplicationController
5
+ class UsersController < Comable::Admin::ApplicationController
6
6
  include Comable::PermittedAttributes
7
7
 
8
- load_and_authorize_resource class: Comable::Customer.name, except: :index
8
+ load_and_authorize_resource class: Comable::User.name, except: :index
9
9
 
10
10
  def index
11
- @q = Comable::Customer.ransack(params[:q])
12
- @customers = @q.result.page(params[:page]).accessible_by(current_ability)
11
+ @q = Comable::User.ransack(params[:q])
12
+ @users = @q.result.page(params[:page]).accessible_by(current_ability)
13
13
  end
14
14
 
15
15
  def show
@@ -19,8 +19,8 @@ module Comable
19
19
  end
20
20
 
21
21
  def update
22
- if @customer.update_attributes(customer_params)
23
- redirect_to comable.admin_customer_path(@customer), notice: Comable.t('successful')
22
+ if @user.update_attributes(user_params)
23
+ redirect_to comable.admin_user_path(@user), notice: Comable.t('successful')
24
24
  else
25
25
  flash.now[:alert] = Comable.t('failure')
26
26
  render :edit
@@ -29,8 +29,8 @@ module Comable
29
29
 
30
30
  private
31
31
 
32
- def customer_params
33
- params.require(:customer).permit(
32
+ def user_params
33
+ params.require(:user).permit(
34
34
  :email,
35
35
  :password,
36
36
  :role,
@@ -0,0 +1,30 @@
1
+ module Comable
2
+ module Admin
3
+ module OrdersHelper
4
+ def options_of_shipment_badge_for(shipment, state:)
5
+ human_name = shipment.class.state_machine.states[state].human_name
6
+ { class: shipment_badge_class_for(shipment, state: state), title: human_name, data: { toggle: 'tooltip', placement: 'top' } }
7
+ end
8
+
9
+ def shipment_badge_class_for(shipment, state:)
10
+ return badge_class_for_state(state) if shipment.state.to_sym == state.to_sym
11
+ can_cancel = shipment.resumed? && state.to_sym == :canceled
12
+ (!can_cancel && shipment.stated?(state)) ? 'comable-badge comable-badge-disable' : 'comable-badge comable-badge-default'
13
+ end
14
+
15
+ alias_method :options_of_payment_badge_for, :options_of_shipment_badge_for
16
+ alias_method :payment_badge_class_for, :shipment_badge_class_for
17
+
18
+ def badge_class_for_state(state)
19
+ case state.to_sym
20
+ when :pending, :ready
21
+ 'comable-badge comable-badge-warning'
22
+ when :completed, :resumed
23
+ 'comable-badge comable-badge-success'
24
+ when :canceled
25
+ 'comable-badge comable-badge-danger'
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -70,7 +70,7 @@ coffee:
70
70
 
71
71
  .comable-page-body
72
72
  fieldset
73
- .col-sm-3
73
+ .col-md-3
74
74
  legend
75
75
  = Comable.t('admin.note')
76
76
  .help-block
@@ -83,7 +83,7 @@ coffee:
83
83
  = Comable.t('admin.link_to_add_new_node')
84
84
  = link_to Comable.t('admin.actions.new'), 'javascript:create_new_node()'
85
85
 
86
- .col-sm-9
86
+ .col-md-9
87
87
  #comable-jstree
88
88
  = form_tag comable.admin_categories_path do
89
89
  .hidden
@@ -4,8 +4,8 @@
4
4
  = Comable.t('admin.nav.dashboard')
5
5
 
6
6
  .comable-page-body
7
- section
8
- .col-sm-4
7
+ section.row
8
+ .col-md-4
9
9
  - number = @this_week_orders.count
10
10
  = render 'widget',
11
11
  title: Comable.t('admin.new_orders'),
@@ -14,7 +14,7 @@
14
14
  color: 'green',
15
15
  fa: 'shopping-cart'
16
16
 
17
- .col-sm-4
17
+ .col-md-4
18
18
  - number = @this_week_orders.sum(:total_price)
19
19
  = render 'widget',
20
20
  title: Comable.t('admin.sales'),
@@ -24,20 +24,19 @@
24
24
  fa: 'dollar'
25
25
 
26
26
  / TODO: Comment out after adding timestamp columns
27
- .col-sm-4
28
- - number = @this_week_customers.count
27
+ .col-md-4
28
+ - number = @this_week_users.count
29
29
  = render 'widget',
30
30
  title: Comable.t('admin.new_users'),
31
31
  number: number_with_delimiter(number),
32
- progress: (number.to_f / @last_week_customers.count) * 100,
32
+ progress: (number.to_f / @last_week_users.count) * 100,
33
33
  color: 'black',
34
34
  fa: 'user'
35
35
 
36
36
  section
37
- .col-sm-12
38
- .panel.panel-default
39
- .panel-body
40
- #comable-morris.morris style="height: 300px;"
37
+ .panel.panel-default
38
+ .panel-body
39
+ #comable-morris.morris style="height: 300px;"
41
40
 
42
41
  javascript:
43
42
  morris_data = #{raw @this_month_orders.to_morris};
@@ -0,0 +1,40 @@
1
+ section.row
2
+ .col-sm-2
3
+ .comable-flow-label
4
+ .comable-flow-label-container
5
+ label
6
+ | #{payment.order.class.human_attribute_name(:payment_state)}:
7
+ p
8
+ = payment.human_state_name
9
+
10
+ .col-sm-10
11
+ ul.comable-flow
12
+ li
13
+ = content_tag :div, options_of_payment_badge_for(payment, state: :pending) do
14
+ i.fa.fa-circle
15
+
16
+ li
17
+ = content_tag :div, options_of_payment_badge_for(payment, state: :ready) do
18
+ i.fa.fa-check-circle
19
+
20
+ li
21
+ = content_tag :div, options_of_payment_badge_for(payment, state: :completed) do
22
+ i.fa.fa-money
23
+
24
+ - if payment.state?(:resumed)
25
+ li
26
+ = content_tag :div, options_of_payment_badge_for(payment, state: :resumed) do
27
+ i.fa.fa-refresh
28
+
29
+ - if payment.state?(:completed) || payment.state?(:resumed)
30
+ li
31
+ = link_to comable.cancel_payment_admin_order_path(payment.order), options_of_payment_badge_for(payment, state: :canceled).merge(method: :post) do
32
+ i.fa.fa-close
33
+
34
+ - if payment.state?(:canceled)
35
+ li
36
+ = content_tag :div, options_of_payment_badge_for(payment, state: :canceled) do
37
+ i.fa.fa-close
38
+ li
39
+ = link_to comable.resume_payment_admin_order_path(payment.order), options_of_payment_badge_for(payment, state: :resumed).merge(method: :post) do
40
+ i.fa.fa-refresh
@@ -0,0 +1,44 @@
1
+ section.row
2
+ .col-sm-2
3
+ .comable-flow-label
4
+ .comable-flow-label-container
5
+ label
6
+ | #{shipment.order.class.human_attribute_name(:shipment_state)}:
7
+ p
8
+ = shipment.human_state_name
9
+
10
+ .col-sm-10
11
+ ul.comable-flow
12
+ li
13
+ = content_tag :div, options_of_shipment_badge_for(shipment, state: :pending) do
14
+ i.fa.fa-circle
15
+
16
+ li
17
+ = content_tag :div, options_of_shipment_badge_for(shipment, state: :ready) do
18
+ i.fa.fa-check-circle
19
+
20
+ li
21
+ - if shipment.state?(:ready)
22
+ = link_to comable.ship_admin_order_path(shipment.order), options_of_shipment_badge_for(shipment, state: :completed).merge(method: :post, disabled: !@order.can_ship?) do
23
+ i.fa.fa-truck
24
+ - else
25
+ = content_tag :div, options_of_shipment_badge_for(shipment, state: :completed) do
26
+ i.fa.fa-truck
27
+
28
+ - if shipment.state?(:resumed)
29
+ li
30
+ = content_tag :div, options_of_shipment_badge_for(shipment, state: :resumed) do
31
+ i.fa.fa-refresh
32
+
33
+ - if shipment.state?(:completed) || shipment.state?(:resumed)
34
+ li
35
+ = link_to comable.cancel_shipment_admin_order_path(shipment.order), options_of_shipment_badge_for(shipment, state: :canceled).merge(method: :post) do
36
+ i.fa.fa-close
37
+
38
+ - if shipment.state?(:canceled)
39
+ li
40
+ = content_tag :div, options_of_shipment_badge_for(shipment, state: :canceled) do
41
+ i.fa.fa-close
42
+ li
43
+ = link_to comable.resume_shipment_admin_order_path(shipment.order), options_of_shipment_badge_for(shipment, state: :resumed).merge(method: :post) do
44
+ i.fa.fa-refresh
@@ -0,0 +1,112 @@
1
+ .comable-page
2
+ .comable-main-fixed-top
3
+ .comable-page-heading
4
+ ul.pull-right.list-inline
5
+ li
6
+ = link_to_save
7
+
8
+ h1.page-header
9
+ ol.breadcrumb
10
+ li>
11
+ = link_to Comable.t('admin.nav.order'), comable.admin_orders_path
12
+ li>
13
+ = link_to @order.code, comable.admin_order_path(@order)
14
+ li.active
15
+ = Comable.t('admin.actions.edit')
16
+
17
+ .comable-page-body
18
+ section
19
+ = error_messages_for @order
20
+
21
+ = form_for @order, url: comable.admin_order_path(@order) do |f|
22
+ .hidden
23
+ = f.submit
24
+
25
+ fieldset
26
+ .col-md-3
27
+ legend
28
+ = Comable.t('admin.general')
29
+ .help-block
30
+
31
+ .col-md-9
32
+ .form-group
33
+ = f.label :email
34
+ = f.email_field :email
35
+
36
+ hr
37
+
38
+ - if f.object.bill_address
39
+ fieldset
40
+ .col-md-3
41
+ legend
42
+ = f.object.class.human_attribute_name(:bill_address)
43
+ .help-block
44
+
45
+ .col-md-9
46
+ = f.fields_for :bill_address do |ff|
47
+ .form-group
48
+ = ff.label :full_name
49
+ .row
50
+ .col-sm-6
51
+ = ff.text_field :family_name, placeholder: ff.object.class.human_attribute_name(:family_name)
52
+ .col-sm-6
53
+ = ff.text_field :first_name, placeholder: ff.object.class.human_attribute_name(:first_name)
54
+
55
+ .form-group
56
+ = ff.label :zip_code
57
+ = ff.text_field :zip_code, max_length: 8
58
+
59
+ .form-group
60
+ = ff.label :state_name
61
+ = ff.text_field :state_name
62
+
63
+ .form-group
64
+ = ff.label :city
65
+ = ff.text_field :city
66
+
67
+ .form-group
68
+ = ff.label :detail
69
+ = ff.text_field :detail
70
+
71
+ .form-group
72
+ = ff.label :phone_number
73
+ = ff.text_field :phone_number, max_length: 18
74
+
75
+ hr
76
+
77
+ - if f.object.ship_address
78
+ fieldset
79
+ .col-md-3
80
+ legend
81
+ = f.object.class.human_attribute_name(:ship_address)
82
+ .help-block
83
+
84
+ .col-md-9
85
+ = f.fields_for :ship_address do |ff|
86
+ .form-group
87
+ = ff.label :full_name
88
+ .row
89
+ .col-sm-6
90
+ = ff.text_field :family_name, placeholder: ff.object.class.human_attribute_name(:family_name)
91
+ .col-sm-6
92
+ = ff.text_field :first_name, placeholder: ff.object.class.human_attribute_name(:first_name)
93
+
94
+ .form-group
95
+ = ff.label :zip_code
96
+ = ff.text_field :zip_code, max_length: 8
97
+
98
+ .form-group
99
+ = ff.label :state_name
100
+ = ff.text_field :state_name
101
+
102
+ .form-group
103
+ = ff.label :city
104
+ = ff.text_field :city
105
+
106
+ .form-group
107
+ = ff.label :detail
108
+ = ff.text_field :detail
109
+
110
+ .form-group
111
+ = ff.label :phone_number
112
+ = ff.text_field :phone_number, max_length: 18
@@ -9,6 +9,15 @@
9
9
  = link_to_next_page @orders, '>', class: 'btn btn-default' do
10
10
  .btn.btn-default disabled="disabled"
11
11
  | >
12
+ li.dropdown
13
+ = link_to '#', class: 'btn btn-default', 'data-toggle' => 'dropdown' do
14
+ = Comable.t('admin.more')
15
+ i.fa.fa-angle-down<
16
+ ul.dropdown-menu.dropdown-menu-right
17
+ li
18
+ = link_to Comable.t('admin.export_to_csv'), comable.export_admin_orders_path(format: :csv, q: params[:q])
19
+ li
20
+ = link_to Comable.t('admin.export_to_excel'), comable.export_admin_orders_path(format: :xlsx, q: params[:q])
12
21
 
13
22
  h1.page-header
14
23
  = Comable.t('admin.nav.order')
@@ -32,8 +41,8 @@
32
41
  span.input-group-btn
33
42
  = f.submit Comable.t('admin.search'), class: 'btn btn-default'
34
43
  .hidden
35
- = f.label :customer_id
36
- = f.text_field :customer_id_eq
44
+ = f.label :user_id
45
+ = f.text_field :user_id_eq
37
46
 
38
47
  = render 'comable/admin/shared/advanced_search', f: f
39
48
 
@@ -46,12 +55,15 @@
46
55
  th
47
56
  = sort_link [:comable, @q], :code
48
57
  th
49
- / TODO: Change to shipment_state and payment_state
50
58
  = sort_link [:comable, @q], :state
59
+ th
60
+ = @orders.klass.human_attribute_name(:payment_state)
61
+ th
62
+ = @orders.klass.human_attribute_name(:shipment_state)
51
63
  th
52
64
  = @orders.klass.human_attribute_name(:bill_full_name)
53
65
  th
54
- = @orders.klass.human_attribute_name(:order_details)
66
+ = @orders.klass.human_attribute_name(:order_items)
55
67
  th
56
68
  = sort_link [:comable, @q], :total_price
57
69
  th
@@ -63,13 +75,17 @@
63
75
  = link_to order.code, comable.admin_order_path(order)
64
76
  td
65
77
  = order.human_state_name
78
+ td
79
+ = order.payment_human_state_name
80
+ td
81
+ = order.shipment_human_state_name
66
82
  td
67
83
  = order.bill_full_name
68
84
  td
69
85
  ul.list-unstyled
70
- - order.order_details.each do |order_detail|
86
+ - order.order_items.each do |order_item|
71
87
  li
72
- | #{order_detail.name_with_sku} x #{order_detail.quantity}
88
+ | #{order_item.name_with_sku} x #{order_item.quantity}
73
89
  td
74
90
  = number_to_currency order.total_price
75
91
  td