<commit_before>require "flash_tool"
class PresentationsController < ApplicationController


  include IndexPager
  include DotGenerator
  include Seek::AssetsCommon

  #before_filter :login_required
  before_filter :find_assets, :only => [ :index ]
  before_filter :find_and_auth, :except => [ :index, :new, :create, :preview]
  before_filter :find_display_presentation, :only=>[:show,:download]

  #before_filter :convert_to_swf, :only => :show

  def new_version
    if (handle_data nil)
      comments=params[:revision_comment]

      @presentation.content_blob = ContentBlob.new(:tmp_io_object => @tmp_io_object, :url=>@data_url)
      @presentation.content_type = params[:presentation][:content_type]
      @presentation.original_filename = params[:presentation][:original_filename]


      respond_to do |format|
        if @presentation.save_as_new_version(comments)

          flash[:notice]="New version uploaded - now on version #{@presentation.version}"
        else
          flash[:error]="Unable to save new version"
        end
        format.html {redirect_to @presentation }
      end
    else
      flash[:error]=flash.now[:error]
      redirect_to @presentation
    end

  end

  # GET /presentations/new
  # GET /presentations/new.xml
  def new
    @presentation=Presentation.new
    respond_to do |format|
      if current_user.person.member?
        format.html # new.html.erb
      else
        flash[:error] = "You are not authorized to upload new Presentations. Only members of known projects, institutions or work groups are allowed to create new content."
        format.html { redirect_to presentations_path }
      end
    end
  end

  # POST /presentations
  # POST /presentations.xml
  def create
    if handle_data
      @presentation = Presentation.new(params[:presentation])
      @presentation.content_blob = ContentBlob.new(:tmp_io_object => @tmp_io_object,:url=>@data_url)

      @presentation.policy.set_attributes_with_sharing params[:sharing], @presentation.project

      update_tags @presentation
      assay_ids = params[:assay_ids] || []
      respond_to do |format|
        if @presentation.save
          # update attributions
          Relationship.create_or_update_attributions(@presentation, params[:attributions])

          # update related publications
          Relationship.create_or_update_attributions(@presentation, params[:related_publication_ids].collect {|i| ["Publication", i.split(",").first]}, Relationship::RELATED_TO_PUBLICATION) unless params[:related_publication_ids].nil?

          #Add creators
          AssetsCreator.add_or_update_creator_list(@presentation, params[:creators])

          flash[:notice] = 'Presentation was successfully uploaded and saved.'
          format.html { redirect_to presentation_path(@presentation) }
          Assay.find(assay_ids).each do |assay|
            if assay.can_edit?
              assay.relate(@presentation)
            end
          end
        else
          format.html {
            render :action => "new"
          }
        end
      end

    end

  end

  def convert_to_swf
      file_type = nil
      if @presentation
        case @presentation.content_type
          when "application/pdf"
             file_type = "pdf"
          when "application/text"
            file_type = "text"
          else

        end

        begin
          FlashTool::FlashObject.new("#{ContentBlob::DATA_STORAGE_PATH}#{RAILS_ENV}/#{@presentation.content_blob.uuid}.dat", file_type) do |f|
            f.output("public/swf/presentations/#{@presentation.title}.swf")
            f.fonts
            f.flashversion("9")
            f.stop
            f.set('param="storeallcharacters"')
            f.flatten
            f.save()
          end
        rescue Exception=>e

          flash[:error]=e.message#[0..50]

        end
      end




  end
  # GET /presentations/1
  # GET /presentations/1.xml
  def show
    # store timestamp of the previous last usage
    @last_used_before_now = @presentation.last_used_at

    # update timestamp in the current Presentation record
    # (this will also trigger timestamp update in the corresponding Asset)
    @presentation.last_used_at = Time.now
    @presentation.save_without_timestamping

    respond_to do |format|
      format.html # show.html.erb
      format.xml
      format.svg { render :text=>to_svg(@presentation,params[:deep]=='true',@presentation)}
      format.dot { render :text=>to_dot(@presentation,params[:deep]=='true',@presentation)}
      format.png { render :text=>to_png(@presentation,params[:deep]=='true',@presentation)}
    end
  end

   # GET /presentations/1/download
  def download
    # update timestamp in the current Presentation record
    # (this will also trigger timestamp update in the corresponding Asset)
    @presentation.last_used_at = Time.now
    @presentation.save_without_timestamping

    handle_download @display_presentation
  end<commit_msg>comment flash stuff out temporarily<commit_after>#require "flash_tool"
