dhatu 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 310d2306a14f602500128b494f6ee13378836145
|
4
|
+
data.tar.gz: ffad0ed3f1b05f4a582c282c359b827fc2dfca13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d206c07bb298481e3b79fb2367735f4c9525f90a856e6c0be8414452b63866b411653c63db43bab70472fc639e7c9ed8e1289b4a7dfd089ff1221ec56de73c1
|
7
|
+
data.tar.gz: 86edc9cd171fdeba5e76515bf0986e1fa9d89da322bb40e85d56abba41a35665255de707db64ea60a4cb8124ab25c9aaaad4d33eeef7f319d5e13c62714957f4
|
@@ -1,26 +1,11 @@
|
|
1
|
-
class Dhatu::Category < ApplicationRecord
|
1
|
+
class Dhatu::Category < Dhatu::ApplicationRecord
|
2
2
|
|
3
|
-
#
|
4
|
-
|
5
|
-
UNPUBLISHED = "unpublished"
|
6
|
-
REMOVED = "removed"
|
7
|
-
|
8
|
-
STATUS = {
|
9
|
-
PUBLISHED => "Published",
|
10
|
-
UNPUBLISHED => "Un-Published",
|
11
|
-
REMOVED => "Removed"
|
12
|
-
}
|
13
|
-
|
14
|
-
STATUS_REVERSE = {
|
15
|
-
"Published" => PUBLISHED,
|
16
|
-
"Un-Published" => UNPUBLISHED,
|
17
|
-
"Removed" => REMOVED
|
18
|
-
}
|
19
|
-
|
20
|
-
FEATURED = {"Featured" => true, "Non Featured" => false}
|
21
|
-
FEATURED_REVERSE = {true => "Featured", false => "Non Featured"}
|
3
|
+
# Set Table Name
|
4
|
+
self.table_name = "categories"
|
22
5
|
|
23
|
-
|
6
|
+
# Including the State Machine Methods
|
7
|
+
include Publishable
|
8
|
+
include Featureable
|
24
9
|
|
25
10
|
# Callbacks
|
26
11
|
before_validation :generate_permalink, on: :create
|
@@ -32,6 +17,7 @@ class Dhatu::Category < ApplicationRecord
|
|
32
17
|
validate_string :name, mandatory: true, min_length: 2, format: /.*/i
|
33
18
|
validate_string :one_liner, mandatory: false, format: /.*/i
|
34
19
|
validate_string :permalink, mandatory: true, format: /.*/i, min_length: 4, max_length: 128
|
20
|
+
validates :category_type, :presence=> true, length: {maximum: 64}
|
35
21
|
validates :status, :presence=> true, :inclusion => {:in => STATUS.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
|
36
22
|
|
37
23
|
# Associations
|
@@ -39,11 +25,7 @@ class Dhatu::Category < ApplicationRecord
|
|
39
25
|
belongs_to :top_parent, :class_name => 'Dhatu::Category', optional: true
|
40
26
|
has_many :sub_categories, :foreign_key => "parent_id", :class_name => "Dhatu::Category"
|
41
27
|
has_one :category_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CategoryImage"
|
42
|
-
|
43
|
-
|
44
|
-
has_one :category_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CoverImage"
|
45
|
-
has_many :gallery_images, :as => :imageable, :dependent => :destroy, :class_name => "Image::GalleryImage"
|
46
|
-
|
28
|
+
|
47
29
|
# ---------------
|
48
30
|
# Class methods
|
49
31
|
# ---------------
|
@@ -120,60 +102,6 @@ class Dhatu::Category < ApplicationRecord
|
|
120
102
|
# Hash[*json.map{|k, v| [k, v || ""]}.flatten]
|
121
103
|
end
|
122
104
|
|
123
|
-
# Status methods
|
124
|
-
# ------------------
|
125
|
-
|
126
|
-
# * Return true if the category is published, else false.
|
127
|
-
# == Examples
|
128
|
-
# >>> category.published?
|
129
|
-
# => true
|
130
|
-
def published?
|
131
|
-
(status == PUBLISHED)
|
132
|
-
end
|
133
|
-
|
134
|
-
# change the status to :published
|
135
|
-
# Return the status
|
136
|
-
# == Examples
|
137
|
-
# >>> category.publish!
|
138
|
-
# => "published"
|
139
|
-
def publish!
|
140
|
-
self.update_attribute(:status, PUBLISHED)
|
141
|
-
end
|
142
|
-
|
143
|
-
# * Return true if the category is unpublished, else false.
|
144
|
-
# == Examples
|
145
|
-
# >>> category.unpublished?
|
146
|
-
# => true
|
147
|
-
def unpublished?
|
148
|
-
(status == UNPUBLISHED)
|
149
|
-
end
|
150
|
-
|
151
|
-
# change the status to :unpublished
|
152
|
-
# Return the status
|
153
|
-
# == Examples
|
154
|
-
# >>> category.unpublish!
|
155
|
-
# => "unpublished"
|
156
|
-
def unpublish!
|
157
|
-
self.update_attribute(:status, UNPUBLISHED)
|
158
|
-
end
|
159
|
-
|
160
|
-
# * Return true if the category is removed, else false.
|
161
|
-
# == Examples
|
162
|
-
# >>> category.removed?
|
163
|
-
# => true
|
164
|
-
def removed?
|
165
|
-
(status == REMOVED)
|
166
|
-
end
|
167
|
-
|
168
|
-
# change the status to :removed
|
169
|
-
# Return the status
|
170
|
-
# == Examples
|
171
|
-
# >>> category.remove!
|
172
|
-
# => "removed"
|
173
|
-
def remove!
|
174
|
-
self.update_attribute(:status, REMOVED)
|
175
|
-
end
|
176
|
-
|
177
105
|
# Other Methods
|
178
106
|
# ------------------
|
179
107
|
|
@@ -199,21 +127,6 @@ class Dhatu::Category < ApplicationRecord
|
|
199
127
|
true
|
200
128
|
end
|
201
129
|
|
202
|
-
def can_be_published?
|
203
|
-
unpublished? or removed?
|
204
|
-
end
|
205
|
-
|
206
|
-
def can_be_unpublished?
|
207
|
-
return false if end_node == false or self.sub_categories.any?
|
208
|
-
published? or removed?
|
209
|
-
end
|
210
|
-
|
211
|
-
def can_be_removed?
|
212
|
-
return false if parent.nil?
|
213
|
-
return false if end_node == false or self.sub_categories.any?
|
214
|
-
published? or unpublished?
|
215
|
-
end
|
216
|
-
|
217
130
|
# Callback methods
|
218
131
|
# ------------------
|
219
132
|
|
@@ -13,7 +13,7 @@
|
|
13
13
|
|
14
14
|
<%
|
15
15
|
@category.parent_id = params[:parent_id] if params[:parent_id]
|
16
|
-
categories = Category.select("id, name").order("name ASC").all
|
16
|
+
categories = Dhatu::Category.select("id, name").order("name ASC").all
|
17
17
|
%>
|
18
18
|
|
19
19
|
<% options = {assoc_collection: categories, required: false, editable: true, assoc_display_method: :name} %>
|
@@ -8,13 +8,13 @@
|
|
8
8
|
|
9
9
|
<%= theme_button('Refresh', 'refresh', categories_path(parent_id: @current_category.try(:id)), classes: "pull-left mr-10", btn_type: "white") %>
|
10
10
|
|
11
|
-
<% if @current_category.try(:id) && @current_user.has_create_permission?(Category) %>
|
11
|
+
<% if @current_category.try(:id) && @current_user.has_create_permission?(Dhatu::Category) %>
|
12
12
|
<%= theme_button('Add a Category', 'plus', new_category_path(parent_id: @current_category.try(:id)), classes: "pull-left mr-10", btn_type: "success") %>
|
13
13
|
<% end %>
|
14
14
|
|
15
15
|
</div>
|
16
16
|
<div class="col-md-6">
|
17
|
-
<%= search_form_kuppayam(Category, categories_path, text: @filters[:query]) %>
|
17
|
+
<%= search_form_kuppayam(Dhatu::Category, categories_path, text: @filters[:query]) %>
|
18
18
|
</div>
|
19
19
|
</div>
|
20
20
|
</div>
|
data/lib/dhatu/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhatu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kpvarma
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|