comable_backend 0.2.3 → 0.3.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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/Rakefile +16 -4
  4. data/app/assets/javascripts/comable/admin/application.coffee +88 -0
  5. data/app/assets/stylesheets/comable/admin/application.scss +590 -0
  6. data/app/controllers/comable/admin/application_controller.rb +28 -0
  7. data/app/controllers/comable/admin/categories_controller.rb +14 -0
  8. data/app/controllers/comable/admin/customers_controller.rb +36 -0
  9. data/app/controllers/comable/admin/dashboard_controller.rb +20 -0
  10. data/app/controllers/comable/admin/orders_controller.rb +14 -0
  11. data/app/controllers/comable/admin/payment_methods_controller.rb +52 -0
  12. data/app/controllers/comable/admin/products_controller.rb +50 -1
  13. data/app/controllers/comable/admin/shipment_methods_controller.rb +11 -27
  14. data/app/controllers/comable/admin/stocks_controller.rb +69 -0
  15. data/app/controllers/comable/admin/store_controller.rb +12 -29
  16. data/app/views/comable/admin/categories/index.slim +94 -0
  17. data/app/views/comable/admin/customers/edit.slim +94 -0
  18. data/app/views/comable/admin/customers/index.slim +68 -0
  19. data/app/views/comable/admin/customers/show.slim +93 -0
  20. data/app/views/comable/admin/dashboard/_widget.slim +13 -0
  21. data/app/views/comable/admin/dashboard/show.slim +63 -0
  22. data/app/views/comable/admin/orders/index.slim +79 -0
  23. data/app/views/comable/admin/orders/show.slim +116 -0
  24. data/app/views/comable/admin/payment_methods/_form.slim +46 -0
  25. data/app/views/comable/admin/payment_methods/edit.slim +28 -0
  26. data/app/views/comable/admin/payment_methods/index.slim +53 -0
  27. data/app/views/comable/admin/payment_methods/new.slim +17 -0
  28. data/app/views/comable/admin/products/_form.slim +130 -0
  29. data/app/views/comable/admin/products/edit.slim +40 -0
  30. data/app/views/comable/admin/products/index.slim +75 -5
  31. data/app/views/comable/admin/products/new.slim +17 -0
  32. data/app/views/comable/admin/shipment_methods/_form.slim +35 -19
  33. data/app/views/comable/admin/shipment_methods/edit.slim +26 -5
  34. data/app/views/comable/admin/shipment_methods/index.slim +46 -13
  35. data/app/views/comable/admin/shipment_methods/new.slim +15 -3
  36. data/app/views/comable/admin/stocks/_form.slim +40 -0
  37. data/app/views/comable/admin/stocks/edit.slim +46 -0
  38. data/app/views/comable/admin/stocks/index.slim +81 -0
  39. data/app/views/comable/admin/stocks/new.slim +17 -0
  40. data/app/views/comable/admin/store/_form.slim +43 -31
  41. data/app/views/comable/admin/store/edit.slim +11 -3
  42. data/app/views/kaminari/comable_backend/_first_page.html.slim +2 -0
  43. data/app/views/kaminari/comable_backend/_gap.html.slim +2 -0
  44. data/app/views/kaminari/comable_backend/_last_page.html.slim +2 -0
  45. data/app/views/kaminari/comable_backend/_next_page.html.slim +2 -0
  46. data/app/views/kaminari/comable_backend/_page.html.slim +3 -0
  47. data/app/views/kaminari/comable_backend/_paginator.html.slim +15 -0
  48. data/app/views/kaminari/comable_backend/_prev_page.html.slim +2 -0
  49. data/app/views/layouts/comable/admin/application.slim +103 -2
  50. data/config/routes.rb +14 -2
  51. data/lib/comable/backend/engine.rb +22 -0
  52. metadata +240 -9
  53. data/app/assets/javascripts/comable/admin/application.js +0 -13
  54. data/app/assets/stylesheets/comable/admin/application.css +0 -15
  55. data/app/views/comable/admin/shipment_methods/show.slim +0 -22
  56. data/app/views/comable/admin/store/new.slim +0 -3
  57. data/app/views/comable/admin/store/show.slim +0 -24
