Update archive action for protocol templates [SCI-7898]

This commit is contained in:
Anton 2023-02-09 14:10:07 +01:00
parent 23e50cf710
commit b55f68c0dc
5 changed files with 22 additions and 34 deletions

View file

@ -1,7 +1,7 @@
//= require protocols/import_export/import
/* eslint-disable no-use-before-define, no-underscore-dangle, max-len */
/* global ProtocolRepositoryHeader PdfPreview DataTableHelpers importProtocolFromFile _
dropdownSelector filterDropdown I18n animateSpinner initHandsOnTable inlineEditing */
dropdownSelector filterDropdown I18n animateSpinner initHandsOnTable inlineEditing HelperModule */
// Global variables
var ProtocolsIndex = (function() {
@ -410,6 +410,21 @@ var ProtocolsIndex = (function() {
});
}
function initArchiveMyModules() {
$('.protocols-index').on('click', '#archiveProtocol', function(e) {
archiveMyModules(e.currentTarget.dataset.url, rowsSelected);
});
}
function archiveMyModules(url, ids) {
$.post(url, { protocol_ids: ids }, (data) => {
HelperModule.flashAlertMsg(data.message, 'success');
protocolsDatatable.ajax.reload();
}).error((data) => {
HelperModule.flashAlertMsg(data.responseJSON.message, 'danger');
});
}
function initLinkedChildrenModal() {
// Only do this if the repository is public/private
if (repositoryType !== 'archive') {
@ -926,6 +941,7 @@ var ProtocolsIndex = (function() {
init();
initManageAccessButton();
initArchiveMyModules();
return {
reloadTable: function() {

View file

@ -1080,26 +1080,10 @@ class ProtocolsController < ApplicationController
def move_protocol(action)
rollbacked = false
results = []
begin
Protocol.transaction do
@protocols.find_each do |protocol|
result = {
name: protocol.name
}
success = protocol.method(action).call(current_user)
# Try renaming protocol
unless success
rename_record(protocol, :name)
success = protocol.method(action).call(current_user)
end
result[:new_name] = protocol.name
result[:type] = protocol.protocol_type
result[:success] = success
results << result
protocol.method(action).call(current_user)
end
end
rescue
@ -1113,12 +1097,7 @@ class ProtocolsController < ApplicationController
end
else
format.json do
render json: {
html: render_to_string({
partial: "protocols/index/results_modal_body.html.erb",
locals: { results: results, en_action: "#{action}_results" }
})
}
render json: { message: t("protocols.index.#{action}_flash_html", count: @protocols.size) }
end
end
end

View file

@ -445,20 +445,12 @@ class Protocol < ApplicationRecord
self.archived_on = Time.now
self.restored_by = nil
self.restored_on = nil
self.protocol_type = Protocol.protocol_types[:in_repository_archived]
self.archived = true
result = save
# Update all module protocols that had
# parent set to this protocol
if result
Protocol.where(parent: self).find_each do |p|
p.update(
parent: nil,
parent_updated_at: nil,
protocol_type: :unlinked
)
end
Activities::CreateActivityService
.call(activity_type: :archive_protocol_in_repository,
owner: user,

View file

@ -15,7 +15,7 @@
<i class="fas fa-download"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.export") %></span>
</button>
<button id="archiveProtocol" class="btn btn-light multiple-object-action hidden only-active" data-for="archivable">
<button id="archiveProtocol" class="btn btn-light multiple-object-action hidden only-active" data-url="<%= archive_protocols_path %>" data-for="archivable">
<i class="fas fa-archive"></i>
<span class="button-text"><%= t("protocols.index.action_toolbar.archive") %></span>
</button>

View file

@ -2584,6 +2584,7 @@ en:
make_private: "Move to My Protocols"
publish: "Move to Team protocols"
archive_action: "Archive"
archive_flash_html: "<b>%{count} protocol</b> template(s) successfully archived."
thead:
name: "Name"
id: "ID"