mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-09-21 15:36:22 +08:00
Merge pull request #5105 from sboursen-scinote/sb_SCI-8007
Bugs for "Protocol templates" [SCI-8007]
This commit is contained in:
commit
bab32b04b6
|
@ -5,6 +5,7 @@
|
|||
|
||||
// Global variables
|
||||
var ProtocolsIndex = (function() {
|
||||
const ALL_VERSIONS_VALUE = 'All';
|
||||
var PERMISSIONS = ['archivable', 'restorable', 'copyable'];
|
||||
var rowsSelected = [];
|
||||
var protocolsTableEl = null;
|
||||
|
@ -554,19 +555,43 @@ var ProtocolsIndex = (function() {
|
|||
modal.modal('show');
|
||||
|
||||
let childrenTableEl = modalBody.find('#linked-children-table');
|
||||
let versionFromDropdown = ALL_VERSIONS_VALUE;
|
||||
|
||||
const initVersionsDropdown = (childrenDatatable) => {
|
||||
const versionSelector = $('#version-selector');
|
||||
dropdownSelector.init(versionSelector, {
|
||||
noEmptyOption: true,
|
||||
singleSelect: true,
|
||||
selectAppearance: 'simple',
|
||||
closeOnSelect: true,
|
||||
onSelect: function() {
|
||||
versionFromDropdown = dropdownSelector.getValues(versionSelector);
|
||||
childrenDatatable.ajax.reload();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
let childrenDatatable;
|
||||
|
||||
if (childrenTableEl) {
|
||||
// Only initialize table if it's present
|
||||
childrenTableEl.DataTable({
|
||||
childrenDatatable = childrenTableEl.DataTable({
|
||||
autoWidth: false,
|
||||
dom: 'RBltpi',
|
||||
dom: 'RBtpl',
|
||||
stateSave: false,
|
||||
buttons: [],
|
||||
processing: true,
|
||||
serverSide: true,
|
||||
ajax: {
|
||||
url: childrenTableEl.data('source'),
|
||||
type: 'POST'
|
||||
type: 'POST',
|
||||
data: function(d) {
|
||||
if (versionFromDropdown !== ALL_VERSIONS_VALUE) {
|
||||
d.version = versionFromDropdown;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
},
|
||||
colReorder: {
|
||||
fixedColumnsLeft: 1000000 // Disable reordering
|
||||
|
@ -579,6 +604,17 @@ var ProtocolsIndex = (function() {
|
|||
columns: [
|
||||
{ data: '1' }
|
||||
],
|
||||
lengthMenu: [
|
||||
[10, 25, 50],
|
||||
[
|
||||
I18n.t('protocols.index.linked_children.length_menu', { number: 10 }),
|
||||
I18n.t('protocols.index.linked_children.length_menu', { number: 25 }),
|
||||
I18n.t('protocols.index.linked_children.length_menu', { number: 50 })
|
||||
]
|
||||
],
|
||||
language: {
|
||||
lengthMenu: '_MENU_'
|
||||
},
|
||||
fnDrawCallback: function() {
|
||||
animateSpinner(this, false);
|
||||
},
|
||||
|
@ -587,6 +623,8 @@ var ProtocolsIndex = (function() {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
initVersionsDropdown(childrenDatatable);
|
||||
},
|
||||
error: function() {
|
||||
// TODO
|
||||
|
|
|
@ -100,6 +100,12 @@ var filterDropdown = (function() {
|
|||
});
|
||||
}
|
||||
|
||||
function initCloseButton() {
|
||||
$('.close', $filterContainer).click(function() {
|
||||
$(this).closest('.dropdown').removeClass('open');
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
init: function(filtersEnabledFunction) {
|
||||
$filterContainer = $('.filter-container');
|
||||
|
@ -107,6 +113,7 @@ var filterDropdown = (function() {
|
|||
initClearButton();
|
||||
preventDropdownClose();
|
||||
initApplyButton();
|
||||
initCloseButton();
|
||||
initSearchField(filtersEnabledFunction);
|
||||
return $filterContainer;
|
||||
},
|
||||
|
|
|
@ -310,3 +310,29 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
#linked-children-modal {
|
||||
.dataTables_length .form-control {
|
||||
width: 160px;
|
||||
}
|
||||
|
||||
.version-dropdown {
|
||||
align-items: center;
|
||||
column-gap: 8px;
|
||||
display: flex;
|
||||
margin-top: 16px;
|
||||
|
||||
label {
|
||||
font-size: 14px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.dropdown-selector-container {
|
||||
width: 86px;
|
||||
}
|
||||
}
|
||||
|
||||
.linked-children-datatable {
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
display: flex;
|
||||
height: 2.75em;
|
||||
margin-bottom: 1em;
|
||||
padding: 0 .3em 0 1em;
|
||||
padding: 1em;
|
||||
|
||||
.title {
|
||||
@include font-h2;
|
||||
|
@ -117,7 +117,7 @@
|
|||
}
|
||||
|
||||
.footer:not(.center) {
|
||||
.btn:last-child {
|
||||
:last-child {
|
||||
margin-left: auto;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,14 +40,16 @@ class ProtocolLinkedChildrenDatatable < CustomDatatable
|
|||
# Query database for records (this will be later paginated and filtered)
|
||||
# after that "data" function will return json
|
||||
def get_raw_records
|
||||
records =
|
||||
Protocol
|
||||
.joins(my_module: { experiment: :project })
|
||||
.includes(my_module: { experiment: :project })
|
||||
.references(my_module: { experiment: :project })
|
||||
.where(protocol_type: Protocol.protocol_types[:linked])
|
||||
.where(parent: @protocol)
|
||||
records.distinct
|
||||
if params[:version].present?
|
||||
records = @protocol.published_versions_with_original
|
||||
.find_by!(version_number: params[:version])
|
||||
.linked_children
|
||||
else
|
||||
records = Protocol.where(protocol_type: Protocol.protocol_types[:linked])
|
||||
records = records.where(parent_id: @protocol.published_versions)
|
||||
.or(records.where(parent_id: @protocol.id))
|
||||
end
|
||||
records.preload(my_module: { experiment: :project }).distinct
|
||||
end
|
||||
|
||||
# Helper methods
|
||||
|
|
|
@ -14,7 +14,8 @@ module ProjectsHelper
|
|||
end
|
||||
|
||||
def user_names_with_roles(user_assignments)
|
||||
user_assignments.map { |up| user_name_with_role(up) }.join('
')
|
||||
names_with_roles = user_assignments.map { |up| user_name_with_role(up) }.join('
')
|
||||
sanitize_input(names_with_roles)
|
||||
end
|
||||
|
||||
def user_name_with_role(user_assignment)
|
||||
|
|
|
@ -1,10 +1,21 @@
|
|||
<% linked_children = protocol.linked_children %>
|
||||
<% published_versions = protocol.published_versions_with_original.order(version_number: :desc)%>
|
||||
|
||||
<% if protocol.nr_of_linked_children > 0 %>
|
||||
<div>
|
||||
<%= t("protocols.index.linked_children.used_in", nr: protocol.nr_of_linked_children) %>
|
||||
<div class="version-dropdown">
|
||||
<%= label_tag "version-selector".to_sym, t("protocols.index.linked_children.show_version") %>
|
||||
<%= select_tag "version",
|
||||
options_for_select(
|
||||
['All'].concat(
|
||||
published_versions.map { |p|
|
||||
[
|
||||
p.version_number
|
||||
]
|
||||
})),
|
||||
{
|
||||
id: 'version-selector'
|
||||
} %>
|
||||
</div>
|
||||
|
||||
<div class="linked-children-datatable">
|
||||
<table id="linked-children-table" class="table" data-source="<%= linked_children_datatable_protocol_path(protocol: protocol) %>">
|
||||
<tbody></tbody>
|
||||
|
|
|
@ -7,7 +7,6 @@
|
|||
<%= render partial: 'shared/filter_dropdown/text_search', locals: {container_class: '', label_text: t('filters_modal.text.label_name_and_keywords')} %>
|
||||
<%= render partial: 'shared/filter_dropdown/datetime_search', locals: {container_class: 'published-on-filter', label: 'Published on', view_mode: nil } %>
|
||||
<%= render partial: 'shared/filter_dropdown/datetime_search', locals: {container_class: 'modified-on-filter', label: 'Modified on', view_mode: nil } %>
|
||||
<%= render partial: 'shared/filter_dropdown/datetime_search', locals: {container_class: 'archived-on-filter', label: 'Archived on', view_mode: 'archived' } %>
|
||||
<div class="select-block">
|
||||
<label>Published by</label>
|
||||
<select class="published-by-filter"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<% protocol.user_assignments[0..3].each_with_index do |user_assigment, i| %>
|
||||
<% protocol.user_assignments[0..2].each_with_index do |user_assigment, i| %>
|
||||
<span class="global-avatar-container" style="z-index: <%= 5 - i %>">
|
||||
<%= image_tag(avatar_path(user_assigment.user, :icon_small), title: user_name_with_role(user_assigment)) %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<% more_users = protocol.user_assignments[4..-1].to_a %>
|
||||
<% more_users = protocol.user_assignments[3..-1].to_a %>
|
||||
<% if more_users.any? %>
|
||||
<span class="more-users" title="<%= user_names_with_roles(more_users) %>">
|
||||
+<%= more_users.size %>
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
<div class="dropdown-menu dropdown-menu-right filter-dropdown <%= container_class %>" role="menu" data-team-id="<%= current_team.id %>" data-search-field-history-key="<%= search_field_history_key %>">
|
||||
<div class="header">
|
||||
<div class="title"><%= dropdown_title %></div>
|
||||
<div class="btn btn-light clear-button">
|
||||
<i class="fas fa-times-circle"></i><%= t("filters_modal.clear_btn") %></div>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
|
||||
</div>
|
||||
<div class="body">
|
||||
<%= yield %>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<div class="btn btn-primary apply-filters"><%= t("filters_modal.show_btn.one") %></div>
|
||||
<div class="buttons">
|
||||
<div class="btn btn-light clear-button">
|
||||
<%= t("filters_modal.clear_btn") %>
|
||||
</div>
|
||||
<div class="btn btn-primary apply-filters">
|
||||
<%= t("filters_modal.show_btn.one") %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2759,6 +2759,8 @@ en:
|
|||
title: "Tasks linked to protocol %{protocol}"
|
||||
used_in: "Number of tasks linked to this protocol: %{nr}"
|
||||
no_linked_children: "This protocol is not linked to any task."
|
||||
length_menu: "Show %{number} per page"
|
||||
show_version: "Show version"
|
||||
archive:
|
||||
description: "Archived protocols can only be seen by you. Restoring protocols will return them to their previous location (team/my protocols)."
|
||||
restore: "Restore"
|
||||
|
|
Loading…
Reference in a new issue