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

メンター向けプラクティスWatch機能の追加 #3402

Merged
merged 4 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
.practice-first-actions
+media-breakpoint-up(md)
display: flex
margin-bottom: 1.5rem
+media-breakpoint-down(sm)
margin-bottom: 1rem

.practice-first-actions__start
flex: 1

.practice-first-actions__end
min-width: 6rem
.is-inactive
background-color: $background-shade
+media-breakpoint-down(sm)
margin-top: .75rem
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
.practice-status-buttons
+media-breakpoint-up(md)
margin-bottom: 1.5rem
+media-breakpoint-down(sm)
margin-bottom: 1rem

.practice-status-buttons__start
text-align: center
width: 100%
Expand Down
1 change: 1 addition & 0 deletions app/models/practice.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class Practice < ApplicationRecord
include Watchable
include Searchable

has_many :learnings, dependent: :destroy
Expand Down
12 changes: 12 additions & 0 deletions app/models/product_callbacks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def after_create(product)

def after_save(product)
if !product.wip? && product.published_at.nil?
notify_to_watching_mentor(product)
if product.user.trainee?
send_notification(
product: product,
Expand Down Expand Up @@ -61,4 +62,15 @@ def create_watch(watchers:, watchable:)
def delete_notification(product)
Notification.where(path: "/products/#{product.id}").destroy_all
end

def notify_to_watching_mentor(product)
practice = Practice.find(product.practice_id)
mentor_ids = practice.watches.where.not(user_id: product.user_id).pluck(:user_id)
mentors = User.where(id: mentor_ids)
send_notification(
product: product,
receivers: mentors,
message: "#{product.user.login_name}さんが#{product.title}を提出しました。"
)
end
end
10 changes: 8 additions & 2 deletions app/views/practices/show.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ header.page-header
#js-annotation-modal
h1.practice-contents__title
= @practice.title
- status = @practice.status_by_learnings(current_user.learnings)
.js-learning-status(data-practice-id="#{@practice.id}" data-status="#{status}" data-submission="#{@practice.submission}")
.practice-first-actions
.practice-first-actions__start
- status = @practice.status_by_learnings(current_user.learnings)
.js-learning-status(data-practice-id="#{@practice.id}" data-status="#{status}" data-submission="#{@practice.submission}")

- if current_user.mentor? && @practice.submission
.practice-first-actions__end.is-only-mentor
#js-watch-toggle(data-watchable-id="#{@practice.id}", data-watchable-type='Practice')

- if @practice.last_updated_user.present?
.practice-contents__pub-date
Expand Down