Skip to content

Commit

Permalink
Generate models into CurationConcerns namespace
Browse files Browse the repository at this point in the history
Backwards incompatible. Need to migrate hasModel assertions.
Fixes #463
  • Loading branch information
jcoyne committed Nov 17, 2015
1 parent d6c6dfb commit fedb125
Show file tree
Hide file tree
Showing 52 changed files with 127 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def show_presenter
# Gives the class of the form. Override this if you want
# to use a different form.
def form_class
CurationConcerns.const_get("#{self.class.curation_concern_type}Form")
CurationConcerns.const_get("#{self.class.curation_concern_type.to_s.demodulize}Form")
end

def edit
Expand Down Expand Up @@ -120,8 +120,8 @@ def _prefixes

def after_create_response
respond_to do |wants|
wants.html { redirect_to [main_app, :curation_concerns, curation_concern] }
wants.json { render :show, status: :created, location: polymorphic_path([main_app, :curation_concerns, curation_concern]) }
wants.html { redirect_to [main_app, curation_concern] }
wants.json { render :show, status: :created, location: polymorphic_path([main_app, curation_concern]) }
end
end

Expand All @@ -131,8 +131,8 @@ def after_update_response
redirect_to main_app.confirm_curation_concerns_permission_path(curation_concern)
else
respond_to do |wants|
wants.html { redirect_to [main_app, :curation_concerns, curation_concern] }
wants.json { render :show, status: :ok, location: polymorphic_path([main_app, :curation_concerns, curation_concern]) }
wants.html { redirect_to [main_app, curation_concern] }
wants.json { render :show, status: :ok, location: polymorphic_path([main_app, curation_concern]) }
end
end
end
Expand All @@ -150,6 +150,6 @@ def attributes_for_actor
end

def hash_key_for_curation_concern
self.class.curation_concern_type.name.underscore.to_sym
self.class.curation_concern_type.model_name.param_key
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def show_presenter

def destroy
actor.destroy
redirect_to [main_app, :curation_concerns, @file_set.in_works.first], notice: 'The file has been deleted.'
redirect_to [main_app, @file_set.in_works.first], notice: 'The file has been deleted.'
end

# routed to /files/:id (PUT)
Expand Down Expand Up @@ -183,7 +183,7 @@ def process_file(file)
if request.xhr?
render 'jq_upload', formats: 'json', content_type: 'text/html'
else
redirect_to [main_app, :curation_concerns, @file_set.in_works.first]
redirect_to [main_app, @file_set.in_works.first]
end
end
format.json do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def confirm
def copy
VisibilityCopyJob.perform_later(curation_concern.id)
flash_message = 'Updating file permissions. This may take a few minutes. You may want to refresh your browser or return to this record later to see the updated file permissions.'
redirect_to polymorphic_path([main_app, :curation_concerns, curation_concern]), notice: flash_message
redirect_to [main_app, curation_concern], notice: flash_message
end

def curation_concern
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/curation_concerns/file_set_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ def parent_path(parent)
if parent.is_a?(Collection)
main_app.collection_path(parent)
else
polymorphic_path([main_app, :curation_concerns, parent])
polymorphic_path([main_app, parent])
end
end

Expand Down
7 changes: 5 additions & 2 deletions app/helpers/curation_concerns/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ module UrlHelper
def url_for_document(doc, _options = {})
if doc.collection?
doc
else
elsif doc.file_set?
# TODO: Namespace FileSet?
polymorphic_path([main_app, :curation_concerns, doc])
else
polymorphic_path([main_app, doc])
end
end

Expand All @@ -21,7 +24,7 @@ def track_file_set_path(*args)
# generated new GenericWork models get registered as curation concerns and need a
# track_model_path to render Blacklight-related views
CurationConcerns.config.registered_curation_concern_types.each do |concern|
define_method("track_#{concern.underscore}_path") { |*args| main_app.track_solr_document_path(*args) }
define_method("track_#{concern.constantize.model_name.singular_route_key}_path") { |*args| main_app.track_solr_document_path(*args) }
end
end
end
2 changes: 1 addition & 1 deletion app/presenters/curation_concerns/file_set_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(solr_document, current_ability)
end

# CurationConcern methods
delegate :stringify_keys, :human_readable_type, :collection?, :image?, :video?,
delegate :stringify_keys, :human_readable_type, :collection?, :file_set?, :image?, :video?,
:audio?, :pdf?, :office_document?, :representative_id, :to_s, to: :solr_document

