mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-14 02:13:24 +08:00
Merge pull request #6745 from ivanscinote/SCI-9561-implement-repository-date-reminder-notification
Add job for RepositoryDateValue, fix translation [SCI-9561]
This commit is contained in:
commit
b1b8059e41
2 changed files with 44 additions and 9 deletions
|
|
@ -4,15 +4,23 @@ class RepositoryItemDateReminderJob < ApplicationJob
|
||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
RepositoryDateTimeValue
|
process_repository_values(RepositoryDateTimeValue, DateTime.current)
|
||||||
|
process_repository_values(RepositoryDateValue, Date.current)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def process_repository_values(model, comparison_value)
|
||||||
|
model
|
||||||
.where(notification_sent: false)
|
.where(notification_sent: false)
|
||||||
.where('data <= ?', DateTime.current)
|
.where('data <= ?', comparison_value)
|
||||||
.joins(repository_cell: { repository_column: :repository })
|
.joins(repository_cell: { repository_column: :repository })
|
||||||
.where(repositories: { type: 'Repository' })
|
.where(repositories: { type: 'Repository' })
|
||||||
.find_each do |date_time_value|
|
.find_each do |value|
|
||||||
RepositoryItemDateNotification
|
RepositoryItemDateNotification
|
||||||
.send_notifications({ date_time_value_id: date_time_value.id,
|
.send_notifications({ "#{value.class.name.underscore}_id": value.id,
|
||||||
repository_row_id: date_time_value.repository_cell.repository_row_id })
|
repository_row_id: value.repository_cell.repository_row_id,
|
||||||
|
repository_column_id: value.repository_cell.repository_column_id })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,12 @@
|
||||||
|
|
||||||
class RepositoryItemDateNotification < BaseNotification
|
class RepositoryItemDateNotification < BaseNotification
|
||||||
def message
|
def message
|
||||||
|
unit = human_readable_unit(column.metadata['reminder_unit'], column.metadata['reminder_value'])
|
||||||
I18n.t(
|
I18n.t(
|
||||||
'notifications.notification.item_date_reminder_html',
|
'notifications.notification.item_date_reminder_html',
|
||||||
repository_row_name: subject.name
|
repository_row_name: subject.name,
|
||||||
|
value: column.metadata['reminder_value'],
|
||||||
|
units: unit
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -18,7 +21,31 @@ class RepositoryItemDateNotification < BaseNotification
|
||||||
RepositoryRow.find(params[:repository_row_id])
|
RepositoryRow.find(params[:repository_row_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def column
|
||||||
|
RepositoryColumn.find(params[:repository_column_id])
|
||||||
|
end
|
||||||
|
|
||||||
after_deliver do
|
after_deliver do
|
||||||
RepositoryDateTimeValue.find(params[:date_time_value_id]).update(notification_sent: true)
|
if params[:repository_date_time_value_id]
|
||||||
|
RepositoryDateTimeValue.find(params[:repository_date_time_value_id]).update(notification_sent: true)
|
||||||
|
elsif params[:repository_date_value_id]
|
||||||
|
RepositoryDateVal7ue.find(params[:repository_date_value_id]).update(notification_sent: true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def human_readable_unit(seconds, value)
|
||||||
|
units_hash = {
|
||||||
|
'2419200' => 'month',
|
||||||
|
'604800' => 'week',
|
||||||
|
'86400' => 'day'
|
||||||
|
}
|
||||||
|
|
||||||
|
base_unit = units_hash.fetch(seconds) do
|
||||||
|
raise ArgumentError, "Unrecognized time unit for seconds value: #{seconds}"
|
||||||
|
end
|
||||||
|
|
||||||
|
value.to_i > 1 ? base_unit.pluralize : base_unit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue