dhatu 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/dhatu/blog_posts_controller.rb +1 -1
  3. data/app/controllers/dhatu/bookings_controller.rb +1 -1
  4. data/app/controllers/dhatu/branches_controller.rb +1 -1
  5. data/app/controllers/dhatu/categories_controller.rb +7 -6
  6. data/app/controllers/dhatu/events_controller.rb +1 -1
  7. data/app/controllers/dhatu/offers_controller.rb +1 -1
  8. data/app/controllers/dhatu/pages_controller.rb +1 -1
  9. data/app/controllers/dhatu/photo_albums_controller.rb +172 -0
  10. data/app/controllers/dhatu/prices_controller.rb +1 -1
  11. data/app/controllers/dhatu/projects_controller.rb +1 -1
  12. data/app/controllers/dhatu/promotion_enquiries_controller.rb +1 -1
  13. data/app/controllers/dhatu/promotions_controller.rb +1 -1
  14. data/app/controllers/dhatu/sections_controller.rb +2 -2
  15. data/app/controllers/dhatu/services_controller.rb +1 -1
  16. data/app/controllers/dhatu/team_members_controller.rb +1 -1
  17. data/app/controllers/dhatu/testimonials_controller.rb +1 -1
  18. data/app/models/dhatu/photo_album.rb +172 -0
  19. data/app/views/dhatu/categories/_header.html.erb +86 -0
  20. data/app/views/dhatu/categories/_index.html.erb +0 -91
  21. data/app/views/dhatu/categories/_row.html.erb +13 -8
  22. data/app/views/dhatu/categories/index.html.erb +6 -1
  23. data/app/views/dhatu/dashboard/_index.html.erb +6 -0
  24. data/app/views/dhatu/pages/_index.html.erb +4 -27
  25. data/app/views/dhatu/pages/_row.html.erb +3 -21
  26. data/app/views/dhatu/pages/index.html.erb +7 -6
  27. data/app/views/dhatu/photo_albums/_form.html.erb +38 -0
  28. data/app/views/dhatu/photo_albums/_header.html.erb +70 -0
  29. data/app/views/dhatu/photo_albums/_index.html.erb +44 -0
  30. data/app/views/dhatu/photo_albums/_row.html.erb +28 -0
  31. data/app/views/dhatu/photo_albums/_show.html.erb +145 -0
  32. data/app/views/dhatu/photo_albums/index.html.erb +34 -0
  33. data/app/views/dhatu/sections/_index.html.erb +29 -53
  34. data/app/views/dhatu/sections/_row.html.erb +9 -25
  35. data/app/views/dhatu/sections_old/_form.html.erb +171 -0
  36. data/app/views/dhatu/sections_old/_index.html.erb +53 -0
  37. data/app/views/dhatu/sections_old/_row.html.erb +26 -0
  38. data/app/views/dhatu/sections_old/_show.html.erb +208 -0
  39. data/app/views/dhatu/sections_old/index.html.erb +52 -0
  40. data/app/views/layouts/kuppayam/_sidebar.html.erb +6 -0
  41. data/config/routes.rb +9 -0
  42. data/db/migrate/20180101093437_create_photo_albums.rb +24 -0
  43. data/lib/dhatu/version.rb +1 -1
  44. data/spec/dummy/spec/factories/photo_album.rb +28 -0
  45. metadata +18 -4
  46. data/app/views/dhatu/categories/_index_list.html.erb +0 -118
  47. 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: d86a2db6606d13b0c37c9761e6f24e14f9ce940c7521c640d1e043a31f207967
4
- data.tar.gz: f6f8cb4ba9b26c523fb2226c1af5e53da3338afa9a4888105dc7e61f32d6889b
3
+ metadata.gz: 015370c1e69610f80d01420fbf7404edd1f34a35f34f61dc66f0b999070bef30
4
+ data.tar.gz: 441b0a9e0d92d720e0ccbb46c6b8660b2df998588f71d80ee8b1deb6c333cc02
5
5
  SHA512:
6
- metadata.gz: e5317626fb1813fe528a7f17006f883b4c1bc3ef371139afbfc6d68fee1b213d7634d28fadb590f06e00951c4037e4709184b1b35f9c5f2c3f4b8644623893b7
7
- data.tar.gz: d4c53785c6fe128b9f825231d7d034959b506144b3befb370a4752fa0e5be1372f4fdadc97323703dddaba7db152fba54da75ddf59775ef6563b6a5e1dcd35e3
6
+ metadata.gz: b7cf2c4c109292b1cf62395dfbdf74cff942300d48429550fafd53a1928dce1b4d860fea0e77c3e67095794688948509b262f0a4dff8b1af84e624cc49763fd9
7
+ data.tar.gz: 0fa5a988ec17486de750ed4ac66adbf6cf027ccba989a2120d6b3b779ec2f86dc84354d41272cd0abdfbe006f8368e4706fde0881efb486e66d78fdee1c1a51d
@@ -138,7 +138,7 @@ module Dhatu
138
138
  js_view_path: "/kuppayam/workflows/default",
