Module: CurateHelper

Defined in:
app/helpers/curate_helper.rb

Instance Method Summary collapse

Instance Method Details

#classify_for_display(curation_concern) ⇒ Object



52
53
54
# File 'app/helpers/curate_helper.rb', line 52

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



13
14
15
# File 'app/helpers/curate_helper.rb', line 13

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

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



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/curate_helper.rb', line 34

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



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

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



25
26
27
28
29
30
31
# File 'app/helpers/curate_helper.rb', line 25

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



81
82
83
# File 'app/helpers/curate_helper.rb', line 81

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


56
57
58
59
60
61
62
63
# File 'app/helpers/curate_helper.rb', line 56

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



65
66
67
68
69
# File 'app/helpers/curate_helper.rb', line 65

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



71
72
73
74
75
76
77
# File 'app/helpers/curate_helper.rb', line 71

def polymorphic_path_args(asset)
  if (Curate.configuration.registered_curation_concern_types + ["GenericFile"]).include? asset.class.inspect
    return [:curation_concern, asset]
  else
    return asset
  end
end

#polymorphic_path_for_asset(asset) ⇒ Object



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

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