vyapari 0.1.5dev10 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/vyapari/admin/base_controller.rb +0 -9
- data/app/controllers/vyapari/admin/countries_controller.rb +2 -2
- data/app/controllers/vyapari/admin/dashboard_controller.rb +1 -3
- data/app/controllers/vyapari/admin/exchange_rates_controller.rb +2 -2
- data/app/controllers/vyapari/admin/regions_controller.rb +1 -1
- data/app/controllers/vyapari/admin/resource_controller.rb +0 -1
- data/app/controllers/vyapari/admin/users_controller.rb +130 -0
- data/app/controllers/vyapari/application_controller.rb +0 -11
- data/app/models/brand.rb +19 -67
- data/app/models/category.rb +19 -63
- data/app/models/country.rb +7 -31
- data/app/models/exchange_rate.rb +7 -32
- data/app/models/product.rb +20 -75
- data/app/models/region.rb +20 -37
- data/app/models/vyapari/application_record.rb +0 -3
- data/app/views/layouts/kuppayam/_footer.html.erb +1 -1
- data/app/views/layouts/kuppayam/_sidebar.html.erb +44 -45
- data/app/views/vyapari/admin/countries/_index.html.erb +1 -1
- data/app/views/vyapari/admin/countries/index.html.erb +3 -19
- data/app/views/vyapari/admin/exchange_rates/_form.html.erb +4 -3
- data/app/views/vyapari/admin/exchange_rates/_index.html.erb +7 -7
- data/app/views/vyapari/admin/exchange_rates/_row.html.erb +3 -3
- data/app/views/vyapari/admin/exchange_rates/_show.html.erb +0 -1
- data/app/views/vyapari/admin/exchange_rates/index.html.erb +3 -19
- data/app/views/vyapari/admin/regions/_index.html.erb +1 -1
- data/app/views/vyapari/admin/regions/index.html.erb +3 -19
- data/app/views/vyapari/admin/users/_form.html.erb +39 -0
- data/app/views/vyapari/admin/users/_index.html.erb +101 -0
- data/app/views/vyapari/admin/users/_row.html.erb +72 -0
- data/app/views/vyapari/admin/users/_show.html.erb +199 -0
- data/app/views/vyapari/admin/{categories → users}/index.html.erb +24 -8
- data/config/routes.rb +5 -66
- data/db/migrate/20170000000200_create_exchange_rates.rb +2 -3
- data/lib/tasks/vyapari_tasks.rake +4 -0
- data/lib/vyapari/version.rb +1 -1
- metadata +15 -167
- data/app/assets/images/vyapari/sample_stock_bundle.csv +0 -1
- data/app/controllers/vyapari/admin/brands_controller.rb +0 -99
- data/app/controllers/vyapari/admin/categories_controller.rb +0 -115
- data/app/controllers/vyapari/admin/products_controller.rb +0 -79
- data/app/controllers/vyapari/admin/stores_controller.rb +0 -67
- data/app/controllers/vyapari/admin/suppliers_controller.rb +0 -67
- data/app/controllers/vyapari/admin/terminals_controller.rb +0 -150
- data/app/controllers/vyapari/store_manager/base_controller.rb +0 -33
- data/app/controllers/vyapari/store_manager/dashboard_controller.rb +0 -31
- data/app/controllers/vyapari/store_manager/reports/invoices_controller.rb +0 -249
- data/app/controllers/vyapari/store_manager/reports/sales_controller.rb +0 -299
- data/app/controllers/vyapari/store_manager/reports/stock_controller.rb +0 -132
- data/app/controllers/vyapari/store_manager/resource_controller.rb +0 -17
- data/app/controllers/vyapari/store_manager/stock_bundles_controller.rb +0 -206
- data/app/controllers/vyapari/store_manager/stock_entries_controller.rb +0 -161
- data/app/controllers/vyapari/terminal_staff/base_controller.rb +0 -38
- data/app/controllers/vyapari/terminal_staff/dashboard_controller.rb +0 -35
- data/app/controllers/vyapari/terminal_staff/invoices_controller.rb +0 -147
- data/app/controllers/vyapari/terminal_staff/line_items_controller.rb +0 -139
- data/app/controllers/vyapari/terminal_staff/resource_controller.rb +0 -17
- data/app/controllers/vyapari/user_dashboard_controller.rb +0 -31
- data/app/models/bank_account.rb +0 -44
- data/app/models/contact.rb +0 -72
- data/app/models/image/brand_image.rb +0 -3
- data/app/models/image/category_image.rb +0 -3
- data/app/models/image/product_image.rb +0 -3
- data/app/models/invoice.rb +0 -256
- data/app/models/line_item.rb +0 -207
- data/app/models/stock_bundle.rb +0 -249
- data/app/models/stock_entry.rb +0 -275
- data/app/models/store.rb +0 -302
- data/app/models/supplier.rb +0 -79
- data/app/models/terminal.rb +0 -158
- data/app/uploaders/brand_image_uploader.rb +0 -14
- data/app/uploaders/category_image_uploader.rb +0 -14
- data/app/uploaders/product_image_uploader.rb +0 -14
- data/app/uploaders/stock_bundle_uploader.rb +0 -10
- data/app/views/layouts/vyapari/_store_manager_menu.html.erb +0 -126
- data/app/views/layouts/vyapari/_terminal_staff_menu.html.erb +0 -106
- data/app/views/layouts/vyapari/store_manager.html.erb +0 -112
- data/app/views/layouts/vyapari/terminal_staff.html.erb +0 -116
- data/app/views/vyapari/admin/brands/_form.html.erb +0 -23
- data/app/views/vyapari/admin/brands/_index.html.erb +0 -89
- data/app/views/vyapari/admin/brands/_row.html.erb +0 -63
- data/app/views/vyapari/admin/brands/_show.html.erb +0 -104
- data/app/views/vyapari/admin/brands/index.html.erb +0 -48
- data/app/views/vyapari/admin/categories/_form.html.erb +0 -28
- data/app/views/vyapari/admin/categories/_index.html.erb +0 -101
- data/app/views/vyapari/admin/categories/_row.html.erb +0 -69
- data/app/views/vyapari/admin/categories/_show.html.erb +0 -115
- data/app/views/vyapari/admin/products/_form.html.erb +0 -32
- data/app/views/vyapari/admin/products/_index.html.erb +0 -58
- data/app/views/vyapari/admin/products/_row.html.erb +0 -30
- data/app/views/vyapari/admin/products/_show.html.erb +0 -81
- data/app/views/vyapari/admin/products/index.html.erb +0 -48
- data/app/views/vyapari/admin/stores/_form.html.erb +0 -37
- data/app/views/vyapari/admin/stores/_index.html.erb +0 -84
- data/app/views/vyapari/admin/stores/_row.html.erb +0 -55
- data/app/views/vyapari/admin/stores/_show.html.erb +0 -110
- data/app/views/vyapari/admin/stores/index.html.erb +0 -48
- data/app/views/vyapari/admin/suppliers/_form.html.erb +0 -32
- data/app/views/vyapari/admin/suppliers/_index.html.erb +0 -58
- data/app/views/vyapari/admin/suppliers/_row.html.erb +0 -30
- data/app/views/vyapari/admin/suppliers/_show.html.erb +0 -81
- data/app/views/vyapari/admin/suppliers/index.html.erb +0 -48
- data/app/views/vyapari/admin/terminals/_form.html.erb +0 -24
- data/app/views/vyapari/admin/terminals/_index.html.erb +0 -75
- data/app/views/vyapari/admin/terminals/_row.html.erb +0 -49
- data/app/views/vyapari/admin/terminals/_show.html.erb +0 -74
- data/app/views/vyapari/store_manager/dashboard/_sales_counts.html.erb +0 -90
- data/app/views/vyapari/store_manager/dashboard/_stock_counts.html.erb +0 -63
- data/app/views/vyapari/store_manager/dashboard/_terminals.html.erb +0 -23
- data/app/views/vyapari/store_manager/dashboard/index.html.erb +0 -64
- data/app/views/vyapari/store_manager/reports/invoices/_index.html.erb +0 -65
- data/app/views/vyapari/store_manager/reports/invoices/index.html.erb +0 -105
- data/app/views/vyapari/store_manager/reports/sales/_index.html.erb +0 -64
- data/app/views/vyapari/store_manager/reports/sales/index.html.erb +0 -105
- data/app/views/vyapari/store_manager/reports/stock/_index.html.erb +0 -72
- data/app/views/vyapari/store_manager/reports/stock/index.html.erb +0 -32
- data/app/views/vyapari/store_manager/stock_bundles/_form.html.erb +0 -99
- data/app/views/vyapari/store_manager/stock_bundles/_index.html.erb +0 -74
- data/app/views/vyapari/store_manager/stock_bundles/_row.html.erb +0 -44
- data/app/views/vyapari/store_manager/stock_bundles/_show.html.erb +0 -110
- data/app/views/vyapari/store_manager/stock_bundles/create.html.erb +0 -57
- data/app/views/vyapari/store_manager/stock_bundles/index.html.erb +0 -36
- data/app/views/vyapari/store_manager/stock_bundles/update.html.erb +0 -57
- data/app/views/vyapari/store_manager/stock_entries/_form.html.erb +0 -50
- data/app/views/vyapari/store_manager/stock_entries/_index.html.erb +0 -80
- data/app/views/vyapari/store_manager/stock_entries/_row.html.erb +0 -33
- data/app/views/vyapari/store_manager/stock_entries/_show.html.erb +0 -110
- data/app/views/vyapari/store_manager/stock_entries/_stock_bundle.html.erb +0 -61
- data/app/views/vyapari/store_manager/stock_entries/index.html.erb +0 -45
- data/app/views/vyapari/terminal_staff/dashboard/_counts.html.erb +0 -131
- data/app/views/vyapari/terminal_staff/dashboard/_invoices.html.erb +0 -44
- data/app/views/vyapari/terminal_staff/dashboard/_search_form.html.erb +0 -6
- data/app/views/vyapari/terminal_staff/dashboard/_search_results.html.erb +0 -24
- data/app/views/vyapari/terminal_staff/dashboard/index.html.erb +0 -56
- data/app/views/vyapari/terminal_staff/dashboard/search.js.erb +0 -12
- data/app/views/vyapari/terminal_staff/invoices/_draft.html.erb +0 -62
- data/app/views/vyapari/terminal_staff/invoices/_form.html.erb +0 -134
- data/app/views/vyapari/terminal_staff/invoices/_index.html.erb +0 -70
- data/app/views/vyapari/terminal_staff/invoices/_row.html.erb +0 -33
- data/app/views/vyapari/terminal_staff/invoices/_show.html.erb +0 -204
- data/app/views/vyapari/terminal_staff/invoices/index.html.erb +0 -35
- data/app/views/vyapari/terminal_staff/invoices/new.js.erb +0 -18
- data/app/views/vyapari/terminal_staff/invoices/show.html.erb +0 -1
- data/app/views/vyapari/terminal_staff/invoices/show.js.erb +0 -13
- data/app/views/vyapari/terminal_staff/line_items/_form.html.erb +0 -40
- data/app/views/vyapari/terminal_staff/line_items/_index.html.erb +0 -96
- data/app/views/vyapari/terminal_staff/line_items/create.js.erb +0 -34
- data/app/views/vyapari/terminal_staff/line_items/destroy.js.erb +0 -25
- data/app/views/vyapari/user_dashboard/index.html.erb +0 -51
- data/db/import_data/brands.csv +0 -7
- data/db/import_data/categories.csv +0 -12
- data/db/import_data/countries.csv +0 -1
- data/db/import_data/dummy/brands.csv +0 -7
- data/db/import_data/dummy/categories.csv +0 -12
- data/db/import_data/dummy/countries.csv +0 -1
- data/db/import_data/dummy/exchange_rates.csv +0 -5
- data/db/import_data/dummy/products-copy.csv +0 -1
- data/db/import_data/dummy/products.csv +0 -1
- data/db/import_data/dummy/products.xlsx +0 -0
- data/db/import_data/dummy/regions.csv +0 -13
- data/db/import_data/dummy/stores.csv +0 -10
- data/db/import_data/dummy/suppliers.csv +0 -14
- data/db/import_data/dummy/terminals.csv +0 -11
- data/db/import_data/exchange_rates.csv +0 -5
- data/db/import_data/regions.csv +0 -13
- data/db/import_data/stores.csv +0 -3
- data/db/import_data/suppliers.csv +0 -14
- data/db/import_data/terminals.csv +0 -3
- data/db/migrate/20170000000203_create_contacts.rb +0 -22
- data/db/migrate/20170000000204_create_bank_accounts.rb +0 -21
- data/db/migrate/20170000000205_create_suppliers.rb +0 -18
- data/db/migrate/20170000000206_create_stores.rb +0 -21
- data/db/migrate/20170000000207_create_terminals.rb +0 -18
- data/db/migrate/20170000000210_create_brands.rb +0 -14
- data/db/migrate/20170000000211_create_categories.rb +0 -22
- data/db/migrate/20170000000212_create_products.rb +0 -29
- data/db/migrate/20170000000213_create_invoices.rb +0 -61
- data/db/migrate/20170000000215_create_stock_bundles.rb +0 -17
- data/db/migrate/20170000000216_create_stock_entries.rb +0 -20
- data/db/sample_reports/products.xlsx +0 -0
- data/lib/tasks/vyapari/all.rake +0 -73
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 909bdbbbd91605efa3e132044390c03dfa9e51c0
|
4
|
+
data.tar.gz: 50305de2181b3f5de0f4ee5e641e853c05daf683
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 = "
|
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: "
|
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: "
|
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(:
|
61
|
+
params.require(:exchange_rate).permit(:currency_name, :value, :effective_date, :country_id)
|
62
62
|
end
|
63
63
|
|
64
64
|
def set_navs
|
@@ -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
|
-
|
9
|
-
|
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
|
16
|
-
validates :status, :presence=> true, :inclusion => {:in =>
|
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
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
149
|
-
|
106
|
+
def display_name
|
107
|
+
self.name
|
150
108
|
end
|
151
109
|
|
152
|
-
|
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
|
data/app/models/category.rb
CHANGED
@@ -5,21 +5,23 @@ class Category < Vyapari::ApplicationRecord
|
|
5
5
|
UNPUBLISHED = "unpublished"
|
6
6
|
REMOVED = "removed"
|
7
7
|
|
8
|
-
|
9
|
-
|
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
|
-
#
|
15
|
-
|
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 =>
|
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(
|
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
|
140
|
-
|
101
|
+
def default_image_url(size="medium")
|
102
|
+
"/assets/defaults/category-#{size}.png"
|
141
103
|
end
|
142
104
|
|
143
|
-
def
|
144
|
-
|
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
|
-
|
156
|
-
|
109
|
+
protected
|
110
|
+
|
111
|
+
def update_permalink
|
112
|
+
self.permalink = "#{self.id}-#{name.parameterize}"
|
157
113
|
end
|
158
114
|
|
159
115
|
end
|