Class: Spotlight::Appearance

Inherits:
Object
  • Object
show all
Extended by:
ActiveModel::Naming, ActiveModel::Translation
Includes:
ActiveModel::Conversion
Defined in:
app/forms/spotlight/appearance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Appearance

Returns a new instance of Appearance.



7
8
9
# File 'app/forms/spotlight/appearance.rb', line 7

def initialize(configuration)
  @configuration = configuration
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



11
12
13
# File 'app/forms/spotlight/appearance.rb', line 11

def configuration
  @configuration
end

Instance Method Details

#allowed_paramsObject



45
46
47
48
49
# File 'app/forms/spotlight/appearance.rb', line 45

def allowed_params
  sort_fields.keys.each_with_object({}) do |field, hsh|
    hsh[field] = [:enabled, :label, :weight]
  end
end

#default_sort_fieldObject



64
65
66
# File 'app/forms/spotlight/appearance.rb', line 64

def default_sort_field
  configuration.blacklight_config.default_sort_field.key
end

#document_index_view_typesObject

This enables us to have a group of checkboxes that is backed by the array stored in Spotlight::BlacklightConfiguration#document_index_view_types



20
21
22
23
24
25
26
27
# File 'app/forms/spotlight/appearance.rb', line 20

def document_index_view_types
  vals = configuration.document_index_view_types
  Blacklight::OpenStructWithHashAccess.new.tap do |s|
    view_type_options.each do |k|
      s[k] = vals.include?(k.to_s)
    end
  end
end

#per_page_optionsObject



60
61
62
# File 'app/forms/spotlight/appearance.rb', line 60

def per_page_options
  default_blacklight_config.per_page
end

#sort_fieldsObject

This enables us to have a group of checkboxes that is backed by the array stored in Spotlight::BlacklightConfiguration#default_sort_fields



32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/forms/spotlight/appearance.rb', line 32

def sort_fields 
  fields = configuration.sort_fields
  Blacklight::OpenStructWithHashAccess.new.tap do |s|
    default_sort_fields.each_with_index do |(k, field), index|
      s[k] = Blacklight::OpenStructWithHashAccess.new.tap do |c|
        c.enabled = fields[k] && fields[k][:enabled]
        c.label = fields[k][:label] if fields[k]
        c.weight = index + 1
      end
    end
  end
end

#update(params) ⇒ Object



51
52
53
54
# File 'app/forms/spotlight/appearance.rb', line 51

def update(params)
  configuration.exhibit.update(exhibit_params(params))
  configuration.update(configuration_params(params))
end

#view_type_optionsObject



56
57
58
# File 'app/forms/spotlight/appearance.rb', line 56

def view_type_options
  default_blacklight_config.view.keys
end