Class: AssetsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- AssetsController
- Includes:
- Blacklight::CatalogHelper, Blacklight::SolrHelper, Hydra::AssetsControllerHelper, Hydra::RepositoryController, MediaShelf::ActiveFedoraHelper, WhiteListHelper
- Defined in:
- vendor/plugins/hydra_repository/app/controllers/assets_controller.rb
Constant Summary
Constants included from Blacklight::SolrHelper
Instance Method Summary (collapse)
- - (Object) destroy
- - (Object) new
- - (Object) show
-
- (Object) update
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.
Methods included from Blacklight::CatalogHelper
#history_session, #search_session, #setup_document_by_counter, #setup_next_and_previous_documents, #setup_next_document, #setup_previous_document
Methods included from Hydra::AssetsControllerHelper
#apply_depositor_metadata, #prep_updater_method_args, #set_collection_type
Methods included from Hydra::RepositoryController
#downloadables, included, #solr_name
Methods included from MediaShelf::ActiveFedoraHelper
#load_af_instance_from_solr, #retrieve_af_model
Methods included from Blacklight::SolrHelper
#facet_limit_for, #facet_limit_hash, #get_facet_pagination, #get_opensearch_response, #get_search_results, #get_single_doc_via_search, #get_solr_response_for_doc_id, #get_solr_response_for_field_values, included, #max_per_page, #solr_doc_params, #solr_facet_params, #solr_opensearch_params, #solr_param_quote, #solr_search_params
Methods inherited from ApplicationController
#current_user, #default_html_head, #error, #extra_head_content, #javascript_includes, #stylesheet_links, #user_class
Methods included from HydraAccessControlsHelper
#editor?, #reader?, #test_permission
Instance Method Details
- (Object) destroy
104 105 106 107 108 109 |
# File 'vendor/plugins/hydra_repository/app/controllers/assets_controller.rb', line 104 def destroy ActiveFedora::Base.load_instance(params[:id]).delete flash[:notice]= "Deleted " + params[:id] redirect_to url_for(:action => 'index', :controller => "catalog", :q => nil , :f => nil) end |
- (Object) new
93 94 95 96 97 98 99 100 101 102 |
# File 'vendor/plugins/hydra_repository/app/controllers/assets_controller.rb', line 93 def new af_model = retrieve_af_model(params[:content_type]) if af_model @asset = af_model.new (@asset) set_collection_type(@asset, params[:content_type]) @asset.save end redirect_to url_for(:action=>"edit", :controller=>"catalog", :id=>@asset.pid) end |
- (Object) show
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'vendor/plugins/hydra_repository/app/controllers/assets_controller.rb', line 17 def show if params.has_key?("field") @response, @document = get_solr_response_for_doc_id # @document = SolrDocument.new(@response.docs.first) result = @document["#{params["field"]}_t"] # document_fedora = SaltDocument.load_instance(params[:id]) # result = document_fedora.datastreams_in_memory[params["datastream"]].send("#{params[:field]}_values") 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=> white_list( RedCloth.new(result, [:sanitize_html]).to_html ) } end else redirect_to :controller=>"catalog", :action=>"show" end end |
- (Object) update
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 put :update, :id=>“PID“, “document”=>Topic”} Appends a new “subject” value of “My Topic” to any appropriate datasreams in the PID document. put :update, :id=>“PID“, “document”=>Document”, “2”=>“Image”} Sets the 1st and 2nd “medium” values on any appropriate datasreams in the PID document, overwriting any existing values.
50 51 52 53 54 55 56 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 82 83 84 85 86 87 88 89 90 91 |
# File 'vendor/plugins/hydra_repository/app/controllers/assets_controller.rb', line 50 def update af_model = retrieve_af_model(params[:content_type]) unless af_model af_model = HydrangeaArticle end @document = af_model.find(params[:id]) updater_method_args = prep_updater_method_args(params) logger.debug("attributes submitted: #{updater_method_args.inspect}") # this will only work if there is only one datastream being updated. # once ActiveFedora::MetadataDatastream supports .update_datastream_attributes, use that method instead (will also be able to pass through params["asset"] as-is without usin prep_updater_method_args!) result = @document.update_indexed_attributes(updater_method_args[:params], updater_method_args[:opts]) @document.save #response = attrs.keys.map{|x| escape_keys({x=>attrs[x].values})} response = Hash["updated"=>[]] last_result_value = "" result.each_pair do |field_name,changed_values| changed_values.each_pair do |index,value| response["updated"] << {"field_name"=>field_name,"index"=>index,"value"=>value} last_result_value = value end end logger.debug("returning #{response.inspect}") # If handling submission from jeditable (which will only submit one value at a time), return the value it submitted if params.has_key?(:field_id) response = last_result_value end respond_to do |want| want.js { render :json=> response } want.textile { if response.kind_of?(Hash) response = response.values.first end render :text=> white_list( RedCloth.new(response, [:sanitize_html]).to_html ) } end end |