mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-21 14:23:13 +08:00
Merge pull request #2510 from aignatov-bio/ai-sci-4509-add-recent-protocols-tab
Add recent protocol tab to load protocal from repository [SCI-4509]
This commit is contained in:
commit
8e20dccc66
12 changed files with 38 additions and 95 deletions
|
@ -178,8 +178,8 @@ function initLoadFromRepository() {
|
|||
|
||||
modal.modal('show');
|
||||
|
||||
// Init Datatable on public tab
|
||||
initLoadFromRepositoryTable(modalBody.find('#public-tab'));
|
||||
// Init Datatable on recent tab
|
||||
initLoadFromRepositoryTable(modalBody.find('#recent-tab'));
|
||||
|
||||
modalBody.find("a[data-toggle='tab']")
|
||||
.on('hide.bs.tab', function(el) {
|
||||
|
@ -212,9 +212,7 @@ function initLoadFromRepository() {
|
|||
|
||||
function initLoadFromRepositoryTable(content) {
|
||||
var tableEl = content.find("[data-role='datatable']");
|
||||
|
||||
var datatable = tableEl.DataTable({
|
||||
order: [[1, 'asc']],
|
||||
dom: "RBfl<'row'<'col-sm-12't>><'row'<'col-sm-7'i><'col-sm-5'p>>",
|
||||
sScrollX: '100%',
|
||||
sScrollXInner: '100%',
|
||||
|
@ -222,6 +220,7 @@ function initLoadFromRepositoryTable(content) {
|
|||
processing: true,
|
||||
serverSide: true,
|
||||
responsive: true,
|
||||
order: tableEl.data('default-order') || [[1, 'asc']],
|
||||
ajax: {
|
||||
url: tableEl.data('source'),
|
||||
type: 'POST'
|
||||
|
@ -432,44 +431,7 @@ function initImport() {
|
|||
});
|
||||
}
|
||||
|
||||
function initRecentProtocols() {
|
||||
var recentProtocolContainer = $('.my-module-recent-protocols');
|
||||
var dropDownList = recentProtocolContainer.find('.dropdown-menu');
|
||||
recentProtocolContainer.find('.dropdown-button').click(function() {
|
||||
dropDownList.find('.protocol').remove();
|
||||
$.get('/protocols/recent_protocols', result => {
|
||||
$.each(result, (i, protocol) => {
|
||||
$('<div class="protocol"><i class="fas fa-file-alt"></i>'
|
||||
+ truncateLongString(protocol.name, GLOBAL_CONSTANTS.NAME_TRUNCATION_LENGTH)
|
||||
+ '</div>').appendTo(dropDownList)
|
||||
.click(() => {
|
||||
$.post(recentProtocolContainer.data('updateUrl'), { source_id: protocol.id })
|
||||
.success(() => {
|
||||
location.reload();
|
||||
})
|
||||
.error(ev => {
|
||||
HelperModule.flashAlertMsg(ev.responseJSON.message, 'warning');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.protocol-description-content').on('ajax:success', () => {
|
||||
updateRecentProtocolsStatus();
|
||||
});
|
||||
}
|
||||
|
||||
function updateRecentProtocolsStatus() {
|
||||
var recentProtocolContainer = $('.my-module-recent-protocols');
|
||||
var steps = $('.step');
|
||||
var protocolDescription = $('#protocol_description_view').html();
|
||||
if (steps.length === 0 && protocolDescription.length === 0) {
|
||||
recentProtocolContainer.css('display', '');
|
||||
} else {
|
||||
recentProtocolContainer.css('display', 'none');
|
||||
}
|
||||
}
|
||||
|
||||
function initProtocolSectionOpenEvent() {
|
||||
$('#protocol-container').on('shown.bs.collapse', function() {
|
||||
|
@ -493,7 +455,6 @@ function init() {
|
|||
initLoadFromRepository();
|
||||
refreshProtocolStatusBar();
|
||||
initImport();
|
||||
initRecentProtocols();
|
||||
initProtocolSectionOpenEvent();
|
||||
}
|
||||
|
||||
|
|
|
@ -620,7 +620,6 @@
|
|||
FilePreviewModal.init();
|
||||
$.initTooltips();
|
||||
if (typeof refreshProtocolStatusBar === 'function') refreshProtocolStatusBar();
|
||||
if (typeof updateRecentProtocolsStatus === 'function') updateRecentProtocolsStatus();
|
||||
},
|
||||
error: function(xhr) {
|
||||
if (xhr.responseJSON['assets.file']) {
|
||||
|
|
|
@ -266,11 +266,6 @@ class MyModulesController < ApplicationController
|
|||
|
||||
def protocols
|
||||
@protocol = @my_module.protocol
|
||||
@recent_protcols_positive = Protocol.recent_protocols(
|
||||
current_user,
|
||||
current_team,
|
||||
Constants::RECENT_PROTOCOL_LIMIT
|
||||
).any?
|
||||
@assigned_repositories = @my_module.assigned_repositories
|
||||
current_team_switch(@protocol.team)
|
||||
end
|
||||
|
|
|
@ -107,14 +107,6 @@ class ProtocolsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def recent_protocols
|
||||
render json: Protocol.recent_protocols(
|
||||
current_user,
|
||||
current_team,
|
||||
Constants::RECENT_PROTOCOL_LIMIT
|
||||
).select(:id, :name)
|
||||
end
|
||||
|
||||
def linked_children
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
|
|
|
@ -93,13 +93,21 @@ class LoadFromRepositoryProtocolsDatatable < CustomDatatable
|
|||
.joins('LEFT OUTER JOIN users ON users.id = protocols.added_by_id')
|
||||
.where('protocols.protocol_type = ?',
|
||||
Protocol.protocol_types[:in_repository_public])
|
||||
else
|
||||
elsif @type == :private
|
||||
records =
|
||||
records
|
||||
.joins('LEFT OUTER JOIN users ON users.id = protocols.added_by_id')
|
||||
.where('protocols.protocol_type = ?',
|
||||
Protocol.protocol_types[:in_repository_private])
|
||||
.where(added_by: @user)
|
||||
else
|
||||
records =
|
||||
records
|
||||
.joins('LEFT OUTER JOIN users ON users.id = protocols.added_by_id')
|
||||
.where('(protocols.protocol_type = ? OR (protocols.protocol_type = ? AND added_by_id = ?))',
|
||||
Protocol.protocol_types[:in_repository_public],
|
||||
Protocol.protocol_types[:in_repository_private],
|
||||
@user.id)
|
||||
end
|
||||
|
||||
records.group('"protocols"."id"')
|
||||
|
|
|
@ -17,12 +17,6 @@ class Protocol < ApplicationRecord
|
|||
in_repository_archived: 4
|
||||
}
|
||||
|
||||
scope :recent_protocols, lambda { |user, team, amount|
|
||||
where(team: team, protocol_type: :in_repository_public)
|
||||
.or(where(team: team, protocol_type: :in_repository_private, added_by: user))
|
||||
.order(updated_at: :desc).limit(amount)
|
||||
}
|
||||
|
||||
auto_strip_attributes :name, :description, nullify: false
|
||||
# Name is required when its actually specified (i.e. :in_repository? is true)
|
||||
validates :name, length: { maximum: Constants::NAME_MAX_LENGTH }
|
||||
|
|
|
@ -1,9 +1,3 @@
|
|||
<div class="protocol-status-container">
|
||||
<% if can_manage_protocol_in_module?(@protocol) %>
|
||||
<%= render partial: "my_modules/recent_protocol_dropdown.html.erb", locals: {protocol: @my_module.protocol}%>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<div class="protocol-description-content">
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
<% display_status = protocol.description.blank? && protocol.steps.count.zero? %>
|
||||
<% if @recent_protcols_positive %>
|
||||
<div class="my-module-recent-protocols"
|
||||
style="display: <%= display_status ? '' : 'none' %>"
|
||||
data-update-url="<%= load_from_repository_protocol_path(protocol) %>"
|
||||
>
|
||||
<div class="btn-group">
|
||||
<div class="title"><%= t('my_modules.module_header.recent_protocols_from_repository') %></div>
|
||||
<div
|
||||
class="dropdown-button"
|
||||
title="Recent protocols"
|
||||
data-toggle="dropdown"
|
||||
aria-haspopup="true"
|
||||
aria-expanded="false">
|
||||
<span class="caret"></span>
|
||||
</div>
|
||||
<ul class="dropdown-menu">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
|
@ -8,12 +8,35 @@
|
|||
</div>
|
||||
|
||||
<ul class="nav nav-tabs nav-settings" role="tablist">
|
||||
<li role="presentation" class="active"><a href="#public-tab" aria-controls="public-tab" role="tab" data-toggle="tab"><%= t("my_modules.protocols.load_from_repository_modal.tab_public") %></a></li>
|
||||
<li role="presentation" class="active"><a href="#recent-tab" aria-controls="recent-tab" role="tab" data-toggle="tab"><%= t("my_modules.protocols.load_from_repository_modal.tab_recent") %></a></li>
|
||||
<li role="presentation"><a href="#public-tab" aria-controls="public-tab" role="tab" data-toggle="tab"><%= t("my_modules.protocols.load_from_repository_modal.tab_public") %></a></li>
|
||||
<li role="presentation"><a href="#private-tab" aria-controls="private-tab" role="tab" data-toggle="tab"><%= t("my_modules.protocols.load_from_repository_modal.tab_private") %></a></li>
|
||||
</ul>
|
||||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<div role="tabpanel" class="tab-pane active" id="public-tab">
|
||||
<div role="tabpanel" class="tab-pane active" id="recent-tab">
|
||||
<div class="protocols-datatable load-from-repository-protocols-datatable">
|
||||
<table id="recent-protocols-table" class="table" data-role="datatable"
|
||||
data-type="recent"
|
||||
data-source="<%= load_from_repository_datatable_protocol_path(@protocol, type: :recent) %>"
|
||||
data-default-order='[[6,"desc"]]'
|
||||
>
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="all"></th>
|
||||
<th class="all" id="protocol-name"><%= t("my_modules.protocols.load_from_repository_modal.thead_name") %></th>
|
||||
<th class="min-tablet-p" id="protocol-keywords"><%= t("my_modules.protocols.load_from_repository_modal.thead_keywords") %></th>
|
||||
<th class="min-tablet-l" id="protocol-nr-of-linked-children"><%= t("my_modules.protocols.load_from_repository_modal.thead_nr_of_linked_children") %></th>
|
||||
<th class="min-tablet-l" id="protocol-published-by"><%= t("my_modules.protocols.load_from_repository_modal.thead_added_by") %></th>
|
||||
<th class="min-desktop" id="protocol-published-on"><%= t("my_modules.protocols.load_from_repository_modal.thead_published_on") %></th>
|
||||
<th class="min-desktop" id="protocol-updated-at"><%= t("my_modules.protocols.load_from_repository_modal.thead_updated_at") %></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
<div role="tabpanel" class="tab-pane" id="public-tab">
|
||||
<div class="protocols-datatable load-from-repository-protocols-datatable">
|
||||
<table id="public-protocols-table" class="table" data-role="datatable" data-type="public" data-source="<%= load_from_repository_datatable_protocol_path(@protocol, type: :public) %>">
|
||||
<thead>
|
||||
|
|
|
@ -64,8 +64,6 @@ class Constants
|
|||
ATWHO_SEARCH_LIMIT = 5
|
||||
# Max characters for repository name in Atwho modal
|
||||
ATWHO_REP_NAME_LIMIT = 16
|
||||
# Number of protocols in recent protocol dropdown
|
||||
RECENT_PROTOCOL_LIMIT = 14
|
||||
|
||||
#=============================================================================
|
||||
# File and data memory size
|
||||
|
|
|
@ -726,6 +726,7 @@ en:
|
|||
text2: "This action will overwrite the current protocol in the task and unlink it from repository. The current protocol will remain unchanged in repository."
|
||||
tab_public: "Team protocols"
|
||||
tab_private: "My protocols"
|
||||
tab_recent: "Recent protocols"
|
||||
tab_archive: "Archived protocols"
|
||||
thead_name: "Name"
|
||||
thead_keywords: "Keywords"
|
||||
|
|
|
@ -586,7 +586,6 @@ Rails.application.routes.draw do
|
|||
to: 'protocols#protocolsio_import_create'
|
||||
post 'protocolsio_import_save', to: 'protocols#protocolsio_import_save'
|
||||
get 'export', to: 'protocols#export'
|
||||
get 'recent_protocols'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue