Module: GeoblacklightAdminHelper

Includes:
Pagy::Frontend
Defined in:
app/helpers/geoblacklight_admin_helper.rb

Overview

GeoblacklightAdminHelper

Instance Method Summary collapse

Instance Method Details

#b1g_institution_codesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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"
  }
end

#diff_class(char) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/helpers/geoblacklight_admin_helper.rb', line 106

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



97
98
99
100
101
102
103
104
# File 'app/helpers/geoblacklight_admin_helper.rb', line 97

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/helpers/geoblacklight_admin_helper.rb', line 80

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


119
120
121
122
123
124
125
126
127
# File 'app/helpers/geoblacklight_admin_helper.rb', line 119

def link_to_admin_import(import)
  path = admin_documents_path(
    {
      f: {b1g_geom_import_id_ssi: [import]}
    }
  )

  link_to import.name, path
end


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/helpers/geoblacklight_admin_helper.rb', line 129

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_badgeObject



60
61
62
63
64
65
# File 'app/helpers/geoblacklight_admin_helper.rb', line 60

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



68
69
70
71
72
73
74
75
76
77
78
# File 'app/helpers/geoblacklight_admin_helper.rb', line 68

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, subauthority = nil)
  path = "/authorities/search/#{CGI.escape vocab}"

  path += "/#{CGI.escape subauthority}" if subauthority

  path
end