comable-backend 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +97 -0
  4. data/app/assets/javascripts/comable/admin/application.coffee +76 -0
  5. data/app/assets/javascripts/comable/admin/categories.coffee +59 -0
  6. data/app/assets/javascripts/comable/admin/dashboard.coffee +32 -0
  7. data/app/assets/javascripts/comable/admin/dispatcher.coffee +21 -0
  8. data/app/assets/javascripts/comable/admin/orders.coffee +44 -0
  9. data/app/assets/javascripts/comable/admin/pages.coffee +69 -0
  10. data/app/assets/javascripts/comable/admin/products.coffee +21 -0
  11. data/app/assets/javascripts/comable/admin/search.coffee +35 -0
  12. data/app/assets/javascripts/comable/admin/themes.coffee +64 -0
  13. data/app/assets/stylesheets/comable/admin/_common.scss +153 -0
  14. data/app/assets/stylesheets/comable/admin/_dashboard.scss +81 -0
  15. data/app/assets/stylesheets/comable/admin/_errors.scss +18 -0
  16. data/app/assets/stylesheets/comable/admin/_flow.scss +149 -0
  17. data/app/assets/stylesheets/comable/admin/_mixins.scss +16 -0
  18. data/app/assets/stylesheets/comable/admin/_orders.scss +54 -0
  19. data/app/assets/stylesheets/comable/admin/_overrides.scss +4 -0
  20. data/app/assets/stylesheets/comable/admin/_pages.scss +30 -0
  21. data/app/assets/stylesheets/comable/admin/_products.scss +18 -0
  22. data/app/assets/stylesheets/comable/admin/_themes.scss +71 -0
  23. data/app/assets/stylesheets/comable/admin/_user_sessions.scss +57 -0
  24. data/app/assets/stylesheets/comable/admin/_variables.scss +38 -0
  25. data/app/assets/stylesheets/comable/admin/application.scss +26 -0
  26. data/app/assets/stylesheets/comable/admin/overrides/awesome_admin_layout.scss +25 -0
  27. data/app/assets/stylesheets/comable/admin/overrides/bootstrap.scss +81 -0
  28. data/app/assets/stylesheets/comable/admin/overrides/jstree.scss +71 -0
  29. data/app/assets/stylesheets/comable/admin/overrides/tagit.scss +22 -0
  30. data/app/controllers/comable/admin/application_controller.rb +58 -0
  31. data/app/controllers/comable/admin/categories_controller.rb +17 -0
  32. data/app/controllers/comable/admin/dashboard_controller.rb +19 -0
  33. data/app/controllers/comable/admin/orders_controller.rb +102 -0
  34. data/app/controllers/comable/admin/pages_controller.rb +72 -0
  35. data/app/controllers/comable/admin/payment_methods_controller.rb +59 -0
  36. data/app/controllers/comable/admin/products_controller.rb +82 -0
  37. data/app/controllers/comable/admin/shipment_methods_controller.rb +57 -0
  38. data/app/controllers/comable/admin/stocks_controller.rb +81 -0
  39. data/app/controllers/comable/admin/store_controller.rb +42 -0
  40. data/app/controllers/comable/admin/themes_controller.rb +101 -0
  41. data/app/controllers/comable/admin/trackers_controller.rb +58 -0
  42. data/app/controllers/comable/admin/user_sessions_controller.rb +8 -0
  43. data/app/controllers/comable/admin/users_controller.rb +47 -0
  44. data/app/helpers/comable/admin/application_helper.rb +53 -0
  45. data/app/helpers/comable/admin/orders_helper.rb +30 -0
  46. data/app/helpers/comable/admin/pages_helper.rb +6 -0
  47. data/app/helpers/comable/admin/products_helper.rb +6 -0
  48. data/app/helpers/comable/admin/shipment_methods_helper.rb +6 -0
  49. data/app/helpers/comable/admin/stores_helper.rb +6 -0
  50. data/app/helpers/comable/admin/themes_helper.rb +69 -0
  51. data/app/views/comable/admin/categories/index.slim +40 -0
  52. data/app/views/comable/admin/dashboard/_widget.slim +13 -0
  53. data/app/views/comable/admin/dashboard/show.slim +43 -0
  54. data/app/views/comable/admin/orders/_google_map.slim +39 -0
  55. data/app/views/comable/admin/orders/_payment_state.slim +40 -0
  56. data/app/views/comable/admin/orders/_shipment_state.slim +44 -0
  57. data/app/views/comable/admin/orders/edit.slim +170 -0
  58. data/app/views/comable/admin/orders/index.slim +95 -0
  59. data/app/views/comable/admin/orders/show.slim +177 -0
  60. data/app/views/comable/admin/pages/_form.slim +69 -0
  61. data/app/views/comable/admin/pages/edit.slim +31 -0
  62. data/app/views/comable/admin/pages/index.slim +55 -0
  63. data/app/views/comable/admin/pages/new.slim +16 -0
  64. data/app/views/comable/admin/payment_methods/_form.slim +35 -0
  65. data/app/views/comable/admin/payment_methods/edit.slim +27 -0
  66. data/app/views/comable/admin/payment_methods/index.slim +40 -0
  67. data/app/views/comable/admin/payment_methods/new.slim +16 -0
  68. data/app/views/comable/admin/products/_form.slim +137 -0
  69. data/app/views/comable/admin/products/edit.slim +41 -0
  70. data/app/views/comable/admin/products/index.slim +95 -0
  71. data/app/views/comable/admin/products/new.slim +16 -0
  72. data/app/views/comable/admin/shared/_advanced_search.slim +7 -0
  73. data/app/views/comable/admin/shared/_condition_fields.slim +15 -0
  74. data/app/views/comable/admin/shared/_footer.slim +8 -0
  75. data/app/views/comable/admin/shared/_grouping_fields.slim +8 -0
  76. data/app/views/comable/admin/shared/_image_fields.slim +15 -0
  77. data/app/views/comable/admin/shared/_notifier.slim +5 -0
  78. data/app/views/comable/admin/shared/_value_fields.slim +1 -0
  79. data/app/views/comable/admin/shared/export.xlsx.axlsx +17 -0
  80. data/app/views/comable/admin/shipment_methods/_form.slim +29 -0
  81. data/app/views/comable/admin/shipment_methods/edit.slim +27 -0
  82. data/app/views/comable/admin/shipment_methods/index.slim +37 -0
  83. data/app/views/comable/admin/shipment_methods/new.slim +16 -0
  84. data/app/views/comable/admin/stocks/_form.slim +34 -0
  85. data/app/views/comable/admin/stocks/edit.slim +37 -0
  86. data/app/views/comable/admin/stocks/index.slim +81 -0
  87. data/app/views/comable/admin/stocks/new.slim +18 -0
  88. data/app/views/comable/admin/store/_form.slim +32 -0
  89. data/app/views/comable/admin/store/edit.slim +12 -0
  90. data/app/views/comable/admin/themes/_editor.slim +8 -0
  91. data/app/views/comable/admin/themes/_form.slim +31 -0
  92. data/app/views/comable/admin/themes/edit.slim +35 -0
  93. data/app/views/comable/admin/themes/index.slim +37 -0
  94. data/app/views/comable/admin/themes/new.slim +16 -0
  95. data/app/views/comable/admin/themes/show_file.slim +93 -0
  96. data/app/views/comable/admin/trackers/_form.slim +109 -0
  97. data/app/views/comable/admin/trackers/edit.slim +27 -0
  98. data/app/views/comable/admin/trackers/index.slim +37 -0
  99. data/app/views/comable/admin/trackers/new.slim +16 -0
  100. data/app/views/comable/admin/user_sessions/new.slim +25 -0
  101. data/app/views/comable/admin/users/edit.slim +79 -0
  102. data/app/views/comable/admin/users/index.slim +71 -0
  103. data/app/views/comable/admin/users/show.slim +88 -0
  104. data/app/views/kaminari/comable_backend/_first_page.html.slim +2 -0
  105. data/app/views/kaminari/comable_backend/_gap.html.slim +2 -0
  106. data/app/views/kaminari/comable_backend/_last_page.html.slim +2 -0
  107. data/app/views/kaminari/comable_backend/_next_page.html.slim +2 -0
  108. data/app/views/kaminari/comable_backend/_page.html.slim +3 -0
  109. data/app/views/kaminari/comable_backend/_paginator.html.slim +15 -0
  110. data/app/views/kaminari/comable_backend/_prev_page.html.slim +2 -0
  111. data/app/views/layouts/comable/admin/application.slim +36 -0
  112. data/config/initializers/awesome_admin_layout.rb +110 -0
  113. data/config/routes.rb +63 -0
  114. data/lib/comable/backend.rb +1 -0
  115. data/lib/comable/backend/engine.rb +67 -0
  116. data/lib/tasks/comable_backend_tasks.rake +4 -0
  117. metadata +514 -0
