Class: Dhatu::PhotoAlbum
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Dhatu::PhotoAlbum
- Includes:
- Featureable, Publishable
- Defined in:
- app/models/dhatu/photo_album.rb
Class Method Summary collapse
-
.save_row_data(hsh) ⇒ Object
Import Methods.
Instance Method Summary collapse
- #can_be_archived? ⇒ Boolean
- #can_be_deleted? ⇒ Boolean
-
#can_be_edited? ⇒ Boolean
Permission Methods ——————.
- #can_be_published? ⇒ Boolean
- #can_be_removed? ⇒ Boolean
- #can_be_unpublished? ⇒ Boolean
- #default_image_url(size = "medium") ⇒ Object
-
#display_name ⇒ Object
Other Methods ——————.
-
#set_end_node! ⇒ Object
Callback methods ——————.
- #set_end_node_of_parent ⇒ Object
Class Method Details
.save_row_data(hsh) ⇒ Object
Import Methods
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/dhatu/photo_album.rb', line 44 def self.save_row_data(hsh) # Initializing error hash for displaying all errors altogether error_object = Kuppayam::Importer::ErrorHash.new return error_object if hsh[:code].to_s.strip.blank? category = Dhatu::PhotoAlbum.find_by_code(hsh[:code].to_s.strip) || Dhatu::PhotoAlbum.new category.name = hsh[:name].to_s.strip category.code = hsh[:code].to_s.strip category.one_liner = hsh[:one_liner].to_s.strip category.description = hsh[:description].to_s.strip parent = Dhatu::PhotoAlbum.find_by_name(hsh[:parent].to_s.strip) category.parent = parent category.top_parent = parent && parent.top_parent ? parent.top_parent : parent category.status = hsh[:status].to_s.strip || PUBLISHED category.priority = hsh[:priority].to_s.strip || 1 # Initializing error hash for displaying all errors altogether error_object = Kuppayam::Importer::ErrorHash.new if category.valid? begin category.save! rescue Exception => e summary = "uncaught #{e} exception while handling connection: #{e.}" details = "Stack trace: #{e.backtrace.map {|l| " #{l}\n"}.join}" error_object.errors << { summary: summary, details: details } end else summary = "Error while saving category: #{category.name}" details = "Error! #{category.errors..to_sentence}" error_object.errors << { summary: summary, details: details } end return error_object end |
Instance Method Details
#can_be_archived? ⇒ Boolean
121 122 123 124 |
# File 'app/models/dhatu/photo_album.rb', line 121 def can_be_archived? return false if end_node == false or self.sub_albums.any? unpublished? or removed? end |
#can_be_deleted? ⇒ Boolean
106 107 108 109 110 |
# File 'app/models/dhatu/photo_album.rb', line 106 def can_be_deleted? return false unless removed? return false if end_node == false or self.sub_albums.any? true end |
#can_be_edited? ⇒ Boolean
Permission Methods
102 103 104 |
# File 'app/models/dhatu/photo_album.rb', line 102 def can_be_edited? published? or unpublished? end |
#can_be_published? ⇒ Boolean
112 113 114 |
# File 'app/models/dhatu/photo_album.rb', line 112 def can_be_published? unpublished? or archived? end |
#can_be_removed? ⇒ Boolean
126 127 128 129 |
# File 'app/models/dhatu/photo_album.rb', line 126 def can_be_removed? return false if end_node == false or self.sub_albums.any? published? or unpublished? end |
#can_be_unpublished? ⇒ Boolean
116 117 118 119 |
# File 'app/models/dhatu/photo_album.rb', line 116 def can_be_unpublished? return false if end_node == false or self.sub_albums.any? published? or removed? end |
#default_image_url(size = "medium") ⇒ Object
95 96 97 |
# File 'app/models/dhatu/photo_album.rb', line 95 def default_image_url(size="medium") "/assets/dhatu/photo-album-#{size}.png" end |
#display_name ⇒ Object
Other Methods
91 92 93 |
# File 'app/models/dhatu/photo_album.rb', line 91 def display_name self.name end |
#set_end_node! ⇒ Object
Callback methods
134 135 136 |
# File 'app/models/dhatu/photo_album.rb', line 134 def set_end_node! self.update_column(:end_node, self.sub_albums.count < 1) end |
#set_end_node_of_parent ⇒ Object
138 139 140 |
# File 'app/models/dhatu/photo_album.rb', line 138 def set_end_node_of_parent self.parent.set_end_node! if self.parent end |