Add recent protocol tab to load protocal from repository

This commit is contained in:
aignatov-bio 2020-04-09 17:29:39 +02:00
parent fc810b5524
commit fe718349da
10 changed files with 37 additions and 90 deletions

View file

@ -181,7 +181,7 @@ function initLoadFromRepository() {
modal.modal('show');
// Init Datatable on public tab
initLoadFromRepositoryTable(modalBody.find('#public-tab'));
initLoadFromRepositoryTable(modalBody.find('#recent-tab'));
modalBody.find("a[data-toggle='tab']")
.on('hide.bs.tab', function(el) {
@ -214,9 +214,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%',
@ -224,6 +222,7 @@ function initLoadFromRepositoryTable(content) {
processing: true,
serverSide: true,
responsive: true,
order: tableEl.data('default-order') || [[1, 'asc']],
ajax: {
url: tableEl.data('source'),
type: 'POST'
@ -433,45 +432,6 @@ 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');
}
}
/**
* Initializes page
*/
@ -484,7 +444,6 @@ function init() {
initLoadFromRepository();
refreshProtocolStatusBar();
initImport();
initRecentProtocols();
}
init();

View 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

View file

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

View file

@ -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"')

View file

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

View file

@ -3,9 +3,6 @@
<%= render partial: "my_modules/protocols/protocol_status_bar.html.erb" %>
</div>
<%= render partial: "my_modules/protocols/protocol_buttons.html.erb" %>
<% 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">

View file

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

View file

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

View file

@ -722,6 +722,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"

View file

@ -558,7 +558,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