mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-21 15:36:22 +08:00
Merge pull request #6561 from G-Chubinidze/gc_SCI_9562
Implement Task Due Date Reminder notification [SCI-9562]
This commit is contained in:
commit
08c817299d
11
app/jobs/my_modules/due_date_reminder_job.rb
Normal file
11
app/jobs/my_modules/due_date_reminder_job.rb
Normal file
|
@ -0,0 +1,11 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class DueDateReminderJob < ApplicationJob
|
||||
def perform
|
||||
my_modules = MyModule.approaching_due_dates
|
||||
|
||||
my_modules.each do |task|
|
||||
TaskDueDateNotification.send_notifications({ my_module_id: task.id })
|
||||
end
|
||||
end
|
||||
end
|
|
@ -20,6 +20,7 @@ class MyModule < ApplicationRecord
|
|||
|
||||
before_validation :archiving_and_restoring_extras, on: :update, if: :archived_changed?
|
||||
before_save -> { report_elements.destroy_all }, if: -> { !new_record? && experiment_id_changed? }
|
||||
before_save :reset_due_date_notification_sent, if: -> { due_date_changed? }
|
||||
around_save :exec_status_consequences, if: :my_module_status_id_changed?
|
||||
before_create :create_blank_protocol
|
||||
before_create :assign_default_status_flow
|
||||
|
@ -139,6 +140,11 @@ class MyModule < ApplicationRecord
|
|||
joins(experiment: :project).where(experiment: { projects: { team: teams } })
|
||||
end
|
||||
|
||||
def self.approaching_due_dates
|
||||
where(due_date_notification_sent: false)
|
||||
.where('due_date > ? AND due_date <= ?', DateTime.current, DateTime.current + 1.day)
|
||||
end
|
||||
|
||||
def parent
|
||||
experiment
|
||||
end
|
||||
|
@ -529,6 +535,10 @@ class MyModule < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def reset_due_date_notification_sent
|
||||
self.due_date_notification_sent = false
|
||||
end
|
||||
|
||||
def archiving_and_restoring_extras
|
||||
if archived?
|
||||
# Removes connections with other modules
|
||||
|
|
24
app/notifications/task_due_date_notification.rb
Normal file
24
app/notifications/task_due_date_notification.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class TaskDueDateNotification < BaseNotification
|
||||
def message
|
||||
I18n.t(
|
||||
'notifications.notification.my_module_due_date_reminder_html',
|
||||
my_module_name: subject.name
|
||||
)
|
||||
end
|
||||
|
||||
def self.subtype
|
||||
:my_module_due_date_reminder
|
||||
end
|
||||
|
||||
def title; end
|
||||
|
||||
def subject
|
||||
MyModule.find(params[:my_module_id])
|
||||
end
|
||||
|
||||
after_deliver do
|
||||
MyModule.find(params[:my_module_id]).update(due_date_notification_sent: true)
|
||||
end
|
||||
end
|
|
@ -21,3 +21,7 @@ if ENV['ENABLE_FLUICS_SYNC'] == 'true'
|
|||
LabelPrinters::Fluics::SyncService.new.sync_templates! if LabelPrinter.fluics.any?
|
||||
end
|
||||
end
|
||||
|
||||
scheduler.every '1h' do
|
||||
DueDateReminderJob.perform_now
|
||||
end
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddTaskDueDateReminderNotification < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :my_modules, :due_date_notification_sent, :boolean, default: false
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue