vyapari 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +49 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/vyapari_manifest.js +2 -0
  6. data/app/assets/javascripts/vyapari/application.js +13 -0
  7. data/app/assets/stylesheets/vyapari/application.css +15 -0
  8. data/app/controllers/vyapari/admin/base_controller.rb +17 -0
  9. data/app/controllers/vyapari/admin/countries_controller.rb +64 -0
  10. data/app/controllers/vyapari/admin/dashboard_controller.rb +26 -0
  11. data/app/controllers/vyapari/admin/exchange_rates_controller.rb +70 -0
  12. data/app/controllers/vyapari/admin/regions_controller.rb +67 -0
  13. data/app/controllers/vyapari/admin/resource_controller.rb +15 -0
  14. data/app/controllers/vyapari/admin/users_controller.rb +130 -0
  15. data/app/controllers/vyapari/application_controller.rb +13 -0
  16. data/app/helpers/vyapari/application_helper.rb +4 -0
  17. data/app/jobs/vyapari/application_job.rb +4 -0
  18. data/app/mailers/vyapari/application_mailer.rb +6 -0
  19. data/app/models/brand.rb +114 -0
  20. data/app/models/category.rb +116 -0
  21. data/app/models/country.rb +45 -0
  22. data/app/models/exchange_rate.rb +38 -0
  23. data/app/models/product.rb +139 -0
  24. data/app/models/region.rb +58 -0
  25. data/app/models/vyapari/application_record.rb +6 -0
  26. data/app/views/layouts/kuppayam/_footer.html.erb +25 -0
  27. data/app/views/layouts/kuppayam/_header.html.erb +43 -0
  28. data/app/views/layouts/kuppayam/_navbar.html.erb +55 -0
  29. data/app/views/layouts/kuppayam/_sidebar.html.erb +136 -0
  30. data/app/views/vyapari/admin/countries/_form.html.erb +24 -0
  31. data/app/views/vyapari/admin/countries/_index.html.erb +51 -0
  32. data/app/views/vyapari/admin/countries/_row.html.erb +26 -0
  33. data/app/views/vyapari/admin/countries/_show.html.erb +73 -0
  34. data/app/views/vyapari/admin/countries/index.html.erb +32 -0
  35. data/app/views/vyapari/admin/dashboard/index.html.erb +52 -0
  36. data/app/views/vyapari/admin/exchange_rates/_form.html.erb +28 -0
  37. data/app/views/vyapari/admin/exchange_rates/_index.html.erb +57 -0
  38. data/app/views/vyapari/admin/exchange_rates/_row.html.erb +30 -0
  39. data/app/views/vyapari/admin/exchange_rates/_show.html.erb +72 -0
  40. data/app/views/vyapari/admin/exchange_rates/index.html.erb +32 -0
  41. data/app/views/vyapari/admin/regions/_form.html.erb +28 -0
  42. data/app/views/vyapari/admin/regions/_index.html.erb +54 -0
  43. data/app/views/vyapari/admin/regions/_row.html.erb +28 -0
  44. data/app/views/vyapari/admin/regions/_show.html.erb +74 -0
  45. data/app/views/vyapari/admin/regions/index.html.erb +32 -0
  46. data/app/views/vyapari/admin/users/_form.html.erb +39 -0
  47. data/app/views/vyapari/admin/users/_index.html.erb +101 -0
  48. data/app/views/vyapari/admin/users/_row.html.erb +72 -0
  49. data/app/views/vyapari/admin/users/_show.html.erb +199 -0
  50. data/app/views/vyapari/admin/users/index.html.erb +64 -0
  51. data/config/routes.rb +28 -0
  52. data/db/migrate/20170000000200_create_exchange_rates.rb +16 -0
  53. data/db/migrate/20170000000201_create_countries.rb +12 -0
  54. data/db/migrate/20170000000202_create_regions.rb +16 -0
  55. data/lib/tasks/vyapari_tasks.rake +4 -0
  56. data/lib/vyapari/engine.rb +20 -0
  57. data/lib/vyapari/version.rb +3 -0
  58. data/lib/vyapari.rb +5 -0
  59. metadata +401 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da218da53569de87da0a9b0c55dacdf25d2bbc70
