Skip to content

Commit

Permalink
Revert "Inline the render_ds_profile_header"
Browse files Browse the repository at this point in the history
  • Loading branch information
mjgiarlo authored Jul 1, 2020
1 parent 79a2d92 commit 8db94ec
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 180 deletions.
2 changes: 1 addition & 1 deletion app/components/datastream_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def control_group
end

def link_to_identifier
link_to dsid, item_datastream_path(pid, dsid), title: dsid, data: { blacklight_modal: 'trigger' }
link_to dsid, ds_solr_document_path(pid, dsid), title: dsid, data: { blacklight_modal: 'trigger' }
end

def size
Expand Down
19 changes: 19 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class CatalogController < ApplicationController
helper ArgoHelper
include DateFacetConfigurations

before_action :show_aspect, only: %i[dc ds]
before_action :limit_facets_on_home_page, only: [:index]

configure_blacklight do |config|
Expand Down Expand Up @@ -214,8 +215,26 @@ def show
end
end

def dc
respond_to do |format|
format.html { render layout: !request.xhr? }
end
end

def ds
respond_to do |format|
format.html { render layout: !request.xhr? }
end
end

private

def show_aspect
pid = params[:id].include?('druid') ? params[:id] : "druid:#{params[:id]}"
@obj ||= Dor.find(pid)
@response, @document = search_service.fetch pid
end

def limit_facets_on_home_page
return if has_search_parameters? || params[:all]

Expand Down
67 changes: 0 additions & 67 deletions app/controllers/datastreams_controller.rb

This file was deleted.