# Methods used by blacklight helpers
Expand Down
4 changes: 2 additions & 2 deletions app/views/catalog/_action_menu_partials/_default.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<ul class="dropdown-menu">
<% if can? :edit, document %>
<li>
<%= link_to [:edit, :curation_concerns, document], class: 'itemicon itemedit' do %><i class="glyphicon glyphicon-pencil"></i> Edit <%= document.human_readable_type %>
<%= link_to [:edit, document], class: 'itemicon itemedit' do %><i class="glyphicon glyphicon-pencil"></i> Edit <%= document.human_readable_type %>
<% end %>
</li>
<li>
<% if @collection || (@presenter and @presenter.collection?) # We're on the view page for @collection. -%>
<%= link_to_remove_from_collection(document) %>
<% else %>
<%= link_to [:curation_concerns, document], class: 'itemicon itemtrash',
<%= link_to document, class: 'itemicon itemtrash',
title: "Delete #{document.human_readable_type}", method: :delete,
data: {
confirm: "Deleting a #{document.human_readable_type} from #{t('curation_concerns.product_name')} is permanent. Click OK to delete this #{document.human_readable_type} from #{t('curation_concerns.product_name')}, or Cancel to cancel this operation" } do %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/curation_concerns/base/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for [main_app, :curation_concerns, curation_concern],
<%= simple_form_for [main_app, curation_concern],
wrapper_mappings: { multifile: :horizontal_file_input } do |f| %>
<% if f.error_notification -%>
<div class="alert alert-danger fade in">
Expand All @@ -16,7 +16,7 @@
<%- if curation_concern.new_record? -%>
<%= link_to 'Cancel', main_app.root_path, class: 'btn btn-link' %>
<%- else -%>
<%= link_to 'Cancel', polymorphic_path([main_app, :curation_concerns, curation_concern]), class: 'btn btn-link' %>
<%= link_to 'Cancel', polymorphic_path([main_app, curation_concern]), class: 'btn btn-link' %>
<%- end -%>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/curation_concerns/base/_show_actions.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<% if collector || editor %>
<div class="form-actions">
<% if editor %>
<%= link_to "Edit This #{@presenter.human_readable_type}", edit_polymorphic_path([main_app, :curation_concerns, @presenter]), class: 'btn btn-default' %>
<%= link_to "Edit This #{@presenter.human_readable_type}", edit_polymorphic_path([main_app, @presenter]), class: 'btn btn-default' %>
<%= link_to "Attach a File", main_app.new_curation_concerns_file_set_path(@presenter), class: 'btn btn-default' %>
<%= link_to "Delete This #{@presenter.human_readable_type}", [main_app, :curation_concerns, @presenter], class: 'btn btn-danger pull-right', data: { confirm: "Delete this #{@presenter.human_readable_type}?" }, method: :delete %>
<%= link_to "Delete This #{@presenter.human_readable_type}", [main_app, @presenter], class: 'btn btn-danger pull-right', data: { confirm: "Delete this #{@presenter.human_readable_type}?" }, method: :delete %>
<% end %>
</div>
<% end %>
6 changes: 3 additions & 3 deletions app/views/curation_concerns/file_sets/upload/_alerts.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
<div class="alert alert-info hide" id="success">
You have successfully uploaded some of your files. Either continue to upload or edit use the links below to abandon the rest of your added files.
<p>
<%= link_to 'Add Descriptions', edit_polymorphic_path([main_app, :curation_concerns, @presenter]), class: 'btn' %>
<%= link_to 'Add Descriptions', edit_polymorphic_path([main_app, @presenter]), class: 'btn' %>
</p>
</div>

<div class="alert hide" id="fail">
There was a problem during upload. Please click the &quot;Start Upload&quot; button or <%= link_to 'start over', edit_polymorphic_path([main_app, :curation_concerns, @presenter]) %>
There was a problem during upload. Please click the &quot;Start Upload&quot; button or <%= link_to 'start over', edit_polymorphic_path([main_app, @presenter]) %>
</div>

<div class="alert hide" id="partial_fail">
One or more files did not upload successfully. To continue using the files uploaded use one of the links below.<br />
<%= link_to 'Add Descriptions', edit_polymorphic_path([main_app, :curation_concerns, @presenter]), class: 'btn' %>
<%= link_to 'Add Descriptions', edit_polymorphic_path([main_app, @presenter]), class: 'btn' %>
</div>

