Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ユーザー一覧の非Vue化をする #7426

Merged
merged 23 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
aa0045f
ユーザー一覧を非vue化する
yocchan-git Feb 23, 2024
61528c7
Slimコードを元のコードに合わせる
yocchan-git Feb 24, 2024
b8bdb15
フォローのドロップダウンが下に潜らないようにした
machida Mar 5, 2024
247798c
検索結果のページネーションでエラーにならないようにする
yocchan-git Mar 5, 2024
94d35cb
どのページにいても検索できるようにする
yocchan-git Mar 5, 2024
7757713
変数や定数名の修正をする
yocchan-git Mar 12, 2024
db8f8d8
不要なgenerationファイルを削除する
yocchan-git Mar 12, 2024
40fdba3
フロント側でボタンの内容を出力するよう修正
yocchan-git Mar 20, 2024
05a09a4
不要なJSONデータを削除する
yocchan-git Mar 21, 2024
5bcc49c
following.jsのフォーマットを修正する
yocchan-git Mar 22, 2024
dcc7402
不要なロジックを削除して置き換える
yocchan-git Mar 24, 2024
f132d09
no_contentを使うように修正する
yocchan-git Mar 24, 2024
f278ef3
検索機能のロジックを修正する
yocchan-git Mar 28, 2024
1163674
共通して使うメソッドを共通化する
yocchan-git Mar 28, 2024
0bf5d39
テストコードを追加する
yocchan-git Mar 28, 2024
d7893ae
SlimLintの修正をする
yocchan-git Mar 28, 2024
892701c
不要な定数を削除する
yocchan-git Mar 28, 2024
5fd4e1a
検索の処理をクラスに抽出する
yocchan-git Mar 29, 2024
32e07cc
インスタンス変数を参照可能にする
yocchan-git Mar 29, 2024
5d240d3
モデルテストを追加する
yocchan-git Mar 29, 2024
871bce7
引数の順番を修正する
yocchan-git Mar 29, 2024
4886626
コンストラクターでエラーが起こらないのと命名の修正
yocchan-git Mar 30, 2024
467a3b3
テスト名を英語に修正する
yocchan-git Mar 30, 2024
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
2 changes: 1 addition & 1 deletion app/controllers/api/followings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def create
user = User.find(params[:id])
watch = params[:watch] == 'true'
if current_user.follow(user, watch:)
render json: { id: user.id }
head :no_content
else
head :bad_request
end
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/generations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

class GenerationsController < ApplicationController
ALLOWED_TARGETS = %w[all trainee adviser graduate mentor retired].freeze
PAGER_NUMBER = 24

def show
@generation = params[:id].to_i
Expand All @@ -10,5 +11,8 @@ def show
def index
@target = ALLOWED_TARGETS.include?(params[:target]) ? params[:target] : ALLOWED_TARGETS.first
redirect_to root_path, alert: '管理者としてログインしてください' if @target == 'retired' && !current_user.admin?

result = Generation.generations(@target).reverse
@generations = Kaminari.paginate_array(result).page(params[:page]).per(PAGER_NUMBER)
end
end
22 changes: 7 additions & 15 deletions app/controllers/talks/action_uncompleted_controller.rb
Copy link
Contributor Author

@yocchan-git yocchan-git Mar 29, 2024

Choose a reason for hiding this comment

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

相談部屋のコードtalksの部分は検索関連で処理をSearchUserクラスに共通化しましたので
ロジックを修正しています。

動作とテストが通ることなどは確認しましたので、コードも見ていただければと思います!

Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,17 @@ def index
.includes(user: [{ avatar_attachment: :blob }, :discord_profile])
.action_uncompleted
.order(updated_at: :desc, id: :asc)
params[:search_word] = validate_search_word(params[:search_word]) if params[:search_word]

if params[:search_word]
@searched_talks = @talks.merge(
User.search_by_keywords({ word: params[:search_word] })
.unscope(where: :retired_on)
).page(params[:page])
else
@talks = @talks.page(params[:page])
search_user = SearchUser.new(word: params[:search_word], require_retire_user: true)
@validated_search_word = search_user.validate_search_word
end
end

private

def validate_search_word(search_word)
if search_word.match?(/^[\w-]+$/)
search_word.strip if search_word.strip.length >= 3
elsif search_word.strip.length >= 2
search_word.strip
if @validated_search_word
searched_users = search_user.search
@searched_talks = @talks.merge(searched_users).page(params[:page])
else
@talks = @talks.page(params[:page])
end
end
end
20 changes: 6 additions & 14 deletions app/controllers/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ def index
.includes(user: [{ avatar_attachment: :blob }, :discord_profile])
.order(updated_at: :desc, id: :asc)
users = User.users_role(@target, allowed_targets: ALLOWED_TARGETS, default_target: 'all')
params[:search_word] = validate_search_word(params[:search_word]) if params[:search_word]