23 changes: 23 additions & 0 deletions app/controllers/items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ItemsController < ApplicationController
before_action :create_obj, except: :purl_preview
before_action :authorize_manage!, only: %i[
add_collection set_collection remove_collection
datastream_update
mods
purge_object
source_id
Expand Down Expand Up @@ -115,6 +116,28 @@ def embargo_update
end
end

##
# @option params [String] `:content` the XML with which to replace the datastream
# @option params [String] `:dsid` the identifier for the datastream, e.g., `identityMetadata`
# @option params [String] `:id` the druid to modify
def datastream_update
raise ArgumentError, 'Missing content' unless params[:content].present?
raise ArgumentError, 'Missing datastream identifier' unless params[:dsid].present?

begin
# check that the content is well-formed xml
Nokogiri::XML(params[:content], &:strict)
rescue Nokogiri::XML::SyntaxError
raise ArgumentError, 'XML is not well formed!'
end
@object.datastreams[params[:dsid]].content = params[:content] # set the XML to be verbatim as posted
save_and_reindex

respond_to do |format|
format.any { redirect_to solr_document_path(params[:id]), notice: 'Datastream was successfully updated' }
end
end

# Given two instances of VersionTag, find the most significant difference
# between the two (return nil if either one is nil or if they're the same)
# @param [String] cur_version_tag current version tag
Expand Down
8 changes: 8 additions & 0 deletions app/helpers/dor_object_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ def render_workflows(doc)
end
render 'catalog/show_workflows', document_id: doc.id, workflows: workflows
end

# rubocop:disable Layout/LineLength
def render_ds_profile_header(ds)
dscd = ds.createDate
dscd = dscd.xmlschema if dscd.is_a?(Time)
%(<foxml:datastream ID="#{ds.dsid}" STATE="#{ds.state}" CONTROL_GROUP="#{ds.controlGroup}" VERSIONABLE="#{ds.versionable}">\n <foxml:datastreamVersion ID="#{ds.dsVersionID}" LABEL="#{ds.label}" CREATED="#{dscd}" MIMETYPE="#{ds.mimeType}">)
end
# rubocop:enable Layout/LineLength
end
2 changes: 1 addition & 1 deletion app/views/catalog/_full_view_links_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class='btn-group full-view-links' role='group'>
<%= link_to 'View full Dublin Core', dc_item_datastream_path(document.id), title: 'Dublin Core (derived from MODS)', class: 'btn btn-secondary btn-sm', data: { blacklight_modal: 'trigger' } %>
<%= link_to 'View full Dublin Core', dc_solr_document_path(document.id), title: 'Dublin Core (derived from MODS)', class: 'btn btn-secondary btn-sm', data: { blacklight_modal: 'trigger' } %>
<%= link_to 'View MODS', purl_preview_item_url(document.id), title: 'MODS View', class: 'btn btn-secondary btn-sm', data: { blacklight_modal: 'trigger' } %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<% dc_xml = Nokogiri::XML(Dor::Services::Client.object(@obj.pid).metadata.dublin_core) %>
<div class="lightbox-head">
<span class="section-head-link">
<%= link_to 'View XML', item_datastream_path(@obj.pid, 'full_dc'), title: 'Dublin Core (derived from MODS)', data: { blacklight_modal: 'trigger' } %>
<%= link_to 'View XML', ds_solr_document_path(@obj.pid, 'full_dc'), title: 'Dublin Core (derived from MODS)', data: { blacklight_modal: 'trigger' } %>
</span>
<%= @obj.pid %>
</div>
Expand Down
45 changes: 45 additions & 0 deletions app/views/catalog/ds.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<%= render BlacklightModalComponent.new do |component| %>
<% component.with(:header, params[:dsid]) %>
<% component.with(:body) do %>
<%
if(params[:edit])
if can?(:manage_item, @obj)
%>
<%= form_tag url_for(controller: :items, action: :datastream_update), id: 'xmlEditForm', method: :POST do %>
<input type="hidden" name="id" value="<%= @obj.pid %>">
<input name="dsid" id="datastream" type="hidden" value="<%= params[:dsid] %>">
<div class="form-group">
<textarea name="content" id="content" class='form-control'><%= @obj.datastreams[params[:dsid]].content.to_s %></textarea>
</div>
<div class="form-group">
<button type="submit" id="update" class="btn btn-primary">Update Datastream</button>
</div>
<% end %>
<%
end
else
# If the user is a repo admin or is permitted to manage both content and
# rights, display raw xml editing
%>
<% if can?(:manage_item, @obj) && Settings.editable_datastreams.include?(params[:dsid]) %>
<%= link_to "Edit #{params[:dsid]}", ds_solr_document_path(params[:id], params[:dsid], edit: 'true'), title: params[:dsid], data: { blacklight_modal: 'preserve' } %>
<% end %>
<% content = if params[:dsid] == 'full_dc'
Nokogiri::XML(Dor::Services::Client.object(@obj.pid).metadata.dublin_core).prettify
elsif @obj.datastreams[params[:dsid]].respond_to? :ng_xml
Nokogiri::XML(@obj.datastreams[params[:dsid]].ng_xml.to_s, &:noblanks).to_s
else
Nokogiri::XML(@obj.datastreams[params[:dsid]].content, &:noblanks).to_s
end
raise ActionController::RoutingError, 'Not Found' if content.nil?

output = CodeRay::Duo[:xml, :div].highlight content %>
<% unless params[:dsid] == 'full_dc' %>
<div class="CodeRay">
<pre><%= render_ds_profile_header @obj.datastreams[params[:dsid]] %></pre>
</div>
<% end %>
<%= output.html_safe %>
<% end %>
<% end %>
<% end %>
17 changes: 0 additions & 17 deletions app/views/datastreams/edit.html.erb

This file was deleted.

20 changes: 0 additions & 20 deletions app/views/datastreams/show.html.erb

This file was deleted.

12 changes: 6 additions & 6 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

resources :solr_documents, only: [:show], controller: 'catalog', path: '/view' do
concerns :exportable

member do
get 'dc', to: 'catalog#dc'
get 'ds/:dsid', to: 'catalog#ds', as: 'ds'
end
end

match 'catalog', via: %i[get post], to: redirect { |params, req| req.fullpath.sub(%r{^/catalog}, '/view') }, as: 'search_catalog_redirect'
Expand Down Expand Up @@ -125,19 +130,14 @@

resource :manage_release, only: :show

resources :datastreams, only: %i[show edit update] do
member do
get 'dc'
end
end

member do
get 'purl_preview'
post 'refresh_metadata'
get 'schema_validate', action: :schema_validation, as: 'schema_validation'
get 'mods'
post 'embargo', action: :embargo_update, as: 'embargo_update'
get 'embargo_form'
post 'datastream', action: :datastream_update, as: 'datastream_update'
get 'source_id_ui'
get 'catkey_ui'
match 'tags_bulk', via: %i[get post]
Expand Down
58 changes: 0 additions & 58 deletions spec/controllers/datastreams_controller_spec.rb

This file was deleted.

Loading

0 comments on commit 8db94ec

Please sign in to comment.