Skip to content

Commit

Permalink
Merge pull request #6404 from fjordllc/main
Browse files Browse the repository at this point in the history
Release 2023-04-13 06:25:02
  • Loading branch information
komagata authored Apr 13, 2023
2 parents 02b7f38 + 3294a89 commit 872c9ef
Show file tree
Hide file tree
Showing 53 changed files with 397 additions and 191 deletions.
10 changes: 5 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ GEM
childprocess (4.1.0)
cocoon (1.2.15)
coderay (1.1.3)
commonmarker (0.23.7)
commonmarker (0.23.9)
concurrent-ruby (1.1.10)
connection_pool (2.3.0)
crack (0.4.5)
Expand Down Expand Up @@ -288,7 +288,7 @@ GEM
mime-types-data (3.2022.0105)
mini_magick (4.11.0)
mini_mime (1.1.2)
mini_portile2 (2.8.0)
mini_portile2 (2.8.1)
minitest (5.17.0)
minitest-ci (3.4.0)
minitest (>= 5.0.6)
Expand All @@ -308,10 +308,10 @@ GEM
netrc (0.11.0)
newspaper (0.2.0)
nio4r (2.5.8)
nokogiri (1.13.10)
nokogiri (1.14.3)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
nokogiri (1.13.10-x86_64-darwin)
nokogiri (1.14.3-x86_64-darwin)
racc (~> 1.4)
oauth (0.6.2)
snaky_hash (~> 2.0)
Expand Down Expand Up @@ -362,7 +362,7 @@ GEM
puma (6.0.0)
nio4r (~> 2.0)
raabro (1.4.0)
racc (1.6.1)
racc (1.6.2)
rack (2.2.6.4)
rack-cors (1.1.1)
rack (>= 2.0.0)
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/api/admin/count_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def show
mentor: false,
adviser: false,
retired_on: nil,
graduated_on: nil
graduated_on: nil,
hibernated_at: nil
).count

render json: { users_count: users_count }
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/api/footprints_controller.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# frozen_string_literal: true

class API::FootprintsController < API::BaseController
before_action :footprintable, only: %i[index]

def index
if params[:footprintable_type].present?
footprintable.footprints.create_or_find_by(user: current_user) if footprintable.user != current_user
@footprints = footprintable.footprints.with_avatar.order(created_at: :desc)
if @footprintable.present?
@footprintable.footprints.create_or_find_by(user: current_user) if @footprintable.user != current_user
@footprints = @footprintable.footprints.with_avatar.order(created_at: :desc)
@footprint_total_count = @footprints.size
else
head :bad_request
Expand All @@ -14,6 +16,10 @@ def index
private

def footprintable
params[:footprintable_type].constantize.find(params[:footprintable_id])
@footprintable = if params[:footprintable_type].nil?
nil
else
params[:footprintable_type].constantize.find_by(id: params[:footprintable_id])
end
end
end
6 changes: 3 additions & 3 deletions app/controllers/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def create
set_wip
canonicalize_learning_times(@report)
if @report.save
Newspaper.publish(:report_create, @report.user)
Newspaper.publish(:report_save, @report)
redirect_to redirect_url(@report), notice: notice_message(@report), flash: flash_contents(@report)
else
render :new
Expand All @@ -64,7 +64,7 @@ def update
@report.assign_attributes(report_params)
canonicalize_learning_times(@report)
if @report.save
Newspaper.publish(:report_update, @report.user)
Newspaper.publish(:report_save, @report)
redirect_to redirect_url(@report), notice: notice_message(@report), flash: flash_contents(@report)
else
render :edit
Expand All @@ -73,7 +73,7 @@ def update

def destroy
@report.destroy
Newspaper.publish(:report_destroy, @report.user)
Newspaper.publish(:report_destroy, @report)
redirect_to reports_url, notice: '日報を削除しました。'
end

Expand Down
2 changes: 2 additions & 0 deletions app/javascript/VueMounter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue'
import store from './check-store.js'

export default class VueMounter {
constructor() {
Expand All @@ -20,6 +21,7 @@ export default class VueMounter {
const component = this.components[name]

new Vue({
store,
render: (h) => h(component, { props: props })
}).$mount(`[data-vue="${name}"]`)
})
Expand Down
3 changes: 3 additions & 0 deletions app/javascript/answers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ export default {
this.resizeTextarea()
this.updateAnswerCount()
this.toast('回答を投稿しました!')
this.$store.dispatch('setWatchable', {
watchableUserId: this.currentUser.id
})
})
.catch((error) => {
console.warn(error)
Expand Down
20 changes: 18 additions & 2 deletions app/javascript/check-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ export default new Vuex.Store({
checkableId: null,
checkableType: null,
productId: null,
productCheckerId: null
productCheckerId: null,
watchableUserId: null
},
getters: {
checkId: (state) => state.checkId,
Expand All @@ -20,7 +21,8 @@ export default new Vuex.Store({
checkableId: (state) => state.checkableId,
checkableType: (state) => state.checkableType,
productId: (state) => state.productId,
productCheckerId: (state) => state.productCheckerId
productCheckerId: (state) => state.productCheckerId,
watchableUserId: (state) => state.watchableUserId
},
mutations: {
setCheckable(
Expand All @@ -36,6 +38,9 @@ export default new Vuex.Store({
setProduct(state, { productId, productCheckerId }) {
state.productId = productId
state.productCheckerId = productCheckerId
},
setWatchable(state, { watchableUserId }) {
state.watchableUserId = watchableUserId
}
},
actions: {
Expand Down Expand Up @@ -107,6 +112,17 @@ export default new Vuex.Store({
.catch((error) => {
console.warn(error)
})
},
setWatchable({ commit }, { watchableUserId }) {
if (watchableUserId) {
commit('setWatchable', {
watchableUserId: watchableUserId
})
} else {
commit('setWatchable', {
watchableUserId: null
})
}
}
}
})
3 changes: 3 additions & 0 deletions app/javascript/comments.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,9 @@ export default {
},
postComment() {
this.createComment()
this.$store.dispatch('setWatchable', {
watchableUserId: this.currentUserId
})
if (this.isUnassignedAndUnchekedProduct) {
this.checkProduct(
this.commentableId,
Expand Down
28 changes: 22 additions & 6 deletions app/javascript/components/watch-toggle.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template lang="pug">
#watch-button.a-watch-button.a-button.is-sm.is-block(
:class='watchId ? "is-active is-main" : "is-inactive is-muted"',
:class='watchId || watchableUserId ? "is-active is-main" : "is-inactive is-muted"',
@click='buttonClick')
| {{ watchLabel }}
</template>
Expand All @@ -20,18 +20,28 @@ export default {
data() {
return {
watchId: null,
watchLabel: 'Watch',
totalPages: 0,
watchValue: null
}
},
computed: {
watchableUserId() {
return this.$store.getters.watchableUserId
},
watchLabel() {
if (this.checked) {
return '削除'
} else {
return this.watchableUserId ? 'Watch中' : 'Watch'
}
}
},
mounted() {
const params = new URL(location.href).searchParams
params.set('watchable_type', this.watchableType)
params.set('watchable_id', this.watchableId)
if (this.checked) {
this.watchId = this.watchIndexId
this.watchLabel = '削除'
} else {
fetch(`/api/watches/toggle.json?${params}`, {
method: 'GET',
Expand All @@ -47,7 +57,9 @@ export default {
.then((json) => {
if (json[0]) {
this.watchId = json[0].id
this.watchLabel = 'Watch中'
this.$store.dispatch('setWatchable', {
watchableUserId: json[0].user_id
})
}
})
.catch((error) => {
Expand Down Expand Up @@ -88,8 +100,10 @@ export default {
})
.then((json) => {
this.watchId = json.id
this.watchLabel = 'Watch中'
this.toast('Watchしました!')
this.$store.dispatch('setWatchable', {
watchableUserId: json.user_id
})
})
.catch((error) => {
console.warn(error)
Expand All @@ -108,8 +122,10 @@ export default {
})
.then(() => {
this.watchId = null
this.watchLabel = 'Watch'
this.toast('Watchを外しました')
this.$store.dispatch('setWatchable', {
watchableUserId: null
})
})
.then(() => {
this.$emit('update-index')
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/stylesheets/application.sass
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8"

@import common-imports

@import application/blocks/admin/admin-table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@
.user-statuses__item
flex: 1
max-width: calc(50% - .75rem)

.user-statuses__delete
display: flex
justify-content: flex-end
margin-top: .75rem
+text-block(.8125rem 1.4)
4 changes: 4 additions & 0 deletions app/javascript/stylesheets/atoms/_a-text-link.sass
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
.a-reversal-text-link
+hover-link-reversal
+reversal-link

.a-muted-text-link
+hover-link-reversal
+muted-link
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
margin-top: 0
*:not(ol):not(ul):last-child
margin-bottom: 0
blockquote
margin-left: calc(.75em + 1px)
blockquote + ul
margin-top: -2em
code
+text-block(.875em 1.7, $default-text inline-flex)
align-items: center
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/stylesheets/not-logged-in.sass
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8"

@import common-imports

@import not-logged-in/not-logged-in-wrapper
Expand Down
2 changes: 2 additions & 0 deletions app/javascript/stylesheets/welcome.sass
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@charset "UTF-8"

@import common-imports

@import welcome/articles/article
Expand Down
22 changes: 22 additions & 0 deletions app/mailers/activity_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ActivityMailer < ApplicationMailer
@question = params[:question] if params&.key?(:question)
@mentionable = params[:mentionable] if params&.key?(:mentionable)
@page = params[:page] if params&.key?(:page)
@watchable = params[:watchable] if params&.key?(:watchable)
@comment = params[:comment] if params&.key?(:comment)
end

# required params: sender, receiver
Expand Down Expand Up @@ -212,4 +214,24 @@ def following_report(args = {})

message
end

# required params: sender, comment, watchable, receiver
def watching_notification(args = {})
@receiver ||= args[:receiver]
@sender ||= args[:sender]
@comment ||= args[:comment]
@watchable ||= args[:watchable]

@user = @receiver
@link_url = notification_redirector_url(
link: @watchable.path,
kind: Notification.kinds[:watched]
)
@action = @watchable.instance_of?(Question) ? '回答' : 'コメント'
subject = "[FBC] #{@watchable.user.login_name}さんの【 #{@watchable.notification_title} 】に#{@sender.login_name}さんが#{@action}しました。"

message = mail to: @user.email, subject: subject
message.perform_deliveries = @user.mail_notification? && !@user.retired?
message
end
end
12 changes: 0 additions & 12 deletions app/mailers/notification_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class NotificationMailer < ApplicationMailer # rubocop:disable Metrics/ClassLeng
@announcement = params[:announcement]
@question = params[:question]
@report = params[:report]
@watchable = params[:watchable]
@sender = params[:sender]
@event = params[:event]
@page = params[:page]
Expand Down Expand Up @@ -54,17 +53,6 @@ def first_report
subject: "[FBC] #{@report.user.login_name}さんがはじめての日報を書きました!"
end

# required params: watchable, receiver
def watching_notification
@sender = @watchable.user
@user = @receiver
link = "/#{@watchable.class.name.underscore.pluralize}/#{@watchable.id}"
@notification = @user.notifications.find_by(link: link)
action = @watchable.instance_of?(Question) ? '回答' : 'コメント'
subject = "[FBC] #{@sender.login_name}さんの【 #{@watchable.notification_title} 】に#{@comment.user.login_name}さんが#{action}しました。"
mail to: @user.email, subject: subject
end

# required params: sender, receiver
def retired
@user = @receiver
Expand Down
2 changes: 1 addition & 1 deletion app/models/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Comment < ApplicationRecord

belongs_to :user, touch: true
belongs_to :commentable, polymorphic: true
after_create Comment::AfterCreateCallback.new
after_commit Comment::AfterCreateCallback.new
after_update Comment::AfterUpdateCallback.new
after_destroy Comment::AfterDestroyCallback.new
alias sender user
Expand Down
Loading

0 comments on commit 872c9ef

Please sign in to comment.