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化する #7447

Merged
merged 8 commits into from
Mar 9, 2024
18 changes: 1 addition & 17 deletions app/controllers/api/talks/action_uncompleted_controller.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# frozen_string_literal: true

class API::Talks::ActionUncompletedController < API::BaseController
PAGER_NUMBER = 20

def index
@talks = Talk.joins(:user)
.includes(user: [{ avatar_attachment: :blob }, :discord_profile])
.action_uncompleted
.order(updated_at: :desc, id: :asc)
@talks =
if params[:search_word]
@talks.merge(
User.search_by_keywords({ word: params[:search_word] })
.unscope(where: :retired_on)
)
else
@talks.page(params[:page]).per(PAGER_NUMBER)
end
end
def index; end
end
21 changes: 1 addition & 20 deletions app/controllers/api/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,8 @@

class API::TalksController < API::BaseController
ALLOWED_TARGETS = %w[all student_and_trainee mentor graduate adviser trainee retired].freeze
PAGER_NUMBER = 20

def index
@target = params[:target]
@talks = Talk.joins(:user)
.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')
@talks =
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'
@talks.merge(searched_users)
else
@talks.merge(users)
.page(params[:page]).per(PAGER_NUMBER)
end
end
def index; end

def update
talk = Talk.find(params[:id])
Expand Down
28 changes: 27 additions & 1 deletion app/controllers/talks/action_uncompleted_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,31 @@

class Talks::ActionUncompletedController < ApplicationController
before_action :require_admin_login
def index; end

def index
@talks = Talk.joins(:user)
.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])
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
end
end
end
26 changes: 26 additions & 0 deletions app/controllers/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,26 @@ class TalksController < ApplicationController
before_action :set_members, only: %i[show]
before_action :allow_show_talk_page_only_admin, only: %i[show]

ALLOWED_TARGETS = %w[all student_and_trainee mentor graduate adviser trainee retired].freeze

def index
@target = params[:target]
@talks = Talk.joins(:user)
.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'
@searched_talks = @talks.merge(searched_users).page(params[:page])
else
@talks = @talks.merge(users).page(params[:page])
end
end

def show; end
Expand All @@ -34,4 +52,12 @@ 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
177 changes: 0 additions & 177 deletions app/javascript/components/talks.vue

This file was deleted.

2 changes: 0 additions & 2 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ import Watches from '../components/watches.vue'
import WatchToggle from '../components/watch-toggle.vue'
import UserMentorMemo from '../components/user_mentor_memo.vue'
import UserRecentReports from '../components/user-recent-reports.vue'
import Talks from '../components/talks.vue'
import Footprints from '../components/footprints.vue'
import QuestionPage from '../components/question-page.vue'
import QuestionEdit from '../components/question-edit.vue'
Expand All @@ -98,7 +97,6 @@ mounter.addComponent(Watches)
mounter.addComponent(WatchToggle)
mounter.addComponent(UserMentorMemo)
mounter.addComponent(UserRecentReports)
mounter.addComponent(Talks)
mounter.addComponent(Footprints)
mounter.addComponent(QuestionPage)
mounter.addComponent(QuestionEdit)
Expand Down
2 changes: 2 additions & 0 deletions app/models/talk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ class Talk < ApplicationRecord

belongs_to :user

paginates_per 20

scope :action_uncompleted, -> { where(action_completed: false) }
end
2 changes: 1 addition & 1 deletion app/views/talks/_nav.html.slim
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nav.tab-nav
.container
ul.tab-nav__items
- API::TalksController::ALLOWED_TARGETS.each do |target|
- TalksController::ALLOWED_TARGETS.each do |target|
li.tab-nav__item
= link_to t("target.#{target}"), talks_path(target:), class: (@target == target ? ['is-active'] : []) << 'tab-nav__item-link'
38 changes: 38 additions & 0 deletions app/views/talks/_talk.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.card-list-item
.card-list-item__inner
.card-list-item__user
= render 'users/icon', user: talk.user, link_class: 'card-list-item__user-link', image_class: 'card-list-item__user-icon'
.card-list-item__rows
.card-list-item__row
.card-list-item-title
h2.card-list-item-title__title(itemprop='name')
= link_to "/talks/#{talk.id}#latest-comment", itemprop: 'url', class: 'card-list-item-title__link a-text-link' do
| #{talk.user.long_name} さんの相談部屋
- if talk.comments.present?
hr.card-list-item__row-separator
- if talk.comments.present?
.card-list-item__row
.card-list-item-meta__items
.card-list-item-meta__item
.card-list-item-meta
.card-list-item-meta__items
.card-list-item-meta__item
.a-meta
| コメント(#{talk.comments.size})
.card-list-item-meta__item
.card-list-item__user-icons
= render partial: 'users/icon',
collection: talk.commented_users.distinct,
locals: { link_class: 'card-list-item__user-icons-icon', image_class: 'a-user-icon' },
as: :user,
cached: true
.card-list-item-meta__item
.a-meta
| 〜 #{l talk.comments.last.updated_at}
.card-list-item-meta__item
- if talk.comments.last.user.admin
.a-meta
| (管理者)
- else
.a-meta
| (#{talk.user.login_name})
Loading