@@ -0,0 +1,22 @@
1
+ ul.tagit > li > input[type="text"] {
2
+ height: auto;
3
+ }
4
+
5
+ ul.tagit-autocomplete.ui-menu {
6
+ @include border-radius($border-radius-base);
7
+ @include box-shadow(0 6px 12px rgba(0, 0, 0, 0.175));
8
+ padding: 5px 0;
9
+ border-color: $dropdown-border;
10
+
11
+ li.ui-menu-item {
12
+ padding: $padding-base-vertical $padding-base-horizontal;
13
+ color: $dropdown-link-color;
14
+ background-color: $dropdown-bg;
15
+ border: none;
16
+
17
+ &.ui-state-focus {
18
+ color: $dropdown-link-active-color;
19
+ background-color: $dropdown-link-active-bg;
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,58 @@
1
+ module Comable
2
+ module Admin
3
+ class ApplicationController < ActionController::Base
4
+ include Comable::ApplicationHelper
5
+
6
+ # Include `asset_path` method for gritter
7
+ helper Sprockets::Helpers::RailsHelper if Rails::VERSION::MAJOR == 3
8
+
9
+ layout 'comable/admin/application'
10
+
11
+ def current_ability
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
25
+ end
26
+
27
+ private
28
+
29
+ rescue_from CanCan::AccessDenied, with: :unauthorized
30
+
31
+ def unauthorized
32
+ if current_comable_user.signed_in?
33
+ flash[:alert] = Comable.t('admin.access_denied')
34
+ redirect_to after_access_denied_path
35
+ else
36
+ store_location
37
+ redirect_to comable.new_admin_user_session_path
38
+ end
39
+ end
40
+
41
+ def after_access_denied_path
42
+ if current_comable_user.customer?
43
+ comable.root_path
44
+ else
45
+ comable.admin_root_path
46
+ end
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
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,17 @@
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 index
9
+ end
10
+
11
+ def create
12
+ Comable::Category.from_jstree!(params[:jstree_json])
13
+ redirect_to comable.admin_categories_path
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,19 @@
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
+ @this_month_users = Comable::User.with_role(:customer).this_month
13
+ @this_week_users = Comable::User.with_role(:customer).this_week
14
+ @last_week_users = Comable::User.with_role(:customer).last_week
15
+ authorize! :read, @this_week_users
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,102 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class OrdersController < Comable::Admin::ApplicationController
6
+ include Comable::PermittedAttributes
7
+
8
+ load_and_authorize_resource class: Comable::Order.name, except: :index
9
+
10
+ def index
11
+ @q = Comable::Order.complete.ransack(params[:q])
12
+ @orders = @q.result.page(params[:page]).per(15).recent.accessible_by(current_ability)
13
+ end
14
+
15
+ def show
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
+ :payment_fee,
93
+ :shipment_fee,
94
+ :total_price,
95
+ bill_address_attributes: permitted_address_attributes,
96
+ ship_address_attributes: permitted_address_attributes,
97
+ order_items_attributes: [:id, :name, :code, :price, :quantity]
98
+ )
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,72 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class PagesController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::Page.name, except: :index, find_by: :slug
7
+
8
+ def index
9
+ @q = Comable::Page.ransack(params[:q])
10
+ @pages = @q.result.accessible_by(current_ability)
11
+ end
12
+
13
+ def show
14
+ edit
15
+ render :edit
16
+ end
17
+
18
+ def new
19
+ end
20
+
21
+ def edit
22
+ set_preview_session
23
+ end
24
+
25
+ def create
26
+ @page = Comable::Page.new(page_params)
27
+ @page.slug = @page.normalize_slug(page_params[:slug])
28
+
29
+ if @page.save
30
+ redirect_to comable.admin_page_path(@page), notice: Comable.t('successful')
31
+ else
32
+ render :new
33
+ end
34
+ end
35
+
36
+ def update
37
+ @page.attributes = page_params
38
+ @page.slug = @page.normalize_slug(page_params[:slug])
39
+
40
+ if @page.save
41
+ redirect_to comable.admin_page_path(@page), notice: Comable.t('successful')
42
+ else
43
+ render :edit
44
+ end
45
+ end
46
+
47
+ def destroy
48
+ @page.destroy
49
+ redirect_to comable.admin_pages_path, notice: Comable.t('successful')
50
+ end
51
+
52
+ private
53
+
54
+ def page_params
55
+ params.require(:page).permit(
56
+ :title, # コンテンツのタイトル
57
+ :content, # コンテンツ
58
+ :page_title, # ページのタイトル
59
+ :meta_description, # ディスクリプション
60
+ :meta_keywords, # キーワード
61
+ :slug, # スラグ
62
+ :published_at # 公開日時
63
+ )
64
+ end
65
+
66
+ def set_preview_session
67
+ session[Comable::Page::PREVIEW_SESSION_KEY] ||= {}
68
+ session[Comable::Page::PREVIEW_SESSION_KEY][@page.slug] = true
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,59 @@
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 new
17
+ end
18
+
19
+ def create
20
+ if @payment_method.save
21
+ redirect_to comable.admin_payment_method_path(@payment_method), 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 @payment_method.update_attributes(payment_method_params)
33
+ redirect_to comable.admin_payment_method_path(@payment_method), 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
+ @payment_method.destroy
42
+ redirect_to comable.admin_payment_methods_path, notice: Comable.t('successful')
43
+ end
44
+
45
+ private
46
+
47
+ def payment_method_params
48
+ params.require(:payment_method).permit(
49
+ :name,
50
+ :payment_provider_type,
51
+ :payment_provider_kind,
52
+ :fee,
53
+ :enable_price_from,
54
+ :enable_price_to
55
+ )
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,82 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class ProductsController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::Product.name, except: :index
7
+
8
+ def index
9
+ @q = Comable::Product.ransack(params[:q])
10
+ @products = @q.result(distinct: true).includes(:stocks, :images).page(params[:page]).accessible_by(current_ability)
11
+ end
12
+
13
+ def show
14
+ render :edit
15
+ end
16
+
17
+ def new
18
+ end
19
+
20
+ def create
21
+ if @product.save
22
+ redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
23
+ else
24
+ flash.now[:alert] = Comable.t('failure')
25
+ render :new
26
+ end
27
+ end
28
+
29
+ def edit
30
+ end
31
+
32
+ def update
33
+ if @product.update_attributes(product_params)
34
+ redirect_to comable.admin_product_path(@product), notice: Comable.t('successful')
35
+ else
36
+ flash.now[:alert] = Comable.t('failure')
37
+ render :edit
38
+ end
39
+ end
40
+
41
+ def destroy
42
+ if @product.destroy
43
+ redirect_to comable.admin_products_path, notice: Comable.t('successful')
44
+ else
45
+ flash.now[:alert] = Comable.t('failure')
46
+ render :edit
47
+ end
48
+ end
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
+
66
+ private
67
+
68
+ def product_params
69
+ params.require(:product).permit(
70
+ :name,
71
+ :code,
72
+ :caption,
73
+ :price,
74
+ :sku_h_item_name,
75
+ :sku_v_item_name,
76
+ category_path_names: [],
77
+ images_attributes: [:id, :file, :_destroy]
78
+ )
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,57 @@
1
+ require_dependency 'comable/admin/application_controller'
2
+
3
+ module Comable
4
+ module Admin
5
+ class ShipmentMethodsController < Comable::Admin::ApplicationController
6
+ load_and_authorize_resource class: Comable::ShipmentMethod.name
7
+
8
+ def index
9
+ @shipment_methods = @shipment_methods.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 @shipment_method.save
21
+ redirect_to comable.admin_shipment_method_path(@shipment_method), 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 @shipment_method.update_attributes(shipment_method_params)
33
+ redirect_to comable.admin_shipment_method_path(@shipment_method), 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
+ @shipment_method.destroy
42
+ redirect_to comable.admin_shipment_methods_path, notice: Comable.t('successful')
43
+ end
44
+
45
+ private
46
+
47
+ def shipment_method_params
48
+ params.require(:shipment_method).permit(
49
+ :activated_flag,
50
+ :name,
51
+ :fee,
52
+ :traking_url
53
+ )
54
+ end
55
+ end
56
+ end
57
+ end