Skip to content

Commit

Permalink
Centralize field type labeling
Browse files Browse the repository at this point in the history
- Moves I18n rules to more generic structure
- Adds new class to centralize I18n pull of field label
- Uses central label algorithm on the search, show view, and ingest form
- Removes subject from search results per requirements
  • Loading branch information
jechols committed Mar 25, 2014
1 parent 97a9bbd commit f1199e3
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/decorators/generic_asset_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def display_field?(field)
end

def field_label(field)
I18n.t("oregondigital.catalog.show.#{field.downcase}", :default => field.humanize)
OregonDigital::Metadata::FieldTypeLabel.for(field)
end

def field_values(field)
Expand Down Expand Up @@ -47,7 +47,7 @@ def property_keys
end

def configured_show_keys
r = I18n.t("oregondigital.catalog.show")
r = I18n.t("oregondigital.metadata")
r = {} unless r.kind_of?(Hash)
r.keys.map{|x| x.to_s.downcase}
end
Expand Down
7 changes: 6 additions & 1 deletion app/helpers/ingest_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,14 @@ def ingest_form_for(form_container)
def type_value_fields(f)
controls = []

options_values = INGEST_MAP[f.object.group.to_sym].keys
options = options_values.collect do |val|
[OregonDigital::Metadata::FieldTypeLabel.for(val.to_s), val]
end

controls << f.input(
:type,
:collection => INGEST_MAP[f.object.group.to_sym].keys,
:collection => options,
:input_html => {:class => "input-medium type-selector"},
:label_html => {:class => "sr-only"},
:wrapper_html => {:class => "ingest-control type"}
Expand Down
6 changes: 4 additions & 2 deletions config/locales/oregondigital.en.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
en:
oregondigital:
metadata:
title: Title
lcsubject: LC Subject

catalog:
show:
title: Title
facet:
subject: Topic
location: Region
Expand Down
7 changes: 4 additions & 3 deletions lib/oregon_digital/catalog/index_fields.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ module IndexFields
configure_blacklight do |config|
# solr fields to be displayed in the index (search results) view
# The ordering of the field names is the order of the display
config.add_index_field solr_name('desc_metadata__subject_label', :displayable), :label => 'Subject:', :helper_method => :controlled_view_label
config.add_index_field solr_name('desc_metadata__description', :displayable), :label => 'Description:'
config.add_index_field solr_name('desc_metadata__modified', :displayable), :label => 'Record Modified:'
for field in [:description, :modified]
label = OregonDigital::Metadata::FieldTypeLabel.for(field)
config.add_index_field solr_name("desc_metadata__#{field}", :displayable), :label => label
end
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions lib/oregon_digital/metadata/field_type_label.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class OregonDigital::Metadata::FieldTypeLabel
# Returns the label for the given internal field name (the value in an
# options dropdown, which is also the "type" on the ingest map)
def self.for(field)
I18n.t(field, :scope => [:oregondigital, :metadata], :default => field.to_s.humanize)
end
end
2 changes: 1 addition & 1 deletion spec/decorators/generic_asset_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
end
before(:each) do
I18n.stub(:t).and_call_original
I18n.stub(:t).with("oregondigital.catalog.show").and_return({:photographer => "photographer", :created => "created"})
I18n.stub(:t).with("oregondigital.metadata").and_return({:photographer => "photographer", :created => "created"})
end
it "should organize those fields at the top in the given order" do
expect(result).to eq ["photographer", "created", "title"]
Expand Down
2 changes: 1 addition & 1 deletion spec/features/show_fields_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
context "and a label is configured" do
let(:stub_setup) do
I18n.stub(:t).and_call_original
I18n.stub(:t).with("oregondigital.catalog.show.title", {:default => "Title"}).and_return("Test Title")
I18n.stub(:t).with("oregondigital.metadata.title", {:default => "Title"}).and_return("Test Title")
end
it "should display it" do
expect(page).to have_content("Test Title")
Expand Down

0 comments on commit f1199e3

Please sign in to comment.