139
139
 
140
140
  # Additional Configurations
141
- load_wysihtml5: true,
141
+ load_rich_text_editor: true,
142
142
  tagsinput: false
143
143
  }
144
144
  end
@@ -100,7 +100,7 @@ module Dhatu
100
100
  js_view_path: "/kuppayam/workflows/default",
101
101
 
102
102
  # Additional Configurations
103
- load_wysihtml5: true,
103
+ load_rich_text_editor: true,
104
104
  tagsinput: false
105
105
  }
106
106
  end
@@ -127,7 +127,7 @@ module Dhatu
127
127
  js_view_path: "/kuppayam/workflows/default",
128
128
 
129
129
  # Additional Configurations
130
- load_wysihtml5: false,
130
+ load_rich_text_editor: false,
131
131
  tagsinput: false
132
132
  }
133
133
  end
@@ -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
- get_collections if @resource_options[:layout] == :table
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: true,
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/default",
155
+ js_view_path: "/kuppayam/workflows/nested_folders",
155
156
 
156
157
  # Additional Configurations
157
- load_wysihtml5: false,
158
+ load_rich_text_editor: false,
158
159
  tagsinput: false
159
160
  }
160
161
  end
@@ -129,7 +129,7 @@ module Dhatu
129
129
  js_view_path: "/kuppayam/workflows/default",
130
130
 
131
131
  # Additional Configurations
132
- load_wysihtml5: true,
132
+ load_rich_text_editor: true,
133
133
  tagsinput: false
134
134
  }
135
135
  end
@@ -132,7 +132,7 @@ module Dhatu
132
132
  js_view_path: "/kuppayam/workflows/default",
133
133
 
134
134
  # Additional Configurations
135
- load_wysihtml5: true,
135
+ load_rich_text_editor: true,
136
136
  tagsinput: false
137
137
  }
138
138
  end
@@ -111,7 +111,7 @@ module Dhatu
111
111
  js_view_path: "/kuppayam/workflows/default",
112
112
 
113
113
  # Additional Configurations
114
- load_wysihtml5: false,
114
+ load_rich_text_editor: false,
115
115
  tagsinput: false
116
116
  }
117
117
  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
@@ -133,7 +133,7 @@ module Dhatu
133
133
  js_view_path: "/kuppayam/workflows/default",
134
134
 
135
135
  # Additional Configurations
136
- load_wysihtml5: true,
136
+ load_rich_text_editor: true,
137
137
  tagsinput: false
138
138
  }
139
139
  end
@@ -130,7 +130,7 @@ module Dhatu
130
130
  js_view_path: "/kuppayam/workflows/default",
131
131
 
132
132
  # Additional Configurations
133
- load_wysihtml5: true,
133
+ load_rich_text_editor: true,
134
134
  tagsinput: false
135
135
  }
136
136
  end
@@ -116,7 +116,7 @@ module Dhatu
116
116
  js_view_path: "/kuppayam/workflows/default",
117
117
 
118
118
  # Additional Configurations
119
- load_wysihtml5: false,
119
+ load_rich_text_editor: false,
120
120
  tagsinput: false
121
121
  }
122
122
  end
@@ -109,7 +109,7 @@ module Dhatu
109
109
  js_view_path: "/kuppayam/workflows/default",
110
110
 
111
111
  # Additional Configurations
112
- load_wysihtml5: true,
112
+ load_rich_text_editor: true,
113
113
  tagsinput: false
114
114
  }
115
115
  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: :table,
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
- load_wysihtml5: true,
97
+ load_rich_text_editor: true,
98
98
  tagsinput: false
99
99
  }
100
100
  end
@@ -130,7 +130,7 @@ module Dhatu
130
130
  js_view_path: "/kuppayam/workflows/default",
131
131
 
132
132
  # Additional Configurations
133
- load_wysihtml5: true,
133
+ load_rich_text_editor: true,
134
134
  tagsinput: false
135
135
  }
136
136
  end
@@ -92,7 +92,7 @@ module Dhatu
92
92
  js_view_path: "/kuppayam/workflows/default",
93
93
 
94
94
  # Additional Configurations
95
- load_wysihtml5: true,
95
+ load_rich_text_editor: true,
96
96
  tagsinput: false
97
97
  }
98
98
  end
@@ -91,7 +91,7 @@ module Dhatu
91
91
  js_view_path: "/kuppayam/workflows/default",
92
92
 
93
93
  # Additional Configurations
94
- load_wysihtml5: true,
94
+ load_rich_text_editor: true,
95
95
  tagsinput: false
96
96
  }
97
97
  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