mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-03-28 07:51:35 +08:00
Fix multiple inventory reminders issues [SCI-7805][SCI-7808][SCI-7809] (#4876)
This commit is contained in:
parent
913cd26e70
commit
b3267d7934
4 changed files with 21 additions and 12 deletions
|
@ -14,7 +14,6 @@ module RepositoryDatatableHelper
|
|||
DT_RowId: record.id,
|
||||
DT_RowAttr: { 'data-state': row_style(record) },
|
||||
recordInfoUrl: Rails.application.routes.url_helpers.repository_repository_row_path(repository, record),
|
||||
hasActiveReminders: record.has_active_stock_reminders || record.has_active_datetime_reminders,
|
||||
rowRemindersUrl:
|
||||
Rails.application.routes.url_helpers
|
||||
.active_reminder_repository_cells_repository_repository_row_url(
|
||||
|
@ -23,6 +22,10 @@ module RepositoryDatatableHelper
|
|||
)
|
||||
)
|
||||
|
||||
if reminders_enabled
|
||||
row['hasActiveReminders'] = record.has_active_stock_reminders || record.has_active_datetime_reminders
|
||||
end
|
||||
|
||||
if has_stock_management
|
||||
row['manageStockUrl'] = if record.has_stock?
|
||||
Rails.application.routes.url_helpers
|
||||
|
@ -108,7 +111,6 @@ module RepositoryDatatableHelper
|
|||
DT_RowAttr: { 'data-state': row_style(record) },
|
||||
'0': escape_input(record.name),
|
||||
recordInfoUrl: Rails.application.routes.url_helpers.repository_repository_row_path(record.repository, record),
|
||||
hasActiveReminders: record.has_active_stock_reminders || record.has_active_datetime_reminders,
|
||||
rowRemindersUrl:
|
||||
Rails.application.routes.url_helpers
|
||||
.active_reminder_repository_cells_repository_repository_row_url(
|
||||
|
@ -117,6 +119,10 @@ module RepositoryDatatableHelper
|
|||
)
|
||||
}
|
||||
|
||||
if reminders_enabled
|
||||
row['hasActiveReminders'] = record.has_active_stock_reminders || record.has_active_datetime_reminders
|
||||
end
|
||||
|
||||
if has_stock_management
|
||||
stock_present = record.repository_stock_cell.present?
|
||||
# Always disabled in a simple view
|
||||
|
@ -276,11 +282,11 @@ module RepositoryDatatableHelper
|
|||
end
|
||||
|
||||
def with_reminders_status(repository_rows, repository)
|
||||
# don't load reminders for archived repositories
|
||||
return repository_rows if repository.archived?
|
||||
|
||||
# don't load reminders for snapshots
|
||||
return repository_rows if repository.is_a?(RepositorySnapshot)
|
||||
# don't load reminders for archived repositories or snapshots
|
||||
if repository.archived? || repository.is_a?(RepositorySnapshot)
|
||||
return repository_rows.select('FALSE AS has_active_stock_reminders')
|
||||
.select('FALSE AS has_active_datetime_reminders')
|
||||
end
|
||||
|
||||
repository_cells = RepositoryCell.joins(
|
||||
"INNER JOIN repository_columns ON repository_columns.id = repository_cells.repository_column_id " \
|
||||
|
|
|
@ -5,13 +5,16 @@ module ReminderRepositoryCellJoinable
|
|||
|
||||
included do
|
||||
def self.reminder_repository_cells_scope(relation, user)
|
||||
relation.joins( # datetime reminders
|
||||
relation.joins(
|
||||
'INNER JOIN repository_columns repository_reminder_columns ON ' \
|
||||
'repository_reminder_columns.id = repository_cells.repository_column_id'
|
||||
).joins( # datetime reminders
|
||||
'LEFT OUTER JOIN "repository_date_time_values" ON '\
|
||||
'"repository_date_time_values"."id" = "repository_cells"."value_id" AND '\
|
||||
'"repository_cells"."value_type" = \'RepositoryDateTimeValueBase\' '\
|
||||
'AND repository_columns.metadata ->> \'reminder_delta\' <> \'\' AND '\
|
||||
'AND repository_reminder_columns.metadata ->> \'reminder_delta\' <> \'\' AND '\
|
||||
'(repository_date_time_values.data - NOW()) <= '\
|
||||
'(repository_columns.metadata ->> \'reminder_delta\')::int * interval \'1 sec\''
|
||||
'(repository_reminder_columns.metadata ->> \'reminder_delta\')::int * interval \'1 sec\''
|
||||
).joins( # stock reminders
|
||||
'LEFT OUTER JOIN "repository_stock_values" ON '\
|
||||
'"repository_cells"."value_type" = \'RepositoryStockValue\' AND '\
|
||||
|
|
|
@ -46,7 +46,7 @@ class RepositoryCell < ApplicationRecord
|
|||
unless: :importing
|
||||
|
||||
scope :with_active_reminder, lambda { |user|
|
||||
reminder_repository_cells_scope(joins(:repository_column), user)
|
||||
reminder_repository_cells_scope(self, user)
|
||||
}
|
||||
|
||||
def self.create_with_value!(row, column, data, user)
|
||||
|
|
|
@ -88,7 +88,7 @@ class RepositoryRow < ApplicationRecord
|
|||
scope :archived, -> { where(archived: true) }
|
||||
|
||||
scope :with_active_reminders, lambda { |user|
|
||||
reminder_repository_cells_scope(joins(repository_cells: :repository_column), user)
|
||||
reminder_repository_cells_scope(joins(:repository_cells), user)
|
||||
}
|
||||
|
||||
def code
|
||||
|
|
Loading…
Add table
Reference in a new issue