Sha256: 8a07f2f1bfbaef3e9f1f8f1705e6f12b4308b4672da8c6150f15767f62b4be97

Contents?: true

Size: 1.8 KB

Versions: 1

Compression:

Stored size: 1.8 KB

Contents

require 'mime/types'

module FcrepoAdmin::Controller
  module DatastreamsControllerBehavior
    extend ActiveSupport::Concern

    included do
      layout 'fcrepo_admin/datastreams', :except => :index
      layout 'fcrepo_admin/objects', :only => :index

      include FcrepoAdmin::Controller::ControllerBehavior

      before_filter :load_and_authorize_object
      before_filter :load_datastream, :except => :index

      helper_method :ds_content_is_text?
      helper_method :ds_content_is_editable?
    end

    # Additional types of content that should be displayed inline
    TEXT_MIME_TYPES = ['application/xml', 'application/rdf+xml', 'application/json']
    MAX_INLINE_SIZE = 1024 * 64

    def index
    end

    def show
    end

    def content
    end

    def download
      mimetypes = MIME::Types[@datastream.mimeType]
      send_data @datastream.content, :disposition => 'attachment', :type => @datastream.mimeType, :filename => "#{@datastream.pid.sub(/:/, '_')}_#{@datastream.dsid}.#{mimetypes.first.extensions.first}"                
    end

    def edit
    end

    def upload
    end

    def update
      if params[:file] # file uploaded
        @datastream.content = params[:file].read
      else # content submitted
        @datastream.content = params[:content]
      end
      @object.save
      flash[:notice] = "Datastream content updated." # i18n
      redirect_to fcrepo_admin.object_datastream_url(@object, @datastream.dsid)
    end

    private
    
    def load_datastream
      @datastream = @object.datastreams[params[:id]]
    end

    protected

    def ds_content_is_text?
      @datastream.mimeType.start_with?('text/') || TEXT_MIME_TYPES.include?(@datastream.mimeType)
    end

    def ds_content_is_editable?
      ds_content_is_text? && (@datastream.dsSize <= MAX_INLINE_SIZE)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fcrepo_admin-0.4.0 lib/fcrepo_admin/controller/datastreams_controller_behavior.rb