<div class="alert hide" id="errmsg"> </div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="alert alert-info hide" id="redirect-loc" type="text/x-jquery-tmpl">
<%-# Script redirects here once the uploads are complete %>
<%= polymorphic_path([main_app, :curation_concerns, @presenter]) %>
<%= polymorphic_path([main_app, @presenter]) %>
</div>

<!-- The template to display files available for upload -->
Expand Down
2 changes: 1 addition & 1 deletion app/views/curation_concerns/permissions/confirm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
</div>
<div class="form-actions panel-footer">
<%= button_to "Yes please.", main_app.copy_curation_concerns_permission_path(curation_concern), class: 'btn btn-primary' %>
<%= link_to "No. I'll update it manually.", polymorphic_path([main_app, :curation_concerns, curation_concern]), class: 'btn' %>
<%= link_to "No. I'll update it manually.", polymorphic_path([main_app, curation_concern]), class: 'btn' %>
</div>
</div>
8 changes: 4 additions & 4 deletions app/views/embargoes/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% end %>

<h2>Current Embargo</h2>
<%= simple_form_for [:curation_concerns, curation_concern] do |f| %>
<%= simple_form_for [main_app, curation_concern] do |f| %>
<fieldset id="set-access-controls">
<section class="help-block">
<p>
Expand All @@ -25,12 +25,12 @@
<div class="col-md-12 form-actions">
<% if curation_concern.embargo_release_date %>
<%= f.submit "Update Embargo", class: 'btn btn-primary' %>
<%= link_to "Deactivate Embargo", embargo_path(curation_concern), :method => :delete, class: 'btn btn-danger' %>
<%= link_to "Deactivate Embargo", embargo_path(curation_concern), method: :delete, class: 'btn btn-danger' %>
<% else %>
<%= f.submit "Apply Embargo", class: 'btn btn-primary' %>
<% end %>
<%= link_to 'Cancel and manage all embargoes', embargoes_path, class: 'btn btn-default' %>
<%= link_to "Return to editing this #{curation_concern.human_readable_type}", edit_polymorphic_path([:curation_concerns, curation_concern]), class: 'btn btn-default' %>
<%= link_to "Return to editing this #{curation_concern.human_readable_type}", [:edit, curation_concern], class: 'btn btn-default' %>
</div>
</div>
<% end %>
Expand All @@ -39,5 +39,5 @@
<% if curation_concern.embargo_history.empty? %>
This <%= curation_concern.human_readable_type %> has never had embargoes applied to it.
<% else %>
<%= render partial:"embargo_history" %>
<%= render partial: "embargo_history" %>
<% end %>
6 changes: 3 additions & 3 deletions app/views/leases/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% end %>

<h2>Current Lease</h2>
<%= simple_form_for [:curation_concerns, curation_concern] do |f| %>
<%= simple_form_for curation_concern do |f| %>
<fieldset id="set-access-controls">
<section class="help-block">
<p>
Expand All @@ -25,12 +25,12 @@
<div class="col-md-12 form-actions">
<% if curation_concern.lease_expiration_date %>
<%= f.submit "Update Lease", class: 'btn btn-primary' %>
<%= link_to "Deactivate Lease", lease_path(curation_concern), :method => :delete, class: 'btn btn-danger' %>
<%= link_to "Deactivate Lease", lease_path(curation_concern), method: :delete, class: 'btn btn-danger' %>
<% else %>
<%= f.submit "Apply Lease", class: 'btn btn-primary' %>
<% end %>
<%= link_to 'Cancel and manage all leases', leases_path, class: 'btn btn-default' %>
<%= link_to "Return to editing this #{curation_concern.human_readable_type}", edit_polymorphic_path([:curation_concerns, curation_concern]), class: 'btn btn-default' %>
<%= link_to "Return to editing this #{curation_concern.human_readable_type}", [:edit, curation_concern], class: 'btn btn-default' %>
</div>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/_add_works.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<% CurationConcerns::QuickClassificationQuery.each_for_context(current_user) do |concern| %>
<li><%= link_to(
"New #{concern.human_readable_type}",
main_app.new_polymorphic_path([:curation_concerns, concern]),
new_polymorphic_path([main_app, concern]),
class: "item-option contextual-quick-classify #{dom_class(concern, 'new').gsub('_', '-')}",
role: 'menuitem'
) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def collection?
hydra_model == 'Collection'
end

def file_set?
hydra_model == 'FileSet'
end

