Skip to content

Commit

Permalink
Merge branch 'release/0.14.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
kalashnikovisme committed Jan 29, 2017
2 parents b196e7e + a857cad commit 3ef0392
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
class Web::Admin::ActivityLines::Lider::YaLider::ParticipantsController < Web::Admin::ActivityLines::Lider::YaLider::ApplicationController
before_filter :choose_users, only: [ :new, :edit ]

def index
participants = if params[:contest_id].present?
ActivityLines::Lider::YaLider.find(params[:contest_id]).participants
else
::ActivityLines::Lider::YaLider::Participant.all
end
if params[:search]
participants = participants.search_everywhere params[:search]
else
participants = participants.send params[:scope]
end
@participants = participants.page(params[:page]).decorate
end

def show
@participant = ::ActivityLines::Lider::YaLider::Participant.find(params[:id]).decorate
@stage = if params[:stage]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
class Web::Admin::ActivityLines::Lider::YaLider::StagesController < Web::Admin::ActivityLines::ApplicationController
def show
@stage = ActivityLines::Lider::YaLider::Stage.find(params[:id]).decorate
@current_participants = @stage.current_participants
stage = ActivityLines::Lider::YaLider::Stage.find(params[:id])
@stage = stage.decorate
participants = if params[:search].present?
::ActivityLines::Lider::YaLider::Participant.where(
id: (stage.participants.search_everywhere(params[:search]).map(&:id) & stage.current_participants.map(&:id))).decorate
else
stage.current_participants
end
@current_participants = Kaminari.paginate_array(participants).page params[:page]
end

def new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,17 @@ def new

def show
@ya_lider = ::ActivityLines::Lider::YaLider.includes(:tokens).where(id: params[:id]).first.decorate
@current_participants = ActivityLines::Lider::YaLider::ParticipantDecorator.decorate_collection @ya_lider.current_stage.participants.active.page params[:page]
current_participants = if @ya_lider.current_stage.present?
if params[:search].present?
::ActivityLines::Lider::YaLider::Participant.where(
id: (@ya_lider.current_stage.participants.search_everywhere(params[:search]).map(&:id) &
@ya_lider.current_stage.current_participants.map(&:id)))
else
@ya_lider.current_stage.participants
end
end
@current_participants = ::ActivityLines::Lider::YaLider::ParticipantDecorator.decorate_collection(
Kaminari.paginate_array(current_participants).page(params[:page])) if current_participants.present?
end

def create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ class ActivityLines::Lider::YaLider::ParticipantDecorator < ApplicationDecorator

decorates_association :user

def self.collections
[:active, :won, :lost, :declined]
end

def full_name
"#{object.user.first_name} #{object.user.patronymic} #{object.user.last_name}"
end
Expand Down
1 change: 1 addition & 0 deletions app/models/activity_lines/lider/ya_lider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class ActivityLines::Lider::YaLider < ActiveRecord::Base
has_many :stages, foreign_key: :contest_id, class_name: 'ActivityLines::Lider::YaLider::Stage'
has_many :tokens, as: :record, dependent: :destroy
has_one :committee, as: :project, class_name: 'Team::Committee'
has_many :participants, class_name: 'ActivityLines::Lider::YaLider::Participant', foreign_key: :contest_id

validates :contest_number, presence: true, uniqueness: { scope: :state }
validates :contest_year, presence: true, uniqueness: { scope: :state }
Expand Down
7 changes: 7 additions & 0 deletions app/models/activity_lines/lider/ya_lider/participant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class ActivityLines::Lider::YaLider::Participant < ActiveRecord::Base
has_many :participations, class_name: 'ActivityLines::Lider::YaLider::Participation'
has_many :fields, class_name: 'ActivityLines::Lider::YaLider::ParticipantField'

validates :user_id, presence: true
validates :contest_id, presence: true

state_machine :state, initial: :active do
state :unviewed
state :active
Expand All @@ -25,6 +28,10 @@ class ActivityLines::Lider::YaLider::Participant < ActiveRecord::Base
end
end

include PgSearch
pg_search_scope :search_everywhere, against: [ :user_id, :contest_id ],
associated_against: { user: [ :first_name, :last_name, :email ] }

