Skip to content

Commit

Permalink
Merge pull request #796 from fjordllc/feature/#782
Browse files Browse the repository at this point in the history
ユーザー個別のコメント一覧で提出物のタイトルを出す
  • Loading branch information
machida authored Feb 13, 2019
2 parents 316fd80 + fe63a49 commit 1480dc3
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 18 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ gem "rails-i18n"
gem "google-cloud-storage", "~> 1.3", require: false
gem "mini_magick"
gem "activestorage-validator"
gem "commonmarker"

group :production, :staging do
gem "newrelic_rpm"
Expand Down
5 changes: 5 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
commonmarker (0.18.2)
ruby-enum (~> 0.5)
concurrent-ruby (1.1.4)
crass (1.0.4)
curb (0.8.8)
Expand Down Expand Up @@ -274,6 +276,8 @@ GEM
retriable (3.1.2)
rollbar (2.18.0)
multi_json
ruby-enum (0.7.2)
i18n
ruby-graphviz (1.2.3)
ruby_dep (1.5.0)
rubyzip (1.2.2)
Expand Down Expand Up @@ -381,6 +385,7 @@ DEPENDENCIES
chromedriver-helper
cocoon
coffee-rails (~> 4.2)
commonmarker
curb (~> 0.8.8)
diffy
dynamic_form
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/blocks/thread/_thread-list-item.sass
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
display: flex
align-items: center
margin-bottom: .125rem
justify-content: space-between
+media-breakpoint-down(sm)
flex-direction: column
align-items: flex-start
Expand Down Expand Up @@ -119,7 +120,7 @@
+text-block(.75rem 1.4, block $muted-text inline-block)

.thread-list-item__body
+text-block(.875rem 1.8)
+text-block(.875rem 1.6)

.thread-list-item-meta__created-at
+text-block(.75rem 1.4, $muted-text)
12 changes: 8 additions & 4 deletions app/helpers/comments_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ def user_comments_page?
controller_path == "users/comments" && action_name == "index"
end

def comment_title(commentable)
if commentable.is_a?(Report)
commentable.title
end
def md2html(text)
html = CommonMarker.render_html(text)
raw(html)
end

def comment_summury(comment, word_count)
summury = strip_tags(md2html(comment)).gsub(/[\r\n]/, "")
simple_format(truncate(summury, length: word_count))
end
end
3 changes: 2 additions & 1 deletion app/views/comments/_comment.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
header.thread-comment__body-header
- if user_comments_page?
h2.thread-comment__title.is-user-comments
= t("activerecord.models.#{commentable.class.to_s.tableize.singularize}")
= link_to commentable, class: "thread-comment__title-link" do
= image_tag commentable.user.avatar.variant(resize: "40x40"), class: "thread-comment__title-icon"
= truncate(comment_title(commentable), length: 50)
= truncate(commentable.title, length: 50)
- else
h2.thread-comment__title
= link_to comment.user, itempro: "url", class: "thread-comment__title-link" do
Expand Down
2 changes: 1 addition & 1 deletion app/views/searchables/_searchable.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
.thread-list-item__title
= link_to searchable.title, searchable, class: "thread-list-item__title-link"
.thread-list-item__body
p = truncate searchable.description, length: 50
= comment_summury(searchable.description, 90)
19 changes: 19 additions & 0 deletions app/views/users/comments/_comment.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
- commentable = comment.commentable
.thread-list-item(class="is-#{commentable.class.to_s.tableize.singularize}")
.thread-list-item__inner
.thread-list-item__label
= t("activerecord.models.#{commentable.class.to_s.tableize.singularize}")
header.thread-list-item__header
- if user_comments_page?
h2.thread-list-item__title
= link_to commentable, class: "thread-list-item__title-link" do
= image_tag commentable.user.avatar.variant(resize: "40x40"), class: "thread-comment__title-icon"
= truncate(commentable.title, length: 50)
- else
h2.thread-list-item__title
= link_to comment.user, itempro: "url", class: "thread-list-item__title-link" do
= comment.user.login_name
time.thread-comment__created-at(datetime="#{commentable.created_at.to_datetime}" pubdate="pubdate")
= l comment.updated_at
.thread-list-item__body
= comment_summury(comment.description, 90)
3 changes: 3 additions & 0 deletions app/views/users/comments/_comments.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.thread-comments-container
.thread-comments
= render partial: "comment", collection: comments.order(:created_at), as: :comment
3 changes: 2 additions & 1 deletion app/views/users/comments/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ header.page-header
.page-body
.container
= paginate @comments, position: "top"
= render "comments/comments", comments: @comments
.thread-list.a-card
= render "comments", comments: @comments
= paginate @comments, position: "bottom"
3 changes: 0 additions & 3 deletions app/views/users/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,3 @@ header.page-header
- if @user.github_account
.a-card
= render "users/github_grass", user: @user
- if @user.admin?
.a-card
= render "users/unchecked"
2 changes: 1 addition & 1 deletion test/system/page_tabs_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ class PageTabsTest < ApplicationSystemTestCase
assert_equal 1, all(".page-tabs__item-link.is-active").length
assert_equal "コメント", first(".page-tabs__item-link.is-active").text
expected_comment_counts = User.find(user_id).comments.where(commentable_type: "Report").size
actual_comment_counts = all(".thread-comment__title-link").size
actual_comment_counts = all(".thread-list-item__title-link").size
assert_equal expected_comment_counts, actual_comment_counts
end

Expand Down
6 changes: 0 additions & 6 deletions test/system/users_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,6 @@ class UsersTest < ApplicationSystemTestCase
assert_text "kensyu"
end

test "admin user can see unchecked number table" do
login_user "komagata", "testtest"
visit "/users/#{users(:komagata).id}"
assert_equal 1, all(".admin-table").length
end

test "nomal user can't see unchecked number table" do
login_user "hatsuno", "testtest"
visit "/users/#{users(:hatsuno).id}"
Expand Down

0 comments on commit 1480dc3

Please sign in to comment.