<commit_before># coding: utf-8
class UsersController < ApplicationController
  respond_to :html, :xml, :json
  helper_method :sort_column, :sort_direction
  before_filter :authenticate_user!, :only => [:edit, :update, :order]
  before_filter :get_user, :except => [:index, :autocomplete]

  def index
    if params[:role].present?
      @role = Role.find_by(:name => params[:role])
      @users = @role.users.page(params[:page]).active.search(params[:search]).order(sort_column + ' ' + sort_direction)
    else
      if params[:office].present?
        @users = User.active.where(:office => params[:office]).order(sort_column + ' ' + sort_direction).paginate(:per_page => 10, :page => params[:page])
      else
        if params[:all].present?
          @users = User.active.order(sort_column + ' ' + sort_direction)
        else
          @users = User.page(params[:page]).active.search(params[:search]).order(sort_column + ' ' + sort_direction)
          #@users, @alphaParams = User.all.alpha_paginate(params[:letter]){|user| user.lastname}
        end
      end
    end
    respond_to do |format|
      format.html
    end
  end

  def autocomplete
    @users = User.active.order(:displayname).where("displayname ilike ?", "%#{params[:term]}%")
    render json: @users.map(&:displayname)
  end

  def show
    @uroles = @usr.user_business_role.includes(:business_role).order('business_roles.name')   # исполняет роли
    @uworkplaces = @usr.user_workplace 	# рабочие места пользователя
    @documents = Document.order(:name).where(owner_id: @usr.id)
    @contracts = Contract.order(:number).where(owner_id: @usr.id)
    @contracts_pay = Contract.order(:number).where(payer_id: @usr.id)
    respond_with()
  end

  def edit
  end

  def update
    if @usr.update_attributes(params[:user])
      redirect_to @usr, notice: "Successfully created user access roles."
    else
      render :edit
    end
    #@usr = User.find(params[:id])
    #if params[:role].present?
      #@business_role = Role.new(params[:business_role])
      #@user_role.save if !@user_role.nil?
    #end
    #redirect_to :action => :edit
  end

  def order   # распоряжение о назначении исполнителей на роли в процессе
    print_order
  end

private

  # распоряжение о назачении на роли в процессе
  def print_order<commit_msg>upd: сортировка договоров пользователя - по дате DESC<commit_after># coding: utf-8
class UsersController < ApplicationController
  respond_to :html, :xml, :json
  helper_method :sort_column, :sort_direction
  before_filter :authenticate_user!, :only => [:edit, :update, :order]
  before_filter :get_user, :except => [:index, :autocomplete]

  def index
    if params[:role].present?
      @role = Role.find_by(:name => params[:role])
      @users = @role.users.page(params[:page]).active.search(params[:search]).order(sort_column + ' ' + sort_direction)
    else
      if params[:office].present?
        @users = User.active.where(:office => params[:office]).order(sort_column + ' ' + sort_direction).paginate(:per_page => 10, :page => params[:page])
      else
        if params[:all].present?
          @users = User.active.order(sort_column + ' ' + sort_direction)
        else
          @users = User.page(params[:page]).active.search(params[:search]).order(sort_column + ' ' + sort_direction)
          #@users, @alphaParams = User.all.alpha_paginate(params[:letter]){|user| user.lastname}
        end
      end
    end
    respond_to do |format|
      format.html
    end
  end

  def autocomplete
    @users = User.active.order(:displayname).where("displayname ilike ?", "%#{params[:term]}%")
    render json: @users.map(&:displayname)
  end

  def show
    @uroles = @usr.user_business_role.includes(:business_role).order('business_roles.name')   # исполняет роли
    @uworkplaces = @usr.user_workplace 	# рабочие места пользователя
    @documents = Document.order(:name).where(owner_id: @usr.id)
    @contracts = Contract.order('date_begin DESC').where(owner_id: @usr.id)
    @contracts_pay = Contract.order('date_begin DESC').where(payer_id: @usr.id)
    respond_with()
  end

  def edit
  end

  def update
    if @usr.update_attributes(params[:user])
      redirect_to @usr, notice: "Successfully created user access roles."
    else
      render :edit
    end
    #@usr = User.find(params[:id])
    #if params[:role].present?
      #@business_role = Role.new(params[:business_role])
      #@user_role.save if !@user_role.nil?
    #end
    #redirect_to :action => :edit
  end

  def order   # распоряжение о назначении исполнителей на роли в процессе
    print_order
  end

private

  # распоряжение о назачении на роли в процессе
  def print_order
{'fraction_non_alphanumeric': 0.13556413556413557, 'fraction_numerical': 0.001287001287001287, 'mean_word_length': 3.612265084075173, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '955077', 'n_tokens_mistral': 1542, 'n_tokens_neox': 1560, 'n_words': 315}