# Method to return the ActiveFedora model
def hydra_model
self[Solrizer.solr_name('active_fedora_model', Solrizer::Descriptor.new(:string, :stored, :indexed))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ def to_s
end
end

# Returns a string identifying the path associated with the object. ActionPack uses this to find a suitable partial to represent the object.
def to_partial_path
"curation_concerns/#{super}"
end

def can_be_member_of_collection?(_collection)
true
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def curation_concerns
private

def normalize_concern_name(c)
c.to_s.camelize
"CurationConcerns::#{c.to_s.camelize}"
end
end

Expand Down
5 changes: 5 additions & 0 deletions lib/curation_concerns/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
require 'qa'

module CurationConcerns
# Ensures that routes to curation_concerns are prefixed with `curation_concerns_`
def self.use_relative_model_naming?
false
end

class Engine < ::Rails::Engine
isolate_namespace CurationConcerns
require 'breadcrumbs_on_rails'
Expand Down
13 changes: 8 additions & 5 deletions lib/curation_concerns/rails/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ def curation_concerns_basic_routes
get 'upload_sets/:id/edit' => 'upload_sets#edit', as: :edit_upload_set
post 'upload_sets/:id' => 'upload_sets#update', as: :upload_set_file_sets

CurationConcerns.config.registered_curation_concern_types.map(&:tableize).each do |curation_concern_name|
namespaced_resources curation_concern_name, except: [:index]
end
namespace :curation_concerns, path: :concern do
CurationConcerns.config.registered_curation_concern_types.map(&:tableize).each do |curation_concern_name|
namespaced_resources curation_concern_name, except: [:index]
end
resources :permissions, only: [] do
member do
get :confirm
Expand Down Expand Up @@ -60,16 +60,19 @@ def curation_concerns_embargo_management

private

# routing namepace arguments, for using a path other than the default
ROUTE_OPTIONS = { 'curation_concerns' => { path: :concern } }

# Namespaces routes appropriately
# @example route_namespaced_target("curation_concerns/generic_work") is equivalent to
# namespace "curation_concerns" do
# namespace "curation_concerns", path: :concern do
# resources "generic_work", except: [:index]
# end
def namespaced_resources(target, opts = {})
if target.include?('/')
the_namespace = target[0..target.index('/') - 1]
new_target = target[target.index('/') + 1..-1]
namespace the_namespace do
namespace the_namespace, ROUTE_OPTIONS.fetch(the_namespace, nil) do
namespaced_resources(new_target, opts)
end
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Generated via
# `rails generate curation_concerns:work <%= class_name %>`

class CurationConcerns::<%= class_name.pluralize %>Controller < ApplicationController
include CurationConcerns::CurationConcernController
set_curation_concern_type <%= class_name %>
module CurationConcerns
class <%= class_name.pluralize %>Controller < ApplicationController
include CurationConcernController
set_curation_concern_type <%= class_name %>
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# `rails generate curation_concerns:work <%= class_name %>`
module CurationConcerns
class <%= class_name %>Form < CurationConcerns::Forms::WorkForm
self.model_class = ::<%= class_name %>
self.model_class = <%= class_name %>
end
end

10 changes: 6 additions & 4 deletions lib/generators/curation_concerns/work/templates/model.rb.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Generated via
# `rails generate curation_concerns:work <%= class_name %>`
class <%= class_name %> < ActiveFedora::Base
include ::CurationConcerns::WorkBehavior
include ::CurationConcerns::BasicMetadata
validates :title, presence: { message: 'Your work must have a title.' }
module CurationConcerns
class <%= class_name %> < ActiveFedora::Base
include WorkBehavior
include BasicMetadata
validates :title, presence: { message: 'Your work must have a title.' }
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# `rails generate curation_concerns:work <%= class_name %>`
require 'rails_helper'

describe <%= class_name %> do
describe CurationConcerns::<%= class_name %> do
it "has tests" do
skip "Add your tests here"
end
Expand Down
4 changes: 2 additions & 2 deletions lib/generators/curation_concerns/work/work_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class CurationConcerns::WorkGenerator < Rails::Generators::NamedBase
# Because I want the output of CurationConcerns::WorkGenerator to include all the processed files.
def create_model_spec
return unless rspec_installed?
template 'model_spec.rb.erb', "spec/models/#{file_name}_spec.rb"
template 'model_spec.rb.erb', "spec/models/curation_concerns/#{file_name}_spec.rb"
end

def create_model
template('model.rb.erb', "app/models/#{file_name}.rb")
template('model.rb.erb', "app/models/curation_concerns/#{file_name}.rb")
end

def create_controller_spec
Expand Down
Loading

0 comments on commit fedb125

Please sign in to comment.