mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-12 08:04:34 +08:00
Make Date/Date&Time and Low Stock notifications work when deleting Repository/row record [SCI-9825]
This commit is contained in:
parent
58acbcaecf
commit
41c5ecf1d8
6 changed files with 43 additions and 7 deletions
|
@ -21,10 +21,19 @@ class RepositoryItemDateReminderJob < ApplicationJob
|
||||||
"(repository_columns.metadata->>'reminder_value')::int) || ' seconds' AS Interval))",
|
"(repository_columns.metadata->>'reminder_value')::int) || ' seconds' AS Interval))",
|
||||||
comparison_value
|
comparison_value
|
||||||
).find_each do |value|
|
).find_each do |value|
|
||||||
|
repository_row = RepositoryRow.find(value.repository_cell.repository_row_id)
|
||||||
|
repository_column = RepositoryColumn.find(value.repository_cell.repository_column_id)
|
||||||
|
|
||||||
RepositoryItemDateNotification
|
RepositoryItemDateNotification
|
||||||
.send_notifications({ "#{value.class.name.underscore}_id": value.id,
|
.send_notifications({
|
||||||
repository_row_id: value.repository_cell.repository_row_id,
|
"#{value.class.name.underscore}_id": value.id,
|
||||||
repository_column_id: value.repository_cell.repository_column_id })
|
repository_row_id: repository_row.id,
|
||||||
|
repository_row_name: repository_row.name,
|
||||||
|
repository_column_id: repository_column.id,
|
||||||
|
repository_column_name: repository_column.name,
|
||||||
|
reminder_unit: repository_column.metadata['reminder_unit'],
|
||||||
|
reminder_value: repository_column.metadata['reminder_value']
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
9
app/models/non_existant_record.rb
Normal file
9
app/models/non_existant_record.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class NonExistantRecord
|
||||||
|
attr_reader :name
|
||||||
|
|
||||||
|
def initialize(name)
|
||||||
|
@name = name
|
||||||
|
end
|
||||||
|
end
|
|
@ -203,6 +203,14 @@ class RepositoryStockValue < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_low_stock_notification
|
def send_low_stock_notification
|
||||||
LowStockNotification.send_notifications({ repository_row_id: repository_cell.repository_row_id })
|
repository_row = RepositoryRow.find(repository_cell.repository_row_id)
|
||||||
|
repository = Repository.find(repository_row.repository_id)
|
||||||
|
|
||||||
|
LowStockNotification.send_notifications({
|
||||||
|
repository_row_id: repository_cell.repository_row_id,
|
||||||
|
repository_row_name: repository_row.name,
|
||||||
|
repository_id: repository_row.repository_id,
|
||||||
|
repository_name: repository.name
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,9 +19,13 @@ class LowStockNotification < BaseNotification
|
||||||
|
|
||||||
def subject
|
def subject
|
||||||
RepositoryRow.find(params[:repository_row_id])
|
RepositoryRow.find(params[:repository_row_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
NonExistantRecord.new(params[:repository_row_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
def repository
|
def repository
|
||||||
Repository.find(subject.repository_id)
|
Repository.find(params[:repository_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
NonExistantRecord.new(params[:repository_name])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
class RepositoryItemDateNotification < BaseNotification
|
class RepositoryItemDateNotification < BaseNotification
|
||||||
def message
|
def message
|
||||||
unit = human_readable_unit(column.metadata['reminder_unit'], column.metadata['reminder_value'])
|
unit = human_readable_unit(params[:reminder_unit], params[:reminder_value])
|
||||||
I18n.t(
|
I18n.t(
|
||||||
'notifications.content.item_date_reminder.message_html',
|
'notifications.content.item_date_reminder.message_html',
|
||||||
repository_row_name: subject.name,
|
repository_row_name: subject.name,
|
||||||
value: column.metadata['reminder_value'],
|
value: params[:reminder_value],
|
||||||
units: unit
|
units: unit
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -21,10 +21,14 @@ class RepositoryItemDateNotification < BaseNotification
|
||||||
|
|
||||||
def subject
|
def subject
|
||||||
RepositoryRow.find(params[:repository_row_id])
|
RepositoryRow.find(params[:repository_row_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
NonExistantRecord.new(params[:repository_row_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
def column
|
def column
|
||||||
RepositoryColumn.find(params[:repository_column_id])
|
RepositoryColumn.find(params[:repository_column_id])
|
||||||
|
rescue ActiveRecord::RecordNotFound
|
||||||
|
NonExistantRecord.new(params[:repository_column_name])
|
||||||
end
|
end
|
||||||
|
|
||||||
after_deliver do
|
after_deliver do
|
||||||
|
|
|
@ -33,6 +33,8 @@ class NotificationSerializer < ActiveModel::Serializer
|
||||||
private
|
private
|
||||||
|
|
||||||
def generate_breadcrumbs(subject, breadcrumbs)
|
def generate_breadcrumbs(subject, breadcrumbs)
|
||||||
|
return [] if subject.is_a?(NonExistantRecord)
|
||||||
|
|
||||||
case subject
|
case subject
|
||||||
when Project
|
when Project
|
||||||
parent = subject.team
|
parent = subject.team
|
||||||
|
|
Loading…
Add table
Reference in a new issue