<commit_before>class CollagesController < BaseController

  cache_sweeper :collage_sweeper

  before_filter :require_user, :except => [:layers, :annotations, :index, :show, :metadata, :description_preview]
  before_filter :prep_resources
  before_filter :load_collage, :only => [:layers, :annotations, :show, :edit, :update, :destroy, :undo_annotation, :spawn_copy]

  access_control do
    allow :superadmin
    allow :admin
    allow :collages_admin
    #FIXME - Allow collage owners to destroy when we fix acts_as_category
    #allow :owner, :of => :collage, :to => [:destroy, :edit, :update]
    allow :owner, :of => :collage, :to => [:edit, :update]
    allow all, :to => [:layers, :annotations, :index, :show, :new, :create, :metadata, :description_preview, :spawn_copy]
  end

  def description_preview
    render :text => Collage.format_content(params[:preview]), :layout => false
  end

  def layers
    respond_to do |format|
      format.json { render :json => @collage.layers }
    end
  end

  def spawn_copy
    @collage_copy = @collage.fork_it(current_user)
    respond_to do |format|
      format.html { redirect_to(@collage_copy) }
      format.xml  { render :xml => @collage_copy, :status => :created, :location => @collage_copy }
    end
  rescue Exception => e
    flash[:notice] = "We couldn't copy that collage - " + e.inspect
    format.html { render :action => "new" }
    format.xml  { render :xml => e.inspect, :status => :unprocessable_entity }
  end

  def annotations
    respond_to do |format|
      format.json { render :json => @collage.annotations.to_json(:include => [:layers], :except => [:annotation, :annotated_content]) }
    end
  end

  # GET /collages
  # GET /collages.xml
  def index
    @collages = Collage.find(:all, :include => [:annotations => [:layers], :annotatable => true])
    if current_user
      @my_collages = @collages.find_all{|c| c.accepts_role?(:owner, current_user)}
    end

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @collages }
    end
  end

  # GET /collages/1
  # GET /collages/1.xml
  def show
    respond_to do |format|<commit_msg>Select only the fields that are needed for this view.<commit_after>class CollagesController < BaseController

  cache_sweeper :collage_sweeper

  before_filter :require_user, :except => [:layers, :annotations, :index, :show, :metadata, :description_preview]
  before_filter :prep_resources
  before_filter :load_collage, :only => [:layers, :annotations, :show, :edit, :update, :destroy, :undo_annotation, :spawn_copy]

  access_control do
    allow :superadmin
    allow :admin
    allow :collages_admin
    #FIXME - Allow collage owners to destroy when we fix acts_as_category
    #allow :owner, :of => :collage, :to => [:destroy, :edit, :update]
    allow :owner, :of => :collage, :to => [:edit, :update]
    allow all, :to => [:layers, :annotations, :index, :show, :new, :create, :metadata, :description_preview, :spawn_copy]
  end

  def description_preview
    render :text => Collage.format_content(params[:preview]), :layout => false
  end

  def layers
    respond_to do |format|
      format.json { render :json => @collage.layers }
    end
  end

  def spawn_copy
    @collage_copy = @collage.fork_it(current_user)
    respond_to do |format|
      format.html { redirect_to(@collage_copy) }
      format.xml  { render :xml => @collage_copy, :status => :created, :location => @collage_copy }
    end
  rescue Exception => e
    flash[:notice] = "We couldn't copy that collage - " + e.inspect
    format.html { render :action => "new" }
    format.xml  { render :xml => e.inspect, :status => :unprocessable_entity }
  end

  def annotations
    respond_to do |format|
      format.json { render :json => @collage.annotations.to_json(:include => [:layers], :except => [:annotation, :annotated_content]) }
    end
  end

  # GET /collages
  # GET /collages.xml
  def index
    @collages = Collage.find(:all, :select => 'id,annotatable_type,annotatable_id,name,description,parent_id,children_count,ancestors_count,descendants_count,position,hidden,created_at,updated_at,word_count', :include => [:annotations => [:layers], :annotatable => true])
    if current_user
      @my_collages = @collages.find_all{|c| c.accepts_role?(:owner, current_user)}
    end

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @collages }
    end
  end

  # GET /collages/1
  # GET /collages/1.xml
  def show
    respond_to do |format|
{'fraction_non_alphanumeric': 0.13003095975232198, 'fraction_numerical': 0.0008845643520566122, 'mean_word_length': 3.821961620469083, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1351814', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1465, 'n_words': 382}