@@ -1,7 +1,35 @@
1
1
  module Comable
2
2
  module Admin
3
3
  class ApplicationController < ActionController::Base
4
+ include Comable::ApplicationHelper
5
+
4
6
  layout 'comable/admin/application'
7
+
8
+ def current_ability
9
+ Comable::Ability.new(current_customer)
10
+ end
11
+
12
+ private
13
+
14
+ rescue_from CanCan::AccessDenied, with: :unauthorized
15
+
16
+ def unauthorized
17
+ if current_customer.signed_in?
18
+ flash[:alert] = Comable.t('admin.access_denied')
19
+ redirect_to after_access_denied_path
20
+ else
21
+ store_location
22
+ redirect_to comable.new_admin_customer_session_path
23
+ end
24
+ end
25
+
26
+ def after_access_denied_path
27
+ if current_customer.customer?
28
+ comable.root_path
29
+ else
30
+ comable.admin_root_path
31
+ end
32
+ end
5
33
  end
6
34
  end
7
35
  end
@@ -0,0 +1,14 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class CategoriesController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::Category.name
7
+
8
+ def create
9
+ Comable::Category.from_jstree!(params[:jstree_json])
10
+ redirect_to comable.admin_categories_path
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,36 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class CustomersController < Comable::Admin::ApplicationController
6
+ include Comable::PermittedAttributes
7
+
8
+ load_and_authorize_resource class: Comable::Customer.name, except: :index
9
+
10
+ def index
11
+ @q = Comable::Customer.ransack(params[:q])
12
+ @customers = @q.result.page(params[:page]).accessible_by(current_ability)
13
+ end
14
+
15
+ def update
16
+ if @customer.update_attributes(customer_params)
17
+ redirect_to comable.admin_customer_path(@customer), notice: Comable.t('successful')
18
+ else
19
+ flash.now[:alert] = Comable.t('failure')
20
+ render :edit
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def customer_params
27
+ params.require(:customer).permit(
28
+ :email,
29
+ :password,
30
+ :role,
31
+ bill_address_attributes: permitted_address_attributes
32
+ )
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,20 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class DashboardController < Comable::Admin::ApplicationController
6
+ def show
7
+ @this_month_orders = Comable::Order.this_month
8
+ @this_week_orders = Comable::Order.this_week
9
+ @last_week_orders = Comable::Order.last_week
10
+ authorize! :read, @this_month_orders
11
+
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
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class OrdersController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::Order.name, except: :index
7
+
8
+ def index
9
+ @q = Comable::Order.complete.ransack(params[:q])
10
+ @orders = @q.result.page(params[:page]).per(15).order('completed_at DESC').accessible_by(current_ability)
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,52 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class PaymentMethodsController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::PaymentMethod.name
7
+
8
+ def index
9
+ @payment_methods = @payment_methods.page(params[:page])
10
+ end
11
+
12
+ def show
13
+ render :edit
14
+ end
15
+
16
+ def create
17
+ if @payment_method.update_attributes(payment_method_params)
18
+ redirect_to comable.admin_payment_method_path(@payment_method), notice: Comable.t('successful')
19
+ else
20
+ flash.now[:alert] = Comable.t('failure')
21
+ render :new
22
+ end
23
+ end
24
+
25
+ def update
26
+ if @payment_method.update_attributes(payment_method_params)
27
+ redirect_to comable.admin_payment_method_path(@payment_method), notice: Comable.t('successful')
28
+ else
29
+ flash.now[:alert] = Comable.t('failure')
30
+ render :edit
31
+ end
32
+ end
33
+
34
+ def destroy
35
+ @payment_method.destroy
36
+ redirect_to comable.admin_payment_methods_path, notice: Comable.t('successful')
37
+ end
38
+
39
+ private
40
+
41
+ def payment_method_params
42
+ params.require(:payment_method).permit(
43
+ :name,
44
+ :payment_provider_type,
45
+ :payment_provider_kind,
46
+ :enable_price_from,
47
+ :enable_price_to
48
+ )
49
+ end
50
+ end
51
+ end
52
+ end
@@ -3,8 +3,57 @@ require_dependency 'comable/admin/application_controller'
3
3
  module Comable
