Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions app/controllers/users/regular_events_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

class Users::RegularEventsController < ApplicationController
def index
@user = User.find(params[:user_id])
@regular_events = @user.participate_regular_events
.includes(:comments, :regular_event_repeat_rules, :user,
{ users: { avatar_attachment: :blob } })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

controller側でavatar_attachment: :blobまで含めてincludesする書き方を知らなかったので、勉強になりました!🙌

.order(:finished, created_at: :desc, id: :desc)
.page(params[:page])
end
end
2 changes: 1 addition & 1 deletion app/helpers/page_tabs/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def user_page_tabs(user, active_tab:)
tabs << { name: '提出物', link: user_products_path(user), count: user.products.length }
tabs << { name: '質問', link: user_questions_path(user), count: user.questions.length }
tabs << { name: '回答', link: user_answers_path(user), count: user.answers.length }
tabs << { name: 'イベント', link: user_events_path(user), count: user.participate_events.length }
tabs << { name: 'イベント', link: user_events_path(user), count: user.participate_events.count + user.participate_regular_events.count }
if Switchlet.enabled?(:micro_report) && (admin_or_mentor_login? || (Rails.env.in? %w[development test]))
tabs << { name: '分報',
link: "#{user_micro_reports_path(user, page: user.latest_micro_report_page)}#latest-micro-report",
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,11 @@ def payment_methods_for_select
def visible_learning_time_frames?(user)
!user.graduated? && user.learning_time_frames.exists?
end

def event_navs(user)
[
{ id: 'events', name: Event.model_name.human, count: user.participate_events.length, path: user_events_path(user) },
{ id: 'regular_events', name: RegularEvent.model_name.human, count: user.participate_regular_events.length, path: user_regular_events_path(user) }
]
end
end
8 changes: 8 additions & 0 deletions app/views/users/_event_nav.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
nav.tab-nav
.container
ul.tab-nav__items
- event_navs(@user).each do |nav|
li.tab-nav__item
- nav_class = 'tab-nav__item-link '
- nav_class << 'is-active' if current_page?(nav[:path])
= link_to "#{nav[:name]}(#{nav[:count]})", nav[:path], class: nav_class
2 changes: 2 additions & 0 deletions app/views/users/events/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
= render 'users/page_title', user: @user
= user_page_tabs(@user, active_tab: 'イベント')

= render 'users/event_nav'

.page-main
.page-body
.page-body__inner.has-side-nav
Expand Down
70 changes: 70 additions & 0 deletions app/views/users/regular_events/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
- title "#{@user.login_name}のイベント一覧"
- set_meta_tags description: "#{@user.login_name}さんのイベントページです。"

= render 'users/page_title', user: @user
= user_page_tabs(@user, active_tab: 'イベント')

= render 'users/event_nav'

.page-main
.page-body
.page-body__inner.has-side-nav
.container.is-md
- if @regular_events.present?
.pagination
= paginate @regular_events
.card-list.a-card
- @regular_events.each do |event|
.card-list-item.is-event
.card-list-item__inner
.card-list-item__label(class="is-#{event.category}")
= t("activerecord.enums.regular_event.category.#{event.category}")
.card-list-item__rows
.card-list-item__row
.card-list-item-title
.card-list-item-title__start
- if event.wip
.a-list-item-badge.is-wip
<span>WIP</span>
- elsif event.finished?
.a-list-item-badge.is-ended
<span>終了</span>
h2.card-list-item-title__title
= link_to event.title, event, class: 'card-list-item-title__link a-text-link'
.card-list-item__row
.card-list-item-meta
.card-list-item-meta__items
.card-list-item-meta__item
.a-meta
= link_to event.user, class: 'a-user-name' do
= event.user.long_name
.card-list-item__row
.card-list-item-meta
.card-list-item-meta__items
- if event.users.size.positive?
.card-list-item-meta__item
.a-meta
.a-meta__label
= '主催'
.card-list-item__user-icons
- event.users.each do |organizer_user|
= render 'users/icon',
user: organizer_user,
link_class: 'card-list-item__user-link',
image_class: 'card-list-item__user-icon'
Comment thread
y-kawahara-gs marked this conversation as resolved.
.card-list-item-meta__item
time.a-meta(datetime="#{event.start_at}")
| 開催日時:
| #{event.holding_cycles} #{l event.start_at, format: :time_only} ~ #{l event.end_at, format: :time_only}
- if event.comments.size.positive?
.card-list-item-meta__item
.a-meta
= event_comment_count(event, styled: false)
.pagination
= paginate @regular_events
- else
.o-empty-message
.o-empty-message__icon
i.fa-regular.fa-sad-tear
p.o-empty-message__text
| イベントはまだありません。
1 change: 1 addition & 0 deletions config/routes/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
resources :answers, only: %i(index), controller: "users/answers"
resources :micro_reports, only: %i[index create destroy], controller: "users/micro_reports"
resources :events, only: %i(index), controller: "users/events"
resources :regular_events, only: %i(index), controller: "users/regular_events"
get "portfolio" => "users/works#index", as: :portfolio
patch "graduation", to: "graduation#update", as: :graduation
resource :mail_notification, only: %i(edit update), controller: "users/mail_notification"
Expand Down
9 changes: 8 additions & 1 deletion test/system/user/events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@ class User::EventsTest < ApplicationSystemTestCase
test 'shows the event listing for a user' do
visit_with_auth "/users/#{users(:komagata).id}/events", 'komagata'
assert_equal 'komagataのイベント一覧 | FBC', title
nav = find('a.tab-nav__item-link', text: /特別イベント\(\d+\)/)
assert nav.matches_css?('.is-active')
end

test 'shows only events the user is participating in' do
test 'shows correct count of user participating events' do
visit_with_auth "/users/#{users(:kimura).id}/events", 'kimura'
assert_selector '.tab-nav__item-link', text: "特別イベント(#{users(:kimura).participate_events.count})"
end

test 'does not show events the user is not participating in' do
visit_with_auth "/users/#{users(:kimura).id}/events", 'kimura'
assert_text 'kimura専用イベント'
assert_no_text '募集期間中のイベント(補欠者なし)'
Expand Down
23 changes: 23 additions & 0 deletions test/system/user/regular_events_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

require 'application_system_test_case'

class User::RegularEventsTest < ApplicationSystemTestCase
test 'shows the regular event listing for a user ' do
visit_with_auth "/users/#{users(:komagata).id}/regular_events", 'komagata'
assert_equal 'komagataのイベント一覧 | FBC', title
nav = find('a.tab-nav__item-link', text: /定期イベント\(\d+\)/)
assert nav.matches_css?('.is-active')
end

test 'shows correct count of user participating regular events' do
visit_with_auth "/users/#{users(:kimura).id}/regular_events", 'kimura'
assert_text "定期イベント(#{users(:kimura).participate_regular_events.count})"
end

test 'does not show regular events the user is not participating in' do
visit_with_auth "/users/#{users(:kimura).id}/regular_events", 'kimura'
assert_text '独習Git輪読会'
assert_no_text '開発MTG'
end
end
Loading