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

提出物に提出者最終コメント日時とメンター最終コメント日時を追加する #3111

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c63d466
提出物に提出者最終コメント日時とメンター最終コメント日時のカラムを追加
Daichi831 Aug 6, 2021
c18628a
コメント後に最終コメント日時を更新するメソッドをCommentCallbacksに追加
Daichi831 Aug 6, 2021
af6224d
提出物個別ページに最終コメント日時があれば表示するように実装
Daichi831 Aug 6, 2021
3d468a4
提出物一覧ページに最終コメント日時があれば表示するように実装
Daichi831 Aug 6, 2021
c793342
rubocopによる修正
Daichi831 Aug 10, 2021
289f7fc
products/showにあった空白を削除
Daichi831 Aug 10, 2021
b717cbb
prettierでproduct.vueを修正
Daichi831 Aug 10, 2021
27adf33
提出物個別ページと一覧ページの見た目を修正
Daichi831 Aug 10, 2021
1d45737
提出者とメンターのコメントの最新の方を表示するように変更&デザインようにクラスを追加
Daichi831 Aug 10, 2021
6889b3b
prettierでproduct.vueを修正
Daichi831 Aug 10, 2021
028f745
不要な空白の削除
Daichi831 Aug 10, 2021
e17ca84
コメントが削除された時最新日時を更新する
Daichi831 Aug 17, 2021
eb70568
既存の提出物にデータを挿入するdata_migrationスクリプトを追加
Daichi831 Aug 17, 2021
da0fc9c
rubocopによる修正
Daichi831 Aug 17, 2021
f7a9190
提出物にコメントがされた際に最終コメントが更新されるか検証するテストを追加
Daichi831 Aug 18, 2021
b8e3961
提出物一覧にある最終コメント表示を変更、提出物個別のレイアウトの調整、変更
machida Sep 6, 2021
dc522c8
lintの指摘対応
machida Sep 6, 2021
0febf7a
最終日時のリセット部分をメソッド化した
Daichi831 Sep 6, 2021
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
1 change: 1 addition & 0 deletions app/assets/stylesheets/atoms/_a-user-name.sass
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
color: $muted-text
font-size: .8125rem
line-height: 1.4
white-space: nowrap

a.a-user-name
+hover-link
17 changes: 9 additions & 8 deletions app/assets/stylesheets/blocks/thread/_thread-list-item.sass
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,15 @@
color: $reversal-text
border-color: #b50f38


.thread-list-item__inner
+position(relative)
padding-left: 3.75rem
+media-breakpoint-down(sm)
padding-left: 3rem
.thread-list-item.has-assigned &
+media-breakpoint-up(md)
padding-right: 8.75rem

.thread-list-item__assignee
+media-breakpoint-up(md)
+position(absolute, right 0, top 0)
+position(absolute, right -.5rem, top -.25rem)
width: 8rem
+media-breakpoint-down(sm)
margin-top: .75rem
Expand Down Expand Up @@ -118,14 +114,19 @@
opacity: .6

.thread-list-item__row-separator
// TODO resetに移す
border: none
margin-bottom: .25rem
border-top: dashed 1px $border
height: 1px
+media-breakpoint-up(md)
+margin(vertical, .5rem)
+media-breakpoint-down(sm)
+margin(vertical, .75rem .25rem)

.thread-list-item__row
&:not(:first-child)
margin-top: .25rem
.thread-list-item.has-assigned &:first-child
+media-breakpoint-up(md)
padding-right: 8.5rem

