Module: CurateHelper

Defined in:
app/helpers/curate_helper.rb

Instance Method Summary collapse

Instance Method Details

#classify_for_display(curation_concern) ⇒ Object



64
65
66
# File 'app/helpers/curate_helper.rb', line 64

def classify_for_display(curation_concern)
  curation_concern.human_readable_type.downcase
end

#collection_title_from_pid(value) ⇒ Object

Loads the object and returns its title



4
5
6
7
8
9
10
11
# File 'app/helpers/curate_helper.rb', line 4

def collection_title_from_pid  value
  begin
    c = Collection.load_instance_from_solr(value)
  rescue => e
    logger.warn("WARN: Helper method collection_title_from_pid raised an error when loading #{value}.  Error was #{e}")
  end
  return c.nil? ? value : c.title
end

#construct_page_title(*elements) ⇒ Object



25
26
27
# File 'app/helpers/curate_helper.rb', line 25

def construct_page_title(*elements)
  (elements.flatten.compact + [application_name]).join(" // ")
end

#creator_name_from_pid(value) ⇒ Object

Loads the person object and returns their name In this case, the value is in the format: info:fedora/<PID> So used split



16
17
18
19
20
21
22
23
# File 'app/helpers/curate_helper.rb', line 16

def creator_name_from_pid value
  begin
    p = Person.load_instance_from_solr(value.split("/").last)
  rescue => e
    logger.warn("WARN: Helper method create_name_from_pid raised an error when loading #{value}.  Error was #{e}")
  end
  return p.nil? ? value : p.name
end

#curation_concern_attribute_to_html(curation_concern, method_name, label = nil, options = {}) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/curate_helper.rb', line 46

def curation_concern_attribute_to_html(curation_concern, method_name, label = nil, options = {})
  markup = ""
  label ||= derived_label_for(curation_concern, method_name)
  subject = curation_concern.send(method_name)
  return markup if !subject.present? && !options[:include_empty]
  markup << %(<tr><th>#{label}</th>\n<td><ul class='tabular'>)
  [subject].flatten.compact.each do |value|
    markup << %(<li class="attribute #{method_name}">#{h(value)}</li>\n)
  end
  markup << %(</ul></td></tr>)
  markup.html_safe
end

#curation_concern_page_title(curation_concern) ⇒ Object



29
30
31
32
33
34
35
# File 'app/helpers/curate_helper.rb', line 29

def curation_concern_page_title(curation_concern)
  if curation_concern.persisted?
    construct_page_title(curation_concern.title, "#{curation_concern.human_readable_type} [#{curation_concern.to_param}]")
  else
    construct_page_title("New #{curation_concern.human_readable_type}")
  end
end

#default_page_titleObject



37
38
39
40
41
42
43
# File 'app/helpers/curate_helper.rb', line 37

def default_page_title
  text = controller_name.singularize.titleize
  if action_name
    text = "#{action_name.titleize} " + text
  end
  construct_page_title(text)
end

#edit_polymorphic_path_for_asset(asset) ⇒ Object



95
96
97
# File 'app/helpers/curate_helper.rb', line 95

def edit_polymorphic_path_for_asset(asset)
  return edit_polymorphic_path(polymorphic_path_args(asset))
end


68
69
70
71
72
73
74
75
# File 'app/helpers/curate_helper.rb', line 68

def link_to_edit_permissions(curation_concern, solr_document = nil)
  markup = <<-HTML
    <a href="#{edit_polymorphic_path_for_asset(curation_concern)}" id="permission_#{curation_concern.to_param}">
      #{permission_badge_for(curation_concern, solr_document)}
    </a>
  HTML
  markup.html_safe
end

#permission_badge_for(curation_concern, solr_document = nil) ⇒ Object



77
78
79
80
81
# File 'app/helpers/curate_helper.rb', line 77

def permission_badge_for(curation_concern, solr_document = nil)
  solr_document ||= curation_concern.to_solr
  dom_label_class, link_title = extract_dom_label_class_and_link_title(solr_document)
  %(<span class="label #{dom_label_class}" title="#{link_title}">#{link_title}</span>).html_safe
end

#polymorphic_path_args(asset) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'app/helpers/curate_helper.rb', line 83

def polymorphic_path_args(asset)
  # A better approximation, but we still need one location for this information
  # either via routes or via the initializer of the application
  if asset.class.included_modules.include?(CurationConcern::Model)
    return [:curation_concern, asset]
  else
    return asset
  end
end

#polymorphic_path_for_asset(asset) ⇒ Object



92
93
94
# File 'app/helpers/curate_helper.rb', line 92

def polymorphic_path_for_asset(asset)
  return polymorphic_path(polymorphic_path_args(asset))
end