diff --git a/app/assets/javascripts/my_modules/protocols.js b/app/assets/javascripts/my_modules/protocols.js index 7432aceb8..bf028dd1e 100644 --- a/app/assets/javascripts/my_modules/protocols.js +++ b/app/assets/javascripts/my_modules/protocols.js @@ -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) => { - $('
' - + truncateLongString(protocol.name, GLOBAL_CONSTANTS.NAME_TRUNCATION_LENGTH) - + '
').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(); } diff --git a/app/assets/javascripts/protocols/steps.js.erb b/app/assets/javascripts/protocols/steps.js.erb index e2494924d..4cd908765 100644 --- a/app/assets/javascripts/protocols/steps.js.erb +++ b/app/assets/javascripts/protocols/steps.js.erb @@ -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']) { diff --git a/app/controllers/my_modules_controller.rb b/app/controllers/my_modules_controller.rb index 4aeb575e4..35156346a 100644 --- a/app/controllers/my_modules_controller.rb +++ b/app/controllers/my_modules_controller.rb @@ -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 diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 7bd814a51..20440ca16 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -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 diff --git a/app/datatables/load_from_repository_protocols_datatable.rb b/app/datatables/load_from_repository_protocols_datatable.rb index d43ecf0ea..a6d3ffd36 100644 --- a/app/datatables/load_from_repository_protocols_datatable.rb +++ b/app/datatables/load_from_repository_protocols_datatable.rb @@ -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"') diff --git a/app/models/protocol.rb b/app/models/protocol.rb index d88da07a2..e7db69345 100644 --- a/app/models/protocol.rb +++ b/app/models/protocol.rb @@ -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 } diff --git a/app/views/my_modules/_my_module_protocol.html.erb b/app/views/my_modules/_my_module_protocol.html.erb index a0eca3e17..d4b6cac2e 100644 --- a/app/views/my_modules/_my_module_protocol.html.erb +++ b/app/views/my_modules/_my_module_protocol.html.erb @@ -1,9 +1,3 @@ -
- <% if can_manage_protocol_in_module?(@protocol) %> - <%= render partial: "my_modules/recent_protocol_dropdown.html.erb", locals: {protocol: @my_module.protocol}%> - <% end %> -
-
diff --git a/app/views/my_modules/_recent_protocol_dropdown.html.erb b/app/views/my_modules/_recent_protocol_dropdown.html.erb deleted file mode 100644 index 1a24d943c..000000000 --- a/app/views/my_modules/_recent_protocol_dropdown.html.erb +++ /dev/null @@ -1,21 +0,0 @@ -<% display_status = protocol.description.blank? && protocol.steps.count.zero? %> -<% if @recent_protcols_positive %> -
-
-
<%= t('my_modules.module_header.recent_protocols_from_repository') %>
- - -
-
-<% end %> \ No newline at end of file diff --git a/app/views/my_modules/protocols/_load_from_repository_modal_body.html.erb b/app/views/my_modules/protocols/_load_from_repository_modal_body.html.erb index 5a66f3c38..1d3fe00fe 100644 --- a/app/views/my_modules/protocols/_load_from_repository_modal_body.html.erb +++ b/app/views/my_modules/protocols/_load_from_repository_modal_body.html.erb @@ -8,12 +8,35 @@
-
+
+
+ + + + + + + + + + + + + +
<%= t("my_modules.protocols.load_from_repository_modal.thead_name") %><%= t("my_modules.protocols.load_from_repository_modal.thead_keywords") %><%= t("my_modules.protocols.load_from_repository_modal.thead_nr_of_linked_children") %><%= t("my_modules.protocols.load_from_repository_modal.thead_added_by") %><%= t("my_modules.protocols.load_from_repository_modal.thead_published_on") %><%= t("my_modules.protocols.load_from_repository_modal.thead_updated_at") %>
+
+
+
diff --git a/config/initializers/constants.rb b/config/initializers/constants.rb index 8d2ed47e7..49ca96e3f 100644 --- a/config/initializers/constants.rb +++ b/config/initializers/constants.rb @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index c3b0cf1c7..21c23dd05 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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" diff --git a/config/routes.rb b/config/routes.rb index 4287683b2..b4c1e6f67 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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