mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-04-02 10:20:51 +08:00
add IDs to the protocol templates tables [SCI-7179]
This commit is contained in:
parent
f65c207e75
commit
43f8370a08
6 changed files with 35 additions and 10 deletions
app
assets/javascripts/protocols
datatables
models
views/protocols/index
config/locales
db/migrate
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class Protocol < ApplicationRecord
|
||||
ID_PREFIX = 'PT'
|
||||
|
||||
include PrefixedIdModel
|
||||
include SearchableModel
|
||||
include RenamingUtil
|
||||
include SearchableByNameModel
|
||||
|
|
|
@ -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 %>
|
||||
|
|
|
@ -2558,6 +2558,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"
|
||||
|
|
|
@ -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
|
Loading…
Add table
Reference in a new issue