Module: DocumentHelper

Defined in:
app/helpers/document_helper.rb

Overview

DocumentHelper

Instance Method Summary collapse

Instance Method Details



57
58
59
# File 'app/helpers/document_helper.rb', line 57

def blacklight_link(document)
  "#{BLACKLIGHT_URL}/catalog/#{document.friendlier_id}"
end


31
32
33
34
35
36
37
38
39
# File 'app/helpers/document_helper.rb', line 31

def link_from_api(link)
  # Append facet - Full URI returned
  uri = URI.parse(link["links"]["self"])
  {action: "add", link: "/admin/documents?#{uri.query}"}
rescue
  # Remove facet - Only path and query returned
  uri = URI.parse(link["links"]["remove"])
  {action: "remove", link: "/admin/documents?#{uri.query}"}
end


22
23
24
25
# File 'app/helpers/document_helper.rb', line 22

def localize_link(link)
  uri = URI.parse(link)
  "/admin/documents?#{uri.query}"
end


49
50
51
52
53
54
55
# File 'app/helpers/document_helper.rb', line 49

def next_link(links)
  if links["next"]
    link_to "Next", localize_link(links["next"]), {class: "btn btn-outline-primary btn-sm"}
  else
    link_to "Next", "javascript:;", {class: "btn btn-outline-primary btn-sm disabled", "aria-disabled": true}
  end
end


41
42
43
44
45
46
47
# File 'app/helpers/document_helper.rb', line 41

def previous_link(links)
  if links["prev"]
    link_to "Previous", localize_link(links["prev"]), {class: "btn btn-outline-primary btn-sm"}
  else
    link_to "Previous", "javascript:;", {class: "btn btn-outline-primary btn-sm disabled", "aria-disabled": true}
  end
end

#publication_state_badge(document) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/helpers/document_helper.rb', line 5

def publication_state_badge(document)
  case document.publication_state
  when "draft"
    link_to("#document_publication_state") do
      tag.span("Draft", class: "badge badge-secondary")
    end
  when "published"
    link_to("#document_publication_state") do
      tag.span("Published", class: "badge badge-success")
    end
  when "unpublished"
    link_to("#document_publication_state") do
      tag.span("Unpublished", class: "badge badge-danger")
    end
  end
end


27
28
29
# File 'app/helpers/document_helper.rb', line 27

def sort_link(link)
  link_to link["attributes"]["label"], localize_link(link["links"]["self"]), {class: "dropdown-item"}
end