dhatu 0.1.2 → 0.1.3

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: b1fd11f5b29e613b8230921745d5a3cf44a765e8
4
- data.tar.gz: f9ac26b4e06d1a7824103400c49a0c67d09b22f9
3
+ metadata.gz: 7fa0a222775b06b12a71c3ee569d4f7143f5d6aa
4
+ data.tar.gz: 9723db066cfbdec803a21f9afc085b2446672914
5
5
  SHA512:
6
- metadata.gz: c7bc2a925e128847a641417eb16be7669d37d981d7e0e6f31a854ef4769d33e5fdbd6e1e8c29caffa32e4537c194b6968edcad0dd64dde22d7da6337b3d7067b
7
- data.tar.gz: 93db27b763708e855f46074f7869959a1f4ea232ff38885f60592d84770fbf3aa57b2fc632886aff5b2817513ebd35b80dbbd31a991bb1ebabfedf4b8b9e5580
6
+ metadata.gz: bd1d3ab466efa68e245050534e7e945fc038a167d33683944894d41f9ffdb812561050c9acf08a3c0838e1b65aeb30557d8d78351c1b979a876f44095b754dcc
7
+ data.tar.gz: 69a608697a1e2754d06db47e02e5d703d95a03aa4a6fc8dd97f1cf6d19040712ad443cd3c06de7e2a511ac285cdd66b751f1a946e007a5f065f6530eca38151a
@@ -0,0 +1,129 @@
1
+ module Dhatu
2
+ class CategoriesController < ResourceController
3
+
4
+ before_action :require_update_permission, only: [:update_status, :make_parent, :mark_as_featured, :remove_from_featured]
5
+
6
+ def update_status
7
+ @category = @r_object = Dhatu::Category.find(params[:id])
8
+ case params[:status]
9
+ when "unpublished"
10
+ @category.unpublish!
11
+ when "removed"
12
+ @category.remove!
13
+ when "published"
14
+ @category.publish!
15
+ end
16
+ set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @r_object.status))
17
+ render_row
18
+ end
19
+
20
+ def make_parent
21
+ @category = @r_object = Dhatu::Category.find(params[:id])
22
+ @category.update_attribute(:parent_id, nil)
23
+ get_collections
24
+ render_accordingly
25
+ end
26
+
27
+ def mark_as_featured
28
+ @category = @r_object = Dhatu::Category.find(params[:id])
29
+ @category.update_attribute(:featured, true) if @category.published?
30
+ render_row
31
+ end
32
+
33
+ def remove_from_featured
34
+ @category = @r_object = Dhatu::Category.find(params[:id])
35
+ @category.update_attribute(:featured, false) if @category.featured?
36
+ render_row
37
+ end
38
+
39
+ private
40
+
41
+ def permitted_params
42
+ params[:category].permit(:name, :permalink, :one_liner, :description, :parent_id, :priority)
43
+ end
44
+
45
+ def resource_url(obj)
46
+ url_for([:admin, obj])
47
+ end
48
+
49
+ def set_navs
50
+ set_nav("admin/categories")
51
+ end
52
+
53
+ def get_collections
54
+
55
+ @current_category = Dhatu::Category.find_by_id(params[:parent_id])
56
+
57
+ filter_param_mapping
58
+ parse_filters
59
+
60
+ if @query
61
+ @relation = Dhatu::Category.includes(:parent)
62
+ else
63
+ if @current_category
64
+ @relation = @current_category.sub_categories.includes(:parent)
65
+ else
66
+ @relation = Dhatu::Category.where("parent_id IS NULL")
67
+ end
68
+ end
69
+
70
+ @relation = @relation.order("priority ASC, name ASC")
71
+
72
+ apply_filters
73
+
74
+ @categories = @r_objects = @relation.page(@current_page).per(@per_page)
75
+
76
+ return true
77
+ end
78
+
79
+ def apply_filters
80
+ @relation = @relation.search(@query) if @query
81
+ @relation = @relation.status(@status) if @status
82
+ @relation = @relation.featured(@featured) unless @featured.nil?
83
+ end
84
+
85
+ def filter_config
86
+ @filter_config = {
87
+ boolean_filters: [
88
+ { filter_name: :featured }
89
+ ],
90
+ string_filters: [
91
+ { filter_name: :query },
92
+ { filter_name: :status }
93
+ ],
94
+ reference_filters: [],
95
+ variable_filters: [],
96
+ }
97
+ end
98
+
99
+ def resource_controller_configuration
100
+ {
101
+ page_title: "Categories",
102
+ js_view_path: "/kuppayam/workflows/peacock",
103
+ view_path: "/dhatu/categories",
104
+ collection_name: :categories,
105
+ item_name: :category,
106
+ class: Dhatu::Category
107
+ }
108
+ end
109
+
110
+ def breadcrumbs_configuration
111
+ {
112
+ heading: "Manage Categories",
113
+ icon: "fa-sitemap",
114
+ description: "Listing all Categories",
115
+ links: [{name: "Home", link: dashboard_path, icon: 'fa-home'},
116
+ {name: "Manage Categories", link: dhatu.categories_path, icon: 'fa-sitemap', active: true}]
117
+ }
118
+ end
119
+
120
+ def permitted_params
121
+ params.require(:category).permit(:name, :one_liner, :description, :priority, :parent_id)
122
+ end
123
+
124
+ def set_navs
125
+ set_nav("dhatu/categories")
126
+ end
127
+
128
+ end
129
+ end
@@ -40,10 +40,6 @@ class Dhatu::BlogPost < Dhatu::ApplicationRecord
40
40
  # Generic Methods
