diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index cb5bc8e1f..6b1bdf9a2 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -173,14 +173,19 @@ { data: '2' }, { data: '3' }, { data: '4' }, - { - data: '5', - visible: repositoryType !== 'archived' - }, + { data: '5' }, { data: '6' }, { data: '7' }, { data: '8' }, - { data: '9' } + { data: '9' }, + { + data: '10', + visible: $('.protocols-index').hasClass('archived') + }, + { + data: '11', + visible: $('.protocols-index').hasClass('archived') + } ], oLanguage: { sSearch: I18n.t('general.filter') diff --git a/app/assets/stylesheets/protocols/index.scss b/app/assets/stylesheets/protocols/index.scss index 9a7b32674..d73eb28dd 100644 --- a/app/assets/stylesheets/protocols/index.scss +++ b/app/assets/stylesheets/protocols/index.scss @@ -1,6 +1,13 @@ // scss-lint:disable IdSelector SelectorDepth NestingDepth .protocols-index { + + .title-row { + .fas { + margin-right: 16px; + } + } + .protocols-datatable { --content-header-size: 5em; --protocol-toolbar-size: 4em; @@ -65,6 +72,18 @@ } } } + + &.archived { + .only-active { + display: none; + } + } + + &:not(.archived) { + .only-archive { + display: none; + } + } } #protocol-versions-modal { @@ -76,7 +95,7 @@ .modal-footer { border: 0; } - + .protocol-version-row { border-bottom: 1px solid $color-concrete; padding: 1em 0; diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 074178e02..fc7d3e0ea 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -1038,13 +1038,13 @@ class ProtocolsController < ApplicationController end def permissions - #if stale?(@protocol) + if stale?(@protocol) render json: { copyable: can_clone_protocol_in_repository?(@protocol), archivable: can_manage_protocol_in_repository?(@protocol), restorable: can_restore_protocol_in_repository?(@protocol) } - #end + end end private diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index 75f94101d..53153af6e 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -30,7 +30,8 @@ class ProtocolsDatatable < CustomDatatable 'Protocol.nr_of_linked_children', 'nr_of_assigned_users', 'full_username_str', - timestamp_db_column, + 'Protocol.archived_on', + 'Protocol.published_on', 'Protocol.updated_at' ] end @@ -38,7 +39,8 @@ class ProtocolsDatatable < CustomDatatable def searchable_columns @searchable_columns ||= [ "Protocol.name", - timestamp_db_column, + 'Protocol.archived_on', + 'Protocol.published_on', "Protocol.updated_at" ] end @@ -93,15 +95,17 @@ class ProtocolsDatatable < CustomDatatable DT_RowAttr: { 'data-permissions-url': permissions_protocol_path(record) }, - '1': record.archived? ? escape_input(record.name) : name_html(record), + '1': name_html(record), '2': record.code, '3': versions_html(record), '4': keywords_html(record), '5': modules_html(record), '6': access_html(record), '7': escape_input(record.full_username_str), - '8': timestamp_column_html(record), - '9': I18n.l(record.updated_at, format: :full) + '8': I18n.l(record.published_on || record.created_at, format: :full), + '9': I18n.l(record.updated_at, format: :full), + '10': escape_input(record.archived_full_username_str), + '11': (I18n.l(record.archived_on, format: :full) if record.archived_on) } end end @@ -129,12 +133,11 @@ class ProtocolsDatatable < CustomDatatable .with_granted_permissions(@user, ProtocolPermissions::READ) .preload(user_assignments: %i(user user_role)) - records = - if @type == :archived - records.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."archived_by_id"').archived - else - records.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"').active - end + records = records.joins('LEFT OUTER JOIN "users" "archived_users" + ON "archived_users"."id" = "protocols"."archived_by_id"') + records = records.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"') + + records = @type == :archived ? records.archived : records.active records.group('"protocols"."id"') end @@ -148,20 +151,13 @@ class ProtocolsDatatable < CustomDatatable 'COUNT("protocol_versions"."id") + 1 AS "nr_of_versions"', 'COUNT("protocol_drafts"."id") AS "nr_of_drafts"', 'COUNT("user_assignments"."id") AS "nr_of_assigned_users"', - 'MAX("users"."full_name") AS "full_username_str"' # "Hack" to get single username + 'MAX("users"."full_name") AS "full_username_str"', # "Hack" to get single username + 'MAX("archived_users"."full_name") AS "archived_full_username_str"' ) end # Various helper methods - def timestamp_db_column - if @type == :archived - 'Protocol.archived_on' - else - 'Protocol.published_on' - end - end - def name_html(record) "#{escape_input(record.name)}" end diff --git a/app/permissions/team.rb b/app/permissions/team.rb index 9e14b5e37..a7f70c8be 100644 --- a/app/permissions/team.rb +++ b/app/permissions/team.rb @@ -70,8 +70,7 @@ Canaid::Permissions.register_for(ProjectFolder) do end Canaid::Permissions.register_for(Protocol) do - %i(read_protocol_in_repository - manage_protocol_in_repository + %i(manage_protocol_in_repository manage_protocol_users) .each do |perm| can perm do |_, protocol| diff --git a/app/views/protocols/index.html.erb b/app/views/protocols/index.html.erb index 9bda09041..09097c5b8 100644 --- a/app/views/protocols/index.html.erb +++ b/app/views/protocols/index.html.erb @@ -11,10 +11,17 @@ <% end %> <% provide(:container_class, 'no-second-nav-container') %> -