From 40e3240a999493933d7d9ac2108f6b4949ca1e07 Mon Sep 17 00:00:00 2001 From: Mojca Lorber Date: Thu, 22 Dec 2016 11:43:11 +0100 Subject: [PATCH] add content to preview modal --- app/assets/javascripts/protocols/index.js | 2 +- app/assets/javascripts/protocols/steps.js.erb | 1 + app/assets/stylesheets/themes/scinote.scss | 18 ++ app/controllers/protocols_controller.rb | 3 +- app/views/protocols/index.html.erb | 14 ++ .../index/_protocol_preview_modal.html.erb | 6 +- .../_protocol_preview_modal_body.html.erb | 179 ++++++++++++++++++ config/locales/en.yml | 2 +- 8 files changed, 219 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/protocols/index.js b/app/assets/javascripts/protocols/index.js index d8aa44818..594504062 100644 --- a/app/assets/javascripts/protocols/index.js +++ b/app/assets/javascripts/protocols/index.js @@ -204,6 +204,7 @@ function initProtocolPreviewModal() { modalTitle.html(data.title); modalBody.html(data.html); modal.modal("show"); + initHandsOnTable($(document)); }, error: function (error) { // TODO @@ -375,7 +376,6 @@ function initModals() { // Protocol preview modal close action $("#protocol-preview-modal").on("hidden.bs.modal", function(e) { $(this).find(".modal-title").html(""); - // Destroy the embedded data $(this).find(".modal-body").html(""); }); } diff --git a/app/assets/javascripts/protocols/steps.js.erb b/app/assets/javascripts/protocols/steps.js.erb index 9dbb8b598..1f2eeeda6 100644 --- a/app/assets/javascripts/protocols/steps.js.erb +++ b/app/assets/javascripts/protocols/steps.js.erb @@ -284,6 +284,7 @@ function toggleButtons(show) { // Creates handsontable where needed function initHandsOnTable(root) { + root.find("[data-role='hot-table']").each(function() { var $container = $(this).find("[data-role='step-hot-table']"); var contents = $(this).find('.hot-contents'); diff --git a/app/assets/stylesheets/themes/scinote.scss b/app/assets/stylesheets/themes/scinote.scss index 7f63232ef..390fb48e9 100644 --- a/app/assets/stylesheets/themes/scinote.scss +++ b/app/assets/stylesheets/themes/scinote.scss @@ -1139,6 +1139,24 @@ 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 385ae2e1d..039cd01c0 100644 --- a/app/controllers/protocols_controller.rb +++ b/app/controllers/protocols_controller.rb @@ -26,7 +26,8 @@ class ProtocolsController < ApplicationController ] before_action :check_view_all_permissions, only: [ :index, - :datatable + :datatable, + :preview ] before_action :check_unlink_permissions, only: [ :unlink, diff --git a/app/views/protocols/index.html.erb b/app/views/protocols/index.html.erb index 12af69280..b7be9f1b9 100644 --- a/app/views/protocols/index.html.erb +++ b/app/views/protocols/index.html.erb @@ -136,3 +136,17 @@ <%= 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 index dd0c46182..28b29bdb0 100644 --- a/app/views/protocols/index/_protocol_preview_modal.html.erb +++ b/app/views/protocols/index/_protocol_preview_modal.html.erb @@ -3,8 +3,8 @@ - \ No newline at end of file + diff --git a/app/views/protocols/index/_protocol_preview_modal_body.html.erb b/app/views/protocols/index/_protocol_preview_modal_body.html.erb index e69de29bb..2a26af512 100644 --- a/app/views/protocols/index/_protocol_preview_modal_body.html.erb +++ b/app/views/protocols/index/_protocol_preview_modal_body.html.erb @@ -0,0 +1,179 @@ +
+
+
+ +
+
+ + <%= l(@protocol.created_at, format: :full) %> +
+
+ +
+
+ +
+
+ + <%= render partial: "protocols/header/updated_at_label.html.erb" %> +
+
+ +
+
+ +
+
+ + <%= @protocol.added_by.full_name %> +
+
+ +
+
+ +
+
+ + <%= render partial: "protocols/header/keywords_label.html.erb" %> +
+
+ +
+
+ +
+
+ + <%= render partial: "protocols/header/authors_label.html.erb" %> +
+
+ +
+
+ +
+
+ + <%= render partial: "protocols/header/description_label.html.erb" %> +
+
+
+ +
+
+
+

<%= t("protocols.steps.subtitle") %>

+
+
+
+ <% protocol.steps.order(:position).each do |step| %> +
"> +
+ <%= step.position + 1 %> +
+
+
+ <%= step.name %> | + <%= raw t("protocols.steps.published_on", timestamp: l(step.created_at, format: :full), user: step.user.full_name) %> +
+
+
+
+
+ <% if strip_tags(step.description).blank? %> + <%= t("protocols.steps.no_description") %> + <% else %> +
+ <%= step.description.html_safe %> +
+ <% end %> +
+
+
+ <% unless step.tables.blank? then %> +
+
+ <%= t("protocols.steps.tables") %> + <% step.tables.each do |table| %> +
+ <%= hidden_field(table, :contents, value: table.contents_utf_8, class: "hot-contents") %> +
+
+ <% end %> +
+ <% end %> + + <% assets = ordered_assets(step) %> + <% unless assets.blank? then %> +
+
+ <%= t("protocols.steps.files") %> +
    + <% assets.each do |asset| %> +
  • + <%= image_tag preview_asset_path(asset) if asset.is_image? %> +

    <%= truncate(asset.file_file_name, + length: Constants::FILENAME_TRUNCATION_LENGTH) %>

    +
  • + <% end %> +
+
+ <% end %> + + <% unless step.checklists.blank? then %> +
+
+ <% step.checklists.each do |checklist| %> + <%= checklist.name %> + <% if checklist.checklist_items.empty? %> +
+ <%= t("protocols.steps.empty_checklist") %> +
+ <% else %> + <% ordered_checklist_items(checklist).each do |checklist_item| %> +
+ +
+ <% end %> + <% end %> + <% end %> +
+ <% end %> + +
+
+
+
+
+ <% end %> +
+ + <% if protocol.steps.count == 0 %> +
+ <%= t("protocols.steps.no_steps") %> +
+ <% end %> +
+ +<%= 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/config/locales/en.yml b/config/locales/en.yml index afd667ea1..adbf4100a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1202,7 +1202,7 @@ en: thead_archived_on: "Archived at" thead_updated_at: "Last modified at" preview: - title: "Protocol preview" + title: "%{protocol} preview" linked_children: title: "Tasks linked to protocol %{protocol}" used_in: "Number of tasks linked to this protocol: %{nr}"