dhatu 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/dhatu/blog_posts_controller.rb +1 -1
- data/app/controllers/dhatu/bookings_controller.rb +1 -1
- data/app/controllers/dhatu/branches_controller.rb +1 -1
- data/app/controllers/dhatu/categories_controller.rb +7 -6
- data/app/controllers/dhatu/events_controller.rb +1 -1
- data/app/controllers/dhatu/offers_controller.rb +1 -1
- data/app/controllers/dhatu/pages_controller.rb +1 -1
- data/app/controllers/dhatu/photo_albums_controller.rb +172 -0
- data/app/controllers/dhatu/prices_controller.rb +1 -1
- data/app/controllers/dhatu/projects_controller.rb +1 -1
- data/app/controllers/dhatu/promotion_enquiries_controller.rb +1 -1
- data/app/controllers/dhatu/promotions_controller.rb +1 -1
- data/app/controllers/dhatu/sections_controller.rb +2 -2
- data/app/controllers/dhatu/services_controller.rb +1 -1
- data/app/controllers/dhatu/team_members_controller.rb +1 -1
- data/app/controllers/dhatu/testimonials_controller.rb +1 -1
- data/app/models/dhatu/photo_album.rb +172 -0
- data/app/views/dhatu/categories/_header.html.erb +86 -0
- data/app/views/dhatu/categories/_index.html.erb +0 -91
- data/app/views/dhatu/categories/_row.html.erb +13 -8
- data/app/views/dhatu/categories/index.html.erb +6 -1
- data/app/views/dhatu/dashboard/_index.html.erb +6 -0
- data/app/views/dhatu/pages/_index.html.erb +4 -27
- data/app/views/dhatu/pages/_row.html.erb +3 -21
- data/app/views/dhatu/pages/index.html.erb +7 -6
- data/app/views/dhatu/photo_albums/_form.html.erb +38 -0
- data/app/views/dhatu/photo_albums/_header.html.erb +70 -0
- data/app/views/dhatu/photo_albums/_index.html.erb +44 -0
- data/app/views/dhatu/photo_albums/_row.html.erb +28 -0
- data/app/views/dhatu/photo_albums/_show.html.erb +145 -0
- data/app/views/dhatu/photo_albums/index.html.erb +34 -0
- data/app/views/dhatu/sections/_index.html.erb +29 -53
- data/app/views/dhatu/sections/_row.html.erb +9 -25
- data/app/views/dhatu/sections_old/_form.html.erb +171 -0
- data/app/views/dhatu/sections_old/_index.html.erb +53 -0
- data/app/views/dhatu/sections_old/_row.html.erb +26 -0
- data/app/views/dhatu/sections_old/_show.html.erb +208 -0
- data/app/views/dhatu/sections_old/index.html.erb +52 -0
- data/app/views/layouts/kuppayam/_sidebar.html.erb +6 -0
- data/config/routes.rb +9 -0
- data/db/migrate/20180101093437_create_photo_albums.rb +24 -0
- data/lib/dhatu/version.rb +1 -1
- data/spec/dummy/spec/factories/photo_album.rb +28 -0
- metadata +18 -4
- data/app/views/dhatu/categories/_index_list.html.erb +0 -118
- data/app/views/dhatu/categories/_row_list.html.erb +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 015370c1e69610f80d01420fbf7404edd1f34a35f34f61dc66f0b999070bef30
|
4
|
+
data.tar.gz: 441b0a9e0d92d720e0ccbb46c6b8660b2df998588f71d80ee8b1deb6c333cc02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7cf2c4c109292b1cf62395dfbdf74cff942300d48429550fafd53a1928dce1b4d860fea0e77c3e67095794688948509b262f0a4dff8b1af84e624cc49763fd9
|
7
|
+
data.tar.gz: 0fa5a988ec17486de750ed4ac66adbf6cf027ccba989a2120d6b3b779ec2f86dc84354d41272cd0abdfbe006f8368e4706fde0881efb486e66d78fdee1c1a51d
|
@@ -55,8 +55,9 @@ module Dhatu
|
|
55
55
|
previous_category = Dhatu::Category.find_by_id(previous_parent_id)
|
56
56
|
previous_category.set_end_node! if previous_category
|
57
57
|
end
|
58
|
-
|
59
|
-
|
58
|
+
@feature = Feature.find_by_name(@r_object.category_type)
|
59
|
+
@current_category = @r_object.parent
|
60
|
+
get_collections
|
60
61
|
set_flash_message(I18n.translate("forms.save", item: default_item_name.titleize), :success)
|
61
62
|
end
|
62
63
|
set_resource_notification(@r_object)
|
@@ -67,7 +68,7 @@ module Dhatu
|
|
67
68
|
|
68
69
|
def get_collections
|
69
70
|
|
70
|
-
@current_category = Dhatu::Category.find_by_id(params[:parent_id])
|
71
|
+
@current_category = Dhatu::Category.find_by_id(params[:parent_id]) unless @current_category
|
71
72
|
|
72
73
|
filter_param_mapping
|
73
74
|
|
@@ -126,7 +127,7 @@ module Dhatu
|
|
126
127
|
|
127
128
|
# Conditions
|
128
129
|
get_collections_after_save_resource: false,
|
129
|
-
show_modal_after_create:
|
130
|
+
show_modal_after_create: false,
|
130
131
|
show_modal_after_update: true,
|
131
132
|
|
132
133
|
# Model Size can be large or generic
|
@@ -151,10 +152,10 @@ module Dhatu
|
|
151
152
|
|
152
153
|
# Rendering Paths
|
153
154
|
view_path: "dhatu/categories",
|
154
|
-
js_view_path: "/kuppayam/workflows/
|
155
|
+
js_view_path: "/kuppayam/workflows/nested_folders",
|
155
156
|
|
156
157
|
# Additional Configurations
|
157
|
-
|
158
|
+
load_rich_text_editor: false,
|
158
159
|
tagsinput: false
|
159
160
|
}
|
160
161
|
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
module Dhatu
|
2
|
+
class PhotoAlbumsController < ResourceController
|
3
|
+
|
4
|
+
before_action :require_update_permission, only: [:update_status, :make_parent, :mark_as_featured, :remove_from_featured]
|
5
|
+
|
6
|
+
def choose_category_type
|
7
|
+
end
|
8
|
+
|
9
|
+
def update_status
|
10
|
+
@photo_album = @r_object = Dhatu::PhotoAlbum.find(params[:id])
|
11
|
+
case params[:status]
|
12
|
+
when "unpublished"
|
13
|
+
@photo_album.unpublish!
|
14
|
+
when "removed"
|
15
|
+
@photo_album.remove!
|
16
|
+
when "published"
|
17
|
+
@photo_album.publish!
|
18
|
+
end
|
19
|
+
set_notification(true, I18n.t('status.success'), I18n.t('state.changed', item: default_item_name.titleize, new_state: @r_object.status))
|
20
|
+
render_row
|
21
|
+
end
|
22
|
+
|
23
|
+
def make_parent
|
24
|
+
@photo_album = @r_object = Dhatu::PhotoAlbum.find(params[:id])
|
25
|
+
@photo_album.update_attribute(:parent_id, nil)
|
26
|
+
get_collections
|
27
|
+
render_accordingly
|
28
|
+
end
|
29
|
+
|
30
|
+
def mark_as_featured
|
31
|
+
@photo_album = @r_object = Dhatu::PhotoAlbum.find(params[:id])
|
32
|
+
@photo_album.published?
|
33
|
+
render_row
|
34
|
+
end
|
35
|
+
|
36
|
+
def remove_from_featured
|
37
|
+
@photo_album = @r_object = Dhatu::PhotoAlbum.find(params[:id])
|
38
|
+
@photo_album.featured?
|
39
|
+
render_row
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def save_resource
|
45
|
+
if @r_object.valid?
|
46
|
+
previous_parent_id = @r_object.parent_id_was
|
47
|
+
@r_object.save
|
48
|
+
if @r_object.parent_id != previous_parent_id
|
49
|
+
@r_object.parent.set_end_node! if @r_object.parent
|
50
|
+
previous_category = Dhatu::PhotoAlbum.find_by_id(previous_parent_id)
|
51
|
+
previous_category.set_end_node! if previous_category
|
52
|
+
end
|
53
|
+
@current_photo_album = @r_object.parent
|
54
|
+
get_collections if @resource_options[:get_collections_after_save_resource]
|
55
|
+
set_flash_message(I18n.translate("forms.save", item: default_item_name.titleize), :success)
|
56
|
+
end
|
57
|
+
set_resource_notification(@r_object)
|
58
|
+
action_name = params[:action].to_s == "create" ? "new" : "edit"
|
59
|
+
url = @r_object.persisted? ? resource_url(@r_object) : nil
|
60
|
+
render_or_redirect(@r_object.errors.any?, url, action_name)
|
61
|
+
end
|
62
|
+
|
63
|
+
def get_collections
|
64
|
+
|
65
|
+
@current_album = Dhatu::PhotoAlbum.find_by_id(params[:parent_id])
|
66
|
+
|
67
|
+
filter_param_mapping
|
68
|
+
|
69
|
+
parse_filters
|
70
|
+
|
71
|
+
if @current_album
|
72
|
+
@relation = @current_album.sub_albums.includes(:parent)
|
73
|
+
else
|
74
|
+
@relation = Dhatu::PhotoAlbum.where("parent_id IS NULL")
|
75
|
+
end
|
76
|
+
|
77
|
+
apply_filters
|
78
|
+
|
79
|
+
@relation = @relation.order("priority ASC, name ASC")
|
80
|
+
|
81
|
+
@photo_albums = @r_objects = @relation.page(@current_page).per(@per_page)
|
82
|
+
return true
|
83
|
+
end
|
84
|
+
|
85
|
+
def apply_filters
|
86
|
+
@relation = @relation.search(@query) if @query
|
87
|
+
@relation = @relation.status(@status) if @status
|
88
|
+
end
|
89
|
+
|
90
|
+
def configure_filter_settings
|
91
|
+
@filter_settings = {
|
92
|
+
boolean_filters: [
|
93
|
+
{ filter_name: :featured }
|
94
|
+
],
|
95
|
+
string_filters: [
|
96
|
+
{ filter_name: :query },
|
97
|
+
{ filter_name: :status }
|
98
|
+
],
|
99
|
+
reference_filters: [
|
100
|
+
{ filter_name: :feature, filter_class: Feature },
|
101
|
+
],
|
102
|
+
variable_filters: [],
|
103
|
+
}
|
104
|
+
end
|
105
|
+
|
106
|
+
def resource_controller_configuration
|
107
|
+
{
|
108
|
+
page_title: "Manage Photo Albums",
|
109
|
+
current_nav: "dhatu/photo_albums",
|
110
|
+
|
111
|
+
# Resource Names
|
112
|
+
class: Dhatu::PhotoAlbum,
|
113
|
+
collection_name: :photo_albums,
|
114
|
+
item_name: :photo_album,
|
115
|
+
|
116
|
+
# Conditions
|
117
|
+
get_collections_after_save_resource: true,
|
118
|
+
show_modal_after_create: false,
|
119
|
+
show_modal_after_update: true,
|
120
|
+
|
121
|
+
# Model Size can be large or generic
|
122
|
+
form_model_size: :generic,
|
123
|
+
show_model_size: :large,
|
124
|
+
|
125
|
+
# Layout can be table or feed
|
126
|
+
# table uses html tables and feed uses div based boxes
|
127
|
+
layout: :feed,
|
128
|
+
|
129
|
+
# "/kuppayam/workflows/default"
|
130
|
+
#
|
131
|
+
# Default partial opens show and form partial according to the model_size configuration
|
132
|
+
# It also respect the configuration layout and refresh the page element on both cases - i.e layout is table or feed
|
133
|
+
|
134
|
+
# "/kuppayam/workflows/peacock"
|
135
|
+
# "/kuppayam/workflows/parrot"
|
136
|
+
#
|
137
|
+
# Peacock & Parrot are old ways of doing things and it respects certail configurations
|
138
|
+
# Peacock opens show and form partials in large popup where as Parrot opens it in small
|
139
|
+
# Both Peacock and Parrot expect table based layout and will reload a single row after create / update
|
140
|
+
|
141
|
+
# Rendering Paths
|
142
|
+
view_path: "dhatu/photo_albums",
|
143
|
+
js_view_path: "/kuppayam/workflows/nested_folders",
|
144
|
+
# js_view_path: "/kuppayam/workflows/default",
|
145
|
+
|
146
|
+
# Additional Configurations
|
147
|
+
load_rich_text_editor: false,
|
148
|
+
tagsinput: false
|
149
|
+
}
|
150
|
+
end
|
151
|
+
|
152
|
+
def configure_filter_ui_settings
|
153
|
+
@filter_ui_settings = {}
|
154
|
+
end
|
155
|
+
|
156
|
+
def breadcrumbs_configuration
|
157
|
+
{
|
158
|
+
heading: "Manage Photo Albums",
|
159
|
+
icon: "fa-image",
|
160
|
+
description: "Listing all Photo Albums",
|
161
|
+
links: [{name: "Home", link: breadcrumb_home_path, icon: 'fa-home'},
|
162
|
+
{name: "Manage Photo Albums", link: dhatu.photo_albums_path, icon: 'fa-image', active: true}]
|
163
|
+
}
|
164
|
+
end
|
165
|
+
|
166
|
+
def permitted_params
|
167
|
+
params.require("dhatu/photo_album").permit(:name, :code, :one_liner, :description, :priority, :parent_id, :category_type)
|
168
|
+
end
|
169
|
+
|
170
|
+
|
171
|
+
end
|
172
|
+
end
|
@@ -75,7 +75,7 @@ module Dhatu
|
|
75
75
|
|
76
76
|
# Layout can be table or feed
|
77
77
|
# table uses html tables and feed uses div based boxes
|
78
|
-
layout: :
|
78
|
+
layout: :feed,
|
79
79
|
|
80
80
|
# "/kuppayam/workflows/default"
|
81
81
|
#
|
@@ -94,7 +94,7 @@ module Dhatu
|
|
94
94
|
js_view_path: "/kuppayam/workflows/default",
|
95
95
|
|
96
96
|
# Additional Configurations
|
97
|
-
|
97
|
+
load_rich_text_editor: true,
|
98
98
|
tagsinput: false
|
99
99
|
}
|
100
100
|
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
class Dhatu::PhotoAlbum < Dhatu::ApplicationRecord
|
2
|
+
|
3
|
+
# Set Table Name
|
4
|
+
self.table_name = "photo_albums"
|
5
|
+
|
6
|
+
# Including the State Machine Methods
|
7
|
+
include Publishable
|
8
|
+
include Featureable
|
9
|
+
|
10
|
+
# Callbacks
|
11
|
+
before_validation :generate_permalink, on: :create
|
12
|
+
before_validation :set_top_parent, on: :create
|
13
|
+
after_create :update_permalink, :set_end_node_of_parent
|
14
|
+
after_destroy :set_end_node_of_parent
|
15
|
+
|
16
|
+
# Validations
|
17
|
+
validate_string :name, mandatory: true, min_length: 2, format: /.*/i
|
18
|
+
validate_string :one_liner, mandatory: false, format: /.*/i
|
19
|
+
validate_string :permalink, mandatory: true, format: /.*/i, min_length: 4, max_length: 128
|
20
|
+
|
21
|
+
# Associations
|
22
|
+
belongs_to :parent, :class_name => 'Dhatu::PhotoAlbum', optional: true
|
23
|
+
belongs_to :top_parent, :class_name => 'Dhatu::PhotoAlbum', optional: true
|
24
|
+
has_many :sub_albums, :foreign_key => "parent_id", :class_name => "Dhatu::PhotoAlbum"
|
25
|
+
has_one :cover_image, :as => :imageable, :dependent => :destroy, :class_name => "Image::CoverImage"
|
26
|
+
has_many :gallery_images, :as => :imageable, :dependent => :destroy, :class_name => "Image::GalleryImage"
|
27
|
+
|
28
|
+
# ---------------
|
29
|
+
# Class methods
|
30
|
+
# ---------------
|
31
|
+
|
32
|
+
# return an active record relation object with the search query in its where clause
|
33
|
+
# Return the ActiveRecord::Relation object
|
34
|
+
# == Examples
|
35
|
+
# >>> object.search(query)
|
36
|
+
# => ActiveRecord::Relation object
|
37
|
+
scope :search, lambda {|query| where("LOWER(name) LIKE LOWER('%#{query}%') OR\
|
38
|
+
LOWER(permalink) LIKE LOWER('%#{query}%') OR\
|
39
|
+
LOWER(one_liner) LIKE LOWER('%#{query}%') OR\
|
40
|
+
LOWER(description) LIKE LOWER('%#{query}%')")
|
41
|
+
}
|
42
|
+
|
43
|
+
# Import Methods
|
44
|
+
def self.save_row_data(hsh)
|
45
|
+
|
46
|
+
# Initializing error hash for displaying all errors altogether
|
47
|
+
error_object = Kuppayam::Importer::ErrorHash.new
|
48
|
+
|
49
|
+
return error_object if hsh[:code].to_s.strip.blank?
|
50
|
+
|
51
|
+
category = Dhatu::PhotoAlbum.find_by_code(hsh[:code].to_s.strip) || Dhatu::PhotoAlbum.new
|
52
|
+
category.name = hsh[:name].to_s.strip
|
53
|
+
category.code = hsh[:code].to_s.strip
|
54
|
+
category.one_liner = hsh[:one_liner].to_s.strip
|
55
|
+
category.description = hsh[:description].to_s.strip
|
56
|
+
|
57
|
+
parent = Dhatu::PhotoAlbum.find_by_name(hsh[:parent].to_s.strip)
|
58
|
+
category.parent = parent
|
59
|
+
category.top_parent = parent && parent.top_parent ? parent.top_parent : parent
|
60
|
+
|
61
|
+
category.status = hsh[:status].to_s.strip || PUBLISHED
|
62
|
+
category.priority = hsh[:priority].to_s.strip || 1
|
63
|
+
|
64
|
+
# Initializing error hash for displaying all errors altogether
|
65
|
+
error_object = Kuppayam::Importer::ErrorHash.new
|
66
|
+
|
67
|
+
if category.valid?
|
68
|
+
begin
|
69
|
+
category.save!
|
70
|
+
rescue Exception => e
|
71
|
+
summary = "uncaught #{e} exception while handling connection: #{e.message}"
|
72
|
+
details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}"
|
73
|
+
error_object.errors << { summary: summary, details: details }
|
74
|
+
end
|
75
|
+
else
|
76
|
+
summary = "Error while saving category: #{category.name}"
|
77
|
+
details = "Error! #{category.errors.full_messages.to_sentence}"
|
78
|
+
error_object.errors << { summary: summary, details: details }
|
79
|
+
end
|
80
|
+
|
81
|
+
return error_object
|
82
|
+
end
|
83
|
+
|
84
|
+
# ------------------
|
85
|
+
# Instance Methods
|
86
|
+
# ------------------
|
87
|
+
|
88
|
+
# Other Methods
|
89
|
+
# ------------------
|
90
|
+
|
91
|
+
def display_name
|
92
|
+
self.name
|
93
|
+
end
|
94
|
+
|
95
|
+
def default_image_url(size="medium")
|
96
|
+
"/assets/dhatu/photo-album-#{size}.png"
|
97
|
+
end
|
98
|
+
|
99
|
+
# Permission Methods
|
100
|
+
# ------------------
|
101
|
+
|
102
|
+
def can_be_edited?
|
103
|
+
published? or unpublished?
|
104
|
+
end
|
105
|
+
|
106
|
+
def can_be_deleted?
|
107
|
+
return false unless removed?
|
108
|
+
return false if end_node == false or self.sub_albums.any?
|
109
|
+
true
|
110
|
+
end
|
111
|
+
|
112
|
+
def can_be_published?
|
113
|
+
unpublished? or archived?
|
114
|
+
end
|
115
|
+
|
116
|
+
def can_be_unpublished?
|
117
|
+
return false if end_node == false or self.sub_albums.any?
|
118
|
+
published? or removed?
|
119
|
+
end
|
120
|
+
|
121
|
+
def can_be_archived?
|
122
|
+
return false if end_node == false or self.sub_albums.any?
|
123
|
+
unpublished? or removed?
|
124
|
+
end
|
125
|
+
|
126
|
+
def can_be_removed?
|
127
|
+
return false if end_node == false or self.sub_albums.any?
|
128
|
+
published? or unpublished?
|
129
|
+
end
|
130
|
+
|
131
|
+
# Callback methods
|
132
|
+
# ------------------
|
133
|
+
|
134
|
+
def set_end_node!
|
135
|
+
self.update_column(:end_node, self.sub_albums.count < 1)
|
136
|
+
end
|
137
|
+
|
138
|
+
def set_end_node_of_parent
|
139
|
+
self.parent.set_end_node! if self.parent
|
140
|
+
end
|
141
|
+
|
142
|
+
protected
|
143
|
+
|
144
|
+
def generate_permalink
|
145
|
+
return unless self.name
|
146
|
+
if self.parent
|
147
|
+
perm = "#{self.name.parameterize}-#{self.parent.name.parameterize}"
|
148
|
+
else
|
149
|
+
perm = self.name.parameterize
|
150
|
+
end
|
151
|
+
self.permalink = "#{SecureRandom.hex(4)}-#{perm[0..110]}"
|
152
|
+
end
|
153
|
+
|
154
|
+
def update_permalink
|
155
|
+
if self.parent
|
156
|
+
self.permalink = "#{self.id}-#{self.name.parameterize}-#{self.parent.name.parameterize}"
|
157
|
+
else
|
158
|
+
self.permalink = "#{self.id}-#{self.name.parameterize}" if self.name
|
159
|
+
end
|
160
|
+
self.save
|
161
|
+
end
|
162
|
+
|
163
|
+
def set_top_parent
|
164
|
+
return if self.parent.blank?
|
165
|
+
if self.parent.top_parent.blank?
|
166
|
+
self.top_parent = self.parent
|
167
|
+
else
|
168
|
+
self.top_parent = self.parent.top_parent
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
end
|