def esse
fields.where(title: :esse).first
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
%tr
%th= model_class.human_attribute_name(:avatar)
%th= model_class.human_attribute_name(:full_name)
%th= model_class.human_attribute_name(:created_at)
- if searching?
%th= model_class.human_attribute_name(:state)
%th=t 'helpers.links.actions'
Expand All @@ -18,6 +19,8 @@
- if participant.is_member?
= image_tag 'apps/logo-mic-square-small.png', style: 'width: 35px; height: 35px'
= link_to fa_icon(:share), member_path(participant.user.ticket)
%td
=l participant.created_at, format: '%d %B %Y %H:%M'
- if searching?
%td= participant.human_state_name
%td.actions
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
= render 'web/admin/default/index', items: @ya_liders
= render 'web/admin/default/index', items: @participants
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
%h1
= @stage.full_title
.row
- if @stage.is_the_first?
= link_to t('helpers.links.add'), new_admin_activity_lines_lider_ya_lider_participant_path(activity_lines_lider_ya_lider_particpant: { contest_id: @stage.contest_id }), class: 'btn btn-success'
= link_to t('helpers.links.back'), admin_activity_lines_lider_ya_lider_path(@stage.contest), class: 'btn btn-default'
.col-md-6
- if @stage.is_the_first?
= link_to t('helpers.links.add'), new_admin_activity_lines_lider_ya_lider_participant_path(activity_lines_lider_ya_lider_particpant: { contest_id: @stage.contest_id }), class: 'btn btn-success'
= link_to t('helpers.links.back'), admin_activity_lines_lider_ya_lider_path(@stage.contest), class: 'btn btn-default'
= render 'web/admin/default/search', model_class: ActivityLines::Lider::YaLider::Participant
.row
%h4
= t('activerecord.attributes.activity_lines/lider/ya_lider/stage.participants')
|
= @current_participants.count
= Russian.p @current_participants.count, 'человек', 'человека', 'человек'
= render 'web/admin/activity_lines/lider/ya_lider/participants/list', activity_lines_lider_ya_lider_participants: Kaminari.paginate_array(@current_participants).page(params[:page])
= render 'web/admin/activity_lines/lider/ya_lider/participants/list', activity_lines_lider_ya_lider_participants: @current_participants
.row
- if @stage.is_the_first?
= link_to t('helpers.links.add'), new_admin_activity_lines_lider_ya_lider_participant_path(activity_lines_lider_ya_lider_particpant: { contest_id: @stage.contest_id }), class: 'btn btn-success'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@
%div
- case params[:tab]
- when 'current_participants', nil
= render 'web/admin/activity_lines/lider/ya_lider/participants/list', activity_lines_lider_ya_lider_participants: @current_participants
- if @current_participants.present?
.row
.col-md-6
= render 'web/admin/default/search', model_class: ActivityLines::Lider::YaLider::Participant
.row
= render 'web/admin/activity_lines/lider/ya_lider/participants/list', activity_lines_lider_ya_lider_participants: @current_participants
- else
- unless params[:search].present?
= text_hint(t('.you_have_not_add_any_stage'), place: :admin)
- when 'info'
.row
.col-md-6
Expand Down
7 changes: 5 additions & 2 deletions config/locales/ru/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ ru:
mobile_phone_link: Мобильный телефон
email_link: Email
birth_date: Дата рождения
member_default: &member_default
full_name: "Ф.И.О."
avatar: Аватар
member_default: &member_default
avatar_small_img: Аватар
full_name: "Ф.И.О."
short_name: Имя
short_name_link: Имя
social_links: Профили в соц. сетях
Expand Down Expand Up @@ -277,6 +277,9 @@ ru:
begin_date: Дата начала
end_date: Дата окончания
participants: Участники этапа
activity_lines/lider/ya_lider/participant:
<<: *default
<<: *user_default
place:
title: Название
description: Описание
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
resources :ya_liders
namespace :ya_lider do
resources :stages, except: [ :index ]
resources :participants, except: [ :index ]
resources :participants
resources :participant_fields, only: [ :new, :create ]
resources :participations, except: [ :index, :show, :new, :edit ]
end
Expand Down
1 change: 1 addition & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
create_table "activity_lines_lider_ya_lider_participations", force: :cascade do |t|
t.integer "participant_id"
t.integer "stage_id"
t.text "state"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ class Web::Admin::ActivityLines::Lider::YaLider::ParticipantsControllerTest < Ac
@exceptions_attributes = ['id', 'created_at', 'updated_at', 'begin_date', 'end_date']
end

test 'should get index' do
get :index
assert_response :success
end

test 'should get index with search' do
get :index, search: @participant.contest_id
assert_response :success
end

test 'should get index with contest_id' do
get :index, contest_id: @participant.contest_id
assert_response :success
end

test 'should get index with contest_id and search' do
get :index, contest_id: @participant.contest_id, search: @participant.user.first_name
assert_response :success
end

test 'should get new' do
get :new, activity_lines_lider_ya_lider_participant: { contest_id: ActivityLines::Lider::YaLider.last.id }
assert_response :success, @response.body
Expand All @@ -21,7 +41,7 @@ class Web::Admin::ActivityLines::Lider::YaLider::ParticipantsControllerTest < Ac
post :create, activity_lines_lider_ya_lider_participant: attributes
participant = ActivityLines::Lider::YaLider::Participant.last
assert_response :redirect, @response.body
assert_redirected_to admin_activity_lines_lider_ya_liders_path
assert_redirected_to admin_activity_lines_lider_ya_lider_stage_path participant.contest.first_stage.id
participant.attributes.keys.except(*@exceptions_attributes).each do |key|
assert_equal attributes[key.to_sym], participant.send(key), key
end
Expand Down
3 changes: 0 additions & 3 deletions test/controllers/web/admin/categories_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class Web::Admin::CategoriesControllerTest < ActionController::TestCase

test 'should create category' do
attributes = attributes_for :category
if Category.where(id: Category.count + 1).any?
attributes[:id] = Category.count + 2
end
post :create, category: attributes
assert_response :redirect, @response.body
assert_redirected_to admin_categories_path
Expand Down
4 changes: 2 additions & 2 deletions test/factories/activity_lines/lider/ya_lider/participants.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
factory :ya_lider_participant, class: 'ActivityLines::Lider::YaLider::Participant' do
contest_id { create(:ya_lider_with_stages) }
contest_id { create(:ya_lider_with_stages).id }
user_id { User.last ? User.last.id : create(:user).id }
#state { ActivityLines::Lider::YaLider::Participant.state_machines[:state].states.map(&:name).first.to_s }
state { ActivityLines::Lider::YaLider::Participant.state_machines[:state].states.map(&:name).first.to_s }
end
end

0 comments on commit 3ef0392

Please sign in to comment.