vyapari 0.1.5dev10 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/vyapari/admin/base_controller.rb +0 -9
  3. data/app/controllers/vyapari/admin/countries_controller.rb +2 -2
  4. data/app/controllers/vyapari/admin/dashboard_controller.rb +1 -3
  5. data/app/controllers/vyapari/admin/exchange_rates_controller.rb +2 -2
  6. data/app/controllers/vyapari/admin/regions_controller.rb +1 -1
  7. data/app/controllers/vyapari/admin/resource_controller.rb +0 -1
  8. data/app/controllers/vyapari/admin/users_controller.rb +130 -0
  9. data/app/controllers/vyapari/application_controller.rb +0 -11
  10. data/app/models/brand.rb +19 -67
  11. data/app/models/category.rb +19 -63
  12. data/app/models/country.rb +7 -31
  13. data/app/models/exchange_rate.rb +7 -32
  14. data/app/models/product.rb +20 -75
  15. data/app/models/region.rb +20 -37
  16. data/app/models/vyapari/application_record.rb +0 -3
  17. data/app/views/layouts/kuppayam/_footer.html.erb +1 -1
  18. data/app/views/layouts/kuppayam/_sidebar.html.erb +44 -45
  19. data/app/views/vyapari/admin/countries/_index.html.erb +1 -1
  20. data/app/views/vyapari/admin/countries/index.html.erb +3 -19
  21. data/app/views/vyapari/admin/exchange_rates/_form.html.erb +4 -3
  22. data/app/views/vyapari/admin/exchange_rates/_index.html.erb +7 -7
  23. data/app/views/vyapari/admin/exchange_rates/_row.html.erb +3 -3
  24. data/app/views/vyapari/admin/exchange_rates/_show.html.erb +0 -1
  25. data/app/views/vyapari/admin/exchange_rates/index.html.erb +3 -19
  26. data/app/views/vyapari/admin/regions/_index.html.erb +1 -1
  27. data/app/views/vyapari/admin/regions/index.html.erb +3 -19
  28. data/app/views/vyapari/admin/users/_form.html.erb +39 -0
  29. data/app/views/vyapari/admin/users/_index.html.erb +101 -0
  30. data/app/views/vyapari/admin/users/_row.html.erb +72 -0
  31. data/app/views/vyapari/admin/users/_show.html.erb +199 -0
  32. data/app/views/vyapari/admin/{categories → users}/index.html.erb +24 -8
  33. data/config/routes.rb +5 -66
  34. data/db/migrate/20170000000200_create_exchange_rates.rb +2 -3
  35. data/lib/tasks/vyapari_tasks.rake +4 -0
  36. data/lib/vyapari/version.rb +1 -1
  37. metadata +15 -167
  38. data/app/assets/images/vyapari/sample_stock_bundle.csv +0 -1
  39. data/app/controllers/vyapari/admin/brands_controller.rb +0 -99
  40. data/app/controllers/vyapari/admin/categories_controller.rb +0 -115
  41. data/app/controllers/vyapari/admin/products_controller.rb +0 -79
  42. data/app/controllers/vyapari/admin/stores_controller.rb +0 -67
  43. data/app/controllers/vyapari/admin/suppliers_controller.rb +0 -67
  44. data/app/controllers/vyapari/admin/terminals_controller.rb +0 -150
  45. data/app/controllers/vyapari/store_manager/base_controller.rb +0 -33
  46. data/app/controllers/vyapari/store_manager/dashboard_controller.rb +0 -31
  47. data/app/controllers/vyapari/store_manager/reports/invoices_controller.rb +0 -249
  48. data/app/controllers/vyapari/store_manager/reports/sales_controller.rb +0 -299
  49. data/app/controllers/vyapari/store_manager/reports/stock_controller.rb +0 -132
  50. data/app/controllers/vyapari/store_manager/resource_controller.rb +0 -17
  51. data/app/controllers/vyapari/store_manager/stock_bundles_controller.rb +0 -206
  52. data/app/controllers/vyapari/store_manager/stock_entries_controller.rb +0 -161
  53. data/app/controllers/vyapari/terminal_staff/base_controller.rb +0 -38
  54. data/app/controllers/vyapari/terminal_staff/dashboard_controller.rb +0 -35
  55. data/app/controllers/vyapari/terminal_staff/invoices_controller.rb +0 -147
  56. data/app/controllers/vyapari/terminal_staff/line_items_controller.rb +0 -139
  57. data/app/controllers/vyapari/terminal_staff/resource_controller.rb +0 -17
  58. data/app/controllers/vyapari/user_dashboard_controller.rb +0 -31
  59. data/app/models/bank_account.rb +0 -44
  60. data/app/models/contact.rb +0 -72
  61. data/app/models/image/brand_image.rb +0 -3
  62. data/app/models/image/category_image.rb +0 -3
  63. data/app/models/image/product_image.rb +0 -3
  64. data/app/models/invoice.rb +0 -256
  65. data/app/models/line_item.rb +0 -207
  66. data/app/models/stock_bundle.rb +0 -249
  67. data/app/models/stock_entry.rb +0 -275
  68. data/app/models/store.rb +0 -302
  69. data/app/models/supplier.rb +0 -79
  70. data/app/models/terminal.rb +0 -158
  71. data/app/uploaders/brand_image_uploader.rb +0 -14
  72. data/app/uploaders/category_image_uploader.rb +0 -14
  73. data/app/uploaders/product_image_uploader.rb +0 -14
  74. data/app/uploaders/stock_bundle_uploader.rb +0 -10
  75. data/app/views/layouts/vyapari/_store_manager_menu.html.erb +0 -126
  76. data/app/views/layouts/vyapari/_terminal_staff_menu.html.erb +0 -106
  77. data/app/views/layouts/vyapari/store_manager.html.erb +0 -112
  78. data/app/views/layouts/vyapari/terminal_staff.html.erb +0 -116
  79. data/app/views/vyapari/admin/brands/_form.html.erb +0 -23
  80. data/app/views/vyapari/admin/brands/_index.html.erb +0 -89
  81. data/app/views/vyapari/admin/brands/_row.html.erb +0 -63
  82. data/app/views/vyapari/admin/brands/_show.html.erb +0 -104
  83. data/app/views/vyapari/admin/brands/index.html.erb +0 -48
  84. data/app/views/vyapari/admin/categories/_form.html.erb +0 -28
  85. data/app/views/vyapari/admin/categories/_index.html.erb +0 -101
  86. data/app/views/vyapari/admin/categories/_row.html.erb +0 -69
  87. data/app/views/vyapari/admin/categories/_show.html.erb +0 -115
  88. data/app/views/vyapari/admin/products/_form.html.erb +0 -32
  89. data/app/views/vyapari/admin/products/_index.html.erb +0 -58
  90. data/app/views/vyapari/admin/products/_row.html.erb +0 -30
  91. data/app/views/vyapari/admin/products/_show.html.erb +0 -81
  92. data/app/views/vyapari/admin/products/index.html.erb +0 -48
  93. data/app/views/vyapari/admin/stores/_form.html.erb +0 -37
  94. data/app/views/vyapari/admin/stores/_index.html.erb +0 -84
  95. data/app/views/vyapari/admin/stores/_row.html.erb +0 -55
  96. data/app/views/vyapari/admin/stores/_show.html.erb +0 -110
  97. data/app/views/vyapari/admin/stores/index.html.erb +0 -48
  98. data/app/views/vyapari/admin/suppliers/_form.html.erb +0 -32
  99. data/app/views/vyapari/admin/suppliers/_index.html.erb +0 -58
  100. data/app/views/vyapari/admin/suppliers/_row.html.erb +0 -30
  101. data/app/views/vyapari/admin/suppliers/_show.html.erb +0 -81
  102. data/app/views/vyapari/admin/suppliers/index.html.erb +0 -48
  103. data/app/views/vyapari/admin/terminals/_form.html.erb +0 -24
  104. data/app/views/vyapari/admin/terminals/_index.html.erb +0 -75
  105. data/app/views/vyapari/admin/terminals/_row.html.erb +0 -49
  106. data/app/views/vyapari/admin/terminals/_show.html.erb +0 -74
  107. data/app/views/vyapari/store_manager/dashboard/_sales_counts.html.erb +0 -90
  108. data/app/views/vyapari/store_manager/dashboard/_stock_counts.html.erb +0 -63
  109. data/app/views/vyapari/store_manager/dashboard/_terminals.html.erb +0 -23
  110. data/app/views/vyapari/store_manager/dashboard/index.html.erb +0 -64
  111. data/app/views/vyapari/store_manager/reports/invoices/_index.html.erb +0 -65
  112. data/app/views/vyapari/store_manager/reports/invoices/index.html.erb +0 -105
  113. data/app/views/vyapari/store_manager/reports/sales/_index.html.erb +0 -64
  114. data/app/views/vyapari/store_manager/reports/sales/index.html.erb +0 -105
  115. data/app/views/vyapari/store_manager/reports/stock/_index.html.erb +0 -72
  116. data/app/views/vyapari/store_manager/reports/stock/index.html.erb +0 -32
  117. data/app/views/vyapari/store_manager/stock_bundles/_form.html.erb +0 -99
  118. data/app/views/vyapari/store_manager/stock_bundles/_index.html.erb +0 -74
  119. data/app/views/vyapari/store_manager/stock_bundles/_row.html.erb +0 -44
  120. data/app/views/vyapari/store_manager/stock_bundles/_show.html.erb +0 -110
  121. data/app/views/vyapari/store_manager/stock_bundles/create.html.erb +0 -57
  122. data/app/views/vyapari/store_manager/stock_bundles/index.html.erb +0 -36
  123. data/app/views/vyapari/store_manager/stock_bundles/update.html.erb +0 -57
  124. data/app/views/vyapari/store_manager/stock_entries/_form.html.erb +0 -50
  125. data/app/views/vyapari/store_manager/stock_entries/_index.html.erb +0 -80
  126. data/app/views/vyapari/store_manager/stock_entries/_row.html.erb +0 -33
  127. data/app/views/vyapari/store_manager/stock_entries/_show.html.erb +0 -110
  128. data/app/views/vyapari/store_manager/stock_entries/_stock_bundle.html.erb +0 -61
  129. data/app/views/vyapari/store_manager/stock_entries/index.html.erb +0 -45
  130. data/app/views/vyapari/terminal_staff/dashboard/_counts.html.erb +0 -131
  131. data/app/views/vyapari/terminal_staff/dashboard/_invoices.html.erb +0 -44
  132. data/app/views/vyapari/terminal_staff/dashboard/_search_form.html.erb +0 -6
  133. data/app/views/vyapari/terminal_staff/dashboard/_search_results.html.erb +0 -24
  134. data/app/views/vyapari/terminal_staff/dashboard/index.html.erb +0 -56
  135. data/app/views/vyapari/terminal_staff/dashboard/search.js.erb +0 -12
  136. data/app/views/vyapari/terminal_staff/invoices/_draft.html.erb +0 -62
  137. data/app/views/vyapari/terminal_staff/invoices/_form.html.erb +0 -134
  138. data/app/views/vyapari/terminal_staff/invoices/_index.html.erb +0 -70
  139. data/app/views/vyapari/terminal_staff/invoices/_row.html.erb +0 -33
  140. data/app/views/vyapari/terminal_staff/invoices/_show.html.erb +0 -204
  141. data/app/views/vyapari/terminal_staff/invoices/index.html.erb +0 -35
  142. data/app/views/vyapari/terminal_staff/invoices/new.js.erb +0 -18
  143. data/app/views/vyapari/terminal_staff/invoices/show.html.erb +0 -1
  144. data/app/views/vyapari/terminal_staff/invoices/show.js.erb +0 -13
  145. data/app/views/vyapari/terminal_staff/line_items/_form.html.erb +0 -40
  146. data/app/views/vyapari/terminal_staff/line_items/_index.html.erb +0 -96
  147. data/app/views/vyapari/terminal_staff/line_items/create.js.erb +0 -34
  148. data/app/views/vyapari/terminal_staff/line_items/destroy.js.erb +0 -25
  149. data/app/views/vyapari/user_dashboard/index.html.erb +0 -51
  150. data/db/import_data/brands.csv +0 -7
  151. data/db/import_data/categories.csv +0 -12
  152. data/db/import_data/countries.csv +0 -1
  153. data/db/import_data/dummy/brands.csv +0 -7
  154. data/db/import_data/dummy/categories.csv +0 -12
  155. data/db/import_data/dummy/countries.csv +0 -1
  156. data/db/import_data/dummy/exchange_rates.csv +0 -5
  157. data/db/import_data/dummy/products-copy.csv +0 -1
  158. data/db/import_data/dummy/products.csv +0 -1
  159. data/db/import_data/dummy/products.xlsx +0 -0
  160. data/db/import_data/dummy/regions.csv +0 -13
  161. data/db/import_data/dummy/stores.csv +0 -10
  162. data/db/import_data/dummy/suppliers.csv +0 -14
  163. data/db/import_data/dummy/terminals.csv +0 -11
  164. data/db/import_data/exchange_rates.csv +0 -5
  165. data/db/import_data/regions.csv +0 -13
  166. data/db/import_data/stores.csv +0 -3
  167. data/db/import_data/suppliers.csv +0 -14
  168. data/db/import_data/terminals.csv +0 -3
  169. data/db/migrate/20170000000203_create_contacts.rb +0 -22
  170. data/db/migrate/20170000000204_create_bank_accounts.rb +0 -21
  171. data/db/migrate/20170000000205_create_suppliers.rb +0 -18
  172. data/db/migrate/20170000000206_create_stores.rb +0 -21
  173. data/db/migrate/20170000000207_create_terminals.rb +0 -18
  174. data/db/migrate/20170000000210_create_brands.rb +0 -14
  175. data/db/migrate/20170000000211_create_categories.rb +0 -22
  176. data/db/migrate/20170000000212_create_products.rb +0 -29
  177. data/db/migrate/20170000000213_create_invoices.rb +0 -61
  178. data/db/migrate/20170000000215_create_stock_bundles.rb +0 -17
  179. data/db/migrate/20170000000216_create_stock_entries.rb +0 -20
  180. data/db/sample_reports/products.xlsx +0 -0
  181. data/lib/tasks/vyapari/all.rake +0 -73
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78c3cde2ff155082088ef1e7606db93fca5223b0
4
- data.tar.gz: 73bca11944d2b9f8996af22561030bd94094f0c1
3
+ metadata.gz: 909bdbbbd91605efa3e132044390c03dfa9e51c0
4
+ data.tar.gz: 50305de2181b3f5de0f4ee5e641e853c05daf683
5
5
  SHA512:
