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化した #8055

Merged
merged 8 commits into from
Nov 15, 2024
9 changes: 8 additions & 1 deletion app/controllers/books_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ class BooksController < ApplicationController
before_action :set_book, only: %i[edit update destroy]
before_action :require_admin_or_mentor_login, except: %i[index]

def index; end
def index
books = Book.all
books = params[:practice_id].present? ? books.joins(:practices).where(practices: { id: params[:practice_id] }) : books
@books = books
.with_attached_cover
.includes(:practices)
.order(updated_at: :desc, id: :desc)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@books = books
.with_attached_cover
.includes(:practices)
.order(updated_at: :desc, id: :desc)
@books = books
.with_attached_cover
.includes(:practices)
.order(updated_at: :desc, id: :desc)

でよかった気がします〜

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komagata
こちら、この位置で揃えないとRubocopのLayout/MultilineMethodCallIndentationというルールに引っかかってしまうのですが、大丈夫でしょうか?👀

Copy link
Member

Choose a reason for hiding this comment

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

すみません、上記だとrubocopに引っかかるんですね。
下記はいかがでしょうか。

Suggested change
@books = books
.with_attached_cover
.includes(:practices)
.order(updated_at: :desc, id: :desc)
@books = books.with_attached_cover
.includes(:practices)
.order(updated_at: :desc, id: :desc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@komagata
こちらの書き方で大丈夫でした🙆

end

def new
@book = Book.new
Expand Down
131 changes: 0 additions & 131 deletions app/javascript/components/books.vue

This file was deleted.

31 changes: 0 additions & 31 deletions app/javascript/components/filterDropdown.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 @@ -58,7 +58,6 @@ import '../user_mentor_memo.js'
import '../invitation-url-updater.js'

import VueMounter from '../VueMounter.js'
import Books from '../components/books.vue'
import Questions from '../components/questions.vue'
import UsersAnswers from '../components/users-answers.vue'
import User from '../components/user.vue'
Expand All @@ -74,7 +73,6 @@ import CourseBooks from '../components/course-books.vue'
import '../stylesheets/application'

const mounter = new VueMounter()
mounter.addComponent(Books)
mounter.addComponent(Questions)
mounter.addComponent(UsersAnswers)
mounter.addComponent(User)
Expand Down
50 changes: 50 additions & 0 deletions app/views/books/_book.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
.col-xxxl-2.col-xxl-3.col-xl-4.col-lg-4.col-md-6.col-xs-12
.card-books-item.a-card
.card-books-item__body
.card-books-item__inner
.card-books-item__start
= link_to book.page_url,
target: '_blank',
rel: 'noopener',
class: 'card-books-item__cover-container' do
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
= link_to book.page_url,
target: '_blank',
rel: 'noopener',
class: 'card-books-item__cover-container' do
= link_to book.page_url,
target: '_blank',
rel: 'noopener',
class: 'card-books-item__cover-container' do

で行けた気がします。

= image_tag book.cover_url,
title: book.page_url,
alt: book.title,
class: 'card-books-item__image'
.card-books-item__end
.card-books-item__rows
.card-books-item__row
h2.card-books-item__title
- if book.must_read_for_any_practices?
span.a-badge.is-danger.is-sm
| 必読
= link_to book.page_url,
target: '_blank',
rel: 'noopener',
class: 'card-books-item__title-link' do
span.card-books-item__title-label
| #{book.title}
.card-books-item__row
p.card-books-item__price
| #{book.price.to_s(:delimited)}円(税込)
- if book.description
.card-books-item__row
.card-books-item__description
.a-short-text
p
|#{book.description}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
p
|#{book.description}
p #{book.description}

.card-books-item__practices
.tag-links
ul.tag-links__items
- book.practices.each do |practice|
li.tag-links__item
= link_to practice.path, class: 'tag-links__item-link' do
| #{practice.title}
hr.a-border-tint
- if admin_or_mentor_login?
footer.card-footer.is-only-mento
.card-main-actions
ul.card-main-actions__items
li.card-main-actions__item
= link_to edit_book_path(book), class: 'card-main-actions__action a-button is-sm is-secondary is-block' do
| 編集
24 changes: 23 additions & 1 deletion app/views/books/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,26 @@ header.page-header
span
| 参考書籍登録
hr.a-border
div(data-vue="Books" data-vue-is-admin:boolean="#{current_user.admin?}" data-vue-is-mentor:boolean="#{current_user.mentor?}")
nav.page-filter.form
.container.is-md
= form_with url: books_path, local: true, method: 'get' do
.form-item.is-inline-md-up
= label_tag :practice_id, 'プラクティスで絞り込む', class: 'a-form-label'
= select_tag :practice_id,
options_from_collection_for_select(current_user.practices, :id, :title, selected: params[:practice_id]),
include_blank: 'すべての参考書籍を表示',
onchange: 'this.form.submit()',
id: 'js-choices-single-select'
.page-content.is-books
.container
.books
- if @books.empty?
.o-empty-message
.o-empty-message__icon
i.fa-regular.fa-sad-tear
p.o-empty-message__text
| 登録されている本はありません
- else
.books__items
.row
= render @books