Skip to content

Commit

Permalink
Merge pull request #7713 from fjordllc/feature/display-count-of-categ…
Browse files Browse the repository at this point in the history
…ory-users-on-generations-all-list

メンター or 管理者でログインしたときだけユーザー一覧の期生別(全員)ページに属性別の人数を表示する
  • Loading branch information
komagata authored May 28, 2024
2 parents 32a476c + f4d7334 commit 1798ca7
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,18 @@
border-radius: 3px

.card-counts__item-label
+text-block(.625rem 1.4, center)
+text-block(.625rem 1.4)
white-space: nowrap
display: flex
justify-content: center
align-items: center
text-align: center
color: var(--semi-muted-text)
padding-block: .125rem
border-bottom: solid 1px var(--border)
height: 1.25rem
&.is-sm span
transform: scale(.85)

.card-counts__item-value
+text-block(.875rem 1.4, center)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
&:not(:first-child)
border-top: solid 1px var(--border-tint)

.user-group__header
display: flex
gap: .5rem
+media-breakpoint-up(md)
justify-content: space-between
+media-breakpoint-down(sm)
flex-direction: column

.user-group__title
+media-breakpoint-up(md)
font-size: 1.125rem
Expand All @@ -12,23 +20,23 @@
.user-group__title-link
text-decoration: none
color: var(--main-text)
display: flex
gap: .5rem
+media-breakpoint-up(md)
display: flex
align-items: flex-end
+media-breakpoint-down(sm)
flex-direction: column
.user-group__title.is-inline &
display: flex
flex-direction: row
align-items: flex-end

.user-group__title-label
display: block
font-weight: 600
+media-breakpoint-up(md)
margin-right: .25em
.user-group__title-link:hover &
text-decoration: underline

.user-group__title-icon
margin-right: .375em
&.is-first
color: var(--gold)
&.is-second
Expand All @@ -45,4 +53,10 @@
font-size: .75rem
font-weight: 400
color: var(--muted-text)
margin-left: .25rem

.user-group__counts
+media-breakpoint-up(md)
margin-top: -.5rem
.card-counts__item
width: 3.5rem
color: var(--default-text)
6 changes: 6 additions & 0 deletions app/models/generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ def target_users(target)
# 退会者は「退会」フィルター時のみ表示させたいため、絞り込みを行う
target == 'retired' ? users : users.unretired
end

def count_classmates_by_target(target)
return classmates.students.count - classmates.hibernated.count if target == :students

classmates.send(target).count
end
end
11 changes: 11 additions & 0 deletions app/views/generations/_generation_count.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- target_labels = %w[現役生 研修生 休会 卒業生 アドバイザー 退会者]
- target_to_scope = %i[students trainees hibernated graduated advisers retired]

.card-counts__items
- target_labels.each_with_index do |label, index|
.card-counts__item
.card-counts__item-inner
.card-counts__item-label
= label
.card-counts__item-value
= generation.count_classmates_by_target(target_to_scope[index])
3 changes: 3 additions & 0 deletions app/views/generations/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ main.page-main
= "#{generation.number}期生"
.user-group__date
= "#{l generation.start_date, format: :year_and_date} ~ #{l generation.end_date, format: :year_and_date}"
- if current_user.mentor? && @target == 'all'
.user-group__counts.is-only-mentor
= render partial: 'generations/generation_count', locals: { generation: generation }
.a-user-icons
.a-user-icons__items
- users.each do |user|
Expand Down
9 changes: 9 additions & 0 deletions test/models/generation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ class GenerationTest < ActiveSupport::TestCase
assert_not_includes Generation.new(5).target_users('retired'), users(:komagata)
assert_not_includes Generation.new(5).target_users('all'), users(:yameo)
end

test '#count_classmates_by_target' do
assert_equal 13, Generation.new(5).count_classmates_by_target(:students)
assert_equal 3, Generation.new(5).count_classmates_by_target(:trainees)
assert_equal 1, Generation.new(5).count_classmates_by_target(:hibernated)
assert_equal 2, Generation.new(5).count_classmates_by_target(:graduated)
assert_equal 2, Generation.new(5).count_classmates_by_target(:advisers)
assert_equal 2, Generation.new(5).count_classmates_by_target(:retired)
end
end
24 changes: 24 additions & 0 deletions test/system/generations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,37 @@ class GenerationsTest < ApplicationSystemTestCase
assert_text '期生別(全員)'
assert_link '33期生'
assert_text '2021年01月01日 ~ 2021年03月31日'
assert_text '現役生'
assert_selector '.card-counts__item-value', text: '2'
assert_text '研修生'
assert_selector '.card-counts__item-value', text: '0'
assert_text '休会'
assert_selector '.card-counts__item-value', text: '0'
assert_text '卒業生'
assert_selector '.card-counts__item-value', text: '0'
assert_text 'アドバイザー'
assert_selector '.card-counts__item-value', text: '0'
assert_text '退会者'
assert_selector '.card-counts__item-value', text: '0'
within all('.a-user-icons__items').first do
within first('.a-user-role.is-admin') do
assert_equal first('.a-user-icons__item-icon.a-user-icon')['title'], 'adminonly (アドミン 能美代): 管理者'
end
end
assert_link '5期生'
assert_text '2014年01月01日 ~ 2014年03月31日'
assert_text '現役生'
assert_selector '.card-counts__item-value', text: '13'
assert_text '研修生'
assert_selector '.card-counts__item-value', text: '3'
assert_text '休会'
assert_selector '.card-counts__item-value', text: '1'
assert_text '卒業生'
assert_selector '.card-counts__item-value', text: '2'
assert_text '退会者'
assert_selector '.card-counts__item-value', text: '2'
assert_text 'アドバイザー'
assert_selector '.card-counts__item-value', text: '2'
within all('.a-user-icons__items').last do
within first('.a-user-role.is-student') do
assert_equal first('.a-user-icons__item-icon.a-user-icon')['title'], 'marumarushain1 (marumarushain1)'
Expand Down

0 comments on commit 1798ca7

Please sign in to comment.