6
- metadata.gz: 5e5af5f8a109d10ea7161c5a34611ccf8d999b8e2b1543772bcb135cb630bb12ceb4aad6bff8a2729b6d79007087ea2aac79663bd0c15bd2f01b59951dabdfb3
7
- data.tar.gz: 1e07162b8f01363c58c93567608d67a93dae49ebeb595dec43347a7c170f3145163f05c2882b1610ea2abdd53f175061e84b9ca684e8a9a5b7fd211da9ea272d
6
+ metadata.gz: d0cb0012ee08b60b372925fb4b363cd5184cc87ffb3b6b106bf363571fe58a80a5915bad89e4b19edbfb4b4c8a168d91c1d705e86a6bf9b4b2edf8ac4a972225
7
+ data.tar.gz: 0ddc9adf0f78d06f2015e3f83078e0e3c7b20abcf67c796995ff849c7bc1974a90ac7611010411190a7c594bf90c04d473ef08c7218db21aeaf60cd3ad2629a9
@@ -5,21 +5,12 @@ module Vyapari
5
5
  layout 'kuppayam/admin'
6
6
 
7
7
  before_action :require_user
8
- before_action :require_site_admin
9
8
 
10
9
  private
11
10
 
12
11
  def set_default_title
13
12
  set_title("Vyapari Admin | Vyapari Stock Management Module")
