<commit_before>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class AspectsController < ApplicationController
  before_filter :authenticate_user!

  respond_to :html
  respond_to :json, :only => :show
  respond_to :js

  def index
    @posts  = current_user.visible_posts(:_type => "StatusMessage").paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
    @post_hashes = hashes_for_posts @posts
    @contacts = Contact.all(:user_id => current_user.id, :pending => false)
    @aspect_hashes = hashes_for_aspects @aspects.all, @contacts, :limit => 8
    @aspect = :all

    @contact_hashes = hashes_for_contacts @contacts

    if current_user.getting_started == true
      redirect_to getting_started_path
    end
  end

  def create
    @aspect = current_user.aspects.create(params[:aspect])
    if @aspect.valid?
      flash[:notice] = I18n.t('aspects.create.success', :name => @aspect.name)
      if current_user.getting_started
        redirect_to :back
      elsif request.env['HTTP_REFERER'].include?("aspects/manage")
        redirect_to :back
      else
        respond_with @aspect
      end
    else
      flash[:error] = I18n.t('aspects.create.failure')
      redirect_to :back
    end
  end

  def new
    @aspect = Aspect.new
  end

  def destroy
    @aspect = current_user.aspect_by_id params[:id]

    begin
      current_user.drop_aspect @aspect
      flash[:notice] = I18n.t 'aspects.destroy.success',:name => @aspect.name
      redirect_to root_url
    rescue RuntimeError => e
      flash[:error] = e.message
      redirect_to :back
    end
  end

  def show
    @aspect = current_user.aspect_by_id params[:id]
    @contacts = current_user.contacts.where(:pending => false)
    unless @aspect
      render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
    else
      @aspect_contacts = hashes_for_contacts Contact.all(:user_id => current_user.id, :aspect_ids.in => [@aspect.id], :pending => false)
      @aspect_contacts_count = @aspect_contacts.count
<commit_msg>Don't redirect to root_url on aspect destroy<commit_after>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

class AspectsController < ApplicationController
  before_filter :authenticate_user!

  respond_to :html
  respond_to :json, :only => :show
  respond_to :js

  def index
    @posts  = current_user.visible_posts(:_type => "StatusMessage").paginate :page => params[:page], :per_page => 15, :order => 'created_at DESC'
    @post_hashes = hashes_for_posts @posts
    @contacts = Contact.all(:user_id => current_user.id, :pending => false)
    @aspect_hashes = hashes_for_aspects @aspects.all, @contacts, :limit => 8
    @aspect = :all

    @contact_hashes = hashes_for_contacts @contacts

    if current_user.getting_started == true
      redirect_to getting_started_path
    end
  end

  def create
    @aspect = current_user.aspects.create(params[:aspect])
    if @aspect.valid?
      flash[:notice] = I18n.t('aspects.create.success', :name => @aspect.name)
      if current_user.getting_started
        redirect_to :back
      elsif request.env['HTTP_REFERER'].include?("aspects/manage")
        redirect_to :back
      else
        respond_with @aspect
      end
    else
      flash[:error] = I18n.t('aspects.create.failure')
      redirect_to :back
    end
  end

  def new
    @aspect = Aspect.new
  end

  def destroy
    @aspect = current_user.aspect_by_id params[:id]

    begin
      current_user.drop_aspect @aspect
      flash[:notice] = I18n.t 'aspects.destroy.success',:name => @aspect.name
      redirect_to :back
    rescue RuntimeError => e
      flash[:error] = e.message
      redirect_to :back
    end
  end

  def show
    @aspect = current_user.aspect_by_id params[:id]
    @contacts = current_user.contacts.where(:pending => false)
    unless @aspect
      render :file => "#{Rails.root}/public/404.html", :layout => false, :status => 404
    else
      @aspect_contacts = hashes_for_contacts Contact.all(:user_id => current_user.id, :aspect_ids.in => [@aspect.id], :pending => false)
      @aspect_contacts_count = @aspect_contacts.count

{'fraction_non_alphanumeric': 0.11080203987019008, 'fraction_numerical': 0.00927213722763097, 'mean_word_length': 3.3629929221435795, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7643220', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1434, 'n_words': 326}