Merge pull request #4633 from G-Chubinidze/gc_SCI_7179

add IDs to the protocol templates tables [SCI-7179]
This commit is contained in:
G-Chubinidze 2022-11-22 14:50:57 +04:00 committed by GitHub
commit 415443a108
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 10 deletions

View file

@ -53,7 +53,7 @@ function initProtocolsTable() {
</div>`;
}
}, {
targets: [ 1, 2, 3, 4, 5 ],
targets: [ 1, 2, 3, 4, 5, 6 ],
searchable: true,
orderable: true
}],
@ -61,13 +61,14 @@ function initProtocolsTable() {
{ data: "0" },
{ data: "1" },
{ data: "2" },
{ data: "3" },
{
data: "3",
data: "4",
visible: repositoryType != "archive"
},
{ data: "4" },
{ data: "5" },
{ data: "6" }
{ data: "6" },
{ data: "7" }
],
oLanguage: {
sSearch: I18n.t('general.filter')

View file

@ -23,6 +23,7 @@ class ProtocolsDatatable < CustomDatatable
def sortable_columns
@sortable_columns ||= [
"Protocol.name",
"Protocol.id",
"protocol_keywords_str",
"Protocol.nr_of_linked_children",
"full_username_str",
@ -34,6 +35,7 @@ class ProtocolsDatatable < CustomDatatable
def searchable_columns
@searchable_columns ||= [
"Protocol.name",
"Protocol.#{Protocol::PREFIXED_ID_SQL}",
timestamp_db_column,
"Protocol.updated_at"
]
@ -56,9 +58,11 @@ class ProtocolsDatatable < CustomDatatable
# now the method checks if the column is the created_at or updated_at and generate a custom SQL to parse
# it back to the caller method
def new_search_condition(column, value)
model, column = column.split('.')
model, column = column.split('.', 2)
model = model.constantize
case column
when Protocol::PREFIXED_ID_SQL
casted_column = ::Arel::Nodes::SqlLiteral.new(Protocol::PREFIXED_ID_SQL)
when 'published_on'
casted_column = ::Arel::Nodes::NamedFunction.new('CAST',
[ Arel.sql("to_char( protocols.created_at, '#{ formated_date }' ) AS VARCHAR") ] )
@ -103,11 +107,12 @@ class ProtocolsDatatable < CustomDatatable
else
name_html(record)
end,
'2': keywords_html(record),
'3': modules_html(record),
'4': escape_input(record.full_username_str),
'5': timestamp_column_html(record),
'6': I18n.l(record.updated_at, format: :full)
'2': escape_input(record.code),
'3': keywords_html(record),
'4': modules_html(record),
'5': escape_input(record.full_username_str),
'6': timestamp_column_html(record),
'7': I18n.l(record.updated_at, format: :full)
}
end
result_data

View file

@ -1,6 +1,9 @@
# frozen_string_literal: true
class Protocol < ApplicationRecord
ID_PREFIX = 'PT'
include PrefixedIdModel
include SearchableModel
include RenamingUtil
include SearchableByNameModel

View file

@ -10,6 +10,7 @@
</div>
</th>
<th id="protocol-name"><%= t("protocols.index.thead_name") %></th>
<th id="protocol-code"><%= t("protocols.index.thead_code") %></th>
<th id="protocol-keywords"><%= t("protocols.index.thead_keywords") %></th>
<th id="protocol-nr-of-linked-children"><%= t("protocols.index.thead_nr_of_linked_children") %></th>
<% if @type == :public %>

View file

@ -2559,6 +2559,7 @@ en:
publish: "Move to Team protocols"
archive_action: "Archive"
thead_name: "Name"
thead_code: "ID"
thead_keywords: "Keywords"
thead_nr_of_linked_children: "No. of linked tasks"
thead_published_by: "Published by"

View file

@ -0,0 +1,14 @@
# frozen_string_literal: true
class AddProtocolRepositoryCodeIndex < ActiveRecord::Migration[6.1]
def up
ActiveRecord::Base.connection.execute(
"CREATE INDEX index_protocol_repository_on_protocol_repository_code ON "\
"protocols using gin (('PT'::text || id) gin_trgm_ops);"
)
end
def down
remove_index :protocols, name: 'index_protocol_repository_on_protocol_repository_code'
end
end