14
13
  end
15
-
16
- def require_site_admin
17
- unless @current_user.has_role?("Site Admin")
18
- text = "#{I18n.t("authentication.permission_denied.heading")}: #{I18n.t("authentication.permission_denied.message")}"
19
- set_flash_message(text, :error, false) if defined?(flash) && flash
20
- redirect_to default_redirect_url_after_sign_in
21
- end
22
- end
23
14
 
24
15
  end
25
16
  end
@@ -18,7 +18,7 @@ module Vyapari
18
18
  def apply_filters
19
19
  @relation = @relation.search(@query) if @query
20
20
 
21
- @order_by = "name ASC" unless @order_by
21
+ @order_by = "created_at desc" unless @order_by
22
22
  @relation = @relation.order(@order_by)
23
23
  end
24
24
 
@@ -39,7 +39,7 @@ module Vyapari
39
39
 
40
40
  def resource_controller_configuration
41
41
  {
42
- page_title: "Countries",
42
+ page_title: "Manage Countries",
43
43
  current_nav: "admin/countries",
44
44
  js_view_path: "/kuppayam/workflows/parrot",
45
45
  view_path: "/vyapari/admin/countries"
@@ -2,8 +2,6 @@ module Vyapari
2
2
  module Admin
3
3
  class DashboardController < Vyapari::Admin::BaseController
4
4
 
5
- before_action :require_site_admin
6
-
7
5
  # GET /dashboard
8
6
  def index
9
7
  end
@@ -12,7 +10,7 @@ module Vyapari
12
10
 
13
11
  def breadcrumbs_configuration
14
12
  {
15
- heading: "Admin Dashboard",
13
+ heading: "Stock Dashboard",
16
14
  description: "A Quick view of stocks",
17
15
  links: [{name: "Dashboard", link: admin_dashboard_path, icon: 'fa-dashboard'}]
18
16
  }
@@ -39,7 +39,7 @@ module Vyapari
39
39
 
40
40
  def resource_controller_configuration
41
41
  {
42
- page_title: "Exchange Rates",
42
+ page_title: "Manage Countries",
43
43
  collection_name: :exchange_rates,
44
44
  item_name: :exchange_rate,
45
45
  class: ExchangeRate,
@@ -58,7 +58,7 @@ module Vyapari
58
58
  end
59
59
 
60
60
  def permitted_params
61
- params.require(:exchange_rate).permit(:base_currency, :counter_currency, :value, :effective_date)
61
+ params.require(:exchange_rate).permit(:currency_name, :value, :effective_date, :country_id)
62
62
  end
63
63
 
64
64
  def set_navs
@@ -39,7 +39,7 @@ module Vyapari
39
39
 
40
40
  def resource_controller_configuration
41
41
  {
42
- page_title: "Regions",
42
+ page_title: "Manage Countries",
43
43
  js_view_path: "/kuppayam/workflows/parrot",
44
44
  view_path: "/vyapari/admin/regions"
45
45
  }
@@ -4,7 +4,6 @@ module Vyapari
4
4
 
5
5
  include ResourceHelper
6
6
 
7
- before_action :require_site_admin
8
7
  before_action :configure_resource_controller
9
8
 
10
9
  def resource_url(obj)
@@ -0,0 +1,130 @@
1
+ module Usman
2
+ module Admin
3
+ class UsersController < ResourceController
4
+
5
+ def make_super_admin
6
+ @user = @r_object = User.find(params[:id])
7
+ if @user
8
+ @user.super_admin = true
9
+ if @user.valid?
10
+ @user.save
11
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @user.status))
12
+ else
13
+ set_notification(false, I18n.t('status.error'), I18n.translate("error"), @user.errors.full_messages.join("<br>"))
14
+ end
15
+ else
16
+ set_notification(false, I18n.t('status.not_found'), I18n.t('status.not_found', item: default_item_name.titleize))
17
+ end
18
+ render_row
19
+ end
20
+
21
+ def remove_super_admin
22
+ @user = @r_object = User.find(params[:id])
23
+ if @user
24
+ @user.super_admin = false
25
+ if @user.valid?
26
+ @user.save
27
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @user.status))
28
+ else
29
+ set_notification(false, I18n.t('status.error'), I18n.translate("error"), @user.errors.full_messages.join("<br>"))
30
+ end
31
+ else
32
+ set_notification(false, I18n.t('status.not_found'), I18n.t('status.not_found', item: default_item_name.titleize))
33
+ end
34
+ render_row
35
+ end
36
+
37
+ def masquerade
38
+ @user = @r_object = User.find(params[:id])
39
+ masquerade_as_user(@user)
40
+ end
41
+
42
+ private
43
+
44
+ def get_collections
45
+ # Fetching the users
46
+ @relation = User.includes(:profile_picture).where("")
47
+
48
+ parse_filters
49
+ apply_filters
50
+
51
+ @users = @r_objects = @relation.page(@current_page).per(@per_page)
52
+
53
+ return true
54
+ end
55
+
56
+ def apply_filters
57
+ @relation = @relation.search(@query) if @query
58
+ @relation = @relation.status(@status) if @status
59
+
60
+ # Normal users should not be able to view super admins
61
+ # He should not be seeing admins even while searching
62
+ if @current_user.is_super_admin?
63
+ @relation = @relation.where("super_admin IS #{@super_admin.to_s.upcase}") if @super_admin.nil? == false && @query.nil?
64
+ else
65
+ @relation = @relation.where("super_admin IS FALSE")
66
+ end
67
+
68
+ @order_by = "created_at desc" unless @order_by
69
+ @relation = @relation.order(@order_by)
70
+ end
71
+
72
+ def configure_filter_settings
73
+ @filter_settings = {
74
+ string_filters: [
75
+ { filter_name: :query },
76
+ { filter_name: :status }
77
+ ],
78
+
79
+ boolean_filters: [
80
+ { filter_name: :super_admin, options: {default: false }}
81
+ ],
82
+
83
+ reference_filters: [],
84
+ variable_filters: [],
85
+ }
86
+ end
87
+
88
+ def configure_filter_ui_settings
89
+ @filter_ui_settings = {
90
+ status: {
91
+ object_filter: false,
92
+ select_label: "Select Status",
93
+ display_hash: User::STATUS,
94
+ current_value: @status,
95
+ values: User::STATUS_REVERSE,
96
+ current_filters: @filters,
97
+ filters_to_remove: [],
98
+ filters_to_add: {},
99
+ url_method_name: 'admin_users_url',
100
+ show_all_filter_on_top: true
101
+ }
102
+ }
103
+ end
104
+
105
+ def resource_controller_configuration
106
+ {
107
+ view_path: "usman/admin/users"
108
+ }
109
+ end
110
+
111
+ def breadcrumbs_configuration
112
+ {
113
+ heading: "Manage Users",
114
+ description: "Listing all Users",
115
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
116
+ {name: "Manage Users", link: admin_users_path, icon: 'fa-user', active: true}]
117
+ }
118
+ end
119
+
120
+ def permitted_params
121
+ params.require(:user).permit(:name, :username, :email, :designation, :phone, :password, :password_confirmation)
122
+ end
123
+
124
+ def set_navs
125
+ set_nav("admin/users")
126
+ end
127
+
128
+ end
129
+ end
130
+ end
@@ -9,16 +9,5 @@ module Vyapari
9
9
  set_title("Vyapari - User Management System")
10
10
  end
11
11
 
12
- def default_redirect_url_after_sign_in
13
- vyapari.user_dashboard_url
14
- # if @current_user.has_role?("Admin")
15
- # vyapari.admin_dashboard_url
16
- # elsif @current_user.has_role?("Admin")
17
- # vyapari.store_dashboard_url
18
- # else
19
- # vyapari.admin_dashboard_url
20
- # end
21
- end
22
-
23
12
  end
24
13
  end
data/app/models/brand.rb CHANGED
@@ -5,19 +5,18 @@ class Brand < Vyapari::ApplicationRecord
5
5
  UNPUBLISHED = "unpublished"
6
6
  REMOVED = "removed"
7
7
 
8
- STATUS = {"Published" => PUBLISHED, "Unpublished" => UNPUBLISHED, "Removed" => REMOVED}
9
- STATUS_REVERSE = {PUBLISHED => "Published", UNPUBLISHED => "Unpublished", REMOVED => "Removed"}
8
+ STATUS_HASH = {"Published" => PUBLISHED, "Unpublished" => UNPUBLISHED, "Removed" => REMOVED}
9
+ STATUS_HASH_REVERSE = {PUBLISHED => "Published", UNPUBLISHED => "Unpublished", REMOVED => "Removed"}
10
10
 
