Skip to content

Commit

Permalink
Use the ResourceTypeService
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed May 18, 2016
1 parent 6ff073e commit 153ad86
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 68 deletions.
2 changes: 1 addition & 1 deletion app/models/concerns/sufia/solr_document_behavior.rb
Expand Up @@ -9,7 +9,7 @@ module SolrDocumentBehavior

# Add a schema.org itemtype
def itemtype
Sufia.config.resource_types_to_schema[resource_type.first] || 'http://schema.org/CreativeWork'
ResourceTypesService.microdata_type(resource_type.first)
end

# Date created indexed as a string. This allows users to enter values like: 'Circa 1840-1844'
Expand Down
11 changes: 2 additions & 9 deletions app/presenters/sufia/file_set_presenter.rb
Expand Up @@ -2,7 +2,8 @@ module Sufia
class FileSetPresenter < ::CurationConcerns::FileSetPresenter
include Sufia::CharacterizationBehavior

delegate :depositor, :keyword, :date_created, :date_modified, to: :solr_document
delegate :depositor, :keyword, :date_created, :date_modified, :itemtype,
to: :solr_document

def editor?
current_ability.can?(:edit, solr_document)
Expand All @@ -22,14 +23,6 @@ def rights
solr_document.rights.first
end

# Add a schema.org itemtype
def itemtype
# Look up the first non-empty resource type value in a hash from the config
Sufia.config.resource_types_to_schema[resource_type.to_a.reject(&:empty?).first] || 'http://schema.org/CreativeWork'
rescue
'http://schema.org/CreativeWork'
end

def stats_path
Sufia::Engine.routes.url_helpers.stats_file_path(self)
end
Expand Down
12 changes: 2 additions & 10 deletions app/presenters/sufia/work_show_presenter.rb
@@ -1,7 +1,8 @@
module Sufia
class WorkShowPresenter < ::CurationConcerns::WorkShowPresenter
# delegate fields from Sufia::Works::Metadata to solr_document
delegate :based_near, :related_url, :depositor, :identifier, :resource_type, :keyword, to: :solr_document
delegate :based_near, :related_url, :depositor, :identifier, :resource_type,
:keyword, :itemtype, to: :solr_document

def editor?
current_ability.can?(:edit, solr_document)
Expand All @@ -24,15 +25,6 @@ def display_unfeature_link?
user_can_feature_works? && solr_document.public? && featured?
end

# Add a schema.org itemtype
def itemtype
# Look up the first non-empty resource type value in a hash from the config
resource_type = solr_document.resource_type.to_a.reject(&:empty?).first
Sufia.config.resource_types_to_schema[resource_type] || 'http://schema.org/CreativeWork'
rescue
'http://schema.org/CreativeWork'
end

def stats_path
Sufia::Engine.routes.url_helpers.stats_work_path(self)
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/records/edit_fields/_resource_type.html.erb
@@ -1,2 +1,2 @@
<%= f.input :resource_type, as: :select_with_help, collection: Sufia.config.resource_types,
<%= f.input :resource_type, as: :select_with_help, collection: ResourceTypesService.select_options,
input_html: { class: 'form-control', multiple: true } %>
2 changes: 1 addition & 1 deletion app/views/sufia/uploads/_js_templates.html.erb
Expand Up @@ -72,7 +72,7 @@
<label for="resource_type_{%=file.id%}" class="col-sm-5 control-label">Resource Type</label>
<div class="col-sm-7">
<select class="form-control resource_type_dropdown" name="resource_type[{%=file.id%}]" id="resource_type_{%=file.id%}" value="{%=file.name%}">
<% Sufia.config.resource_types.each do |type| %>
<% ResourceTypesService.select_options.each do |type| %>
<option value="<%= type[0] %>"><%= type[1] %></option>
<% end %>
</select>
Expand Down
46 changes: 0 additions & 46 deletions lib/generators/sufia/templates/config/sufia.rb
Expand Up @@ -8,52 +8,6 @@

config.max_notifications_for_dashboard = 5

config.resource_types = {
"Article" => "Article",
"Audio" => "Audio",
"Book" => "Book",
"Capstone Project" => "Capstone Project",
"Conference Proceeding" => "Conference Proceeding",
"Dataset" => "Dataset",
"Dissertation" => "Dissertation",
"Image" => "Image",
"Journal" => "Journal",
"Map or Cartographic Material" => "Map or Cartographic Material",
"Masters Thesis" => "Masters Thesis",
"Part of Book" => "Part of Book",
"Poster" => "Poster",
"Presentation" => "Presentation",
"Project" => "Project",
"Report" => "Report",
"Research Paper" => "Research Paper",
"Software or Program Code" => "Software or Program Code",
"Video" => "Video",
"Other" => "Other"
}

config.resource_types_to_schema = {
"Article" => "http://schema.org/Article",
"Audio" => "http://schema.org/AudioObject",
"Book" => "http://schema.org/Book",
"Capstone Project" => "http://schema.org/CreativeWork",
"Conference Proceeding" => "http://schema.org/ScholarlyArticle",
"Dataset" => "http://schema.org/Dataset",
"Dissertation" => "http://schema.org/ScholarlyArticle",
"Image" => "http://schema.org/ImageObject",
"Journal" => "http://schema.org/CreativeWork",
"Map or Cartographic Material" => "http://schema.org/Map",
"Masters Thesis" => "http://schema.org/ScholarlyArticle",
"Part of Book" => "http://schema.org/Book",
"Poster" => "http://schema.org/CreativeWork",
"Presentation" => "http://schema.org/CreativeWork",
"Project" => "http://schema.org/CreativeWork",
"Report" => "http://schema.org/CreativeWork",
"Research Paper" => "http://schema.org/ScholarlyArticle",
"Software or Program Code" => "http://schema.org/Code",
"Video" => "http://schema.org/VideoObject",
"Other" => "http://schema.org/CreativeWork"
}

config.permission_levels = {
"Choose Access" => "none",
"View/Download" => "read",
Expand Down

0 comments on commit 153ad86

Please sign in to comment.