diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 921cf04de..71dc3f8be 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -53,7 +53,7 @@ function initProtocolsTable() { `; } }, { - 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') diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index 5f4294b8b..6c9f1f48e 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -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 diff --git a/app/models/protocol.rb b/app/models/protocol.rb index 7eb8ecddb..c39c29ba6 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -1,6 +1,9 @@ # frozen_string_literal: true class Protocol < ApplicationRecord + ID_PREFIX = 'PT' + + include PrefixedIdModel include SearchableModel include RenamingUtil include SearchableByNameModel diff --git a/app/views/protocols/index/_protocols_datatable.html.erb b/app/views/protocols/index/_protocols_datatable.html.erb index 59d86ecb2..318116fd2 100644 --- a/app/views/protocols/index/_protocols_datatable.html.erb +++ b/app/views/protocols/index/_protocols_datatable.html.erb @@ -10,6 +10,7 @@ <%= t("protocols.index.thead_name") %> + <%= t("protocols.index.thead_code") %> <%= t("protocols.index.thead_keywords") %> <%= t("protocols.index.thead_nr_of_linked_children") %> <% if @type == :public %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 4b9888408..f8ba036c5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/db/migrate/20221121132449_add_protocol_repository_code_index.rb b/db/migrate/20221121132449_add_protocol_repository_code_index.rb new file mode 100644 index 000000000..6c3129c1f --- /dev/null +++ b/db/migrate/20221121132449_add_protocol_repository_code_index.rb @@ -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