11
11
  FEATURED_HASH = {"Featured" => true, "Non Featured" => false}
12
12
  FEATURED_HASH_REVERSE = {true => "Featured", false => "Non Featured"}
13
13
 
14
14
  # Validations
15
- validates :name, :presence=> true, uniqueness: true, length: {minimum: 3, maximum: 250}
16
- validates :status, :presence=> true, :inclusion => {:in => STATUS_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
15
+ validates :name, :presence=> true
16
+ validates :status, :presence=> true, :inclusion => {:in => STATUS_HASH_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
17
17
 
18
18
  # Associations
19
19
  has_one :brand_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::BrandImage"
20
- has_many :products
21
20
 
22
21
  # ------------------
23
22
  # Class Methods
@@ -32,60 +31,16 @@ class Brand < Vyapari::ApplicationRecord
32
31
  # => ActiveRecord::Relation object
33
32
  scope :search, lambda { |query| where("LOWER(name) LIKE LOWER('%#{query}%')")
34
33
  }
35
- scope :featured, lambda { |val| where(featured: val) }
36
34
 
37
35
  scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
36
+ scope :featured, lambda { |val| where(featured: val) }
37
+
38
38
  scope :published, -> { where(status: PUBLISHED) }
39
39
  scope :unpublished, -> { where(status: UNPUBLISHED) }
40
40
  scope :removed, -> { where(status: REMOVED) }
41
41
 
42
42
  scope :this_month, lambda { where("created_at >= ? AND created_at <= ?", Time.zone.now.beginning_of_month, Time.zone.now.end_of_month) }
43
43
 
44
- # Import Methods
45
- # --------------
46
-
47
- def self.save_row_data(row)
48
-
49
- row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
50
-
51
- return if row[:name].blank?
52
-
53
- brand = Brand.find_by_name(row[:name]) || Brand.new
54
-
55
- brand.name = row[:name]
56
- brand.featured = row[:featured]
57
- brand.status = row[:status]
58
- brand.priority = row[:priority]
59
-
60
- # Initializing error hash for displaying all errors altogether
61
- error_object = Kuppayam::Importer::ErrorHash.new
62
-
63
- if brand.valid?
64
- brand.save!
65
- else
66
- summary = "Error while saving brand: #{brand.name}"
67
- details = "Error! #{brand.errors.full_messages.to_sentence}"
68
- error_object.errors << { summary: summary, details: details }
69
- end
70
- return error_object
71
- end
72
-
73
- # ------------------
74
- # Instance Methods
75
- # ------------------
76
-
77
- def display_name
78
- self.name
79
- end
80
-
81
- def slug
82
- self.name.parameterize
83
- end
84
-
85
- def to_param
86
- "#{id}-#{slug}"
87
- end
88
-
89
44
  # * Return true if the brand is published, else false.
90
45
  # == Examples
91
46
  # >>> brand.published?
@@ -137,26 +92,23 @@ class Brand < Vyapari::ApplicationRecord
137
92
  self.update_attributes(status: REMOVED, featured: false)
138
93
  end
139
94
 
140
- def can_be_published?
141
- unpublished? or removed?
142
- end
143
-
144
- def can_be_unpublished?
145
- published? or removed?
95
+ # TODO
96
+ def can_be_deleted?
97
+ #if self.jobs.any?
98
+ # self.errors.add(:base, DELETE_MESSAGE)
99
+ # return false
100
+ #else
101
+ # return true
102
+ #end
103
+ return true
146
104
  end
147
105
 
148
- def can_be_removed?
149
- published? or unpublished?
106
+ def display_name
107
+ self.name
150
108
  end
151
109
 
152
- # TODO
153
-
154
- def can_be_edited?
155
- true
156
- end
157
-
158
- def can_be_deleted?
159
- removed? && self.products.blank?
110
+ def default_image_url(size="medium")
111
+ "/assets/defaults/brand-#{size}.png"
160
112
  end
161
113
 
162
114
  end
@@ -5,21 +5,23 @@ class Category < Vyapari::ApplicationRecord
5
5
  UNPUBLISHED = "unpublished"
6
6
  REMOVED = "removed"
7
7
 
8
- STATUS = {"Published" => PUBLISHED, "Unpublished" => UNPUBLISHED, "Removed" => REMOVED}
9
- STATUS_REVERSE = {PUBLISHED => "Published", UNPUBLISHED => "Unpublished", REMOVED => "Removed"}
8
+ STATUS_HASH = {"Published" => PUBLISHED, "Unpublished" => UNPUBLISHED, "Removed" => REMOVED}
9
+ STATUS_HASH_REVERSE = {PUBLISHED => "Published", UNPUBLISHED => "Unpublished", REMOVED => "Removed"}
10
10
 
11
11
  FEATURED_HASH = {"Featured" => true, "Non Featured" => false}
12
12
  FEATURED_HASH_REVERSE = {true => "Featured", false => "Non Featured"}
13
13
 
14
- # Validations
15
- validates :name, presence: true, uniqueness: true
14
+ # Callbacks
15
+ before_validation :update_permalink
16
+
17
+ # Validations
18
+ validates :name, presence: true
16
19
  validates :one_liner, presence: false
17
- validates :status, :presence=> true, :inclusion => {:in => STATUS_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
20
+ validates :status, :presence=> true, :inclusion => {:in => STATUS_HASH_REVERSE.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
18
21
 
19
22
  # Associations
20
23
  has_many :products
21
24
  belongs_to :parent, :class_name => 'Category', optional: true
22
- belongs_to :top_parent, :class_name => 'Category', optional: true
23
25
  has_many :sub_categories, :foreign_key => "parent_id", :class_name => "Category"
24
26
  has_one :category_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CategoryImage"
25
27
 
@@ -29,7 +31,9 @@ class Category < Vyapari::ApplicationRecord
29
31
  # >>> object.search(query)
30
32
  # => ActiveRecord::Relation object
31
33
  scope :search, lambda {|query| where("LOWER(name) LIKE LOWER('%#{query}%') OR\
32
- LOWER(one_liner) LIKE LOWER('%#{query}%')")
34
+ LOWER(permalink) LIKE LOWER('%#{query}%') OR\
35
+ LOWER(one_liner) LIKE LOWER('%#{query}%') OR\
36
+ LOWER(description) LIKE LOWER('%#{query}%')")
33
37
  }
34
38
 
35
39
  scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
@@ -39,52 +43,10 @@ class Category < Vyapari::ApplicationRecord
39
43
  scope :unpublished, -> { where(status: UNPUBLISHED) }
40
44
  scope :removed, -> { where(status: REMOVED) }
41
45
 
42
- def self.save_row_data(row)
43
-
44
- row.headers.each{ |cell| row[cell] = row[cell].to_s.strip }
45
-
46
- return if row[:name].blank?
47
-
48
- category = Category.find_by_name(row[:name]) || Category.new
49
-
50
- category.name = row[:name]
51
- category.one_liner = row[:one_liner]
52
- category.parent = Category.find_by_name(row[:parent])
53
- category.top_parent = category.parent.top_parent if category.parent
54
-
55
- category.featured = row[:featured]
56
- category.status = row[:status]
57
- category.priority = row[:priority]
58
-
59
- # Initializing error hash for displaying all errors altogether
60
- error_object = Kuppayam::Importer::ErrorHash.new
61
-
62
- if category.valid?
63
- category.save!
64
- else
65
- summary = "Error while saving category: #{category.name}"
66
- details = "Error! #{category.errors.full_messages.to_sentence}"
67
- error_object.errors << { summary: summary, details: details }
68
- end
69
- return error_object
70
- end
71
-
72
46
  # ------------------
73
47
  # Instance variables
74
48
  # ------------------
75
49
 
76
- def display_name
77
- self.name
78
- end
79
-
80
- def slug
81
- self.name.parameterize
82
- end
83
-
84
- def to_param
85
- "#{id}-#{slug}"
86
- end
87
-
88
50
  # * Return true if the category is published, else false.
89
51
  # == Examples
90
52
  # >>> category.published?
@@ -136,24 +98,18 @@ class Category < Vyapari::ApplicationRecord
136
98
  self.update_attribute(:status, REMOVED)
137
99
  end
138
100
 
139
- def can_be_published?
140
- unpublished? or removed?
101
+ def default_image_url(size="medium")
102
+ "/assets/defaults/category-#{size}.png"
141
103
  end
142
104
 
143
- def can_be_unpublished?
144
- published? or removed?
145
- end
146
-
147
- def can_be_removed?
148
- published? or unpublished?
149
- end
150
-
151
- def can_be_edited?
152
- true
105
+ def display_name
106
+ self.name
153
107
  end
154
108
 
155
- def can_be_deleted?
156
- true
109
+ protected
110
+
111
+ def update_permalink
112
+ self.permalink = "#{self.id}-#{name.parameterize}"
157
113
  end
158
114
 
159
115
  end