41
41
  # ---------------
42
42
 
43
- def to_param
44
- "#{id}-#{slug}"
45
- end
46
-
47
43
  def display_name
48
44
  "#{title_was}"
49
45
  end
@@ -0,0 +1,264 @@
1
+ class Dhatu::Category < ApplicationRecord
2
+
3
+ # Constants
4
+ PUBLISHED = "published"
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"}
22
+
23
+ EXCLUDED_JSON_ATTRIBUTES = [:created_at, :updated_at, :parent_id, :top_parent_id]
24
+
25
+ # Callbacks
26
+ before_validation :generate_permalink, on: :create
27
+ before_validation :set_top_parent, on: :create
28
+ after_create :update_permalink, :set_end_node_of_parent
29
+ after_destroy :set_end_node_of_parent
30
+
31
+ # Validations
32
+ validate_string :name, mandatory: true, min_length: 2, format: /.*/i
33
+ validate_string :one_liner, mandatory: false, format: /.*/i
34
+ validate_string :permalink, mandatory: true, format: /.*/i, min_length: 4, max_length: 128
35
+ validates :status, :presence=> true, :inclusion => {:in => STATUS.keys, :presence_of => :status, :message => "%{value} is not a valid status" }
36
+
37
+ # Associations
38
+ belongs_to :parent, :class_name => 'Dhatu::Category', optional: true
39
+ belongs_to :top_parent, :class_name => 'Dhatu::Category', optional: true
40
+ has_many :sub_categories, :foreign_key => "parent_id", :class_name => "Dhatu::Category"
41
+ has_one :category_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CategoryImage"
42
+ has_many :classified_attributes
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
+
47
+ # ---------------
48
+ # Class methods
49
+ # ---------------
50
+
51
+ # return an active record relation object with the search query in its where clause
52
+ # Return the ActiveRecord::Relation object
53
+ # == Examples
54
+ # >>> object.search(query)
55
+ # => ActiveRecord::Relation object
56
+ scope :search, lambda {|query| where("LOWER(name) LIKE LOWER('%#{query}%') OR\
57
+ LOWER(permalink) LIKE LOWER('%#{query}%') OR\
58
+ LOWER(one_liner) LIKE LOWER('%#{query}%') OR\
59
+ LOWER(description) LIKE LOWER('%#{query}%')")
60
+ }
61
+
62
+ scope :status, lambda { |status| where("LOWER(status)='#{status}'") }
63
+ scope :featured, lambda { |val| where(featured: val) }
64
+
65
+ scope :published, -> { where(status: PUBLISHED) }
66
+ scope :unpublished, -> { where(status: UNPUBLISHED) }
67
+ scope :removed, -> { where(status: REMOVED) }
68
+
69
+ # Import Methods
70
+
71
+ def self.save_row_data(hsh)
72
+
73
+ # Initializing error hash for displaying all errors altogether
74
+ error_object = Kuppayam::Importer::ErrorHash.new
75
+
76
+ return error_object if hsh[:name].blank?
77
+
78
+ category = Dhatu::Category.find_by_name(hsh[:name]) || Dhatu::Category.new
79
+ category.name = hsh[:name]
80
+ category.one_liner = hsh[:one_liner]
81
+ category.description = hsh[:description]
82
+ category.priority = hsh[:priority]
83
+
84
+ parent = Dhatu::Category.find_by_name(hsh[:parent])
85
+ category.parent = parent
86
+ category.top_parent = parent && parent.top_parent ? parent.top_parent : parent
87
+ category.status = PUBLISHED
88
+
89
+ # Initializing error hash for displaying all errors altogether
90
+ error_object = Kuppayam::Importer::ErrorHash.new
91
+
92
+ if category.valid?
93
+ begin
94
+ category.save!
95
+ rescue Exception => e
96
+ summary = "uncaught #{e} exception while handling connection: #{e.message}"
97
+ details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}"
98
+ error_object.errors << { summary: summary, details: details }
99
+ end
100
+ else
101
+ summary = "Error while saving category: #{category.name}"
102
+ details = "Error! #{category.errors.full_messages.to_sentence}"
103
+ error_object.errors << { summary: summary, details: details }
104
+ end
105
+
106
+ return error_object
107
+ end
108
+
109
+ # ------------------
110
+ # Instance methods
111
+ # ------------------
112
+
113
+ # Exclude some attributes info from json output.
114
+ def as_json(options={})
115
+ options[:except] ||= EXCLUDED_JSON_ATTRIBUTES
116
+ options[:include] ||= [:parent, :top_parent, :sub_categories]
117
+ #options[:methods] = []
118
+ #options[:methods] << :profile_image
119
+ json = super(options)
120
+ # Hash[*json.map{|k, v| [k, v || ""]}.flatten]
121
+ end
122
+
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
+ # Other Methods
178
+ # ------------------
179
+
180
+ def display_name
181
+ self.name
182
+ end
183
+
184
+ def default_image_url(size="medium")
185
+ "/assets/defaults/category-#{size}.png"
186
+ end
187
+
188
+ # Permission Methods
189
+ # ------------------
190
+
191
+ def can_be_edited?
192
+ published? or unpublished?
193
+ end
194
+
195
+ def can_be_deleted?
196
+ return false unless removed?
197
+ return false if parent.nil?
198
+ return false if end_node == false or self.sub_categories.any?
199
+ true
200
+ end
201
+
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
+ # Callback methods
218
+ # ------------------
219
+
220
+ def set_end_node!
221
+ self.update_attribute(:end_node, !self.sub_categories.any?)
222
+ end
223
+
224
+ def set_end_node_of_parent
225
+ if self.parent
226
+ if self.parent.sub_categories.any?
227
+ self.parent.update_attribute(:end_node, false)
228
+ else
229
+ self.parent.update_attribute(:end_node, true)
230
+ end
231
+ end
232
+ end
233
+
234
+ protected
235
+
236
+ def generate_permalink
237
+ return unless self.name
238
+ if self.parent
239
+ perm = "#{self.name.parameterize}-#{self.parent.name.parameterize}"
240
+ else
241
+ perm = self.name.parameterize
242
+ end
243
+ self.permalink = "#{SecureRandom.hex(4)}-#{perm[0..110]}"
244
+ end
245
+
246
+ def update_permalink
247
+ if self.parent
248
+ self.permalink = "#{self.id}-#{self.name.parameterize}-#{self.parent.name.parameterize}"
249
+ else
250
+ self.permalink = "#{self.id}-#{self.name.parameterize}" if self.name
251
+ end
252
+ self.save
253
+ end
254
+
255
+ def set_top_parent
256
+ return if self.parent.blank?
257
+ if self.parent.top_parent.blank?
258
+ self.top_parent = self.parent
259
+ else
260
+ self.top_parent = self.parent.top_parent
261
+ end
262
+ end
263
+
264
+ end
@@ -0,0 +1,3 @@
1
+ class Image::CategoryImage < Image::Base
2
+ mount_uploader :image, CategoryImageUploader
3
+ end
@@ -0,0 +1,15 @@
1
+ class CategoryImageUploader < ImageUploader
2
+
3
+ def store_dir
4
+ "uploads/category_images/#{model.id}"
5
+ end
6
+
7
+ version :small do
8
+ process :resize_to_fill => [100, 100]
9
+ end
10
+
11
+ version :tiny do
12
+ process :resize_to_fill => [40, 40]
13
+ end
14
+
15
+ end
@@ -0,0 +1,36 @@
1
+ <%= form_for([:admin, @category], :html => {:id=>"form_category", :class=>"mb-0 form-horizontal", :role => "form", :method => (@category.new_record? ? :post : :put), :remote=>true}) do |f| %>
2
+
3
+ <div id="category_form_error">
4
+ <%= @category.errors[:base].to_sentence %>
5
+ </div>
6
+
7
+ <div class="form-inputs mb-30 mt-30">
8
+ <%= theme_form_field(@category, :name) %>
9
+
10
+ <%= theme_form_field(@category, :one_liner, required: false) %>
11
+ <%= theme_form_field(@category, :description, required: false, html_options: {type: :textarea}) %>
12
+ <%= theme_form_field(@category, :priority, required: false, html_options: {type: :number, style: "width:70px;"}) %>
13
+
14
+ <%
15
+ @category.parent_id = params[:parent_id] if params[:parent_id]
16
+ categories = Category.select("id, name").order("name ASC").all
17
+ %>
18
+
19
+ <% options = {assoc_collection: categories, required: false, editable: true, assoc_display_method: :name} %>
20
+ <%= theme_form_assoc_group(@category, :parent_id, **options) %>
21
+ </div>
22
+
23
+
24
+
25
+ <div>
26
+
27
+ <%= submit_tag("Save", :class=>"btn btn-primary pull-right ml-10") %>
28
+
29
+ <%= link_to raw("<i class='fa fa-close mr-5'></i><span>Cancel</span>"), "#", onclick: "closeGenericModal();", class: "pull-right ml-10 btn btn-white" %>
30
+
31
+ </div>
32
+ <%= clear_tag(10) %>
33
+ </div>
34
+
35
+ <% end %>
36
+
@@ -0,0 +1,157 @@
1
+ <div id="div_category_action_buttons">
2
+ <div class="row">
3
+ <div class="col-md-6">
4
+
5
+ <% if @current_category %>
6
+ <%= theme_button('Back', 'arrow-left', categories_path(parent_id: @current_category.parent_id), classes: "pull-left mr-10", btn_type: "white") %>
7
+ <% end %>
8
+
9
+ <%= theme_button('Refresh', 'refresh', categories_path(parent_id: @current_category.try(:id)), classes: "pull-left mr-10", btn_type: "white") %>
10
+
11
+ <% if @current_category.try(:id) && @current_user.has_create_permission?(Category) %>
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
+ <% end %>
14
+
15
+ </div>
16
+ <div class="col-md-6">
17
+ <%= search_form_kuppayam(Category, categories_path, text: @filters[:query]) %>
18
+ </div>
19
+ </div>
20
+ </div>
21
+ <%= clear_tag(10) %>
22
+
23
+ <div id="div_category_breadcrumbs">
24
+ <% c_list = [] %>
25
+ <% c = @current_category %>
26
+ <% while c do %>
27
+ <% c_list << c %>
28
+ <% c = c.parent %>
29
+ <% end %>
30
+
31
+ <% if c_list.count >= 1 %>
32
+ <ol class="breadcrumb auto-hidden1 bc-3">
33
+ <% c_list.reverse.each do |c| %>
34
+ <% if c_list[0] == c %>
35
+ <li class="active"><strong><%= c.display_name %></strong></li>
36
+ <% else %>
37
+ <li><%= link_to c.display_name, categories_path(parent_id: c.id), remote: true, class: "collapsed" %></li>
38
+ <% end %>
39
+ <% end %>
40
+ </ol>
41
+ <% end %>
42
+ </div>
43
+ <%= clear_tag %>
44
+
45
+ <div class="table-responsive">
46
+ <table class="table table-hover members-table middle-align">
47
+ <thead>
48
+ <tr>
49
+ <th style="text-align: center;width:60px">#</th>
50
+ <th>Name</th>
51
+ <th>Parent</th>
52
+ <th>Top Parent</th>
53
+ <th style="text-align: center;width:100px;">Status</th>
54
+ <th style="text-align: center;width:100px;">Priority</th>
55
+ <th style="text-align: center;width:120px;">End Node?</th>
56
+ <% if display_manage_links? %>
57
+ <th style="text-align: center;" colspan="2">Actions</th>
58
+ <% end %>
59
+ </tr>
60
+ </thead>
61
+ <tbody>
62
+ <% @categories.each_with_index do |category, i| %>
63
+ <tr id="tr_category_<%= category.id %>">
64
+
65
+ <th scope="row" style="text-align: center;">
66
+ <% if i < 0 %>
67
+ <i class="fa fa-check text-success"></i>
68
+ <% else %>
69
+ <%= i + 1 + (@per_page.to_i * (@current_page.to_i - 1)) %>
70
+ <% end %>
71
+ </th>
72
+
73
+ <% if category.end_node? %>
74
+ <td class="category-name"><%= category.display_name %></td>
75
+ <% else %>
76
+ <td class="category-name">
77
+ <%= link_to raw("<i class=\"fa fa-caret-right\"></i> #{category.display_name}"), categories_path(parent_id: category.id), remote: true %></td>
78
+ <% end %>
79
+
80
+ <% if category.parent == @current_category %>
81
+ <td class="category-name"><%= category.parent.display_name if category.parent %></td>
82
+ <% else %>
83
+ <td class="category-name"><%= link_to category.parent.display_name, categories_path(parent_id: category.parent.id), remote: true if category.parent %></td>
84
+ <% end %>
85
+
86
+ <% if category.top_parent == @current_category %>
87
+ <td class="category-name"><%= category.top_parent.display_name if category.top_parent %></td>
88
+ <% else %>
89
+ <td class="category-name"><%= link_to category.top_parent.display_name, categories_path(parent_id: category.top_parent.id), remote: true if category.top_parent %></td>
90
+ <% end %>
91
+
92
+ <td style="text-align: center;width:100px;">
93
+ <% if category.unpublished? %>
94
+ <span class="ml-5 mt-5 label label-default">Un-Published</span>
95
+ <% elsif category.published? %>
96
+ <span class="ml-5 mt-5 label label-success">Published</span>
97
+ <% elsif category.removed? %>
98
+ <span class="ml-5 mt-5 label label-danger">Disabled</span>
99
+ <% end %>
100
+ </td>
101
+
102
+ <td style="text-align: center;width:100px;"><%= category.priority if category.priority %></td>
103
+ <td style="text-align: center;width:120px;"><%= category.end_node.to_s.titleize %></td>
104
+
105
+ <% if display_manage_links? %>
106
+ <% edit_link = edit_category_path(id: category.id) %>
107
+ <% delete_link = category_path(id: category.id) %>
108
+
109
+ <td class="action-links" style="width:10%">
110
+
111
+ <% case category.status %>
112
+ <% when "published" %>
113
+ <!-- Un-Publish -->
114
+ <%= link_to raw("<i class=\"fa fa-circle mr-5\"></i> Un-Publish"), update_status_category_path(:id =>category.id, :status =>'unpublished'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_unpublished? %>
115
+
116
+ <!-- Remove -->
117
+ <%= link_to raw("<i class=\"fa fa-edit mr-5\"></i> Remove"), update_status_category_path(:id =>category.id, :status =>'removed'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_removed? %>
118
+ <% when "unpublished" %>
119
+ <!-- Publish -->
120
+ <%= link_to raw("<i class=\"fa fa-circle-o mr-5\"></i> Publish"), update_status_category_path(:id =>category.id, :status =>'published'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_published? %>
121
+ <!-- Remove -->
122
+ <%= link_to raw("<i class=\"fa fa-edit mr-5\"></i> Remove"), update_status_category_path(:id =>category.id, :status =>'removed'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_removed? %>
123
+ <% when "removed" %>
124
+ <!-- Un-Publish -->
125
+ <%= link_to raw("<i class=\"fa fa-circle mr-5\"></i> Un-Publish"), update_status_category_path(:id =>category.id, :status =>'unpublished'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_unpublished? %>
126
+ <!-- Publish -->
127
+ <%= link_to raw("<i class=\"fa fa-circle-o mr-5\"></i> Publish"), update_status_category_path(:id =>category.id, :status =>'published'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1",:class=>"category_status" if category.can_be_published? %>
128
+ <% end %>
129
+
130
+ </td>
131
+
132
+ <td class="action-links" style="width:10%">
133
+
134
+ <%= link_to raw("<i class=\"linecons-desktop\"></i> View Details"), category_path(category), :remote=>true, style: "color:#40bbea" %>
135
+
136
+ <%= link_to raw("<i class=\"fa-plus\"></i> Add Sub Category"), new_category_path(parent_id: category.id), :remote=>true, class: "edit" %>
137
+
138
+ <%= link_to raw("<i class=\"linecons-pencil\"></i> Edit Category"), edit_link, :remote=>true, class: "edit1" if category.can_be_edited? %>
139
+
140
+ <%= link_to raw("<i class=\"linecons-trash\"></i> Delete"), delete_link, method: :delete, role: "menuitem", tabindex: "-1", data: { confirm: 'Are you sure?' }, :remote=>true, class: "delete" if category.can_be_deleted? && display_delete_links? %>
141
+
142
+ </td>
143
+
144
+ <% end %>
145
+
146
+ </tr>
147
+ <% end %>
148
+ </tbody>
149
+ </table>
150
+ </div>
151
+
152
+ <div class="row">
153
+ <div class="col-sm-12">
154
+ <%= paginate_kuppayam(@categories) %>
155
+ </div>
156
+ </div>
157
+
@@ -0,0 +1,84 @@
1
+ <tr id="tr_category_<%= category.id %>">
2
+
3
+ <th scope="row" style="text-align: center;">
4
+ <% if i < 0 %>
5
+ <i class="fa fa-check text-success"></i>
6
+ <% else %>
7
+ <%= i + 1 + (@per_page.to_i * (@current_page.to_i - 1)) %>
8
+ <% end %>
9
+ </th>
10
+
11
+ <% if category.end_node? %>
12
+ <td class="category-name"><%= category.display_name %></td>
13
+ <% else %>
14
+ <td class="category-name">
15
+ <%= link_to raw("<i class=\"fa fa-caret-right\"></i> #{category.display_name}"), categories_path(parent_id: category.id), remote: true %></td>
16
+ <% end %>
17
+
18
+ <% if category.parent == @current_category %>
19
+ <td class="category-name"><%= category.parent.display_name if category.parent %></td>
20
+ <% else %>
21
+ <td class="category-name"><%= link_to category.parent.display_name, categories_path(parent_id: category.parent.id), remote: true if category.parent %></td>
22
+ <% end %>
23
+
24
+ <% if category.top_parent == @current_category %>
25
+ <td class="category-name"><%= category.top_parent.display_name if category.top_parent %></td>
26
+ <% else %>
27
+ <td class="category-name"><%= link_to category.top_parent.display_name, categories_path(parent_id: category.top_parent.id), remote: true if category.top_parent %></td>
28
+ <% end %>
29
+
30
+ <td style="text-align: center;width:100px;">
31
+ <% if category.unpublished? %>
32
+ <span class="ml-5 mt-5 label label-default">Un-Published</span>
33
+ <% elsif category.published? %>
34
+ <span class="ml-5 mt-5 label label-success">Published</span>
35
+ <% elsif category.removed? %>
36
+ <span class="ml-5 mt-5 label label-danger">Disabled</span>
37
+ <% end %>
38
+ </td>
39
+
40
+ <td style="text-align: center;width:100px;"><%= category.priority if category.priority %></td>
41
+ <td style="text-align: center;width:120px;"><%= category.end_node.to_s.titleize %></td>
42
+
43
+ <% if display_manage_links? %>
44
+ <% edit_link = edit_category_path(id: category.id) %>
45
+ <% delete_link = category_path(id: category.id) %>
46
+
47
+ <td class="action-links" style="width:10%">
48
+
49
+ <% case category.status %>
50
+ <% when "published" %>
51
+ <!-- Un-Publish -->
52
+ <%= link_to raw("<i class=\"fa fa-circle mr-5\"></i> Un-Publish"), update_status_category_path(:id =>category.id, :status =>'unpublished'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_unpublished? %>
53
+
54
+ <!-- Remove -->
55
+ <%= link_to raw("<i class=\"fa fa-edit mr-5\"></i> Remove"), update_status_category_path(:id =>category.id, :status =>'removed'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_removed? %>
56
+ <% when "unpublished" %>
57
+ <!-- Publish -->
58
+ <%= link_to raw("<i class=\"fa fa-circle-o mr-5\"></i> Publish"), update_status_category_path(:id =>category.id, :status =>'published'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_published? %>
59
+ <!-- Remove -->
60
+ <%= link_to raw("<i class=\"fa fa-edit mr-5\"></i> Remove"), update_status_category_path(:id =>category.id, :status =>'removed'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_removed? %>
61
+ <% when "removed" %>
62
+ <!-- Un-Publish -->
63
+ <%= link_to raw("<i class=\"fa fa-circle mr-5\"></i> Un-Publish"), update_status_category_path(:id =>category.id, :status =>'unpublished'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1", :class=>"category_status" if category.can_be_unpublished? %>
64
+ <!-- Publish -->
65
+ <%= link_to raw("<i class=\"fa fa-circle-o mr-5\"></i> Publish"), update_status_category_path(:id =>category.id, :status =>'published'), :method =>'PUT', :remote=>true, role: "menuitem", tabindex: "-1",:class=>"category_status" if category.can_be_published? %>
66
+ <% end %>
67
+
68
+ </td>
69
+
70
+ <td class="action-links" style="width:10%">
71
+
72
+ <%= link_to raw("<i class=\"linecons-desktop\"></i> View Details"), category_path(category), :remote=>true, style: "color:#40bbea" %>
73
+
74
+ <%= link_to raw("<i class=\"fa-plus\"></i> Add Sub Category"), new_category_path(parent_id: category.id), :remote=>true, class: "edit" %>
75
+
76
+ <%= link_to raw("<i class=\"linecons-pencil\"></i> Edit Category"), edit_link, :remote=>true, class: "edit1" if category.can_be_edited? %>
77
+
78
+ <%= link_to raw("<i class=\"linecons-trash\"></i> Delete"), delete_link, method: :delete, role: "menuitem", tabindex: "-1", data: { confirm: 'Are you sure?' }, :remote=>true, class: "delete" if category.can_be_deleted? && display_delete_links? %>
79
+
80
+ </td>
81
+
82
+ <% end %>
83
+
84
+ </tr>
@@ -0,0 +1,100 @@
1
+ <% status_hash = {published: "success", unpublished: "default", disabled: "danger"} %>
2
+
3
+ <div class="media <%= status_hash[@category.status.to_sym] %>">
4
+
5
+ <!-- <div class="pull-left pt-10 pr-10 pb-10" style="width:30%;"> -->
6
+ <%#= edit_image(@category,
7
+ "category_image.image.small.url",
8
+ upload_image_link(@category, :category_image, nil ),
9
+ remove_image_link(@category, :category_image, nil ),
10
+ image_options: {assoc_name: :category_image }) %>
11
+ <!-- </div> -->
12
+
13
+ <!-- <div class="pull-left ml-10" style="width:65%;"> -->
14
+ <div class="">
15
+
16
+ <h1><%= @category.name %></h1>
17
+
18
+ <% if @category.one_liner %>
19
+ <strong><%= @category.one_liner %></strong>
20
+ <% end %>
21
+
22
+ <% if @category.description %>
23
+ <p><%= @category.description %></p>
24
+ <% end %>
25
+
26
+ <span class="label label-<%= status_hash[@category.status.to_sym] %>"><%= @category.status.titleize %></span>
27
+
28
+ <%= clear_tag %>
29
+ </div>
30
+
31
+ </div>
32
+
33
+ <%= clear_tag(30) %>
34
+
35
+ <ul class="nav nav-pills">
36
+
37
+ <li class="active">
38
+ <a href="#technical_details" data-toggle="tab" aria-expanded="false">
39
+ <span class="visible-xs"><i class="fa-database"></i></span>
40
+ <span class="hidden-xs">Technical Details</span>
41
+ </a>
42
+ </li>
43
+
44
+ </ul>
45
+
46
+ <div class="tab-content">
47
+ <div class="tab-pane active" id="technical_details" style="border: 1px solid #000;min-height:200px;padding:20px;margin-bottom:20px;max-height: 400px;overflow-y: auto;">
48
+
49
+ <%= clear_tag(20) %>
50
+
51
+ <div class="table-responsive mb-50">
52
+ <table class="table table-striped table-condensed table-bordered">
53
+ <tbody>
54
+
55
+ <tr>
56
+ <th>ID</th><td><%= @category.id %></td>
57
+ <th>Permalink</th><td><%= @category.permalink %></td>
58
+ </tr>
59
+
60
+ <tr>
61
+ <th>Parent</th><td><%= @category.parent.try(:display_name) %> (<%= @category.parent.try(:id) %>)</td>
62
+ <th>Top Parent</th><td><%= @category.top_parent.try(:display_name) %> (<%= @category.top_parent.try(:id) %>)</td>
63
+ </tr>
64
+
65
+ <tr>
66
+ <th>Status</th><td><%= @category.status %></td>
67
+ <th>Featured</th><td><%= @category.featured? ? "Yes" : "No" %></td>
68
+ </tr>
69
+
70
+ <tr>
71
+ <th>Priority</th><td><%= @category.priority %></td>
72
+ <th>End Node</th><td><%= @category.end_node? ? "Yes" : "No" %></td>
73
+ </tr>
74
+
75
+ <tr>
76
+ <th>Created At</th><td><%= @category.created_at.strftime("%m/%d/%Y - %H:%M:%S") if @category.created_at %></td>
77
+ <th>Updated At</th><td><%= @category.updated_at.strftime("%m/%d/%Y - %H:%M:%S") if @category.updated_at %></td>
78
+ </tr>
79
+
80
+ </tbody>
81
+ </table>
82
+ </div>
83
+
84
+ </div>
85
+ </div>
86
+
87
+ <div>
88
+ <%
89
+ edit_link = edit_category_url(id: @category.id)
90
+ delete_link = category_url(id: @category.id)
91
+ %>
92
+
93
+ <%= link_to raw("<i class=\"fa fa-close mr-5\"></i> <span>Cancel</span>"), "#", onclick: "closeGenericModal();", class: "btn btn-white pull-left" %>
94
+
95
+ <%= link_to raw("<i class=\"fa fa-trash mr-5\"></i> <span>Delete</span>"), delete_link, method: :delete, :remote=>true, class: "btn btn-gray pull-right" %>
96
+
97
+ <%= link_to raw("<i class=\"fa fa-edit mr-5\"></i> Edit"), edit_link, method: :get, :remote=>true, class: "btn btn-gray pull-right mr-10" %>
98
+ </div>
99
+
100
+ <%= clear_tag %>
@@ -0,0 +1,20 @@
1
+ <div class="row">
2
+
3
+ <div class="col-md-12">
4
+
5
+ <ul class="nav nav-tabs">
6
+ </ul>
7
+ <div class="tab-content">
8
+ <div class="tab-pane active">
9
+
10
+ <div id="div_category_index">
11
+ <%= render :partial=>"dhatu/categories/index" %>
12
+ </div>
13
+ <%= clear_tag(10) %>
14
+
15
+ </div>
16
+ </div>
17
+
18
+ </div>
19
+
20
+ </div>
data/config/routes.rb CHANGED
@@ -60,6 +60,15 @@ Dhatu::Engine.routes.draw do
60
60
  end
61
61
  end
62
62
 
63
+ resources :categories do
64
+ member do
65
+ put :make_parent, as: :make_parent
66
+ put :update_status, as: :update_status
67
+ put :mark_as_featured, as: :mark_as_featured
68
+ put :remove_from_featured, as: :remove_from_featured
69
+ end
70
+ end
71
+
63
72
  end
64
73
 
65
74
  end
data/lib/dhatu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Dhatu
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
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.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kpvarma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-26 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -107,7 +107,7 @@ dependencies:
107
107
  version: '0.1'
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: 0.1.16
110
+ version: 0.1.18
111
111
  type: :runtime
112
112
  prerelease: false
113
113
  version_requirements: !ruby/object:Gem::Requirement
@@ -117,7 +117,7 @@ dependencies:
117
117
  version: '0.1'
118
118
  - - ">="
119
119
  - !ruby/object:Gem::Version
120
- version: 0.1.16
120
+ version: 0.1.18
121
121
  - !ruby/object:Gem::Dependency
122
122
  name: pattana
123
123
  requirement: !ruby/object:Gem::Requirement
@@ -127,7 +127,7 @@ dependencies:
127
127
  version: '0.1'
128
128
  - - ">="
129
129
  - !ruby/object:Gem::Version
130
- version: 0.1.13
130
+ version: 0.1.15
131
131
  type: :runtime
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
@@ -137,7 +137,7 @@ dependencies:
137
137
  version: '0.1'
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 0.1.13
140
+ version: 0.1.15
141
141
  - !ruby/object:Gem::Dependency
142
142
  name: usman
143
143
  requirement: !ruby/object:Gem::Requirement
@@ -147,7 +147,7 @@ dependencies:
147
147
  version: '0.3'
148
148
  - - ">="
149
149
  - !ruby/object:Gem::Version
150
- version: 0.3.10
150
+ version: 0.3.12
151
151
  type: :runtime
152
152
  prerelease: false
153
153
  version_requirements: !ruby/object:Gem::Requirement
@@ -157,7 +157,7 @@ dependencies:
157
157
  version: '0.3'
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
- version: 0.3.10
160
+ version: 0.3.12
161
161
  - !ruby/object:Gem::Dependency
162
162
  name: bcrypt
163
163
  requirement: !ruby/object:Gem::Requirement
@@ -408,6 +408,7 @@ files:
408
408
  - app/controllers/dhatu/application_controller.rb
409
409
  - app/controllers/dhatu/blog_posts_controller.rb
410
410
  - app/controllers/dhatu/branches_controller.rb
411
+ - app/controllers/dhatu/categories_controller.rb
411
412
  - app/controllers/dhatu/dashboard_controller.rb
412
413
  - app/controllers/dhatu/events_controller.rb
413
414
  - app/controllers/dhatu/offers_controller.rb
@@ -421,11 +422,14 @@ files:
421
422
  - app/models/dhatu/application_record.rb
422
423
  - app/models/dhatu/blog_post.rb
423
424
  - app/models/dhatu/branch.rb
425
+ - app/models/dhatu/category.rb
424
426
  - app/models/dhatu/event.rb
425
427
  - app/models/dhatu/offer.rb
426
428
  - app/models/dhatu/section.rb
427
429
  - app/models/dhatu/team_member.rb
428
430
  - app/models/dhatu/testimonial.rb
431
+ - app/models/image/category_image.rb
432
+ - app/uploaders/category_image_uploader.rb
429
433
  - app/views/dhatu/blog_posts/_form.html.erb
430
434
  - app/views/dhatu/blog_posts/_index.html.erb
431
435
  - app/views/dhatu/blog_posts/_row.html.erb
@@ -436,6 +440,11 @@ files:
436
440
  - app/views/dhatu/branches/_row.html.erb
437
441
  - app/views/dhatu/branches/_show.html.erb
438
442
  - app/views/dhatu/branches/index.html.erb
443
+ - app/views/dhatu/categories/_form.html.erb
444
+ - app/views/dhatu/categories/_index.html.erb
445
+ - app/views/dhatu/categories/_row.html.erb
446
+ - app/views/dhatu/categories/_show.html.erb
447
+ - app/views/dhatu/categories/index.html.erb
439
448
  - app/views/dhatu/dashboard/_index.html.erb
440
449
  - app/views/dhatu/dashboard/index.html.erb
441
450
  - app/views/dhatu/events/_form.html.erb