4
4
  module Admin
5
5
  class ProductsController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::Product.name, except: :index
7
+
8
+ def show
9
+ render :edit
10
+ end
11
+
6
12
  def index
7
- @products = Comable::Product.all
13
+ @q = Comable::Product.ransack(params[:q])
14
+ @products = @q.result.includes(:stocks).page(params[:page]).accessible_by(current_ability)
15
+ end
16
+
17
+ def create
18
+ if @product.update_attributes(product_params)
19
+ redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
20
+ else
21
+ flash.now[:alert] = Comable.t('failure')
22
+ render :new
23
+ end
24
+ end
25
+
26
+ def update
27
+ if @product.update_attributes(product_params)
28
+ redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
29
+ else
30
+ flash.now[:alert] = Comable.t('failure')
31
+ render :edit
32
+ end
33
+ end
34
+
35
+ def destroy
36
+ if @product.destroy
37
+ redirect_to comable.admin_products_path, notice: Comable.t('successful')
38
+ else
39
+ flash.now[:alert] = Comable.t('failure')
40
+ render :edit
41
+ end
42
+ end
43
+
44
+ private
45
+
46
+ def product_params
47
+ params.require(:product).permit(
48
+ :name,
49
+ :code,
50
+ :caption,
51
+ :price,
52
+ :sku_h_item_name,
53
+ :sku_v_item_name,
54
+ category_path_names: [],
55
+ images_attributes: [:id, :file, :_destroy]
56
+ )
8
57
  end
9
58
  end
10
59
  end
@@ -3,57 +3,41 @@ require_dependency 'comable/admin/application_controller'
3
3
  module Comable
4
4
  module Admin
5
5
  class ShipmentMethodsController < Comable::Admin::ApplicationController
6
- # GET /admin/shipment_methods
6
+ load_and_authorize_resource class: Comable::ShipmentMethod.name
7
+
7
8
  def index
8
- @shipment_methods = Comable::ShipmentMethod.all
9
+ @shipment_methods = @shipment_methods.page(params[:page])
9
10
  end
10
11
 
11
- # GET /admin/shipment_methods/1
12
12
  def show
13
- @shipment_method = Comable::ShipmentMethod.find(params[:id])
14
- end
15
-
16
- # GET /admin/shipment_methods/new
17
- def new
18
- @shipment_method = Comable::ShipmentMethod.new
13
+ render :edit
19
14
  end
20
15
 
21
- # GET /admin/shipment_methods/1/edit
22
- def edit
23
- @shipment_method = Comable::ShipmentMethod.find(params[:id])
24
- end
25
-
26
- # POST /admin/shipment_methods
27
16
  def create
28
- @shipment_method = Comable::ShipmentMethod.new(shipment_method_params)
29
-
30
- if @shipment_method.save
31
- redirect_to comable.admin_shipment_method_url(@shipment_method), notice: 'Shipment method was successfully created.'
17
+ if @shipment_method.update_attributes(shipment_method_params)
18
+ redirect_to comable.admin_shipment_method_path(@shipment_method), notice: Comable.t('successful')
32
19
  else
20
+ flash.now[:alert] = Comable.t('failure')
33
21
  render :new
34
22
  end
35
23
  end
36
24
 
37
- # PATCH/PUT /admin/shipment_methods/1
38
25
  def update
39
- @shipment_method = Comable::ShipmentMethod.find(params[:id])
40
- if @shipment_method.update(shipment_method_params)
41
- redirect_to comable.admin_shipment_method_url(@shipment_method), notice: 'Shipment method was successfully updated.'
26
+ if @shipment_method.update_attributes(shipment_method_params)
27
+ redirect_to comable.admin_shipment_method_path(@shipment_method), notice: Comable.t('successful')
42
28
  else
29
+ flash.now[:alert] = Comable.t('failure')
43
30
  render :edit
44
31
  end
45
32
  end
46
33
 
47
- # DELETE /admin/shipment_methods/1
48
34
  def destroy
