Module: Hydra::Controller::AssetsControllerBehavior

Extended by:
ActiveSupport::Concern, Deprecation
Includes:
Blacklight::Catalog, Blacklight::SolrHelper, AssetsControllerHelper, RepositoryControllerBehavior
Defined in:
lib/hydra/controller/assets_controller_behavior.rb

Instance Method Summary collapse

Methods included from AssetsControllerHelper

#apply_depositor_metadata, #sanitize_update_params, #set_collection_type, #tidy_response_from_update, #update_document

Instance Method Details

#destroyObject Also known as: withdraw



98
99
100
101
102
103
104
105
106
# File 'lib/hydra/controller/assets_controller_behavior.rb', line 98

def destroy
  af = ActiveFedora::Base.find(params[:id], :cast=>true)
  assets = af.destroy_child_assets
  af.delete
  msg = "Deleted #{params[:id]}"
  msg.concat(" and associated file_asset(s): #{assets.join(", ")}") unless assets.empty?
  flash[:notice]= msg
  redirect_to catalog_index_path()
end

#newObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/hydra/controller/assets_controller_behavior.rb', line 83

def new
  af_model = retrieve_af_model(params[:content_type])
  raise "Can't find a model for #{params[:content_type]}" unless af_model
  @asset = af_model.new
  (@asset)
  set_collection_type(@asset, params[:content_type])
  @asset.save
  model_display_name = af_model.to_s.camelize.scan(/[A-Z][^A-Z]*/).join(" ")
  msg = "Created a #{model_display_name} with pid #{@asset.pid}. Now it's ready to be edited."
  flash[:notice]= msg
  session[:scripts] = params[:combined] == "true"

  redirect_to edit_catalog_path(@asset.pid, :new_asset=>true)
end

#showObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/hydra/controller/assets_controller_behavior.rb', line 28

def show
  if params.has_key?("field")
    
    @response, @document = get_solr_response_for_doc_id
    result = @document["#{params["field"]}_t"]
    unless result.nil?
      if params.has_key?("field_index")
        result = result[params["field_index"].to_i-1]
      elsif result.kind_of?(Array)
        result = result.first
      end
    end
    respond_to do |format|
      format.html     { render :text=>result }
      format.textile  { render :text=> RedCloth.new(result, [:sanitize_html]).to_html  }
    end
  else
    redirect_to catalog_path(params[:id])
  end
end

#updateObject

Uses the update_indexed_attributes method provided by ActiveFedora::Base This should behave pretty much like the ActiveRecord update_indexed_attributes method For more information, see the ActiveFedora docs.

Examples:

Appends a new “subject” value of “My Topic” to on the descMetadata datastream in in the PID document.

put :update, :id=>"_PID_", "asset"=>{"descMetadata"=>{"subject"=>{"-1"=>"My Topic"}}

Sets the 1st and 2nd “medium” values on the descMetadata datastream in the PID document, overwriting any existing values.

put :update, :id=>"_PID_", "asset"=>{"descMetadata"=>{"medium"=>{"0"=>"Paper Document", "1"=>"Image"}}


57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hydra/controller/assets_controller_behavior.rb', line 57

def update
  logger.debug("attributes submitted: #{@sanitized_params.inspect}")
       
  @response = update_document(@document, @sanitized_params)
 
  @document.save
  flash[:notice] = "Your changes have been saved."
  
  #logger.debug("returning #{@response.inspect}")
  
  respond_to do |want| 
    want.html {
      redirect_to next_step(params[:id])
    }
    want.js {
      render :json=> tidy_response_from_update(@response)  
    }
    want.textile {
      if @response.kind_of?(Hash)
        textile_response = tidy_response_from_update(@response).values.first
      end
      render :text=> RedCloth.new(textile_response, [:sanitize_html]).to_html
    }
  end
end