class PresentationsController < ApplicationController


  include IndexPager
  include DotGenerator
  include Seek::AssetsCommon

  #before_filter :login_required
  before_filter :find_assets, :only => [ :index ]
  before_filter :find_and_auth, :except => [ :index, :new, :create, :preview]
  before_filter :find_display_presentation, :only=>[:show,:download]

  #before_filter :convert_to_swf, :only => :show

  def new_version
    if (handle_data nil)
      comments=params[:revision_comment]

      @presentation.content_blob = ContentBlob.new(:tmp_io_object => @tmp_io_object, :url=>@data_url)
      @presentation.content_type = params[:presentation][:content_type]
      @presentation.original_filename = params[:presentation][:original_filename]


      respond_to do |format|
        if @presentation.save_as_new_version(comments)

          flash[:notice]="New version uploaded - now on version #{@presentation.version}"
        else
          flash[:error]="Unable to save new version"
        end
        format.html {redirect_to @presentation }
      end
    else
      flash[:error]=flash.now[:error]
      redirect_to @presentation
    end

  end

  # GET /presentations/new
  # GET /presentations/new.xml
  def new
    @presentation=Presentation.new
    respond_to do |format|
      if current_user.person.member?
        format.html # new.html.erb
      else
        flash[:error] = "You are not authorized to upload new Presentations. Only members of known projects, institutions or work groups are allowed to create new content."
        format.html { redirect_to presentations_path }
      end
    end
  end

  # POST /presentations
  # POST /presentations.xml
  def create
    if handle_data
      @presentation = Presentation.new(params[:presentation])
      @presentation.content_blob = ContentBlob.new(:tmp_io_object => @tmp_io_object,:url=>@data_url)

      @presentation.policy.set_attributes_with_sharing params[:sharing], @presentation.project

      update_tags @presentation
      assay_ids = params[:assay_ids] || []
      respond_to do |format|
        if @presentation.save
          # update attributions
          Relationship.create_or_update_attributions(@presentation, params[:attributions])

          # update related publications
          Relationship.create_or_update_attributions(@presentation, params[:related_publication_ids].collect {|i| ["Publication", i.split(",").first]}, Relationship::RELATED_TO_PUBLICATION) unless params[:related_publication_ids].nil?

          #Add creators
          AssetsCreator.add_or_update_creator_list(@presentation, params[:creators])

          flash[:notice] = 'Presentation was successfully uploaded and saved.'
          format.html { redirect_to presentation_path(@presentation) }
          Assay.find(assay_ids).each do |assay|
            if assay.can_edit?
              assay.relate(@presentation)
            end
          end
        else
          format.html {
            render :action => "new"
          }
        end
      end

    end

  end

#  def convert_to_swf
#      file_type = nil
#      if @presentation
#        case @presentation.content_type
#          when "application/pdf"
#             file_type = "pdf"
#          when "application/text"
#            file_type = "text"
#          else
#
#        end
#
#        begin
#          FlashTool::FlashObject.new("#{ContentBlob::DATA_STORAGE_PATH}#{RAILS_ENV}/#{@presentation.content_blob.uuid}.dat", file_type) do |f|
#            f.output("public/swf/presentations/#{@presentation.title}.swf")
#            f.fonts
#            f.flashversion("9")
#            f.stop
#            f.set('param="storeallcharacters"')
#            f.flatten
#            f.save()
#          end
#        rescue Exception=>e
#
#          flash[:error]=e.message#[0..50]
#
#        end
#      end
#
#  end
  # GET /presentations/1
  # GET /presentations/1.xml
  def show
    # store timestamp of the previous last usage
    @last_used_before_now = @presentation.last_used_at

    # update timestamp in the current Presentation record
    # (this will also trigger timestamp update in the corresponding Asset)
    @presentation.last_used_at = Time.now
    @presentation.save_without_timestamping

    respond_to do |format|
      format.html # show.html.erb
      format.xml
      format.svg { render :text=>to_svg(@presentation,params[:deep]=='true',@presentation)}
      format.dot { render :text=>to_dot(@presentation,params[:deep]=='true',@presentation)}
      format.png { render :text=>to_png(@presentation,params[:deep]=='true',@presentation)}
    end
  end

   # GET /presentations/1/download
  def download
    # update timestamp in the current Presentation record
    # (this will also trigger timestamp update in the corresponding Asset)
    @presentation.last_used_at = Time.now
    @presentation.save_without_timestamping

    handle_download @display_presentation
  end
{'fraction_non_alphanumeric': 0.0995771244462344, 'fraction_numerical': 0.001409585179218687, 'mean_word_length': 2.951073985680191, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2547416', 'n_tokens_mistral': 2925, 'n_tokens_neox': 2743, 'n_words': 615}