mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-20 23:16:15 +08:00
Switch to showing of total sum of all versions in protocols table [SCI-8066] (#5082)
This commit is contained in:
parent
1d9785efbe
commit
8956d72f12
|
@ -410,7 +410,7 @@ class ProtocolsController < ApplicationController
|
|||
Protocol.transaction do
|
||||
begin
|
||||
@protocol.unlink
|
||||
rescue Exception
|
||||
rescue StandardError
|
||||
transaction_error = true
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
|
@ -769,9 +769,9 @@ class ProtocolsController < ApplicationController
|
|||
Protocol.transaction do
|
||||
begin
|
||||
protocol = @importer.import_new_protocol(@db_json)
|
||||
rescue Exception
|
||||
rescue StandardError
|
||||
transaction_error = true
|
||||
raise ActiveRecord:: Rollback
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
p_name =
|
||||
|
|
|
@ -30,7 +30,7 @@ class ProtocolsDatatable < CustomDatatable
|
|||
'adjusted_parent_id',
|
||||
'nr_of_versions',
|
||||
'protocol_keywords_str',
|
||||
'nr_of_linked_children',
|
||||
'nr_of_linked_tasks',
|
||||
'nr_of_assigned_users',
|
||||
'full_username_str',
|
||||
'published_on',
|
||||
|
@ -183,6 +183,16 @@ class ProtocolsDatatable < CustomDatatable
|
|||
.joins("LEFT OUTER JOIN protocols protocol_versions " \
|
||||
"ON protocol_versions.protocol_type = #{Protocol.protocol_types[:in_repository_published_version]} " \
|
||||
"AND protocol_versions.parent_id = protocols.parent_id")
|
||||
.joins("LEFT OUTER JOIN protocols self_linked_task_protocols " \
|
||||
"ON self_linked_task_protocols.protocol_type = #{Protocol.protocol_types[:linked]} " \
|
||||
"AND self_linked_task_protocols.parent_id = protocols.id")
|
||||
.joins("LEFT OUTER JOIN protocols parent_linked_task_protocols " \
|
||||
"ON parent_linked_task_protocols.protocol_type = #{Protocol.protocol_types[:linked]} " \
|
||||
"AND parent_linked_task_protocols.parent_id = protocols.parent_id")
|
||||
.joins("LEFT OUTER JOIN protocols version_linked_task_protocols " \
|
||||
"ON version_linked_task_protocols.protocol_type = #{Protocol.protocol_types[:linked]} " \
|
||||
"AND version_linked_task_protocols.parent_id = protocol_versions.id " \
|
||||
"AND version_linked_task_protocols.parent_id != protocols.id")
|
||||
.joins('LEFT OUTER JOIN "protocol_protocol_keywords" ' \
|
||||
'ON "protocol_protocol_keywords"."protocol_id" = "protocols"."id"')
|
||||
.joins('LEFT OUTER JOIN "protocol_keywords" ' \
|
||||
|
@ -197,8 +207,11 @@ class ProtocolsDatatable < CustomDatatable
|
|||
'COALESCE("protocols"."parent_id", "protocols"."id") AS adjusted_parent_id',
|
||||
'STRING_AGG(DISTINCT("protocol_keywords"."name"), \', \') AS "protocol_keywords_str"',
|
||||
"CASE WHEN protocols.protocol_type = #{Protocol.protocol_types[:in_repository_draft]} " \
|
||||
"THEN COUNT(DISTINCT(\"protocol_versions\".\"id\")) ELSE COUNT(DISTINCT(\"protocol_versions\".\"id\")) + 1 " \
|
||||
"THEN 0 ELSE COUNT(DISTINCT(\"protocol_versions\".\"id\")) + 1 " \
|
||||
"END AS nr_of_versions",
|
||||
'(COUNT(DISTINCT("self_linked_task_protocols"."id")) + ' \
|
||||
'COUNT(DISTINCT("parent_linked_task_protocols"."id")) + ' \
|
||||
'COUNT(DISTINCT("version_linked_task_protocols"."id"))) AS nr_of_linked_tasks',
|
||||
'COUNT("user_assignments"."id") AS "nr_of_assigned_users"',
|
||||
'MAX("users"."full_name") AS "full_username_str"', # "Hack" to get single username
|
||||
'MAX("archived_users"."full_name") AS "archived_full_username_str"'
|
||||
|
@ -232,8 +245,8 @@ class ProtocolsDatatable < CustomDatatable
|
|||
|
||||
def modules_html(record)
|
||||
"<a href='#' data-action='load-linked-children'" \
|
||||
"data-url='#{linked_children_protocol_path(record)}'>" \
|
||||
"#{record.nr_of_linked_children}" \
|
||||
"data-url='#{linked_children_protocol_path(record.parent || record)}'>" \
|
||||
"#{record.nr_of_linked_tasks}" \
|
||||
"</a>"
|
||||
end
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ class Protocol < ApplicationRecord
|
|||
class_name: 'User',
|
||||
inverse_of: :published_protocols, optional: true
|
||||
has_many :linked_children,
|
||||
-> { linked },
|
||||
class_name: 'Protocol',
|
||||
foreign_key: 'parent_id'
|
||||
has_one :next_version,
|
||||
|
|
Loading…
Reference in a new issue