.thread-list-item__show-user-detail
+position(absolute, top 0)
Expand Down
4 changes: 2 additions & 2 deletions app/javascript/comments.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template lang="pug">
.thread-comments(v-if='loaded === false')
#comments.thread-comments(v-if='loaded === false')
commentPlaceholder(v-for='num in placeholderCount', :key='num')
.thread-comments(v-else)
#comments.thread-comments(v-else)
comment(
v-for='(comment, index) in comments',
:key='comment.id',
Expand Down
52 changes: 38 additions & 14 deletions app/javascript/product.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template lang="pug">
.thread-list-item(:class='product.wip ? "is-wip" : ""')
.thread-list-item.has-assigned(:class='product.wip ? "is-wip" : ""')
.thread-list-item__strip-label(v-if='notResponded || unassigned')
.thread-list-item__elapsed-days.is-reply-warning.is-only-mentor(
v-if='isLatestProductSubmittedJust5days'
Expand Down Expand Up @@ -29,25 +29,26 @@
.thread-list-item-meta__items
.thread-list-item-meta__item
a.a-user-name(:href='product.user.url') {{ product.user.login_name }}
.thread-list-item__row
.thread-list-item-meta
.thread-list-item-meta__items
.thread-list-item-meta__item(v-if='product.wip')
.a-meta 提出物作成中
.thread-list-item-meta__item(v-else-if='product.published_at')
time.a-meta(datetime='product.published_at_date_time')
time.a-meta
span.a-meta__label 提出日
| {{ product.published_at }}
.thread-list-item-meta__item(v-else)
time.a-meta(datetime='product.created_at_date_time')
time.a-meta
span.a-meta__label 提出日
| {{ product.created_at }}
time.a-meta(
v-if='product.updated_at',
datetime='product.updated_at_date_time'
)
span.a-meta__label 更新
| {{ product.updated_at }}
.thread-list-item-meta__item
time.a-meta(v-if='product.updated_at')
span.a-meta__label 更新
| {{ product.updated_at }}

hr.thread-list-item__row-separator(v-if='product.comments.size > 0')
.thread-list-item__row(v-if='product.comments.size > 0')
hr.thread-list-item__row-separator
.thread-list-item-meta
.thread-list-item-meta__items
.thread-list-item-meta__item
Expand All @@ -67,10 +68,33 @@
:src='user.avatar_url',
:class='[roleClass, daimyoClass]'
)
time.a-meta(
datetime='product.comments.last_created_at_date_time'
)
| 〜 {{ product.comments.last_created_at }}

.thread-list-item-meta__item(
v-if='product.self_last_comment_at_date_time && product.mentor_last_comment_at_date_time'
)
time.a-meta(
v-if='product.self_last_comment_at_date_time > product.mentor_last_comment_at_date_time'
)
| 〜 {{ product.self_last_comment_at }}(
strong
| 提出者
| )
time.a-meta(
v-if='product.self_last_comment_at_date_time < product.mentor_last_comment_at_date_time'
)
| 〜 {{ product.mentor_last_comment_at }}(メンター)

.thread-list-item-meta__item(
v-else-if='product.self_last_comment_at_date_time || product.mentor_last_comment_at_date_time'
)
time.a-meta(v-if='product.self_last_comment_at_date_time')
| 〜 {{ product.self_last_comment_at }}(
strong
| 提出者
| )
time.a-meta(v-else-if='product.mentor_last_comment_at_date_time')
| 〜 {{ product.mentor_last_comment_at }}(メンター)

.stamp.stamp-approve(v-if='product.checks.size > 0')
h2.stamp__content.is-title 確認済
time.stamp__content.is-created-at {{ product.checks.last_created_at }}
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/report.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
.thread-list-item-meta__item
time.a-meta {{ report.reportedOn }}
| の日報
hr.thread-list-item__row-separator
.thread-list-item__row(v-if='report.hasAnyComments')
hr.thread-list-item__row-separator
.thread-list-item-meta
.thread-list-item-meta__items
.thread-list-item-meta__item
Expand Down
1 change: 1 addition & 0 deletions app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class Comment < ApplicationRecord
belongs_to :user, touch: true
belongs_to :commentable, polymorphic: true
after_create CommentCallbacks.new
after_update CommentCallbacks.new
after_destroy CommentCallbacks.new
alias sender user

Expand Down
38 changes: 38 additions & 0 deletions app/models/comment_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,55 @@ def after_create(comment)

return unless comment.commentable.instance_of?(Product)

update_last_comment_at(comment)
delete_product_cache(comment.commentable.id)
end

def after_update(comment)
return unless comment.commentable.instance_of?(Product)

update_last_comment_at(comment)
end

def after_destroy(comment)
return unless comment.commentable.instance_of?(Product)

delete_last_comment_at(comment.commentable.id)
delete_product_cache(comment.commentable.id)
end

private

def reset_last_comment_at
product.mentor_last_comment_at = nil
product.self_last_comment_at = nil
end

def delete_last_comment_at(product_id)
product = Product.find(product_id)

reset_last_comment_at

product.comments.each do |comment|
if comment.user.mentor
product.mentor_last_comment_at = comment.updated_at
elsif comment.user == product.user
product.self_last_comment_at = comment.updated_at
end
end
product.save!
end

def update_last_comment_at(comment)
product = Product.find(comment.commentable.id)
if comment.user.mentor
product.mentor_last_comment_at = comment.updated_at
elsif comment.user == product.user
product.self_last_comment_at = comment.updated_at
end
product.save!
end

def notify_comment(comment)
NotificationFacade.came_comment(
comment,
Expand Down
10 changes: 10 additions & 0 deletions app/views/api/products/_product.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ if product.updated_at.present?
json.updated_at_date_time product.updated_at.to_datetime
end

if product.self_last_comment_at.present?
json.self_last_comment_at l(product.self_last_comment_at)
json.self_last_comment_at_date_time product.self_last_comment_at.to_datetime
end

if product.mentor_last_comment_at.present?
json.mentor_last_comment_at l(product.mentor_last_comment_at)
json.mentor_last_comment_at_date_time product.mentor_last_comment_at.to_datetime
end

json.user do
json.partial! "api/users/user", user: product.user
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/products/_report.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
= l report.reported_on
= 'の日報'
- if report.comments.any?
hr.thread-list-item__row-separator
.thread-list-item__row
hr.thread-list-item__row-separator
.thread-list-item-meta
.thread-list-item-meta__items
.thread-list-item-meta__item
Expand Down
39 changes: 20 additions & 19 deletions app/views/products/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,26 @@ header.page-header
.thread-header-metas__meta
= link_to @product.user, class: 'a-user-name' do
= @product.user.long_name

.thread-header-metas__end
.thread-header-metas__meta
- length = @product.comments.length
a.a-meta(href='#comments' class="#{length.zero? ? 'is-disabled' : ''}")
| コメント(
span(class="#{length.zero? ? 'is-muted' : 'is-emphasized'}")
= length
| )
.thread-header__row
h1.thread-header-title(class="#{@product.wip? ? 'is-wip' : ''}")
- if @product.wip?
span.thread-header-title__label
| WIP
span.thread-header-title__title
- if @product.user.daimyo?
| ★
| #{link_to @product.practice.title, @product.practice, class: 'thread-header-title__link'}の提出物
.thread-header__row
.thread-header-metas
.thread-header-metas__start
.thread-header-metas__meta
.a-meta
- if @product.wip?
Expand All @@ -74,24 +93,6 @@ header.page-header
time.a-meta__value(datetime="#{@product.updated_at.to_datetime}")
= l @product.updated_at

.thread-header-metas__meta
- length = @product.comments.length
a.a-meta(href='#comments' class="#{length.zero? ? 'is-disabled' : ''}")
| コメント(
span(class="#{length.zero? ? 'is-muted' : 'is-emphasized'}")
= length
| )

.thread-header__row
h1.thread-header-title(class="#{@product.wip? ? 'is-wip' : ''}")
- if @product.wip?
span.thread-header-title__label
| WIP
span.thread-header-title__title
- if @product.user.daimyo?
| ★
| #{link_to @product.practice.title, @product.practice, class: 'thread-header-title__link'}の提出物

.thread-header__row
.thread-header-actions
.thread-header-actions__start
Expand Down
2 changes: 1 addition & 1 deletion app/views/reports/_report.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
= l report.reported_on
= 'の日報'
- if report.comments.any?
hr.thread-list-item__row-separator
.thread-list-item__row
hr.thread-list-item__row-separator
.thread-list-item-meta
.thread-list-item-meta__items
.thread-list-item-meta__item
Expand Down
23 changes: 23 additions & 0 deletions db/data/20210816082555_add_last_comment_at.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# frozen_string_literal: true

class AddLastCommentAt < ActiveRecord::Migration[6.1]
def up
products = Product.where(self_last_comment_at: nil).where(mentor_last_comment_at: nil)
products.each do |product|
next unless product.comments.size.positive?

product.comments.each do |comment|
if comment.user.mentor
product.mentor_last_comment_at = comment.updated_at
elsif comment.user == product.user
product.self_last_comment_at = comment.updated_at
end
end
product.save!
end
end

def down
raise ActiveRecord::IrreversibleMigration
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddSelfLastCommentAtColumnAndMentorLastCommentAtColumnToProducts < ActiveRecord::Migration[6.1]
def change
add_column :products, :self_last_comment_at, :datetime

add_column :products, :mentor_last_comment_at, :datetime
end
end
2 changes: 2 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@
t.boolean "wip", default: false, null: false
t.datetime "published_at"
t.bigint "checker_id"
t.datetime "self_last_comment_at"
t.datetime "mentor_last_comment_at"
t.index ["practice_id"], name: "index_products_on_practice_id"
t.index ["user_id", "practice_id"], name: "index_products_on_user_id_and_practice_id", unique: true
t.index ["user_id"], name: "index_products_on_user_id"
Expand Down