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: '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')

View file

@ -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;

View file

@ -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

View file

@ -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)
"<a href='#{protocol_path(record)}'>#{escape_input(record.name)}</a>"
end

View file

@ -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|

View file

@ -11,10 +11,17 @@
<% end %>
<% 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="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 class="protocols-container">

View file

@ -3,7 +3,7 @@
<%= image_tag 'icon/versions.svg' %>
<span class="button-text"><%= t("protocols.index.action_toolbar.versions") %></span>
</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>
<span class="button-text"><%= t("protocols.index.action_toolbar.access") %></span>
</button>

View file

@ -1,11 +1,11 @@
<template id="protocolGeneralToolbar">
<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="hidden-xs"><%= t("protocols.index.create_new") %></span>
<% 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) %>"
data-toggle="dropdown"
aria-haspopup="true"

View file

@ -15,14 +15,13 @@
<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-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 %>
<th id="protocol-archived-by"><%= t("protocols.index.thead.archived_by") %></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 %>
<th id="protocol-updated-at"><%= t("protocols.index.thead.updated_at") %></th>
</tr>
</thead>
<tbody></tbody>

View file

@ -3,10 +3,10 @@
<i class="fas fa-caret-right toggle-branch collapsed"></i>
<%= link_to t('sidebar.templates.protocol_templates'),
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">
<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>
<%= t("protocols.index.navigation.archive") %>
<% end %>

View file

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