Module: GeoblacklightAdminHelper
- Includes:
- Pagy::Frontend
- Defined in:
- app/helpers/geoblacklight_admin_helper.rb
Overview
GeoblacklightAdminHelper
Instance Method Summary collapse
- #assets_dct_references_options ⇒ Object
- #b1g_institution_codes ⇒ Object
- #bookmarks_badge ⇒ Object
- #diff_class(char) ⇒ Object
- #flash_class(level) ⇒ Object
- #flat_hash_key(names) ⇒ Object
- #flatten_hash(hash, ancestor_names = []) ⇒ Object
- #link_to_admin_import(import) ⇒ Object
- #link_to_gbl_import(label, import, state = false) ⇒ Object
-
#no_json_blanks(value) ⇒ Object
jbuilder helper.
- #notifications_badge ⇒ Object
-
#params_as_hidden_fields(params) ⇒ Object
From Blacklight::HiddenSearchStateComponent.
-
#qa_search_vocab_path(vocab, subauthority = nil) ⇒ Object
qa (questioning_authoriry) gem oddly gives us no route helpers, so let’s make one ourselves, for it’s current mount point, we can change it if needed but at least it’s DRY.
Instance Method Details
#assets_dct_references_options ⇒ Object
155 156 157 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 155 def escape_javascript((I18n.t("activemodel.enum_values.document/reference.category").invert.sort.insert(0, ["Choose Reference Type", nil]))).to_s end |
#b1g_institution_codes ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 41 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 ⇒ Object
61 62 63 64 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 61 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) ⇒ Object
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 112 def diff_class(char) case char when "~" "table-warning" when "-" "table-danger" when "+" "table-success" else "" end end |
#flash_class(level) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 31 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) ⇒ Object
103 104 105 106 107 108 109 110 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 103 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 = []) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 86 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) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 125 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) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 135 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) ⇒ Object
jbuilder helper
11 12 13 14 15 16 17 18 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 11 def no_json_blanks(value) case value when String value.presence when Array value.join.blank? ? nil : value end end |
#notifications_badge ⇒ Object
66 67 68 69 70 71 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 66 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) ⇒ Object
From Blacklight::HiddenSearchStateComponent
74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 74 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) ⇒ Object
qa (questioning_authoriry) gem oddly gives us no route helpers, so let’s make one ourselves, for it’s current mount point, we can change it if needed but at least it’s DRY.
23 24 25 26 27 28 29 |
# File 'app/helpers/geoblacklight_admin_helper.rb', line 23 def qa_search_vocab_path(vocab, = nil) path = "/authorities/search/#{CGI.escape vocab}" path += "/#{CGI.escape }" if path end |