if params[:search_word]
# search_by_keywords内では { unretired } というスコープが設定されている
# 退会したユーザーも検索対象に含めたいので、unscope(where: :retired_on) で上記のスコープを削除
searched_users = users.search_by_keywords(word: params[:search_word]).unscope(where: :retired_on)
# もし検索対象が退会したユーザーである場合、searched_usersには退会していないユーザーも含まれているため、retired スコープを設定する
searched_users = searched_users.retired if @target == 'retired'
search_user = SearchUser.new(word: params[:search_word], users:, target: @target, require_retire_user: true)
@validated_search_word = search_user.validate_search_word
end

if @validated_search_word
searched_users = search_user.search
@searched_talks = @talks.merge(searched_users).page(params[:page])
else
@talks = @talks.merge(users).page(params[:page])
Expand Down Expand Up @@ -52,12 +52,4 @@ def set_members
.where(id: User.admins.ids.push(@talk.user_id))
.order(:id)
end

def validate_search_word(search_word)
if search_word.match?(/^[\w-]+$/)
search_word.strip if search_word.strip.length >= 3
elsif search_word.strip.length >= 2
search_word.strip
end
end
end
28 changes: 18 additions & 10 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,26 @@ class UsersController < ApplicationController
before_action :require_token, only: %i[new] if Rails.env.production?
before_action :set_user, only: %w[show]

PAGER_NUMBER = 20
PAGER_NUMBER = 24

yocchan-git marked this conversation as resolved.
Show resolved Hide resolved
def index
@target = params[:target]
@target = 'student_and_trainee' unless target_allowlist.include?(@target)
@entered_tag = params[:tag]
@watch = params[:watch]

target_users =
if @target == 'followings'
current_user.followees_list(watch: @watch)
elsif params[:tag]
User.tagged_with(params[:tag])
else
users = User.users_role(@target, allowed_targets: target_allowlist)
@target == 'inactive' ? users.order(:last_activity_at) : users
end
target_users = fetch_target_users

@users = target_users
.page(params[:page]).per(PAGER_NUMBER)
.preload(:avatar_attachment, :course, :taggings)
.order(updated_at: :desc)

@users = @users.unhibernated.unretired unless @target.in? %w[hibernated retired]
if params[:search_word]
search_user = SearchUser.new(word: params[:search_word], users: @users, target: @target)
@users = search_user.search
end

@random_tags = User.tags.sample(20)
@top3_tags_counts = User.tags.limit(3).map(&:count).uniq
Expand Down Expand Up @@ -77,6 +74,17 @@ def create

private

yocchan-git marked this conversation as resolved.
Show resolved Hide resolved
def fetch_target_users
if @target == 'followings'
current_user.followees_list(watch: @watch)
elsif @entered_tag
User.tagged_with(@entered_tag)
else
users = User.users_role(@target, allowed_targets: target_allowlist)
@target == 'inactive' ? users.order(:last_activity_at) : users
end
end

def target_allowlist
target_allowlist = %w[student_and_trainee followings mentor graduate adviser trainee year_end_party]
target_allowlist.push('job_seeking') if current_user.adviser?
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ def users_name
User.pluck(:login_name, :id).sort
end

def button_label(user)
yocchan-git marked this conversation as resolved.
Show resolved Hide resolved
if current_user.following?(user)
current_user.watching?(user) ? 'コメントあり' : 'コメントなし'
else
'フォローする'
end
end

def desc_paragraphs(user)
yocchan-git marked this conversation as resolved.
Show resolved Hide resolved
max_description = user.description.length <= 200 ? user.description : "#{user.description[0...200]}..."
max_description.split(/\n|\r\n/).map.with_index { |text, i| { id: i, text: } }
end

def all_countries_with_subdivisions
ISO3166::Country.all
.map { |country| [country.alpha2, country.subdivision_names_with_codes(I18n.locale.to_s)] }
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/components/user.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
user-tags(:user='user')
user-practice-progress(:user='user')
hr.a-border-tint
footer.card-footer
footer.card-footer.users-item__footer
.card-main-actions
ul.card-main-actions__items
li.card-main-actions__item(
Expand Down
212 changes: 0 additions & 212 deletions app/javascript/components/users.vue

This file was deleted.

Loading