mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-10-02 18:04:29 +08:00
Add linked_at to the Protocols [SCI-7964] (#5042)
* Add linked_at to the Protocols [SCI-7964] * Add activity subject_type constrain for migration query [SCI-7964]
This commit is contained in:
parent
f23094602d
commit
b24c823597
3 changed files with 25 additions and 1 deletions
|
@ -538,6 +538,7 @@ class Protocol < ApplicationRecord
|
|||
self.parent_updated_at = source.published_on
|
||||
self.added_by = current_user
|
||||
self.parent = source
|
||||
self.linked_at = Time.zone.now
|
||||
save!
|
||||
end
|
||||
|
||||
|
@ -558,6 +559,7 @@ class Protocol < ApplicationRecord
|
|||
self.parent = source
|
||||
self.parent_updated_at = source.published_on
|
||||
self.added_by = current_user
|
||||
self.linked_at = Time.zone.now
|
||||
self.protocol_type = Protocol.protocol_types[:linked]
|
||||
save!
|
||||
end
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<% if @protocol.linked?%>
|
||||
<div class="info-line">
|
||||
<div class="description"><%= t("my_modules.protocols.protocol_status_bar.protocol_loaded") %></div>
|
||||
<div class="value"></div>
|
||||
<div class="value"><%= @protocol.linked_at ? I18n.l(@protocol.linked_at, format: :full) : '' %></div>
|
||||
</div>
|
||||
<div class="info-line">
|
||||
<div class="description"><%= t("my_modules.protocols.protocol_status_bar.protocol_published") %></div>
|
||||
|
|
22
db/migrate/20230227131215_add_linked_at_to_table.rb
Normal file
22
db/migrate/20230227131215_add_linked_at_to_table.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AddLinkedAtToTable < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
add_column :protocols, :linked_at, :datetime
|
||||
|
||||
execute(
|
||||
'UPDATE protocols
|
||||
SET linked_at = act.activities_created_at
|
||||
FROM (SELECT MAX(activities.created_at) AS activities_created_at, MAX(activities.subject_id) AS subject_id
|
||||
FROM protocols
|
||||
LEFT JOIN activities ON activities.subject_id = protocols.id AND activities.subject_type=\'Protocol\'
|
||||
WHERE protocols.protocol_type = 1 AND activities.type_of = 46
|
||||
GROUP BY protocols.id) as act
|
||||
WHERE id = act.subject_id'
|
||||
)
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :protocols, :linked_at
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue