Module: SearchHelper

Defined in:
frontend/app/helpers/search_helper.rb

Defined Under Namespace

Classes: ExtraColumn

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_browse_columns(model, enum_locales = {})



141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'frontend/app/helpers/search_helper.rb', line 141

def add_browse_columns(model, enum_locales = {})
  (1..5).to_a.each do |n|
    prop = user_prefs["#{model}_browse_column_#{n}"]
    if prop && prop != 'no_value'
      enum_locale_key = enum_locales.has_key?(prop) ? enum_locales[prop] : "#{model}_#{prop}"
      add_column(I18n.t("#{model}.#{prop}"),
                 proc { |record|
                   v = record[prop] || ASUtils.json_parse(record['json'])[prop]
                   I18n.t("enumerations.#{enum_locale_key}.#{v}", :default => v.to_s)
                 }, :sortable => true, :sort_by => prop)
    end
  end
end

- (Object) add_column(label, block, opts = {})



121
122
123
124
125
126
127
128
129
130
# File 'frontend/app/helpers/search_helper.rb', line 121

def add_column(label, block, opts = {})
  @extra_columns ||= []

  if opts[:sortable] && opts[:sort_by]
    @search_data.sort_fields << opts[:sort_by]
  end

  col = ExtraColumn.new(label, block, opts, @search_data)
  @extra_columns.push(col)
end

- (Object) add_identifier_column



132
133
134
135
136
137
138
139
# File 'frontend/app/helpers/search_helper.rb', line 132

def add_identifier_column
  prop = "identifier" 
  add_column(identifier_column_header_label,
                 proc { |record|
                    record[prop] || ASUtils.json_parse(record['json'])[prop]
                 }, :sortable => true, :sort_by => prop)

end

- (Boolean) allow_multi_select?

Returns:

  • (Boolean)


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

def allow_multi_select?
  @show_multiselect_column
end

- (Object) build_search_params(opts = {})



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'frontend/app/helpers/search_helper.rb', line 3

def build_search_params(opts = {})
  search_params = {}

  search_params["filter_term"] = Array(opts["filter_term"] || params["filter_term"]).clone
  search_params["filter_term"].concat(Array(opts["add_filter_term"])) if opts["add_filter_term"]
  search_params["filter_term"] = search_params["filter_term"].reject{|f| Array(opts["remove_filter_term"]).include?(f)} if opts["remove_filter_term"]
  
  search_params["simple_filters"] = Array(opts["simple_filters"] || params["simple_filters"]).clone

  if params["multiplicity"]
    search_params["multiplicity"] = params["multiplicity"] 
  end

  sort = (opts["sort"] || params["sort"])

  if show_identifier_column? 
    search_params["display_identifier"] = true
  end

  # if the browse list was sorted by default
  if sort.nil? && !@search_data.nil? && @search_data.sorted?
    sort = @search_data[:criteria]["sort"]
  end

  if sort
    sort = sort.split(', ')
    sort[1] = opts["sort2"] if opts["sort2"]
    search_params["sort"] = sort.uniq.join(', ')
  end

  if (opts["format"] || params["format"]).blank?
    search_params.delete("format")
  else
    search_params["format"] =  opts["format"] || params["format"]
  end

  search_params["linker"] = opts["linker"] || params["linker"] || false
  search_params["type"] = opts["type"] || params["type"]
  search_params["facets"] = opts["facets"] || params["facets"]
  search_params["exclude"] = opts["exclude"] || params["exclude"]
  search_params["listing_only"] = true if params["listing_only"]
  search_params["include_components"] = opts.has_key?("include_components") ? opts["include_components"] : params["include_components"]

  search_params["q"] = opts["q"] || params["q"]

  # retain advanced search params
  if params["advanced"]
    search_params["advanced"] = params["advanced"]
    params.keys.each do |param_key|
      ["op", "f", "v", "dop", "t"].each do |adv_search_prefix|
        if param_key =~ /^#{adv_search_prefix}\d+/
          search_params[param_key] = params[param_key]
        end
      end
    end
  end

  search_params.reject{|k,v| k.blank? or v.blank?}
end

- (Boolean) can_edit_search_result?(record)

Returns:

  • (Boolean)


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

def can_edit_search_result?(record)
  return user_can?('update_container_record', record['id']) if record['primary_type'] === "top_container"
  return user_can?('manage_repository', record['id']) if record['primary_type'] === "repository"
  return user_can?('update_location_record') if record['primary_type'] === "location"
  return user_can?('update_subject_record') if record['primary_type'] === "subject"
  return user_can?('update_classification_record') if ["classification", "classification_term"].include?(record['primary_type'])
  return user_can?('update_agent_record') if Array(record['types']).include?("agent")

  return user_can?('update_accession_record') if record['primary_type'] === "accession"
  return user_can?('update_resource_record') if ["resource", "archival_object"].include?(record['primary_type'])
  return user_can?('update_digital_object_record') if ["digital_object", "digital_object_component"].include?(record['primary_type'])
end

- (Object) extra_columns



156
157
158
# File 'frontend/app/helpers/search_helper.rb', line 156

def extra_columns
  @extra_columns
end

- (Boolean) extra_columns?

Returns:

  • (Boolean)


161
162
163
164
165
# File 'frontend/app/helpers/search_helper.rb', line 161

def extra_columns?
  return false if @extra_columns == nil

  !@extra_columns.empty?
end

- (Object) identifier_column_header_label



102
103
104
# File 'frontend/app/helpers/search_helper.rb', line 102

def identifier_column_header_label
  I18n.t("search_results.result_identifier")
end

- (Object) no_title!

in case the title needs to be handled among other columns



75
76
77
# File 'frontend/app/helpers/search_helper.rb', line 75

def no_title!
  @no_title = true
end

- (Boolean) show_identifier_column?

Returns:

  • (Boolean)


79
80
81
# File 'frontend/app/helpers/search_helper.rb', line 79

def show_identifier_column?
  @display_identifier
end

- (Boolean) show_record_type?

Returns:

  • (Boolean)


69
70
71
# File 'frontend/app/helpers/search_helper.rb', line 69

def show_record_type?
  !@search_data.single_type? || (@search_data[:criteria].has_key?("type[]") && @search_data[:criteria]["type[]"].include?("agent"))
end

- (Boolean) show_title_column?

Returns:

  • (Boolean)


83
84
85
# File 'frontend/app/helpers/search_helper.rb', line 83

def show_title_column?
  @search_data.has_titles? && !@no_title
end

- (Object) title_column_header(title_header)



88
89
90
# File 'frontend/app/helpers/search_helper.rb', line 88

def title_column_header(title_header)
  @title_column_header = title_header
end

- (Object) title_column_header_label



93
94
95
# File 'frontend/app/helpers/search_helper.rb', line 93

def title_column_header_label
  @title_column_header or I18n.t("search_results.result_title")
end

- (Object) title_sort_label



98
99
100
# File 'frontend/app/helpers/search_helper.rb', line 98

def title_sort_label
  @title_column_header or I18n.t("search_sorting.title_sort")
end