Skip to content

Commit

Permalink
Location (#110)
Browse files Browse the repository at this point in the history
* Display edit form label on documentation page, order by label

* For the template, return the csv headers rather than the attributes
  • Loading branch information
maxkadel committed Aug 31, 2021
1 parent 53f2d75 commit bfafe65
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
5 changes: 3 additions & 2 deletions app/lib/zizia/metadata_details.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def details(work_attributes:)
detail_list = work_attributes.properties.sort.map { |p| definition_hash_for(p, validators) }
detail_list << visibility_definition
detail_list << file_definition
detail_list.sort_by { |prop| prop[:label] }
end

def to_csv(work_attributes:)
Expand Down Expand Up @@ -57,12 +58,12 @@ def validator_to_string(validator:)

def definition_hash_for(field_properties, validators)
Hash[
label: I18n.t("simple_form.labels.defaults.#{field_properties[0]}"),
attribute: field_properties[0],
predicate: field_properties[1].predicate.to_s,
multiple: field_properties[1].try(:multiple?).to_s,
type: type_to_s(field_properties[1].type),
validator: validator_to_string(validator: validators[field_properties[0].to_sym][0]),
label: I18n.t("simple_form.labels.defaults.#{field_properties[0]}"),
csv_header: csv_header(field_properties[0]),
required_on_form: required_on_form_to_s(field_properties[0]),
usage: MetadataUsage.instance.usage[field_properties[0]]
Expand All @@ -76,7 +77,7 @@ def file_definition
multiple: 'true',
type: 'String',
validator: 'Required, must name a file on the server',
label: 'Items (listed at bottom of page)',
label: 'Files',
csv_header: 'files',
required_on_form: 'true',
usage: MetadataUsage.instance.usage['files']
Expand Down
6 changes: 5 additions & 1 deletion app/views/zizia/metadata_details/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
<% @details.each do |detail| %>
<div class="metadata-field <%= system_field(detail) %>" <%= hide_system_field(detail) %>>
<h2 class="field-label">
<%= detail[:attribute] %>
<%= detail[:label] %>
</h2>
<div>
<b>Attribute:</b>
<%= detail[:attribute] %>
</div>
<div>
<b>Predicate:</b>
<a href="<%= detail[:predicate] %>"><%= detail[:predicate] %></a>
Expand Down
2 changes: 1 addition & 1 deletion lib/zizia/csv_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Zizia
class CsvTemplate
def to_s
Zizia.config.metadata_mapper_class.new.fields.join(',')
Zizia.config.metadata_mapper_class.new.headers.join(',')
end
end
end
10 changes: 9 additions & 1 deletion lib/zizia/hyrax/hyrax_basic_metadata_mapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def fields
core_fields + basic_fields + [:visibility, :files] + zizia_fields
end

def headers
fields.map do |field|
Zizia::HyraxBasicMetadataMapper.csv_header(field)
end
end

# Properties defined with `multiple: false` in
# Hyrax should return a single value instead of
# an Array of values.
Expand Down Expand Up @@ -112,7 +118,9 @@ def map_field(name)
end

def self.csv_header(field)
CSV_HEADERS[field.to_sym]
header = CSV_HEADERS[field.to_sym]
return header if header
field
end

protected
Expand Down
5 changes: 4 additions & 1 deletion spec/zizia/csv_template_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

before do
Zizia.config.metadata_mapper_class = Zizia::HyraxBasicMetadataMapper
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(Zizia::HyraxBasicMetadataMapper).to receive(:fields).and_return([:based_near, :resource_type, :description])
# rubocop:enable RSpec/AnyInstance
end

it 'returns a CSV string based on the headers in the Hyrax mapper' do
expect(csv_template.to_s).to eq(Zizia::HyraxBasicMetadataMapper.new.fields.join(','))
expect(csv_template.to_s).to eq("location,resource type,abstract or summary")
end
end

0 comments on commit bfafe65

Please sign in to comment.