4
+ data.tar.gz: 31b85dcfba5486a6aaab46572c30e470a26e3f06
5
+ SHA512:
6
+ metadata.gz: 9a64c3922a42bad1aa34bca312761afe95a1738245c351e25accc5d7a7b86e53ed0b25d53bfd3bd685cd160e7d76342312a338f5fabdc38dec83d82e5745c639
7
+ data.tar.gz: c1cbd25d90287b049a4bd0611fece2c941d4a75f71c149c94c2b7960285f266c99992ba74e65bc1760a123104c9c38b02a60682e40ed9755af41da61257cc328
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Prasad V
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Vyapari
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'vyapari'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install vyapari
22
+ ```
23
+
24
+
25
+ Installation Instructions
26
+
27
+ # Installation Instructions
28
+
29
+ Copy the migrations from the engines you are using
30
+ Run the below command
31
+
32
+ ```bash
33
+ $ bundle exec rake railties:install:migrations
34
+ ```
35
+
36
+ This will copy migrations from kuppayam and usman engines
37
+ which will have migrations to create images, documents, users, features and permissions respectively.
38
+
39
+
40
+ ## Configurations
41
+
42
+ config.railties_order = [:main_app, Vyapari::Engine, Usman::Engine, :all]
43
+
44
+
45
+ ## Contributing
46
+ Contribution directions go here.
47
+
48
+ ## License
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Vyapari'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/vyapari .js
2
+ //= link_directory ../stylesheets/vyapari .css
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,17 @@
1
+ module Vyapari
2
+ module Admin
3
+ class BaseController < ApplicationController
4
+
5
+ layout 'kuppayam/admin'
6
+
7
+ before_action :require_user
8
+
9
+ private
10
+
11
+ def set_default_title
12
+ set_title("Vyapari Admin | Vyapari Stock Management Module")
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,64 @@
1
+ module Vyapari
2
+ module Admin
3
+ class CountriesController < ResourceController
4
+
5
+ private
6
+
7
+ def get_collections
8
+ @relation = Country.where("")
9
+
10
+ parse_filters
11
+ apply_filters
12
+
13
+ @countries = @r_objects = @relation.page(@current_page).per(@per_page)
14
+
15
+ return true
16
+ end
17
+
18
+ def apply_filters
19
+ @relation = @relation.search(@query) if @query
20
+
21
+ @order_by = "created_at desc" unless @order_by
22
+ @relation = @relation.order(@order_by)
23
+ end
24
+
25
+ def configure_filter_settings
26
+ @filter_settings = {
27
+ string_filters: [
28
+ { filter_name: :query }
29
+ ],
30
+ boolean_filters: [],
31
+ reference_filters: [],
32
+ variable_filters: [],
33
+ }
34
+ end
35
+
36
+ def configure_filter_ui_settings
37
+ @filter_ui_settings = {}
38
+ end
39
+
40
+ def resource_controller_configuration
41
+ {
42
+ page_title: "Manage Countries",
43
+ current_nav: "admin/countries",
44
+ js_view_path: "/kuppayam/workflows/parrot",
45
+ view_path: "/vyapari/admin/countries"
46
+ }
47
+ end
48
+
49
+ def breadcrumbs_configuration
50
+ {
51
+ heading: "Manage Countries",
52
+ description: "Listing all Countries",
53
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
54
+ {name: "Manage Countries", link: admin_countries_path, icon: 'fa-calendar', active: true}]
55
+ }
56
+ end
57
+
58
+ def permitted_params
59
+ params.require(:country).permit(:name, :code)
60
+ end
61
+
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,26 @@
1
+ module Vyapari
2
+ module Admin
3
+ class DashboardController < Vyapari::Admin::BaseController
4
+
5
+ # GET /dashboard
6
+ def index
7
+ end
8
+
9
+ private
10
+
11
+ def breadcrumbs_configuration
12
+ {
13
+ heading: "Stock Dashboard",
14
+ description: "A Quick view of stocks",
15
+ links: [{name: "Dashboard", link: admin_dashboard_path, icon: 'fa-dashboard'}]
16
+ }
17
+ end
18
+
19
+ def set_navs
20
+ set_nav("admin/dashboard")
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+
@@ -0,0 +1,70 @@
1
+ module Vyapari
2
+ module Admin
3
+ class ExchangeRatesController < ResourceController
4
+
5
+ private
6
+
7
+ def get_collections
8
+ @relation = ExchangeRate.where("")
9
+
10
+ parse_filters
11
+ apply_filters
12
+
13
+ @exchange_rates = @r_objects = @relation.page(@current_page).per(@per_page)
14
+
15
+ return true
16
+ end
17
+
18
+ def apply_filters
19
+ @relation = @relation.search(@query) if @query
20
+
21
+ @order_by = "created_at desc" unless @order_by
22
+ @relation = @relation.order(@order_by)
23
+ end
24
+
25
+ def configure_filter_settings
26
+ @filter_settings = {
27
+ string_filters: [
28
+ { filter_name: :query }
29
+ ],
30
+ boolean_filters: [],
31
+ reference_filters: [],
32
+ variable_filters: [],
33
+ }
34
+ end
35
+
36
+ def configure_filter_ui_settings
37
+ @filter_ui_settings = {}
38
+ end
39
+
40
+ def resource_controller_configuration
41
+ {
42
+ page_title: "Manage Countries",
43
+ collection_name: :exchange_rates,
44
+ item_name: :exchange_rate,
45
+ class: ExchangeRate,
46
+ js_view_path: "/kuppayam/workflows/parrot",
47
+ view_path: "/vyapari/admin/exchange_rates"
48
+ }
49
+ end
50
+
51
+ def breadcrumbs_configuration
52
+ {
53
+ heading: "Manage Exchange Rates",
54
+ description: "Listing all Exchange Rates",
55
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
56
+ {name: "Manage Exchange Rates", link: admin_exchange_rates_path, icon: 'fa-calendar', active: true}]
57
+ }
58
+ end
59
+
60
+ def permitted_params
61
+ params.require(:exchange_rate).permit(:currency_name, :value, :effective_date, :country_id)
62
+ end
63
+
64
+ def set_navs
65
+ set_nav("admin/exchange_rates")
66
+ end
67
+
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,67 @@
1
+ module Vyapari
2
+ module Admin
3
+ class RegionsController < ResourceController
4
+
5
+ private
6
+
7
+ def get_collections
8
+ @relation = Region.where("")
9
+
10
+ parse_filters
11
+ apply_filters
12
+
13
+ @regions = @r_objects = @relation.page(@current_page).per(@per_page)
14
+
15
+ return true
16
+ end
17
+
18
+ def apply_filters
19
+ @relation = @relation.search(@query) if @query
20
+
21
+ @order_by = "created_at desc" unless @order_by
22
+ @relation = @relation.order(@order_by)
23
+ end
24
+
25
+ def configure_filter_settings
26
+ @filter_settings = {
27
+ string_filters: [
28
+ { filter_name: :query }
29
+ ],
30
+ boolean_filters: [],
31
+ reference_filters: [],
32
+ variable_filters: [],
33
+ }
34
+ end
35
+
36
+ def configure_filter_ui_settings
37
+ @filter_ui_settings = {}
38
+ end
39
+
40
+ def resource_controller_configuration
41
+ {
42
+ page_title: "Manage Countries",
43
+ js_view_path: "/kuppayam/workflows/parrot",
44
+ view_path: "/vyapari/admin/regions"
45
+ }
46
+ end
47
+
48
+ def breadcrumbs_configuration
49
+ {
50
+ heading: "Manage Regions",
51
+ description: "Listing all Regions",
52
+ links: [{name: "Home", link: admin_dashboard_path, icon: 'fa-home'},
53
+ {name: "Manage Regions", link: admin_regions_path, icon: 'fa-calendar', active: true}]
54
+ }
55
+ end
56
+
57
+ def permitted_params
58
+ params.require(:region).permit(:name, :code, :country_id)
59
+ end
60
+
61
+ def set_navs
62
+ set_nav("admin/regions")
63
+ end
64
+
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,15 @@
1
+ module Vyapari
2
+ module Admin
3
+ class ResourceController < Vyapari::Admin::BaseController
4
+
5
+ include ResourceHelper
6
+
7
+ before_action :configure_resource_controller
8
+
9
+ def resource_url(obj)
10
+ url_for([:admin, obj])
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -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
@@ -0,0 +1,13 @@
1
+ module Vyapari
2
+ class ApplicationController < Kuppayam::BaseController
3
+
4
+ include Usman::AuthenticationHelper
5
+
6
+ before_action :current_user
7
+
8
+ def set_default_title
9
+ set_title("Vyapari - User Management System")
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Vyapari
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Vyapari
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Vyapari
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,114 @@
1
+ class Brand < Vyapari::ApplicationRecord
2
+
3
+ # Constants
4
+ PUBLISHED = "published"
5
+ UNPUBLISHED = "unpublished"
6
+ REMOVED = "removed"
7
+
8
+ STATUS_HASH = {"Published" => PUBLISHED, "Unpublished" => UNPUBLISHED, "Removed" => REMOVED}
9
+ STATUS_HASH_REVERSE = {PUBLISHED => "Published", UNPUBLISHED => "Unpublished", REMOVED => "Removed"}
10
+
11
+ FEATURED_HASH = {"Featured" => true, "Non Featured" => false}
12
+ FEATURED_HASH_REVERSE = {true => "Featured", false => "Non Featured"}
13
+
14
+ # Validations
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
+
18
+ # Associations
19
+ has_one :brand_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::BrandImage"
20
+
21
+ # ------------------
22
+ # Class Methods
23
+ # ------------------
24
+
25
+ # Scopes
26
+
27
+ # return an published record relation object with the search query in its where clause
28
+ # Return the ActiveRecord::Relation object
29
+ # == Examples
30
+ # >>> brand.search(query)
31
+ # => ActiveRecord::Relation object
32
+ scope :search, lambda { |query| where("LOWER(name) LIKE LOWER('%#{query}%')")
33
+ }
34
+
35
+ scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
36
+ scope :featured, lambda { |val| where(featured: val) }
37
+
38
+ scope :published, -> { where(status: PUBLISHED) }
39
+ scope :unpublished, -> { where(status: UNPUBLISHED) }
40
+ scope :removed, -> { where(status: REMOVED) }
41
+
42
+ scope :this_month, lambda { where("created_at >= ? AND created_at <= ?", Time.zone.now.beginning_of_month, Time.zone.now.end_of_month) }
43
+
44
+ # * Return true if the brand is published, else false.
45
+ # == Examples
46
+ # >>> brand.published?
47
+ # => true
48
+ def published?
49
+ (status == PUBLISHED)
50
+ end
51
+
52
+ # change the status to :published
53
+ # Return the status
54
+ # == Examples
55
+ # >>> brand.publish!
56
+ # => "published"
57
+ def publish!
58
+ self.update_attribute(:status, PUBLISHED)
59
+ end
60
+
61
+ # * Return true if the brand is unpublished, else false.
62
+ # == Examples
63
+ # >>> brand.unpublished?
64
+ # => true
65
+ def unpublished?
66
+ (status == UNPUBLISHED)
67
+ end
68
+
69
+ # change the status to :unpublished
70
+ # Return the status
71
+ # == Examples
72
+ # >>> brand.unpublish!
73
+ # => "unpublished"
74
+ def unpublish!
75
+ self.update_attributes(status: UNPUBLISHED, featured: false)
76
+ end
77
+
78
+ # * Return true if the brand is removed, else false.
79
+ # == Examples
80
+ # >>> brand.removed?
81
+ # => true
82
+ def removed?
83
+ (status == REMOVED)
84
+ end
85
+
86
+ # change the status to :removed
87
+ # Return the status
88
+ # == Examples
89
+ # >>> brand.remove!
90
+ # => "removed"
91
+ def remove!
92
+ self.update_attributes(status: REMOVED, featured: false)
93
+ end
94
+
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
104
+ end
105
+
106
+ def display_name
107
+ self.name
108
+ end
109
+
110
+ def default_image_url(size="medium")
111
+ "/assets/defaults/brand-#{size}.png"
112
+ end
113
+
114
+ end