Module: GeoblacklightAdminHelper
- Includes:
- Pagy::Frontend
- Defined in:
- app/helpers/geoblacklight_admin_helper.rb
Overview
GeoblacklightAdminHelper
This module provides helper methods for the GeoBlacklight admin interface. It includes methods for handling JSON data, generating paths, formatting flash messages, and more.
Instance Method Summary collapse
-
#assets_dct_references_options ⇒ String
Generates options for asset DCT references.
-
#b1g_institution_codes ⇒ Hash
Provides a mapping of institution codes to institution names.
-
#bookmarks_badge ⇒ String
Generates an HTML badge for bookmarks.
-
#diff_class(char) ⇒ String
Maps a character to a CSS class for diff highlighting.
-
#flash_class(level) ⇒ String
Maps flash message levels to CSS classes.
-
#flat_hash_key(names) ⇒ String
Generates a key for a flattened hash from an array of names.
-
#flatten_hash(hash, ancestor_names = []) ⇒ Hash
Flattens a nested hash into a single-level hash with keys representing the nested structure.
-
#link_to_admin_import(import) ⇒ String
Generates a link to the admin import page for a given import.
-
#link_to_gbl_import(label, import, state = false) ⇒ String
Generates a link to the GeoBlacklight import page with optional state.
-
#no_json_blanks(value) ⇒ String, ...
Removes blank values from JSON data.
-
#notifications_badge ⇒ String
Generates an HTML badge for notifications.
-
#params_as_hidden_fields(params) ⇒ String
Converts parameters into hidden form fields.
-
#qa_search_vocab_path(vocab, subauthority = nil) ⇒ String
Generates a search path for the QA (questioning_authority) gem.
-
#thumb_to_render?(document) ⇒ Boolean
Determines if a document’s thumbnail should be rendered.
-
#thumbnail_to_render(document) ⇒ String
Returns the URL of the thumbnail to render for a document.
Instance Method Details
#assets_dct_references_options ⇒ String
Generates options for asset DCT references.
205 206 207 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 205 def escape_javascript((I18n.t("activemodel.asset_enum_values.document/reference.category").invert.sort.insert(0, ["Choose Reference Type", nil]))).to_s end |
#b1g_institution_codes ⇒ Hash
Provides a mapping of institution codes to institution names.
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 55 def b1g_institution_codes { "01" => "Indiana University", "02" => "University of Illinois Urbana-Champaign", "03" => "University of Iowa", "04" => "University of Maryland", "05" => "University of Minnesota", "06" => "Michigan State University", "07" => "University of Michigan", "08" => "Purdue University", "09" => "Pennsylvania State University", "10" => "University of Wisconsin-Madison", "11" => "The Ohio State University", "12" => "University of Chicago", "13" => "University of Nebraska-Lincoln", "14" => "Rutgers University-New Brunswick", "15" => "Northwestern University" } end |
#bookmarks_badge ⇒ String
Generates an HTML badge for bookmarks.
78 79 80 81 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 78 def bookmarks_badge bookmarks_classes = ["badge", "badge-dark"] "<span class='#{bookmarks_classes.join(" ")}' id='bookmarks-count'>#{current_user.bookmarks.size}</span>" end |
#diff_class(char) ⇒ String
Maps a character to a CSS class for diff highlighting.
149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 149 def diff_class(char) case char when "~" "table-warning" when "-" "table-danger" when "+" "table-success" else "" end end |
#flash_class(level) ⇒ String
Maps flash message levels to CSS classes.
42 43 44 45 46 47 48 49 50 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 42 def flash_class(level) alerts = { "notice" => "alert alert-info", "success" => "alert alert-success", "error" => "alert alert-error", "alert" => "alert alert-error" } alerts[level] end |
#flat_hash_key(names) ⇒ String
Generates a key for a flattened hash from an array of names.
136 137 138 139 140 141 142 143 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 136 def flat_hash_key(names) names = Array.new(names) name = names.shift.to_s.dup names.each do |n| name << "[#{n}]" end name end |
#flatten_hash(hash, ancestor_names = []) ⇒ Hash
Flattens a nested hash into a single-level hash with keys representing the nested structure.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 115 def flatten_hash(hash, ancestor_names = []) flat_hash = {} hash.each do |k, v| names = Array.new(ancestor_names) names << k if v.is_a?(Hash) flat_hash.merge!(flatten_hash(v, names)) else key = flat_hash_key(names) key += "[]" if v.is_a?(Array) flat_hash[key] = v end end flat_hash end |
#link_to_admin_import(import) ⇒ String
Generates a link to the admin import page for a given import.
166 167 168 169 170 171 172 173 174 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 166 def link_to_admin_import(import) path = admin_documents_path( { f: {b1g_geom_import_id_ssi: [import]} } ) link_to import.name, path end |
#link_to_gbl_import(label, import, state = false) ⇒ String
Generates a link to the GeoBlacklight import page with optional state.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 182 def link_to_gbl_import(label, import, state = false) path = if state blacklight_path( { f: {b1g_geom_import_id_ssi: [import]}, publication_state: state } ) else blacklight_path( { f: {b1g_geom_import_id_ssi: [import]}, publication_state: "*" } ) end link_to(label, path) end |
#no_json_blanks(value) ⇒ String, ...
Removes blank values from JSON data.
18 19 20 21 22 23 24 25 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 18 def no_json_blanks(value) case value when String value.presence when Array value.join.blank? ? nil : value end end |
#notifications_badge ⇒ String
Generates an HTML badge for notifications.
86 87 88 89 90 91 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 86 def notifications_badge notifications_classes = ["badge"] notifications_classes << "badge-dark" if current_user.notifications.unread.empty? notifications_classes << "badge-danger" if current_user.notifications.unread.size.positive? "<span class='#{notifications_classes.join(" ")}' id='notification-count'>#{current_user.notifications.unread.size}</span>" end |
#params_as_hidden_fields(params) ⇒ String
Converts parameters into hidden form fields.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 97 def params_as_hidden_fields(params) hidden_fields = [] flatten_hash(params).each do |name, value| value = Array.wrap(value) value.each do |v| hidden_fields << hidden_field_tag(name, v.to_s, id: nil) end end safe_join(hidden_fields, "\n") end |
#qa_search_vocab_path(vocab, subauthority = nil) ⇒ String
Generates a search path for the QA (questioning_authority) gem.
32 33 34 35 36 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 32 def qa_search_vocab_path(vocab, = nil) path = "/authorities/search/#{CGI.escape vocab}" path += "/#{CGI.escape subauthority}" if path end |
#thumb_to_render?(document) ⇒ Boolean
Determines if a document’s thumbnail should be rendered.
213 214 215 216 217 218 219 220 221 222 223 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 213 def thumb_to_render?(document) if document&.thumbnail&.file_url&.present? && document&.thumbnail&.file_derivatives&.present? true elsif document&.document_assets&.any? document.document_assets.any? do |asset| asset.file_derivatives&.key?(:thumb_standard_2X) end else false end end |
#thumbnail_to_render(document) ⇒ String
Returns the URL of the thumbnail to render for a document.
229 230 231 232 233 234 235 236 237 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 229 def thumbnail_to_render(document) if document&.thumbnail&.file_url&.present? && document&.thumbnail&.file_derivatives&.present? document.thumbnail.file_url(:thumb_standard_2X) elsif document&.document_assets&.any? document.document_assets.find do |asset| asset.file_derivatives&.key?(:thumb_standard_2X) end&.file_url(:thumb_standard_2X) end end |