diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index 844f9bb75..eed54dc7c 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -16,6 +16,7 @@ function init() { initProtocolsTable(); initRowSelection(); initKeywordFiltering(); + initProtocolPreviewModal(); initLinkedChildrenModal(); initCreateNewModal(); initModals(); @@ -187,6 +188,37 @@ function initKeywordFiltering() { }); } +function initProtocolPreviewModal() { + // Only do this if the repository is public/private + if (repositoryType !== "archive") { + protocolsTableEl.on("click", "a[data-action='protocol-preview']", function(e) { + var link = $(this); + $.ajax({ + url: link.attr("data-url"), + type: "GET", + dataType: "json", + success: function (data) { + var modal = $("#protocol-preview-modal"); + var modalTitle = modal.find(".modal-title"); + var modalBody = modal.find(".modal-body"); + var modalFooter = modal.find(".modal-footer"); + modalTitle.html(data.title); + modalBody.html(data.html); + modalFooter.html(data.footer); + initHandsOnTable(modalBody); + modal.modal("show"); + initHandsOnTable(modalBody); + }, + error: function (error) { + // TODO + } + }); + e.preventDefault(); + return false; + }); + } +} + function initLinkedChildrenModal() { // Only do this if the repository is public/private if (repositoryType !== "archive") { @@ -343,6 +375,13 @@ function initModals() { $(this).find(".modal-body #linked-children-table").DataTable().destroy(); $(this).find(".modal-body").html(""); }); + + // Protocol preview modal close action + $("#protocol-preview-modal").on("hidden.bs.modal", function(e) { + $(this).find(".modal-title").html(""); + $(this).find(".modal-body").html(""); + $(this).find(".modal-footer").html(""); + }); } function updateDataTableSelectAllCheckbox() { diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 067fc0128..b96b025b5 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1139,6 +1139,25 @@ ul.content-module-activities { } } +// Preview protocol modal +@media (min-width: 768px) { + #protocol-preview-modal .modal-dialog { + width: 70%; + } +} + +#protocol-preview-modal .modal-dialog { + .modal-body { + max-height: 75vh; + overflow-y: auto; + width: 100%; + + .ql-editor { + min-height: initial; + } + } +} + /* Import protocol/s modal */ #import-protocol-modal .modal-dialog { width: 70%; diff --git a/app/controllers/protocols_controller.rb b/app/controllers/protocols_controller.rb index 0f715831a..578e9d806 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -11,6 +11,7 @@ class ProtocolsController < ApplicationController before_action :check_view_permissions, only: [ :protocol_status_bar, :updated_at_label, + :preview, :linked_children, :linked_children_datatable ] @@ -80,6 +81,25 @@ class ProtocolsController < ApplicationController end end + def preview + respond_to do |format| + format.json do + render json: { + title: I18n.t('protocols.index.preview.title', + protocol: @protocol.name), + html: render_to_string( + partial: 'protocols/index/protocol_preview_modal_body.html.erb', + locals: { protocol: @protocol } + ), + footer: render_to_string( + partial: 'protocols/index/protocol_preview_modal_footer.html.erb', + locals: { protocol: @protocol } + ) + } + end + end + end + def linked_children respond_to do |format| format.json { diff --git a/app/datatables/protocols_datatable.rb b/app/datatables/protocols_datatable.rb index 59abf56ac..1c6ecab6c 100644 --- a/app/datatables/protocols_datatable.rb +++ b/app/datatables/protocols_datatable.rb @@ -12,6 +12,7 @@ class ProtocolsDatatable < AjaxDatatablesRails::Base def_delegator :@view, :can_restore_protocol def_delegator :@view, :can_export_protocol def_delegator :@view, :linked_children_protocol_path + def_delegator :@view, :preview_protocol_path def initialize(view, organization, type, user) super(view) @@ -94,7 +95,7 @@ class ProtocolsDatatable < AjaxDatatablesRails::Base "DT_CanArchive": can_archive_protocol(protocol), "DT_CanRestore": can_restore_protocol(protocol), "DT_CanExport": can_export_protocol(protocol), - "1": record.name, + "1": protocol.in_repository_archived? ? record.name : name_html(record), "2": keywords_html(record), "3": modules_html(record), "4": record.full_username_str, @@ -164,6 +165,13 @@ class ProtocolsDatatable < AjaxDatatablesRails::Base end end + def name_html(record) + "" \ + "#{record.name}" \ + "" + end + def keywords_html(record) if !record.protocol_keywords_str || record.protocol_keywords_str.empty? "#{I18n.t("protocols.no_keywords")}" diff --git a/app/views/protocols/index.html.erb b/app/views/protocols/index.html.erb index 02a22d0e6..b7be9f1b9 100644 --- a/app/views/protocols/index.html.erb +++ b/app/views/protocols/index.html.erb @@ -130,8 +130,23 @@ <%= render partial: "protocols/index/restore_results_modal.html.erb" %> <%= render partial: "protocols/index/import_results_modal.html.erb" %> <%= render partial: "protocols/index/linked_children_modal.html.erb" %> +<%= render partial: "protocols/index/protocol_preview_modal.html.erb" %> <%= render partial: "protocols/import_export/import_elements.html.erb" %> <%= stylesheet_link_tag 'datatables' %> <%= javascript_include_tag "protocols/index" %> +<%= javascript_include_tag "protocols/steps" %> + + +<%= javascript_include_tag "lodash" %> +<%= javascript_include_tag "numeral" %> +<%= javascript_include_tag "numeric" %> +<%= javascript_include_tag "md5" %> +<%= javascript_include_tag "jstat" %> +<%= javascript_include_tag "formula" %> +<%= javascript_include_tag "parser" %> +<%= javascript_include_tag "ruleJS" %> +<%= javascript_include_tag "handsontable.formula" %> +<%= javascript_include_tag "big.min" %> +<%= stylesheet_link_tag "handsontable.formula" %> \ No newline at end of file diff --git a/app/views/protocols/index/_protocol_preview_modal.html.erb b/app/views/protocols/index/_protocol_preview_modal.html.erb new file mode 100644 index 000000000..68f35c55b --- /dev/null +++ b/app/views/protocols/index/_protocol_preview_modal.html.erb @@ -0,0 +1,13 @@ +
<%= truncate(asset.file_file_name, + length: Constants::FILENAME_TRUNCATION_LENGTH) %>
+