Add archive view for protocols template

This commit is contained in:
Anton 2023-01-24 21:17:50 +01:00
parent a72de2800f
commit 1a0b28c74e
11 changed files with 69 additions and 43 deletions

View file

@ -173,14 +173,19 @@
{ data: '2' }, { data: '2' },
{ data: '3' }, { data: '3' },
{ data: '4' }, { data: '4' },
{ { data: '5' },
data: '5',
visible: repositoryType !== 'archived'
},
{ data: '6' }, { data: '6' },
{ data: '7' }, { data: '7' },
{ data: '8' }, { data: '8' },
{ data: '9' } { data: '9' },
{
data: '10',
visible: $('.protocols-index').hasClass('archived')
},
{
data: '11',
visible: $('.protocols-index').hasClass('archived')
}
], ],
oLanguage: { oLanguage: {
sSearch: I18n.t('general.filter') sSearch: I18n.t('general.filter')

View file

@ -1,6 +1,13 @@
// scss-lint:disable IdSelector SelectorDepth NestingDepth // scss-lint:disable IdSelector SelectorDepth NestingDepth
.protocols-index { .protocols-index {
.title-row {
.fas {
margin-right: 16px;
}
}
.protocols-datatable { .protocols-datatable {
--content-header-size: 5em; --content-header-size: 5em;
--protocol-toolbar-size: 4em; --protocol-toolbar-size: 4em;
@ -65,6 +72,18 @@
} }
} }
} }
&.archived {
.only-active {
display: none;
}
}
&:not(.archived) {
.only-archive {
display: none;
}
}
} }
#protocol-versions-modal { #protocol-versions-modal {
@ -76,7 +95,7 @@
.modal-footer { .modal-footer {
border: 0; border: 0;
} }
.protocol-version-row { .protocol-version-row {
border-bottom: 1px solid $color-concrete; border-bottom: 1px solid $color-concrete;
padding: 1em 0; padding: 1em 0;

View file

@ -1038,13 +1038,13 @@ class ProtocolsController < ApplicationController
end end
def permissions def permissions
#if stale?(@protocol) if stale?(@protocol)
render json: { render json: {
copyable: can_clone_protocol_in_repository?(@protocol), copyable: can_clone_protocol_in_repository?(@protocol),
archivable: can_manage_protocol_in_repository?(@protocol), archivable: can_manage_protocol_in_repository?(@protocol),
restorable: can_restore_protocol_in_repository?(@protocol) restorable: can_restore_protocol_in_repository?(@protocol)
} }
#end end
end end
private private

View file

@ -30,7 +30,8 @@ class ProtocolsDatatable < CustomDatatable
'Protocol.nr_of_linked_children', 'Protocol.nr_of_linked_children',
'nr_of_assigned_users', 'nr_of_assigned_users',
'full_username_str', 'full_username_str',
timestamp_db_column, 'Protocol.archived_on',
'Protocol.published_on',
'Protocol.updated_at' 'Protocol.updated_at'
] ]
end end
@ -38,7 +39,8 @@ class ProtocolsDatatable < CustomDatatable
def searchable_columns def searchable_columns
@searchable_columns ||= [ @searchable_columns ||= [
"Protocol.name", "Protocol.name",
timestamp_db_column, 'Protocol.archived_on',
'Protocol.published_on',
"Protocol.updated_at" "Protocol.updated_at"
] ]
end end
@ -93,15 +95,17 @@ class ProtocolsDatatable < CustomDatatable
DT_RowAttr: { DT_RowAttr: {
'data-permissions-url': permissions_protocol_path(record) 'data-permissions-url': permissions_protocol_path(record)
}, },
'1': record.archived? ? escape_input(record.name) : name_html(record), '1': name_html(record),
'2': record.code, '2': record.code,
'3': versions_html(record), '3': versions_html(record),
'4': keywords_html(record), '4': keywords_html(record),
'5': modules_html(record), '5': modules_html(record),
'6': access_html(record), '6': access_html(record),
'7': escape_input(record.full_username_str), '7': escape_input(record.full_username_str),
'8': timestamp_column_html(record), '8': I18n.l(record.published_on || record.created_at, format: :full),
'9': I18n.l(record.updated_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
end end
@ -129,12 +133,11 @@ class ProtocolsDatatable < CustomDatatable
.with_granted_permissions(@user, ProtocolPermissions::READ) .with_granted_permissions(@user, ProtocolPermissions::READ)
.preload(user_assignments: %i(user user_role)) .preload(user_assignments: %i(user user_role))
records = records = records.joins('LEFT OUTER JOIN "users" "archived_users"
if @type == :archived ON "archived_users"."id" = "protocols"."archived_by_id"')
records.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."archived_by_id"').archived records = records.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"')
else
records.joins('LEFT OUTER JOIN "users" ON "users"."id" = "protocols"."added_by_id"').active records = @type == :archived ? records.archived : records.active
end
records.group('"protocols"."id"') records.group('"protocols"."id"')
end end
@ -148,20 +151,13 @@ class ProtocolsDatatable < CustomDatatable
'COUNT("protocol_versions"."id") + 1 AS "nr_of_versions"', 'COUNT("protocol_versions"."id") + 1 AS "nr_of_versions"',
'COUNT("protocol_drafts"."id") AS "nr_of_drafts"', 'COUNT("protocol_drafts"."id") AS "nr_of_drafts"',
'COUNT("user_assignments"."id") AS "nr_of_assigned_users"', '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 end
# Various helper methods # Various helper methods
def timestamp_db_column
if @type == :archived
'Protocol.archived_on'
else
'Protocol.published_on'
end
end
def name_html(record) def name_html(record)
"<a href='#{protocol_path(record)}'>#{escape_input(record.name)}</a>" "<a href='#{protocol_path(record)}'>#{escape_input(record.name)}</a>"
end end

View file

@ -70,8 +70,7 @@ Canaid::Permissions.register_for(ProjectFolder) do
end end
Canaid::Permissions.register_for(Protocol) do Canaid::Permissions.register_for(Protocol) do
%i(read_protocol_in_repository %i(manage_protocol_in_repository
manage_protocol_in_repository
manage_protocol_users) manage_protocol_users)
.each do |perm| .each do |perm|
can perm do |_, protocol| can perm do |_, protocol|

View file

@ -11,10 +11,17 @@
<% end %> <% end %>
<% provide(:container_class, 'no-second-nav-container') %> <% provide(:container_class, 'no-second-nav-container') %>
<div class="content-pane flexible protocols-index"> <div class="content-pane flexible protocols-index <%= @type %>">
<div class="content-header sticky-header"> <div class="content-header sticky-header">
<div class="title-row"> <div class="title-row">
<h1><%= t('sidebar.templates.protocol_templates') %></h1> <% if @type == :archived %>
<h1>
<i class="fas fa-archive"></i>
<%= t('protocols.index.head_title_archived') %>
</h1>
<% else %>
<h1><%= t('protocols.index.head_title') %></h1>
<% end %>
</div> </div>
</div> </div>
<div class="protocols-container"> <div class="protocols-container">

View file

@ -3,7 +3,7 @@
<%= image_tag 'icon/versions.svg' %> <%= image_tag 'icon/versions.svg' %>
<span class="button-text"><%= t("protocols.index.action_toolbar.versions") %></span> <span class="button-text"><%= t("protocols.index.action_toolbar.versions") %></span>
</button> </button>
<button id="manageProtocolAccess" class="btn btn-light single-object-action hidden"> <button id="manageProtocolAccess" class="btn btn-light single-object-action hidden only-active">
<i class="fas fa-door-open"></i> <i class="fas fa-door-open"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.access") %></span> <span class="button-text"><%= t("protocols.index.action_toolbar.access") %></span>
</button> </button>

View file

@ -1,11 +1,11 @@
<template id="protocolGeneralToolbar"> <template id="protocolGeneralToolbar">
<div class="left-general-toolbar"> <div class="left-general-toolbar">
<%= button_to protocols_path(type: @type), disabled: !can_create_protocols_in_repository?(@current_team), class: 'btn btn-primary' do %> <%= button_to protocols_path(type: @type), disabled: !can_create_protocols_in_repository?(@current_team), class: 'btn btn-primary only-active' do %>
<span class="fas fa-plus"></span> <span class="fas fa-plus"></span>
<span class="hidden-xs"><%= t("protocols.index.create_new") %></span> <span class="hidden-xs"><%= t("protocols.index.create_new") %></span>
<% end %> <% end %>
<div id="protocol-import-group" class="sci-btn-group" role="group"> <div id="protocol-import-group" class="sci-btn-group only-active" role="group">
<button class="btn btn-light btn-open-file <%= 'disabled' unless can_create_protocols_in_repository?(@current_team) %>" <button class="btn btn-light btn-open-file <%= 'disabled' unless can_create_protocols_in_repository?(@current_team) %>"
data-toggle="dropdown" data-toggle="dropdown"
aria-haspopup="true" aria-haspopup="true"

View file

@ -15,14 +15,13 @@
<th id="protocol-keywords"><%= t("protocols.index.thead.keywords") %></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> <th id="protocol-nr-of-linked-children"><%= t("protocols.index.thead.nr_of_linked_children") %></th>
<th id="protocol-access"><%= t("protocols.index.thead.access") %></th> <th id="protocol-access"><%= t("protocols.index.thead.access") %></th>
<th id="protocol-published-by"><%= t("protocols.index.thead.published_by") %></th>
<th id="protocol-published-on"><%= t("protocols.index.thead.published_on") %></th>
<th id="protocol-updated-at"><%= t("protocols.index.thead.updated_at") %></th>
<% if @type == :archived %> <% if @type == :archived %>
<th id="protocol-archived-by"><%= t("protocols.index.thead.archived_by") %></th> <th id="protocol-archived-by"><%= t("protocols.index.thead.archived_by") %></th>
<th id="protocol-archived-on"><%= t("protocols.index.thead.archived_on") %></th> <th id="protocol-archived-on"><%= t("protocols.index.thead.archived_on") %></th>
<% else %>
<th id="protocol-published-by"><%= t("protocols.index.thead.published_by") %></th>
<th id="protocol-published-on"><%= t("protocols.index.thead.published_on") %></th>
<% end %> <% end %>
<th id="protocol-updated-at"><%= t("protocols.index.thead.updated_at") %></th>
</tr> </tr>
</thead> </thead>
<tbody></tbody> <tbody></tbody>

View file

@ -3,10 +3,10 @@
<i class="fas fa-caret-right toggle-branch collapsed"></i> <i class="fas fa-caret-right toggle-branch collapsed"></i>
<%= link_to t('sidebar.templates.protocol_templates'), <%= link_to t('sidebar.templates.protocol_templates'),
protocols_path, protocols_path,
class: "sidebar-link #{'selected' if active == :protocol && params[:type] != 'archive'}" %> class: "sidebar-link #{'selected' if active == :protocol && params[:type] != 'archived'}" %>
<ul class="sidebar-branch"> <ul class="sidebar-branch">
<li class="sidebar-leaf"> <li class="sidebar-leaf">
<%= link_to protocols_path(type: :archive), class: "sidebar-link #{'selected' if active == :protocol && params[:type] == 'archive'}" do %> <%= link_to protocols_path(type: :archived), class: "sidebar-link #{'selected' if active == :protocol && params[:type] == 'archived'}" do %>
<i class="fas fa-archive"></i> <i class="fas fa-archive"></i>
<%= t("protocols.index.navigation.archive") %> <%= t("protocols.index.navigation.archive") %>
<% end %> <% end %>

View file

@ -2552,7 +2552,8 @@ en:
title: "Edit description of protocol %{protocol}" title: "Edit description of protocol %{protocol}"
label: "Description" label: "Description"
index: index:
head_title: "Protocol management" head_title: "Protocol templates"
head_title_archived: "Archived protocol templates"
default_name: 'New protocol' default_name: 'New protocol'
navigation: navigation:
public: "Team protocols" public: "Team protocols"
@ -2593,7 +2594,7 @@ en:
archived_by: "Archived by" archived_by: "Archived by"
published_on: "Published on" published_on: "Published on"
created_at: "Created at" created_at: "Created at"
archived_on: "Archived at" archived_on: "Archived on"
updated_at: "Modified on" updated_at: "Modified on"
table: table:
draft: "Draft" draft: "Draft"