49
- @shipment_method = Comable::ShipmentMethod.find(params[:id])
50
35
  @shipment_method.destroy
51
- redirect_to comable.admin_shipment_methods_url, notice: 'Shipment method was successfully destroyed.'
36
+ redirect_to comable.admin_shipment_methods_path, notice: Comable.t('successful')
52
37
  end
53
38
 
54
39
  private
55
40
 
56
- # Only allow a trusted parameter "white list" through.
57
41
  def shipment_method_params
58
42
  params.require(:shipment_method).permit(
59
43
  :activate_flag,
@@ -0,0 +1,69 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class StocksController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource :product, class: Comable::Product.name
7
+ load_and_authorize_resource :stock, class: Comable::Stock.name, through: :product
8
+
9
+ before_filter :redirect_to_show_when_nonsku_product, only: :index
10
+
11
+ def show
12
+ render :edit
13
+ end
14
+
15
+ def index
16
+ @q = @product.stocks.ransack(params[:q])
17
+ @stocks = @q.result.includes(:product).page(params[:page]).accessible_by(current_ability)
18
+ end
19
+
20
+ def create
21
+ if @stock.update_attributes(stock_params)
22
+ redirect_to comable.admin_product_stock_path(@product, @stock), notice: Comable.t('successful')
23
+ else
24
+ flash.now[:alert] = Comable.t('failure')
25
+ render :new
26
+ end
27
+ end
28
+
29
+ def update
30
+ if @stock.update_attributes(stock_params)
31
+ redirect_to comable.admin_product_stock_path(@product, @stock), notice: Comable.t('successful')
32
+ else
33
+ flash.now[:alert] = Comable.t('failure')
34
+ render :edit
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ if @stock.destroy
40
+ redirect_to comable.admin_product_stocks_path(@product), notice: Comable.t('successful')
41
+ else
42
+ flash.now[:alert] = Comable.t('failure')
43
+ render :edit
44
+ end
45
+ end
46
+
47
+ private
48
+
49
+ def stock_params
50
+ params.require(:stock).permit(
51
+ :code,
52
+ :quantity,
53
+ :sku_h_choice_name,
54
+ :sku_v_choice_name
55
+ )
56
+ end
57
+
58
+ def redirect_to_show_when_nonsku_product
59
+ return if @product.sku?
60
+
61
+ if @product.stocks.first
62
+ redirect_to comable.admin_product_stock_path(@product, @product.stocks.first)
63
+ else
64
+ redirect_to comable.new_admin_product_stock_path(@product)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -3,50 +3,33 @@ require_dependency 'comable/admin/application_controller'
3
3
  module Comable
4
4
  module Admin
5
5
  class StoreController < Comable::Admin::ApplicationController
6
- # GET /admin/store
7
- def show
8
- @store = Comable::Store.first
9
- return redirect_to action: :new unless @store
10
- end
11
-
12
- # GET /admin/store/new
13
- def new
14
- @store = Comable::Store.new
15
- end
16
-
17
- # GET /admin/store/edit
18
- def edit
19
- @store = Comable::Store.first
20
- end
6
+ authorize_resource class: Comable::Store.name
21
7
 
22
- # POST /admin/store
23
- def create
24
- @store = Comable::Store.new(store_params)
8
+ before_filter :find_store, only: [:show, :edit, :update]
25
9
 
26
- if @store.save
27
- redirect_to comable.admin_store_url(@store), notice: 'Store was successfully created.'
28
- else
29
- render :new
30
- end
10
+ def show
11
+ render :edit
31
12
  end
32
13
 
33
- # PATCH/PUT /admin/store
34
14
  def update
35
- @store = Comable::Store.first
36
- if @store.update(store_params)
37
- redirect_to comable.admin_store_url(@store), notice: 'Store was successfully updated.'
15
+ if @store.update_attributes(store_params)
16
+ redirect_to comable.admin_store_url, notice: Comable.t('successful')
38
17
  else
18
+ flash.now[:alert] = Comable.t('failure')
39
19
  render :edit
40
20
  end
41
21
  end
42
22
 
43
23
  private
44
24
 
45
- # Only allow a trusted parameter "white list" through.
25
+ def find_store
26
+ @store = Comable::Store.instance
27
+ end
28
+
46
29
  def store_params
47
30
  params.require(:store).permit(
48
31
  :name,
49
- :meta_keyword,
32
+ :meta_keywords,
50
33
  :meta_description,
51
34
  :email_sender,
52
35
  :email_activate_flag
@@ -0,0 +1,94 @@
1
+ #comable-category
2
+ ol.breadcrumb
3
+ li
4
+ = link_to Comable.t('admin.nav.dashboard'), comable.admin_root_path
5
+ li.active
6
+ = Comable.t('admin.nav.category')
7
+
8
+ h1.page-header
9
+ = Comable.t('admin.nav.category')
10
+
11
+ javascript:
12
+ comable_jstree_json = #{raw @categories.to_jstree(state: { opened: true }, icon: 'fa fa-bars')};
13
+ comable_new_node_label = '#{Comable.t('admin.categories.new_node')}';
14
+ comable_action_new = '#{Comable.t('admin.actions.new')}';
15
+ comable_action_edit = '#{Comable.t('admin.actions.edit')}';
16
+ comable_action_destroy = '#{Comable.t('admin.actions.destroy')}';
17
+ comable_destroied_nodes = [];
18
+
19
+ coffee:
20
+ jQuery(->
21
+ $comable_jstree = $('#comable-jstree')
22
+ $comable_jstree.jstree({
23
+ core: {
24
+ check_callback: true,
25
+ data: comable_jstree_json,
26
+ strings : { new_node: comable_new_node_label, icon: 'fa fa-bars' }
27
+ },
28
+ contextmenu: {
29
+ items: ($node) ->
30
+ _this = $comable_jstree.jstree(true)
31
+ {
32
+ create: {
33
+ label: comable_action_new,
34
+ action: -> create_new_node($node)
35
+ }
36
+ edit: {
37
+ label: comable_action_edit,
38
+ action: -> _this.edit($node)
39
+ }
40
+ destory: {
41
+ label: comable_action_destroy,
42
+ action: ->
43
+ comable_destroied_nodes.push { _destroy: $node.id }
44
+ _this.delete_node($node)
45
+ }
46
+ }
47
+ },
48
+ plugins: ['dnd', 'wholerow', 'contextmenu']
49
+ })
50
+
51
+ window.create_new_node = ($node = '#') ->
52
+ jstree = $comable_jstree.jstree(true)
53
+ new_node = jstree.create_node($node)
54
+ jstree.open_node($node) unless jstree.is_open($node)
55
+ jstree.rename_node(new_node, comable_new_node_label)
56
+ jstree.set_icon(new_node, 'fa fa-bars')
57
+
58
+ $('form').submit(->
59
+ json = $comable_jstree.jstree(true).get_json().concat(comable_destroied_nodes)
60
+ json_string = JSON.stringify(json)
61
+ $(this).find('#jstree_json').val(json_string)
62
+ )
63
+ )
64
+
65
+ .row
66
+ section.col-sm-8
67
+ .panel.panel-inverse
68
+ .panel-heading
69
+ .panel-title
70
+ = Comable.t('admin.actions.edit')
71
+ - if @categories.empty?
72
+ .panel-body
73
+ = Comable.t('admin.not_found')
74
+ - else
75
+ .panel-body
76
+ .well.well-sm
77
+ p
78
+ strong
79
+ = Comable.t('admin.note')
80
+ ul
81
+ li
82
+ = Comable.t('admin.you_can_drag_and_drop')
83
+ li
84
+ = Comable.t('admin.you_can_right_click')
85
+ li
86
+ = Comable.t('admin.link_to_add_new_node')
87
+ = link_to Comable.t('admin.actions.new'), '#', onclick: 'create_new_node()'
88
+ #comable-jstree
89
+ .panel-footer
90
+ = form_tag comable.admin_categories_path do
91
+ = hidden_field_tag :jstree_json
92
+ = submit_tag Comable.t('admin.actions.update')
93
+
94
+ nav.col-sm-4